Logo ROOT   6.08/07
Reference Guide
Go to the documentation of this file.
1 // @(#)root/treeplayer:$Id$
2 // Author: Rene Brun 19/01/96
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 // ---------------------------------- TreeFormula.h
13 #ifndef ROOT_TTreeFormula
14 #define ROOT_TTreeFormula
18 //////////////////////////////////////////////////////////////////////////
19 // //
20 // TTreeFormula //
21 // //
22 // The Tree formula class //
23 // //
24 //////////////////////////////////////////////////////////////////////////
26 #ifndef ROOT_v5_TFormula
27 #include "v5/TFormula.h"
28 #endif
30 #ifndef ROOT_TLeaf
31 #include "TLeaf.h"
32 #endif
34 #ifndef ROOT_TObjArray
35 #include "TObjArray.h"
36 #endif
38 #include <string>
39 #include <vector>
41 #ifdef R__OLDHPACC
42 namespace std {
43  using ::string;
44  using ::vector;
45 }
46 #endif
48 const Int_t kMAXCODES = kMAXFOUND; // must be the same as kMAXFOUND in TFormulaOld
49 const Int_t kMAXFORMDIM = 5; // Maximum number of array dimensions support in TTreeFormula
51 class TTree;
52 class TArrayI;
53 class TMethodCall;
54 class TLeafObject;
55 class TDataMember;
56 class TStreamerElement;
58 class TFormLeafInfo;
59 class TBranchElement;
60 class TAxis;
66 friend class TTreeFormulaManager;
68 protected:
69  enum {
70  kIsCharacter = BIT(12),
71  kMissingLeaf = BIT(15), // true if some of the needed leaves are missing in the current TTree
72  kIsInteger = BIT(17), // true if the branch contains an integer variable
73  kNeedEntries = BIT(18) // true if the formula uses Entries$
74  };
75  enum {
76  kDirect, kDataMember, kMethod,
77  kIndexOfEntry, kEntries, kLength, kIteration, kLengthFunc, kSum, kEntryList,
80  kMin, kMax,
81  kLocalEntries
83  };
84  enum {
85  kAlias = 200,
86  kAliasString = 201,
87  kAlternate = 202,
88  kAlternateString = 203,
89  kMinIf = 204,
90  kMaxIf = 205
91  };
93  // Helper struct to hold a cache
94  // that can accelerate calculation of the RealIndex.
96  Int_t fInstanceCache = 0;
97  Int_t fLocalIndexCache = 0;
98  Int_t fVirtAccumCache = 0;
99  };
101  TTree *fTree; //! pointer to Tree
102  Int_t fCodes[kMAXCODES]; // List of leaf numbers referenced in formula
103  Int_t fNdata[kMAXCODES]; //! This caches the physical number of element in the leaf or datamember.
104  Int_t fNcodes; // Number of leaves referenced in formula
105  Bool_t fHasCast; // Record whether the formula contain a cast operation or not
106  Int_t fMultiplicity; // Indicator of the variability of the formula
107  Int_t fNindex; // Size of fIndex
108  Int_t *fLookupType; //[fNindex] array indicating how each leaf should be looked-up
109  TObjArray fLeaves; //! List of leaf used in this formula.
110  TObjArray fDataMembers; //! List of leaf data members
111  TObjArray fMethods; //! List of leaf method calls
112  TObjArray fExternalCuts; //! List of TCutG and TEntryList used in the formula
113  TObjArray fAliases; //! List of TTreeFormula for each alias used.
114  TObjArray fLeafNames; // List of TNamed describing leaves
115  TObjArray fBranches; //! List of branches to read. Similar to fLeaces but duplicates are zeroed out.
116  Bool_t fQuickLoad; //! If true, branch GetEntry is only called when the entry number changes.
117  Bool_t fNeedLoading; //! If true, the current entry has not been loaded yet.
119  Int_t fNdimensions[kMAXCODES]; //Number of array dimensions in each leaf
120  Int_t fFixedSizes[kMAXCODES][kMAXFORMDIM]; //Physical sizes of lower dimensions for each leaf
121  UChar_t fHasMultipleVarDim[kMAXCODES]; //True if the corresponding variable is an array with more than one variable dimension.
123  //the next line should have a mutable in front. See GetNdata()
124  Int_t fCumulSizes[kMAXCODES][kMAXFORMDIM]; //Accumulated sizes of lower dimensions for each leaf after variable dimensions has been calculated
125  Int_t fIndexes[kMAXCODES][kMAXFORMDIM]; //Index of array selected by user for each leaf
126  TTreeFormula *fVarIndexes[kMAXCODES][kMAXFORMDIM]; //Pointer to a variable index.
128  TAxis *fAxis; //! pointer to histogram axis if this is a string
129  Bool_t fDidBooleanOptimization; //! True if we executed one boolean optimization since the last time instance number 0 was evaluated
130  TTreeFormulaManager *fManager; //! The dimension coordinator.
132  // Helper members and function used during the construction and parsing
133  TList *fDimensionSetup; //! list of dimension setups, for delayed creation of the dimension information.
134  std::vector<std::string> fAliasesUsed; //! List of aliases used during the parsing of the expression.
136  LongDouble_t* fConstLD; //! local version of fConsts able to store bigger numbers
138  RealInstanceCache fRealInstanceCache; //! Cache accelerating the GetRealInstance function
140  TTreeFormula(const char *name, const char *formula, TTree *tree, const std::vector<std::string>& aliases);
141  void Init(const char *name, const char *formula);
142  Bool_t BranchHasMethod(TLeaf* leaf, TBranch* branch, const char* method,const char* params, Long64_t readentry) const;
143  Int_t DefineAlternate(const char* expression);
144  void DefineDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * info, Int_t& virt_dim);
145  Int_t FindLeafForExpression(const char* expression, TLeaf *&leaf, TString &leftover, Bool_t &final, UInt_t &paran_level, TObjArray &castqueue, std::vector<std::string>& aliasUsed, Bool_t &useLeafCollectionObject, const char *fullExpression);
146  TLeaf* GetLeafWithDatamember(const char* topchoice, const char* nextchice, Long64_t readentry) const;
147  Int_t ParseWithLeaf(TLeaf *leaf, const char *expression, Bool_t final, UInt_t paran_level, TObjArray &castqueue, Bool_t useLeafCollectionObject, const char *fullExpression);
148  Int_t RegisterDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * multidim = 0);
149  Int_t RegisterDimensions(Int_t code, TBranchElement *branch);
150  Int_t RegisterDimensions(Int_t code, TFormLeafInfo *info, TFormLeafInfo *maininfo, Bool_t useCollectionObject);
151  Int_t RegisterDimensions(Int_t code, TLeaf *leaf);
152  Int_t RegisterDimensions(const char *size, Int_t code);
154  virtual Double_t GetValueFromMethod(Int_t i, TLeaf *leaf) const;
155  virtual void* GetValuePointerFromMethod(Int_t i, TLeaf *leaf) const;
156  Int_t GetRealInstance(Int_t instance, Int_t codeindex);
158  void LoadBranches();
159  Bool_t LoadCurrentDim();
160  void ResetDimensions();
162  virtual TClass* EvalClass(Int_t oper) const;
163  virtual Bool_t IsLeafInteger(Int_t code) const;
164  virtual Bool_t IsString(Int_t oper) const;
165  virtual Bool_t IsLeafString(Int_t code) const;
166  virtual Bool_t SwitchToFormLeafInfo(Int_t code);
167  virtual Bool_t StringToNumber(Int_t code);
169  void Convert(UInt_t fromVersion);
171 private:
172  // Not implemented yet
173  TTreeFormula(const TTreeFormula&);
174  TTreeFormula& operator=(const TTreeFormula&);
176  template<typename T> T GetConstant(Int_t k);
178 public:
179  TTreeFormula();
180  TTreeFormula(const char *name,const char *formula, TTree *tree);
181  virtual ~TTreeFormula();
183  virtual Int_t DefinedVariable(TString &variable, Int_t &action);
184  virtual TClass* EvalClass() const;
186  template<typename T> T EvalInstance(Int_t i=0, const char *stringStack[]=0);
187  virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<Double_t>(i, stringStack); }
188  virtual Long64_t EvalInstance64(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<Long64_t>(i, stringStack); }
189  virtual LongDouble_t EvalInstanceLD(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<LongDouble_t>(i, stringStack); }
191  virtual const char *EvalStringInstance(Int_t i=0);
192  virtual void* EvalObject(Int_t i=0);
193  // EvalInstance should be const. See comment on GetNdata()
194  TFormLeafInfo *GetLeafInfo(Int_t code) const;
195  TTreeFormulaManager*GetManager() const { return fManager; }
196  TMethodCall *GetMethodCall(Int_t code) const;
197  virtual Int_t GetMultiplicity() const {return fMultiplicity;}
198  virtual TLeaf *GetLeaf(Int_t n) const;
199  virtual Int_t GetNcodes() const {return fNcodes;}
200  virtual Int_t GetNdata();
201  //GetNdata should probably be const. However it need to cache some information about the actual dimension
202  //of arrays, so if GetNdata is const, the variables fUsedSizes and fCumulUsedSizes need to be declared
203  //mutable. We will be able to do that only when all the compilers supported for ROOT actually implemented
204  //the mutable keyword.
205  //NOTE: Also modify the code in PrintValue which current goes around this limitation :(
206  virtual Bool_t IsInteger(Bool_t fast=kTRUE) const;
207  Bool_t IsQuickLoad() const { return fQuickLoad; }
208  virtual Bool_t IsString() const;
209  virtual Bool_t Notify() { UpdateFormulaLeaves(); return kTRUE; }
210  virtual char *PrintValue(Int_t mode=0) const;
211  virtual char *PrintValue(Int_t mode, Int_t instance, const char *decform = "9.9") const;
212  virtual void SetAxis(TAxis *axis=0);
213  void SetQuickLoad(Bool_t quick) { fQuickLoad = quick; }
214  virtual void SetTree(TTree *tree) {fTree = tree;}
215  virtual void ResetLoading();
216  virtual TTree* GetTree() const {return fTree;}
217  virtual void UpdateFormulaLeaves();
219  ClassDef(TTreeFormula, 10); //The Tree formula
220 };
222 #endif
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:37
const Int_t kMAXFORMDIM
Definition: TTreeFormula.h:49
An array of TObjects.
Definition: TObjArray.h:39
long long Long64_t
Definition: RtypesCore.h:69
TObjArray fBranches
Definition: TTreeFormula.h:115
virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:187
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
double T(double x)
Definition: ChebyshevPol.h:34
A TLeaf for a general object derived from TObject.
Definition: TLeafObject.h:35
#define BIT(n)
Definition: Rtypes.h:120
Bool_t IsQuickLoad() const
Definition: TTreeFormula.h:207
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
Int_t fMultiplicity
Definition: TTreeFormula.h:106
virtual void SetTree(TTree *tree)
Definition: TTreeFormula.h:214
A helper class to implement reading a data member on a variable size array inside a TClonesArray obje...
Array of integers (32 bits per element).
Definition: TArrayI.h:29
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TTreeFormula.h:209
TObjArray fLeafNames
List of TTreeFormula for each alias used.
Definition: TTreeFormula.h:114
Used to coordinate one or more TTreeFormula objects.
#define ClassDef(name, id)
Definition: Rtypes.h:254
TObjArray fExternalCuts
List of leaf method calls.
Definition: TTreeFormula.h:112
TTreeFormulaManager * GetManager() const
Definition: TTreeFormula.h:195
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
const Int_t kMAXFOUND
Definition: TFormula.h:37
Method or function calling interface.
Definition: TMethodCall.h:41
virtual Int_t GetNcodes() const
Definition: TTreeFormula.h:199
Used to pass a selection expression to the Tree drawing routine.
Definition: TTreeFormula.h:64
virtual Int_t GetMultiplicity() const
Definition: TTreeFormula.h:197
A doubly linked list.
Definition: TList.h:47
TObjArray fDataMembers
List of leaf used in this formula.
Definition: TTreeFormula.h:110
Class to manage histogram axis.
Definition: TAxis.h:36
const Int_t kMAXCODES
Definition: TTreeFormula.h:48
RealInstanceCache fRealInstanceCache
local version of fConsts able to store bigger numbers
Definition: TTreeFormula.h:138
Int_t fNcodes
This caches the physical number of element in the leaf or datamember.
Definition: TTreeFormula.h:104
unsigned int UInt_t
Definition: RtypesCore.h:42
TObjArray fAliases
List of TCutG and TEntryList used in the formula.
Definition: TTreeFormula.h:113
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
long double LongDouble_t
Definition: RtypesCore.h:57
std::vector< std::string > fAliasesUsed
list of dimension setups, for delayed creation of the dimension information.
Definition: TTreeFormula.h:134
A Branch for the case of an object.
TAxis * fAxis
Definition: TTreeFormula.h:128
Bool_t fHasCast
Definition: TTreeFormula.h:105
LongDouble_t * fConstLD
List of aliases used during the parsing of the expression.
Definition: TTreeFormula.h:136
TObjArray fLeaves
Definition: TTreeFormula.h:109
double Double_t
Definition: RtypesCore.h:55
The FORMULA class (ROOT version 5)
Definition: TFormula.h:71
Bool_t fDidBooleanOptimization
pointer to histogram axis if this is a string
Definition: TTreeFormula.h:129
This class is a small helper class to implement reading a data member on an object stored in a TTree...
Definition: TFormLeafInfo.h:53
TTree * fTree
Definition: TTreeFormula.h:101
virtual TTree * GetTree() const
Definition: TTreeFormula.h:216
Bool_t fQuickLoad
List of branches to read. Similar to fLeaces but duplicates are zeroed out.
Definition: TTreeFormula.h:116
TTreeFormulaManager * fManager
True if we executed one boolean optimization since the last time instance number 0 was evaluated...
Definition: TTreeFormula.h:130
Int_t * fLookupType
Definition: TTreeFormula.h:108
TList * fDimensionSetup
The dimension coordinator.
Definition: TTreeFormula.h:133
virtual Long64_t EvalInstance64(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:188
Definition: tree.py:1
TObjArray fMethods
List of leaf data members.
Definition: TTreeFormula.h:111
A TTree object has a header with a name and a title.
Definition: TTree.h:98
virtual LongDouble_t EvalInstanceLD(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:189
void SetQuickLoad(Bool_t quick)
Definition: TTreeFormula.h:213
unsigned char UChar_t
Definition: RtypesCore.h:34
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
Bool_t fNeedLoading
If true, branch GetEntry is only called when the entry number changes.
Definition: TTreeFormula.h:117
char name[80]
Definition: TGX11.cxx:109