From 7c51142e5eba6ccd4f8a203dd90255722a430127 Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Thu, 15 Jun 2006 10:02:13 +0000
Subject: [PATCH] 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
---
 tree/inc/TTreeFilePrefetch.h   |  3 ++-
 tree/src/TTreeFilePrefetch.cxx | 27 +++++++++++++--------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tree/inc/TTreeFilePrefetch.h b/tree/inc/TTreeFilePrefetch.h
index 3552bcb0497..0a4117766fa 100644
--- a/tree/inc/TTreeFilePrefetch.h
+++ b/tree/inc/TTreeFilePrefetch.h
@@ -1,4 +1,4 @@
-// @(#)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
 
 /*************************************************************************
@@ -34,6 +34,7 @@ protected:
    Long64_t        fEntryMin;    //! first 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        fZipBytes;    //! Total compressed size of branches in cache
    Int_t           fNbranches;   //! Number of branches 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
diff --git a/tree/src/TTreeFilePrefetch.cxx b/tree/src/TTreeFilePrefetch.cxx
index 0bcf5942101..675612128e3 100644
--- a/tree/src/TTreeFilePrefetch.cxx
+++ b/tree/src/TTreeFilePrefetch.cxx
@@ -1,4 +1,4 @@
-// @(#)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
 
 /*************************************************************************
@@ -47,6 +47,7 @@ TTreeFilePrefetch::TTreeFilePrefetch() : TFilePrefetch(),
    fEntryMin(0),
    fEntryMax(1),
    fEntryNext(1),
+   fZipBytes(0),
    fNbranches(0),
    fBranches(0),
    fIsLearning(kTRUE)
@@ -59,6 +60,7 @@ TTreeFilePrefetch::TTreeFilePrefetch(TTree *tree, Int_t buffersize) : TFilePrefe
    fEntryMin(0),
    fEntryMax(tree->GetEntries()),
    fEntryNext(0),
+   fZipBytes(0),
    fNbranches(0),
    fBranches(0),
    fIsLearning(kTRUE)
@@ -100,7 +102,6 @@ void TTreeFilePrefetch::AddBranch(TBranch *b)
    //this function is called by TBranch::GetBasket
       
    if (!fIsLearning) return;
-   //if (b->GetListOfBranches()->GetEntries() > 0) return;
 
    //Is branch already in the cache?
    Bool_t isNew = kTRUE;
@@ -110,6 +111,7 @@ void TTreeFilePrefetch::AddBranch(TBranch *b)
    if (isNew) {
       fBranches[fNbranches] = b;
       fNbranches++;
+      fZipBytes += b->GetZipBytes();
       if (gDebug > 0) printf("Entry: %lld, registering branch: %s\n",b->GetTree()->GetReadEntry(),b->GetName());
    }
 }
@@ -120,7 +122,8 @@ void TTreeFilePrefetch::Clear(Option_t *)
    //clear the cache (called by TChain::LoadTree)
    
    Prefetch(0,0);
-   fNbranches = 0;
+   fNbranches  = 0;
+   fZipBytes   = 0;
    fIsLearning = kTRUE;
 }
    
@@ -133,21 +136,16 @@ Bool_t TTreeFilePrefetch::FillBuffer()
    if (fNbranches <= 0) return kFALSE;
    TTree *tree = fBranches[0]->GetTree();
    Long64_t entry = tree->GetReadEntry();
-   if (fIsLearning && 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();
-   }
+   if (entry < fEntryNext) return kFALSE;
+   
    //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;
          
    //clear cache buffer
    TFilePrefetch::Prefetch(0,0);
    //store baskets
-   for (i=0;i<fNbranches;i++) {
+   for (Int_t i=0;i<fNbranches;i++) {
       TBranch *b = fBranches[i];
       Int_t nb = b->GetMaxBaskets();
       Int_t *lbaskets   = b->GetBasketBytes();
@@ -218,9 +216,10 @@ void TTreeFilePrefetch::SetEntryRange(Long64_t emin, Long64_t emax)
    fEntryMax  = emax;
    Long64_t learn = Long64_t(fgLearnRatio*(fEntryMax-fEntryMin));
    if (learn < 2) learn = 2;
-   fEntryNext = emin + learn;
+   fEntryNext  = emin + learn;
    fIsLearning = kTRUE;
-   fNbranches = 0;
+   fNbranches  = 0;
+   fZipBytes   = 0;
    if (gDebug > 0) printf("SetEntryRange: fEntryMin=%lld, fEntryMax=%lld, fEntryNext=%lld\n",fEntryMin,fEntryMax,fEntryNext);
    
 }
-- 
GitLab