Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TTreeFormula.h
Go to the documentation of this file.
1 // @(#)root/treeplayer:$Id$
2 // Author: Rene Brun 19/01/96
3 
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
12 
13 #ifndef ROOT_TTreeFormula
14 #define ROOT_TTreeFormula
15 
16 
17 
18 //////////////////////////////////////////////////////////////////////////
19 // //
20 // TTreeFormula //
21 // //
22 // The Tree formula class //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #include "v5/TFormula.h"
27 
28 #include "TLeaf.h"
29 
30 #include "TObjArray.h"
31 
32 #include <string>
33 #include <vector>
34 
35 #ifdef R__OLDHPACC
36 namespace std {
37  using ::string;
38  using ::vector;
39 }
40 #endif
41 
42 const Int_t kMAXCODES = kMAXFOUND; // must be the same as kMAXFOUND in TFormulaOld
43 const Int_t kMAXFORMDIM = 5; // Maximum number of array dimensions support in TTreeFormula
44 
45 class TTree;
46 class TArrayI;
47 class TMethodCall;
48 class TLeafObject;
49 class TDataMember;
50 class TStreamerElement;
52 class TFormLeafInfo;
53 class TBranchElement;
54 class TAxis;
56 
57 
59 
60 friend class TTreeFormulaManager;
61 
62 protected:
63  enum {
65  kMissingLeaf = BIT(15), // true if some of the needed leaves are missing in the current TTree
66  kIsInteger = BIT(17), // true if the branch contains an integer variable
67  kNeedEntries = BIT(18) // true if the formula uses Entries$
68  };
69  enum {
76 
77  };
78  enum {
79  kAlias = 200,
80  kAliasString = 201,
81  kAlternate = 202,
83  kMinIf = 204,
84  kMaxIf = 205
85  };
86 
87  TTree *fTree; //! pointer to Tree
88  Int_t fCodes[kMAXCODES]; // List of leaf numbers referenced in formula
89  Int_t fNdata[kMAXCODES]; //! This caches the physical number of element in the leaf or datamember.
90  Int_t fNcodes; // Number of leaves referenced in formula
91  Bool_t fHasCast; // Record whether the formula contain a cast operation or not
92  Int_t fMultiplicity; // Indicator of the variability of the formula
93  Int_t fNindex; // Size of fIndex
94  Int_t *fLookupType; //[fNindex] array indicating how each leaf should be looked-up
95  TObjArray fLeaves; //! List of leaf used in this formula.
96  TObjArray fDataMembers; //! List of leaf data members
97  TObjArray fMethods; //! List of leaf method calls
98  TObjArray fExternalCuts; //! List of TCutG and TEntryList used in the formula
99  TObjArray fAliases; //! List of TTreeFormula for each alias used.
100  TObjArray fLeafNames; // List of TNamed describing leaves
101  TObjArray fBranches; //! List of branches to read. Similar to fLeaces but duplicates are zeroed out.
102  Bool_t fQuickLoad; //! If true, branch GetEntry is only called when the entry number changes.
103  Bool_t fNeedLoading; //! If true, the current entry has not been loaded yet.
104 
105  Int_t fNdimensions[kMAXCODES]; //Number of array dimensions in each leaf
106  Int_t fFixedSizes[kMAXCODES][kMAXFORMDIM]; //Physical sizes of lower dimensions for each leaf
107  UChar_t fHasMultipleVarDim[kMAXCODES]; //True if the corresponding variable is an array with more than one variable dimension.
108 
109  //the next line should have a mutable in front. See GetNdata()
110  Int_t fCumulSizes[kMAXCODES][kMAXFORMDIM]; //Accumulated sizes of lower dimensions for each leaf after variable dimensions has been calculated
111  Int_t fIndexes[kMAXCODES][kMAXFORMDIM]; //Index of array selected by user for each leaf
112  TTreeFormula *fVarIndexes[kMAXCODES][kMAXFORMDIM]; //Pointer to a variable index.
113 
114  TAxis *fAxis; //! pointer to histogram axis if this is a string
115  Bool_t fDidBooleanOptimization; //! True if we executed one boolean optimization since the last time instance number 0 was evaluated
116  TTreeFormulaManager *fManager; //! The dimension coordinator.
117 
118  // Helper members and function used during the construction and parsing
119  TList *fDimensionSetup; //! list of dimension setups, for delayed creation of the dimension information.
120  std::vector<std::string> fAliasesUsed; //! List of aliases used during the parsing of the expression.
121 
122  LongDouble_t* fConstLD; //! local version of fConsts able to store bigger numbers
123 
124  TTreeFormula(const char *name, const char *formula, TTree *tree, const std::vector<std::string>& aliases);
125  void Init(const char *name, const char *formula);
126  Bool_t BranchHasMethod(TLeaf* leaf, TBranch* branch, const char* method,const char* params, Long64_t readentry) const;
127  Int_t DefineAlternate(const char* expression);
128  void DefineDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * info, Int_t& virt_dim);
129  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);
130  TLeaf* GetLeafWithDatamember(const char* topchoice, const char* nextchice, Long64_t readentry) const;
131  Int_t ParseWithLeaf(TLeaf *leaf, const char *expression, Bool_t final, UInt_t paran_level, TObjArray &castqueue, Bool_t useLeafCollectionObject, const char *fullExpression);
132  Int_t RegisterDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * multidim = 0);
134  Int_t RegisterDimensions(Int_t code, TFormLeafInfo *info, TFormLeafInfo *maininfo, Bool_t useCollectionObject);
135  Int_t RegisterDimensions(Int_t code, TLeaf *leaf);
136  Int_t RegisterDimensions(const char *size, Int_t code);
137 
138  virtual Double_t GetValueFromMethod(Int_t i, TLeaf *leaf) const;
139  virtual void* GetValuePointerFromMethod(Int_t i, TLeaf *leaf) const;
140  Int_t GetRealInstance(Int_t instance, Int_t codeindex);
141 
142  void LoadBranches();
144  void ResetDimensions();
145 
146  virtual TClass* EvalClass(Int_t oper) const;
147  virtual Bool_t IsLeafInteger(Int_t code) const;
148  virtual Bool_t IsString(Int_t oper) const;
149  virtual Bool_t IsLeafString(Int_t code) const;
150  virtual Bool_t SwitchToFormLeafInfo(Int_t code);
151  virtual Bool_t StringToNumber(Int_t code);
152 
153  void Convert(UInt_t fromVersion);
154 
155 private:
156  // Not implemented yet
157  TTreeFormula(const TTreeFormula&);
159 
160  template<typename T> T GetConstant(Int_t k);
161 
162 public:
163  TTreeFormula();
164  TTreeFormula(const char *name,const char *formula, TTree *tree);
165  virtual ~TTreeFormula();
166 
167  virtual Int_t DefinedVariable(TString &variable, Int_t &action);
168  virtual TClass* EvalClass() const;
169 
170  template<typename T> T EvalInstance(Int_t i=0, const char *stringStack[]=0);
171  virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<Double_t>(i, stringStack); }
172  virtual Long64_t EvalInstance64(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<Long64_t>(i, stringStack); }
173  virtual LongDouble_t EvalInstanceLD(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<LongDouble_t>(i, stringStack); }
174 
175  virtual const char *EvalStringInstance(Int_t i=0);
176  virtual void* EvalObject(Int_t i=0);
177  // EvalInstance should be const. See comment on GetNdata()
178  TFormLeafInfo *GetLeafInfo(Int_t code) const;
180  TMethodCall *GetMethodCall(Int_t code) const;
181  virtual Int_t GetMultiplicity() const {return fMultiplicity;}
182  virtual TLeaf *GetLeaf(Int_t n) const;
183  virtual Int_t GetNcodes() const {return fNcodes;}
184  virtual Int_t GetNdata();
185  //GetNdata should probably be const. However it need to cache some information about the actual dimension
186  //of arrays, so if GetNdata is const, the variables fUsedSizes and fCumulUsedSizes need to be declared
187  //mutable. We will be able to do that only when all the compilers supported for ROOT actually implemented
188  //the mutable keyword.
189  //NOTE: Also modify the code in PrintValue which current goes around this limitation :(
190  virtual Bool_t IsInteger(Bool_t fast=kTRUE) const;
191  Bool_t IsQuickLoad() const { return fQuickLoad; }
192  virtual Bool_t IsString() const;
193  virtual Bool_t Notify() { UpdateFormulaLeaves(); return kTRUE; }
194  virtual char *PrintValue(Int_t mode=0) const;
195  virtual char *PrintValue(Int_t mode, Int_t instance, const char *decform = "9.9") const;
196  virtual void SetAxis(TAxis *axis=0);
197  void SetQuickLoad(Bool_t quick) { fQuickLoad = quick; }
198  virtual void SetTree(TTree *tree) {fTree = tree;}
199  virtual void ResetLoading();
200  virtual TTree* GetTree() const {return fTree;}
201  virtual void UpdateFormulaLeaves();
202 
203  ClassDef(TTreeFormula, 10); //The Tree formula
204 };
205 
206 #endif
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:32
const Int_t kMAXFORMDIM
Definition: TTreeFormula.h:43
An array of TObjects.
Definition: TObjArray.h:37
virtual Bool_t IsLeafInteger(Int_t code) const
Return TRUE if the leaf corresponding to code is short, int or unsigned short, int When a leaf is of ...
long long Long64_t
Definition: RtypesCore.h:69
TObjArray fBranches
Definition: TTreeFormula.h:101
virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:171
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:31
double T(double x)
Definition: ChebyshevPol.h:34
TTreeFormulaManager * GetManager() const
Definition: TTreeFormula.h:179
virtual Int_t DefinedVariable(TString &variable, Int_t &action)
Check if name is in the list of Tree/Branch leaves.
A TLeaf for a general object derived from TObject.
Definition: TLeafObject.h:31
virtual TLeaf * GetLeaf(Int_t n) const
Return leaf corresponding to serial number n.
#define BIT(n)
Definition: Rtypes.h:75
void DefineDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim *info, Int_t &virt_dim)
This method is used internally to decode the dimensions of the variables.
Basic string class.
Definition: TString.h:129
Int_t fNdimensions[kMAXCODES]
If true, the current entry has not been loaded yet.
Definition: TTreeFormula.h:105
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsString() const
Return TRUE if the formula is a string.
T GetConstant(Int_t k)
Int_t fMultiplicity
Definition: TTreeFormula.h:92
virtual void SetTree(TTree *tree)
Definition: TTreeFormula.h:198
virtual void * EvalObject(Int_t i=0)
Evaluate this treeformula.
TFormLeafInfo * GetLeafInfo(Int_t code) const
Return DataMember corresponding to code.
Int_t fNdata[kMAXCODES]
Definition: TTreeFormula.h:89
TTreeFormula & operator=(const TTreeFormula &)
virtual void * GetValuePointerFromMethod(Int_t i, TLeaf *leaf) const
Return result of a leafobject method.
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:27
void Init(const char *name, const char *formula)
Initialiation called from the constructors.
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TTreeFormula.h:193
Bool_t LoadCurrentDim()
Calculate the actual dimension for the current entry.
TMethodCall * GetMethodCall(Int_t code) const
Return methodcall corresponding to code.
void Convert(UInt_t fromVersion)
TObjArray fLeafNames
List of TTreeFormula for each alias used.
Definition: TTreeFormula.h:100
Used to coordinate one or more TTreeFormula objects.
virtual Bool_t SwitchToFormLeafInfo(Int_t code)
Convert the underlying lookup method from the direct technique (dereferencing the address held by the...
#define ClassDef(name, id)
Definition: Rtypes.h:297
TObjArray fExternalCuts
List of leaf method calls.
Definition: TTreeFormula.h:98
void ResetDimensions()
Populate the TTreeFormulaManager with the dimension information.
Int_t RegisterDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim *multidim=0)
This method stores the dimension information for later usage.
virtual Double_t GetValueFromMethod(Int_t i, TLeaf *leaf) const
Return result of a leafobject method.
const Int_t kMAXFOUND
Definition: TFormula.h:31
virtual TClass * EvalClass() const
Evaluate the class of this treeformula.
Method or function calling interface.
Definition: TMethodCall.h:37
void LoadBranches()
Make sure that all the branches have been loaded properly.
virtual const char * EvalStringInstance(Int_t i=0)
Eval the instance as a string.
Used to pass a selection expression to the Tree drawing routine.
Definition: TTreeFormula.h:58
A doubly linked list.
Definition: TList.h:43
UChar_t fHasMultipleVarDim[kMAXCODES]
Definition: TTreeFormula.h:107
virtual Bool_t StringToNumber(Int_t code)
Try to &#39;demote&#39; a string into an array bytes.
TObjArray fDataMembers
List of leaf used in this formula.
Definition: TTreeFormula.h:96
Class to manage histogram axis.
Definition: TAxis.h:30
const Int_t kMAXCODES
Definition: TTreeFormula.h:42
Int_t ParseWithLeaf(TLeaf *leaf, const char *expression, Bool_t final, UInt_t paran_level, TObjArray &castqueue, Bool_t useLeafCollectionObject, const char *fullExpression)
Decompose &#39;expression&#39; as pointing to something inside the leaf Returns:
Int_t fNcodes
This caches the physical number of element in the leaf or datamember.
Definition: TTreeFormula.h:90
unsigned int UInt_t
Definition: RtypesCore.h:42
TObjArray fAliases
List of TCutG and TEntryList used in the formula.
Definition: TTreeFormula.h:99
virtual Int_t GetNcodes() const
Definition: TTreeFormula.h:183
virtual void UpdateFormulaLeaves()
This function is called TTreePlayer::UpdateFormulaLeaves, itself called by TChain::LoadTree when a ne...
Int_t fCumulSizes[kMAXCODES][kMAXFORMDIM]
Definition: TTreeFormula.h:110
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
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:120
A Branch for the case of an object.
virtual TTree * GetTree() const
Definition: TTreeFormula.h:200
TAxis * fAxis
Definition: TTreeFormula.h:114
Bool_t fHasCast
Definition: TTreeFormula.h:91
virtual Int_t GetNdata()
Return number of available instances in the formula.
Int_t GetRealInstance(Int_t instance, Int_t codeindex)
Now let calculate what physical instance we really need.
Bool_t BranchHasMethod(TLeaf *leaf, TBranch *branch, const char *method, const char *params, Long64_t readentry) const
Return the leaf (if any) of the tree with contains an object of a class having a method which has the...
LongDouble_t * fConstLD
List of aliases used during the parsing of the expression.
Definition: TTreeFormula.h:122
virtual Bool_t IsLeafString(Int_t code) const
Return TRUE if the leaf or data member corresponding to code is a string.
TObjArray fLeaves
Definition: TTreeFormula.h:95
double Double_t
Definition: RtypesCore.h:55
Int_t DefineAlternate(const char *expression)
This method check for treat the case where expression contains $Atl and load up both fAliases and fEx...
The FORMULA class (ROOT version 5)
Definition: TFormula.h:65
Bool_t fDidBooleanOptimization
pointer to histogram axis if this is a string
Definition: TTreeFormula.h:115
Int_t fIndexes[kMAXCODES][kMAXFORMDIM]
Definition: TTreeFormula.h:111
This class is a small helper class to implement reading a data member on an object stored in a TTree...
Definition: TFormLeafInfo.h:49
T EvalInstance(Int_t i=0, const char *stringStack[]=0)
Evaluate this treeformula.
TTree * fTree
Definition: TTreeFormula.h:87
Bool_t fQuickLoad
List of branches to read. Similar to fLeaces but duplicates are zeroed out.
Definition: TTreeFormula.h:102
TTreeFormula * fVarIndexes[kMAXCODES][kMAXFORMDIM]
Definition: TTreeFormula.h:112
TTreeFormulaManager * fManager
True if we executed one boolean optimization since the last time instance number 0 was evaluated...
Definition: TTreeFormula.h:116
virtual ~TTreeFormula()
Tree Formula default destructor.
Int_t * fLookupType
Definition: TTreeFormula.h:94
TList * fDimensionSetup
The dimension coordinator.
Definition: TTreeFormula.h:119
virtual Long64_t EvalInstance64(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:172
Bool_t IsQuickLoad() const
Definition: TTreeFormula.h:191
TObjArray fMethods
List of leaf data members.
Definition: TTreeFormula.h:97
virtual char * PrintValue(Int_t mode=0) const
Return value of variable as a string.
TLeaf * GetLeafWithDatamember(const char *topchoice, const char *nextchice, Long64_t readentry) const
Return the leaf (if any) which contains an object containing a data member which has the name provide...
A TTree object has a header with a name and a title.
Definition: TTree.h:78
virtual LongDouble_t EvalInstanceLD(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:173
void SetQuickLoad(Bool_t quick)
Definition: TTreeFormula.h:197
unsigned char UChar_t
Definition: RtypesCore.h:34
A TTree is a list of TBranches.
Definition: TBranch.h:57
virtual Int_t GetMultiplicity() const
Definition: TTreeFormula.h:181
const Bool_t kTRUE
Definition: RtypesCore.h:91
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)
Look for the leaf corresponding to the start of expression.
const Int_t n
Definition: legend1.C:16
Int_t fFixedSizes[kMAXCODES][kMAXFORMDIM]
Definition: TTreeFormula.h:106
Bool_t fNeedLoading
If true, branch GetEntry is only called when the entry number changes.
Definition: TTreeFormula.h:103
char name[80]
Definition: TGX11.cxx:109
virtual void ResetLoading()
Tell the formula that we are going to request a new entry.
Int_t fCodes[kMAXCODES]
pointer to Tree
Definition: TTreeFormula.h:88
virtual Bool_t IsInteger(Bool_t fast=kTRUE) const
Return TRUE if the formula corresponds to one single Tree leaf and this leaf is short, int or unsigned short, int When a leaf is of type integer or string, the generated histogram is forced to have an integer bin width.
virtual void SetAxis(TAxis *axis=0)
Set the axis (in particular get the type).