ROOT Version: 6.14/00
Platform: ArchLinux x86_64
Compiler: GCC 8.1.1
Hi,
I’m having a very weird issue. Let’s look at the following code:
void foo() {
auto tree = std::unique_ptr<TChain>(new TChain("DecayTree"));
tree->AddFile("some_big_enough_file.root", 0); // open and load file
tree->GetEntry(0); // make sure branch type checks work
int test;
if (tree->GetBranch("branch_may_not_exist")) { // could be any check, but this shows my runtime usecase
std::cout << "Should not print if branch does not exist\n";
tree->SetBranchAddress("some_branch", &test); // returns 0
} else {
tree->SetBranchAddress("some_other_branch", &test); // returns 0
}
for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i);
// none of the branches should contain values outside [-1, 0, 1]
if (test >= 2 || test <= -2) std::cout << "test failed at entry " << i << std::endl;
}
return;
}
This is to process ROOT
files depending on what branches are inside. In my opinion this test can only fail if there is a type mismatch, memory misalignment or some weird overflow. The test indeed fails if the file is big enough - in my case > ~16k
entries.
Weirdly enough, after it fails for one entry, then it doesn’t fail again until ~45k
and then succeeds again until ~60k
and so on at ~80k
, ~100k
, …
The weird thing is, if I run this code however:
void foo() {
auto tree = std::unique_ptr<TChain>(new TChain("DecayTree"));
tree->AddFile("some_big_enough_file.root", 0); // open and load file
tree->GetEntry(0); // make sure branch type checks work
int test1, test2;
if (tree->GetBranch("branch_may_not_exist")) { // could be any check, but this shows my runtime usecase
std::cout << "Should not print if branch does not exist\n";
tree->SetBranchAddress("some_branch", &test1); // returns 0
} else {
tree->SetBranchAddress("some_other_branch", &test2); // returns 0
}
for (Long64_t i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i);
// none of the branches should contain values outside [-1, 0, 1]
if (tree->GetBranch("branch_may_not_exist")) {
if (test1 >= 2 || test1 <= -2) std::cout << "test failed at entry " << i << std::endl;
else {
if (test2 >= 2 || test2 <= -2) std::cout << "test failed at entry " << i << std::endl;
}
}
return;
}
the test succeeds.
Is this intended behaviour or a bug?
EDIT: Actually, this must be a big. Second code snippet still had 1 failure in a million entries.
Thanks.