From df3c0becb45be5fc9f21f1fc9870e25c791ee7fc Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Mon, 7 Feb 2005 17:23:31 +0000
Subject: [PATCH] From Philippe: This patch insures that TTreeFormula only call
 GetEntry once per branch per entry (This speeds up evaluating formula where
 the same branch is use several times).

Update TTreeIndex (and hence TTree::BuildIndex) to be able to
work correctly independently of the state of the TTree object (It previously
__required__ TTree::fReadEntry to be equal to -1).

Make TTreeIndex::Print platform independent (it was not
printing correctly on windows).


git-svn-id: http://root.cern.ch/svn/root/trunk@11046 27541ba8-7e3a-0410-8455-c3a389f83636
---
 treeplayer/inc/TTreeFormula.h   |  3 ++-
 treeplayer/src/TTreeFormula.cxx | 25 +++++++++++++++++++++----
 treeplayer/src/TTreeIndex.cxx   | 18 ++++++++++--------
 3 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/treeplayer/inc/TTreeFormula.h b/treeplayer/inc/TTreeFormula.h
index a8850abd3c3..6734c6b9c48 100644
--- a/treeplayer/inc/TTreeFormula.h
+++ b/treeplayer/inc/TTreeFormula.h
@@ -1,4 +1,4 @@
-// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.h,v 1.38 2004/08/12 04:33:45 brun Exp $
+// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.h,v 1.39 2004/10/05 13:21:10 brun Exp $
 // Author: Rene Brun   19/01/96
 
 /*************************************************************************
@@ -75,6 +75,7 @@ protected:
    TObjArray   fMethods;          //!  List of leaf method calls
    TObjArray   fAliases;          //!  List of TTreeFormula for each alias used.
    TObjArray   fLeafNames;        //   List of TNamed describing leaves
+   TObjArray   fBranches;         //!  List of branches to read.  Similar to fLeaces but duplicates are zeroed out.
 
    Int_t         fNdimensions[kMAXCODES];              //Number of array dimensions in each leaf
    Int_t         fFixedSizes[kMAXCODES][kMAXFORMDIM];  //Physical sizes of lower dimensions for each leaf
diff --git a/treeplayer/src/TTreeFormula.cxx b/treeplayer/src/TTreeFormula.cxx
index fac02e78ccd..160cf0cc6db 100644
--- a/treeplayer/src/TTreeFormula.cxx
+++ b/treeplayer/src/TTreeFormula.cxx
@@ -1,4 +1,4 @@
-// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.cxx,v 1.160 2005/01/13 20:07:46 brun Exp $
+// @(#)root/treeplayer:$Name:  $:$Id: TTreeFormula.cxx,v 1.161 2005/01/19 07:52:45 brun Exp $
 // Author: Rene Brun   19/01/96
 
 /*************************************************************************
@@ -231,7 +231,16 @@ TTreeFormula::TTreeFormula(const char *name,const char *expression, TTree *tree)
       }
    }
 
-
+   // Create a list of uniques branches to load.
+   for(k=0; k<fNcodes; k++) {
+      TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(k);
+      TBranch *branch = 0;
+      if (leaf) {
+         branch = leaf->GetBranch();
+         if (fBranches.FindObject(branch)) branch = 0;
+      }
+      fBranches.AddAtAndExpand(branch,k);
+   }
 }
 
 //______________________________________________________________________________
@@ -2646,8 +2655,15 @@ const char* TTreeFormula::EvalStringInstance(Int_t instance)
    /* Now let calculate what physical instance we really need.  */                              \
    const Int_t real_instance = GetRealInstance(instance,code);                                  \
                                                                                                 \
-   if (!instance) leaf->GetBranch()->GetEntry(leaf->GetBranch()->GetTree()->GetReadEntry());    \
-   else {                                                                                       \
+   if (!instance) {                                                                             \
+        TBranch *branch = (TBranch*)fBranches.UncheckedAt(code);                                \
+        if (branch) branch->GetEntry(branch->GetTree()->GetReadEntry());                        \
+        else if (fDidBooleanOptimization) {                                                     \
+           branch = leaf->GetBranch();                                                          \
+           Long64_t treeEntry = branch->GetTree()->GetReadEntry();                              \
+           if (branch->GetReadEntry() != treeEntry) branch->GetEntry( treeEntry );              \
+        }                                                                                       \
+   } else {                                                                                     \
       /* In the cases where we are behind (i.e. right of) a potential boolean optimization      \
          this tree variable reading may have not been executed with instance==0 which would     \
          result in the branch being potentially not read in. */                                 \
@@ -3490,6 +3506,7 @@ void TTreeFormula::UpdateFormulaLeaves()
       sprintf(names,"%s/%s",fLeafNames[i]->GetTitle(),fLeafNames[i]->GetName());
       TLeaf *leaf = fTree->GetLeaf(names);
       fLeaves[i] = leaf;
+      if (fBranches[i]) fBranches[i]=leaf->GetBranch();
    }
    for (Int_t j=0; j<kMAXCODES; j++) {
       for (Int_t k = 0; k<kMAXFORMDIM; k++) {
diff --git a/treeplayer/src/TTreeIndex.cxx b/treeplayer/src/TTreeIndex.cxx
index f802cfcd281..f18b613d5a8 100644
--- a/treeplayer/src/TTreeIndex.cxx
+++ b/treeplayer/src/TTreeIndex.cxx
@@ -1,4 +1,4 @@
-// @(#)root/tree:$Name:  $:$Id: TTreeIndex.cxx,v 1.6 2004/07/19 19:48:47 brun Exp $
+// @(#)root/tree:$Name:  $:$Id: TTreeIndex.cxx,v 1.7 2004/12/08 10:15:30 brun Exp $
 // Author: Rene Brun   05/07/2004
 
 /*************************************************************************
@@ -135,8 +135,9 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
 
    Long64_t *w = new Long64_t[fN];
    Long64_t i;
+   Long64_t oldEntry = fTree->GetReadEntry();
    for (i=0;i<fN;i++) {
-      GetEntry(i);
+      fTree->LoadTree(i);
       Double_t majord = fMajorFormula->EvalInstance();
       Double_t minord = fMinorFormula->EvalInstance();
       Long64_t majorv = (Long64_t)majord;
@@ -152,6 +153,7 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
    }
 
    delete [] w;
+   fTree->LoadTree(oldEntry);
 }
 
 //______________________________________________________________________________
@@ -326,15 +328,15 @@ void TTreeIndex::Print(Option_t * option) const
    if (opt.Contains("100"))  n = 100;
    if (opt.Contains("1000")) n = 1000;
 
-   printf("\n**********************************************\n");
-   printf("*    Index of Tree: %s/%s\n",fTree->GetName(),fTree->GetTitle());
-   printf("**********************************************\n");
-   printf("%8s : %16s : %16s\n","serial",fMajorName.Data(),fMinorName.Data());
-   printf("**********************************************\n");
+   Printf("\n**********************************************");
+   Printf("*    Index of Tree: %s/%s",fTree->GetName(),fTree->GetTitle());
+   Printf("**********************************************");
+   Printf("%8s : %16s : %16s","serial",fMajorName.Data(),fMinorName.Data());
+   Printf("**********************************************");
    for (Long64_t i=0;i<n;i++) {
       Long64_t minor = fIndexValues[i] & 0xffff;
       Long64_t major = fIndexValues[i]>>31;
-      printf("%8lld :         %8lld :         %8lld\n",i,major,minor);
+      Printf("%8lld :         %8lld :         %8lld",i,major,minor);
    }
 }
 
-- 
GitLab