Loop() method runs slow

I have thousands of root files with my desired branches in it. I generated a class from MakeClass method of root and read all the file in the Loop() method. The root files are added in a TChain so that I can read them all in one go. But this takes a lot of time (> 10 hours).

But if create some short root files combining the above root files (where I have only few branches in it) then the Loop() method runs within an < 1/2 hour.

I am accessing the same variable in either case inside the Loop() method.

Is there a way so that it can be faster in the 1st case so that I do not have to go through 2nd case?

Any suggestions are welcome.
with best regards,

Just to forgot to mention that I create ans shared object to run the code.


It is likely that you are always reading all the branches of your Tree where in fact you should only read the branches that you use.
-call mytree.SetBranchStatus("*",0), then mytree.SetBranchStatus(“branchName”,1) for all the branches that you want to activate, then mytree.GetEntry(i)
-or better solution if you read only a fee branches, call branch.GetEntry(i) instead of mytree.GetEntry(i)
-see also how to use the TreeCache in the 5.26 release notes


Hi Rene,

I try SetBranchStatus("bname",0) for those branch which are not needed in loop method. It improves a bit but still taking a lot of time compare to case where I have few branches and combining them to a single file.

I tried these llines also :

Long64_t nentries = fChain->GetEntriesFast();

But it complaints;
class TTree’ has no member named 'AddBranchToCache

I am using FNAL cluster where root 5.22 is available so do not know I can make it work there.

with best regards,

you must use 5.26 or newer