I need to access some TLeafD in a TBranch of a TTree, but using TChain, not single files.
The attached macro works if I use a single file as argument, but not if I use multiple files. Using a chain of files, I can access the values in the branch “t”, but not those in the leaf “x” belonging to the branch “position”.
Try to modify your loop over all entries (not sure if it is enough, @pcanal would need to confirm):
Long64_t nentries = chain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0; // not really needed
for (Long64_t jentry = 0; jentry < nentries; jentry++) {
Long64_t ientry = chain->LoadTree(jentry);
if (ientry < 0) break; // no new entries (or opening the file failed)
if (ientry == 0) { // the first entry from the (next) file
// ... set all addresses of branches and leaves here ...
}
nb = chain->GetEntry(jentry); nbytes += nb;
// ... analyze this entry here ...
}
@fra_root, @Wile_E_Coyote is correct. Every time the TChain switch from one file to another the underlying TTree object and all its branch and leafs are deleted. Only the address register via SetBranchAddress are carried from one file to the other. Any addresses set directly to the TBranch or TLeaf object needs to be set again at the beginning of each file.