I may have stumbled on a TChain bug of some sort…
I have 3 root files, which I chain, and run a script on. Here’s the content of the script:
testchain.C –
void testchain(TTree* ptree) //threshold at 50keV, by default
{
TBranch *event =ptree->GetBranch("event"); //get the event branch
TLeaf *cn=event->GetLeaf("cn");
int nentries=ptree->GetEntries();
int i=0;
do{
ptree->GetEntry(i);
i++;
std::cout << "got here\n";
} while(cn->GetValue()!=0);
return;
}
Here are my actions, and the subsequent seg. fault:
root [0] TChain a("ptree");a.Add("/home/aregjan/data_vx511/root_all/2012_08_23_13_41_06_secondary_[145]_plus15_lowth.root")
(Int_t)3
root [1] .L testchain.C
root [2] testchain(ptree)
got here
*** Break *** segmentation violation
...blah blah blah deleted...
Both the script, and the operation are quite correct, right?
Now, here’s how you can avoid the segfault:
a) instead of chaining 3 root files, chain only the first two:
root [0] TChain a("ptree");a.Add("/home/aregjan/data_vx511/root_all/2012_08_23_13_41_06_secondary_[14]_plus15_lowth.root")
(Int_t)2
root [1] .L ../scripts/testchain.C
root [2] testchain(ptree)
got here
root [3]
and it runs fine. “Ah , it’s probably a problem with the 3rd root file!”, you’ll say. BUT –
b) you can also “fix” the problem by commenting the ptree->GetEntries() line in the script itself. If you do this, you can still chain over 3 root files and have the script run successfully:
root [0] TChain a("ptree");a.Add("/home/aregjan/data_vx511/root_all/2012_08_23_13_41_06_secondary_[145]_plus15_lowth.root")
(Int_t)3
root [1] .L ../scripts/testchain_modified.C
root [2] testchain(ptree)
got here
got here
got here
got here
got here
root [3]
So, what’s going on?
p.s. before you ask, I did try this by putting the 3rd root file alone in the chain, and everything runs fine.
So I doubt that it’s something wrong with the file…