Skip to content
Snippets Groups Projects
Commit 7c51142e authored by Rene Brun's avatar Rene Brun
Browse files

Speed improvement, keeping the total size of teh branches in the cache

as a data member instead of computing this value every time FillBuffer is called.


git-svn-id: http://root.cern.ch/svn/root/trunk@15440 27541ba8-7e3a-0410-8455-c3a389f83636
parent 146bc820
No related branches found
No related tags found
No related merge requests found
// @(#)root/tree:$Name: $:$Id: TTreeFilePrefetch.h,v 1.4 2006/06/14 13:15:55 brun Exp $ // @(#)root/tree:$Name: $:$Id: TTreeFilePrefetch.h,v 1.5 2006/06/15 07:59:19 brun Exp $
// Author: Rene Brun 04/06/2006 // Author: Rene Brun 04/06/2006
/************************************************************************* /*************************************************************************
...@@ -34,6 +34,7 @@ protected: ...@@ -34,6 +34,7 @@ protected:
Long64_t fEntryMin; //! first entry in the cache Long64_t fEntryMin; //! first entry in the cache
Long64_t fEntryMax; //! last entry in the cache Long64_t fEntryMax; //! last entry in the cache
Long64_t fEntryNext; //! next entry number where cache must be filled Long64_t fEntryNext; //! next entry number where cache must be filled
Long64_t fZipBytes; //! Total compressed size of branches in cache
Int_t fNbranches; //! Number of branches in the cache Int_t fNbranches; //! Number of branches in the cache
TBranch **fBranches; //! [fNbranches] List of branches to be stored in the cache TBranch **fBranches; //! [fNbranches] List of branches to be stored in the cache
Bool_t fIsLearning; //! true if cache is in learning mode Bool_t fIsLearning; //! true if cache is in learning mode
......
// @(#)root/tree:$Name: $:$Id: TTreeFilePrefetch.cxx,v 1.8 2006/06/14 22:54:35 brun Exp $ // @(#)root/tree:$Name: $:$Id: TTreeFilePrefetch.cxx,v 1.9 2006/06/15 07:59:19 brun Exp $
// Author: Rene Brun 04/06/2006 // Author: Rene Brun 04/06/2006
/************************************************************************* /*************************************************************************
...@@ -47,6 +47,7 @@ TTreeFilePrefetch::TTreeFilePrefetch() : TFilePrefetch(), ...@@ -47,6 +47,7 @@ TTreeFilePrefetch::TTreeFilePrefetch() : TFilePrefetch(),
fEntryMin(0), fEntryMin(0),
fEntryMax(1), fEntryMax(1),
fEntryNext(1), fEntryNext(1),
fZipBytes(0),
fNbranches(0), fNbranches(0),
fBranches(0), fBranches(0),
fIsLearning(kTRUE) fIsLearning(kTRUE)
...@@ -59,6 +60,7 @@ TTreeFilePrefetch::TTreeFilePrefetch(TTree *tree, Int_t buffersize) : TFilePrefe ...@@ -59,6 +60,7 @@ TTreeFilePrefetch::TTreeFilePrefetch(TTree *tree, Int_t buffersize) : TFilePrefe
fEntryMin(0), fEntryMin(0),
fEntryMax(tree->GetEntries()), fEntryMax(tree->GetEntries()),
fEntryNext(0), fEntryNext(0),
fZipBytes(0),
fNbranches(0), fNbranches(0),
fBranches(0), fBranches(0),
fIsLearning(kTRUE) fIsLearning(kTRUE)
...@@ -100,7 +102,6 @@ void TTreeFilePrefetch::AddBranch(TBranch *b) ...@@ -100,7 +102,6 @@ void TTreeFilePrefetch::AddBranch(TBranch *b)
//this function is called by TBranch::GetBasket //this function is called by TBranch::GetBasket
if (!fIsLearning) return; if (!fIsLearning) return;
//if (b->GetListOfBranches()->GetEntries() > 0) return;
//Is branch already in the cache? //Is branch already in the cache?
Bool_t isNew = kTRUE; Bool_t isNew = kTRUE;
...@@ -110,6 +111,7 @@ void TTreeFilePrefetch::AddBranch(TBranch *b) ...@@ -110,6 +111,7 @@ void TTreeFilePrefetch::AddBranch(TBranch *b)
if (isNew) { if (isNew) {
fBranches[fNbranches] = b; fBranches[fNbranches] = b;
fNbranches++; fNbranches++;
fZipBytes += b->GetZipBytes();
if (gDebug > 0) printf("Entry: %lld, registering branch: %s\n",b->GetTree()->GetReadEntry(),b->GetName()); if (gDebug > 0) printf("Entry: %lld, registering branch: %s\n",b->GetTree()->GetReadEntry(),b->GetName());
} }
} }
...@@ -120,7 +122,8 @@ void TTreeFilePrefetch::Clear(Option_t *) ...@@ -120,7 +122,8 @@ void TTreeFilePrefetch::Clear(Option_t *)
//clear the cache (called by TChain::LoadTree) //clear the cache (called by TChain::LoadTree)
Prefetch(0,0); Prefetch(0,0);
fNbranches = 0; fNbranches = 0;
fZipBytes = 0;
fIsLearning = kTRUE; fIsLearning = kTRUE;
} }
...@@ -133,21 +136,16 @@ Bool_t TTreeFilePrefetch::FillBuffer() ...@@ -133,21 +136,16 @@ Bool_t TTreeFilePrefetch::FillBuffer()
if (fNbranches <= 0) return kFALSE; if (fNbranches <= 0) return kFALSE;
TTree *tree = fBranches[0]->GetTree(); TTree *tree = fBranches[0]->GetTree();
Long64_t entry = tree->GetReadEntry(); Long64_t entry = tree->GetReadEntry();
if (fIsLearning && entry < fEntryNext) return kFALSE; if (entry < fEntryNext) return kFALSE;
//compute total size of the branches stored in cache
Long64_t totbytes = 0;
Int_t i;
for (i=0;i<fNbranches;i++) {
totbytes += fBranches[i]->GetZipBytes();
}
//estimate number of entries that can fit in the cache //estimate number of entries that can fit in the cache
fEntryNext = entry + tree->GetEntries()*fBufferSize/totbytes; fEntryNext = entry + tree->GetEntries()*fBufferSize/fZipBytes;
if (fEntryNext > fEntryMax) fEntryNext = fEntryMax+1; if (fEntryNext > fEntryMax) fEntryNext = fEntryMax+1;
//clear cache buffer //clear cache buffer
TFilePrefetch::Prefetch(0,0); TFilePrefetch::Prefetch(0,0);
//store baskets //store baskets
for (i=0;i<fNbranches;i++) { for (Int_t i=0;i<fNbranches;i++) {
TBranch *b = fBranches[i]; TBranch *b = fBranches[i];
Int_t nb = b->GetMaxBaskets(); Int_t nb = b->GetMaxBaskets();
Int_t *lbaskets = b->GetBasketBytes(); Int_t *lbaskets = b->GetBasketBytes();
...@@ -218,9 +216,10 @@ void TTreeFilePrefetch::SetEntryRange(Long64_t emin, Long64_t emax) ...@@ -218,9 +216,10 @@ void TTreeFilePrefetch::SetEntryRange(Long64_t emin, Long64_t emax)
fEntryMax = emax; fEntryMax = emax;
Long64_t learn = Long64_t(fgLearnRatio*(fEntryMax-fEntryMin)); Long64_t learn = Long64_t(fgLearnRatio*(fEntryMax-fEntryMin));
if (learn < 2) learn = 2; if (learn < 2) learn = 2;
fEntryNext = emin + learn; fEntryNext = emin + learn;
fIsLearning = kTRUE; fIsLearning = kTRUE;
fNbranches = 0; fNbranches = 0;
fZipBytes = 0;
if (gDebug > 0) printf("SetEntryRange: fEntryMin=%lld, fEntryMax=%lld, fEntryNext=%lld\n",fEntryMin,fEntryMax,fEntryNext); if (gDebug > 0) printf("SetEntryRange: fEntryMin=%lld, fEntryMax=%lld, fEntryNext=%lld\n",fEntryMin,fEntryMax,fEntryNext);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment