Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tree] test for limits in buildindex #1090

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions root/tree/index/index64.ref
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

Processing runindex64.C...
Tree BuildIndex returns 9
Entry should be 3: 3
Entry should be 6: 6
Entries in chain: 9
BuildIndex returns 9
Try to get value that is not in the chain, this should return a -1:
Tree BuildIndex returns 13
Entries in chain: 13
BuildIndex returns 13
Try to find the position of run=0, event=500 in the chain, as it does not exist, this should return a -1:
-1
3
Entries in chain: 9
Try to find the position of run=5, event=bigval in the chain, which was inserted in position 4:
4
Entries in chain: 13
BuildIndex returns 1
Try to get value that is not in the chain, this should return a -1:
Try to find the position of run=0, event=500 in the chain, as it does not exist, this should return a -1:
-1
3
Try to find the position of run=5, event=bigval in the chain, which was inserted in position 4:
4
(int) 0
38 changes: 25 additions & 13 deletions root/tree/index/runindex64.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const char* fname = "index64.root";
// Apple M1 has long double == double; these values exceed its range
// and cannot be represented as (even temporary) expression results.
// There would be a warning if you'd try.
// More info: https://github.com/root-project/roottest/commit/f3c97809c9064feccaed3844007de9e7c6a5980d and https://github.com/root-project/roottest/commit/9e3843d4bf50bc34e6e15dfe7c027f029417d6c0
static constexpr bool shortlongdouble = sizeof(long double) < 16; // was true for __APPLE__ and __arm64__
const Long64_t bigval = shortlongdouble ? 0xFFFFFFFFFFFF : 0xFFFFFFFFFFFFFFF; // still positive number
const Long64_t bigval = shortlongdouble ? 0x0FFFFFFFFFFFF : 0x0FFFFFFFFFFFFFFF; // still positive number
const ULong64_t biguval = shortlongdouble ? 0xFFFFFFFFFFFF0 : 0xFFFFFFFFFFFFFFF0; // "negative" number

int runindex64(){
Expand All @@ -25,20 +26,30 @@ int runindex64(){
tree->Branch("run", &run, "run/l");
tree->Branch("event", &event, "event/l");

ULong64_t events[] = { 1,2,3, bigval, biguval, 5 };
run = 5;
for(int i=0; i<sizeof(events)/sizeof(*events); i++){
ULong64_t runs[] = { 8,5,5,5, 5, 5, 0, 4, 6, biguval, bigval, bigval, biguval};
ULong64_t events[] = { 0,1,3,2, bigval, biguval, 5, bigval, 3, bigval, biguval, bigval, biguval};
for(size_t i=0; i<sizeof(events)/sizeof(*events); i++){
run = runs[i];
event = events[i];
tree->Fill();
}
run = 4; event = bigval; tree->Fill();
run = 6; event = 3; tree->Fill();
run = biguval; event = bigval; tree->Fill();
tree->Write();


bool pass = true;
cout<<"Tree BuildIndex returns "<<tree->BuildIndex("run", "event")<<endl;
cout << "Entry should be 3: " << tree->GetEntryNumberWithIndex(5,bigval) << endl;
cout << "Entry should be 6: " << tree->GetEntryNumberWithIndex(4,bigval) << endl;
for (size_t i=0; i<sizeof(events)/sizeof(*events); i++) {
run = runs[i];
event = events[i];
pass &= (tree->GetEntryNumberWithIndex(run, event) == i);
}
if (!pass) {
tree->Scan("run:event","","colsize=30");
for (size_t i=0; i<sizeof(events)/sizeof(*events); i++) {
run = runs[i];
event = events[i];
cout << i << ": Run " << run << ", Event " << event << " found at entry number: " << tree->GetEntryNumberWithIndex(run, event) << endl;
}
}

test(tree);
file.Close();
Expand All @@ -60,8 +71,9 @@ bool test(TTree *chain)
{
cout<<"Entries in chain: "<<chain->GetEntries()<<endl;
cout<<"BuildIndex returns "<<chain->BuildIndex("run", "event")<<endl;
cout<<"Try to get value that is not in the chain, this should return a -1:"<<endl;
cout<<"Try to find the position of run=0, event=500 in the chain, as it does not exist, this should return a -1:"<<endl;
cout<<chain->GetEntryWithIndex(500)<<endl;
cout<<(int)chain->GetEntryNumberWithIndex(5, bigval)<<endl;
return (chain->GetEntryNumberWithIndex(500)==-1);
cout<<"Try to find the position of run=5, event=bigval in the chain, which was inserted in position 4:"<<endl;
cout<<chain->GetEntryNumberWithIndex(5, bigval)<<endl;
return (chain->GetEntryNumberWithIndex(500)==-1) && (chain->GetEntryNumberWithIndex(5, bigval) == 4);
}