Dear ROOTers,
I’m using (with ROOT version 5.28.00h or 5.26.00e) the skeleton produced by TChain::MakeClass (well, to be precise 3 skeleton classes from 3 chains… I suspect it doesn’t matter here, but, in case, see old post TChain::MakeClass including friend chains) to write my selection and analysis algorithm.
So far I always used TChain::SetBranchStatus() before looping over the events to limit the amount of data to be read from disk, but I could do better if I could split the reading from disk in two steps. So I tried to specify with TChain::SetBranchStatus() a first set of (not-to-heavy-to-load) branches, required for the first set of cuts. Then, for events passing such cuts, I tried to manually load extra branches with TBranch::GetEntry(localentry, 1), where I expected with the 1 argument to force the reading also of non-active branches. Please take into account that each branch is a vector or a vector< vector > branch.
I get crash with sparks as soon as my code arrives to read my first non-active branch, so I’m wondering if I’m doing wrong or if this is not the intended use of the two possibility, i.e. I have to use either TChain::GetEntry() after disabling not used branches OR TBranch::GetEntry() on the branches I’m interested.
I did the following observations on the variables defined in the skeleton typically like this:
vector<float>* var;
[...]
TBranch* b_var;
They are defined as pointer (is there a reason why as a pointer, besides the fact that TChain::SetBranchAddress() wants the address of a pointer to the object?), so they are typically set to 0 until the object is allocated (and my code crashes because the object is non allocated after TBranch::GetEntry() ).
The skeleton constructor always calls the Init() method after opening, in case a new tree is not specified, the TFile used when generating the skeleton (why that? I have to delete and recreate fChain to have the list of TFiles in each specific run).
I noticed that TChain::SetBranchAddress() contained in Init() returns 5 (“Underlying TBranch not yet available so no check was made”) and both pointers, var and b_var, remains 0.
Then I noticed that TChain::GetEntry() correctly allocates both var and b_var on activates branches, while only b_var are non-null for non-activate branches.
At this point, b_var->GetEntry(localentry,1) returns 0 if the branch is non-active, and the var pointer stays zero.
What am I doing wrong? How am I supposed to use the TBranch::GetEntry() ?
Thanks a lot and sorry for this long post.
Matteo