Using TTreeCache

I am trying to use TTreeCache to speed up my analysis code. I would like to ask whether I am using it correctly.
The code runs on a chain of files.
A tree contains 100 entries, has 440 activated branches which are stored in ~490 baskets on disk.
During ordinary processing, without TTreeCache the following happens.
For example, for the first file in a chain 483 branch baskets are needed for analysis. It is clear that for the first entry 440 read calls are issued. Then requests for the remaining 43 baskets are distributed among 99 entries.
Same happens for every next file in the chain.
When I try to use TTreeCache, I set it up at the initialization of the chain by doing

TTreeCache *ca=new TTreeCache(); TFile *curfile = tree->GetCurrentFile(); ca = (TTreeCache*)curfile->GetCacheRead(); ca->AddBranch("*"); ca->SetLearnEntries(1);
which results in reading the same 440 calls every first entry, and merging only the remaining requests.
For example, 43 requests were now merged to 18.
My question is whether it is possible to merge 440 requests at the start of every next file in the chain, or TTreeCache is working only in the scope of one file.
Thank you, Misha

Hi Misha,

Which version of ROOT are you using (and which version of ROOT where the file written with)?


Dear Philippe,
I am using 5.23/02 ROOT version, but within AliROOT analysis framework with files written with AliROOT v4-16-Rev-08. Therefore I am not sure if it is feasible to provide the code for reproduction of this behaviour.
Thank you, Misha.


Can you provide me with a couple of your files?


File #0
File #1
File #2
they have the same name


You can solve the prloblem by calling StopLearningPhase. In addition your TTree contains a branch which is stored in an auxiliary file. This triggers a bug in the TTreeCache (which is solved in the trunk), so you need to explicitly disable those branches. So use: c = new TChain("esdTree"); c->Add("AliESDs*.root"); c->SetCacheSize(); c->SetBranchStatus("ESDfriend*",0); c->GetEntry(0); c->SetBranchStatus("ESDfriend*",0); c->GetEntry(0); TFile *curfile = tree->GetCurrentFile(); ca = (TTreeCache*)curfile->GetCacheRead(); ca->StopLearningPhase();

Also note that with the code in the trunk the disable and the StopLearningPhase are no longer needed (but do not hurt).


Works! Thank you very much!