diff --git a/test/MainEvent.cxx b/test/MainEvent.cxx index d6893a9082dfd420d86b4e303c5bfea720c2a88b..41faade1dc3f1f4553fefa3d68bff8ef33faddf2 100644 --- a/test/MainEvent.cxx +++ b/test/MainEvent.cxx @@ -88,6 +88,7 @@ #include "TNetFile.h" #include "TRandom.h" #include "TTree.h" +#include "TTreeCache.h" #include "TBranch.h" #include "TClonesArray.h" #include "TStopwatch.h" @@ -158,13 +159,19 @@ int main(int argc, char **argv) hfile = new TFile("Event.root"); if(punzip) TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable); tree = (TTree*)hfile->Get("T"); - tree->SetCacheSize(10000000); //this is the default value: 10 MBytes TBranch *branch = tree->GetBranch("event"); branch->SetAddress(&event); Int_t nentries = (Int_t)tree->GetEntries(); nevent = TMath::Max(nevent,nentries); if (read == 1) { //read sequential + //set the read cache + Int_t cachesize = 10000000; //this is the default value: 10 MBytes + tree->SetCacheSize(cachesize); + TTreeCache::SetLearnEntries(1); //one entry is sufficient to learn + TTreeCache *tc = (TTreeCache*)hfile->GetCacheRead(); + tc->SetEntryRange(0,nevent); for (ev = 0; ev < nevent; ev++) { + tree->LoadTree(ev); //this call is required when using the cache if (ev%printev == 0) { tnew = timer.RealTime(); printf("event:%d, rtime=%f s\n",ev,tnew-told); diff --git a/test/stress.cxx b/test/stress.cxx index 3587965519b33a49f27e7e272a73019f7e6f7616..7a86f10695b5423b30d252f8392d40a0053bd0f3 100644 --- a/test/stress.cxx +++ b/test/stress.cxx @@ -85,6 +85,7 @@ #include <TRandom.h> #include <TPostScript.h> #include <TNtuple.h> +#include <TTreeCache.h> #include <TChain.h> #include <TCut.h> #include <TCutG.h> @@ -723,6 +724,12 @@ Int_t stress8read(Int_t nevent) tree->SetBranchAddress("event",&event); Int_t nentries = (Int_t)tree->GetEntries(); Int_t nev = TMath::Max(nevent,nentries); + //activate the treeCache + Int_t cachesize = 10000000; //this is the default value: 10 MBytes + tree->SetCacheSize(cachesize); + TTreeCache::SetLearnEntries(1); //one entry is sufficient to learn + TTreeCache *tc = (TTreeCache*)hfile->GetCacheRead(); + tc->SetEntryRange(0,nevent); Int_t nb = 0; for (Int_t ev = 0; ev < nev; ev++) { nb += tree->GetEntry(ev); //read complete event in memory