ROOT  6.07/01
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 #ifndef ROOT_v5_TFormula
27 #include "v5/TFormula.h"
28 #endif
29 
30 #ifndef ROOT_TLeaf
31 #include "TLeaf.h"
32 #endif
33 
34 #ifndef ROOT_TObjArray
35 #include "TObjArray.h"
36 #endif
37 
38 #include <string>
39 #include <vector>
40 
41 #ifdef R__OLDHPACC
42 namespace std {
43  using ::string;
44  using ::vector;
45 }
46 #endif
47 
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
50 
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;
62 
63 
65 
66 friend class TTreeFormulaManager;
67 
68 protected:
69  enum {
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 {
81 
82  };
83  enum {
84  kAlias = 200,
85  kAliasString = 201,
86  kAlternate = 202,
88  kMinIf = 204,
89  kMaxIf = 205
90  };
91 
92  TTree *fTree; //! pointer to Tree
93  Int_t fCodes[kMAXCODES]; // List of leaf numbers referenced in formula
94  Int_t fNdata[kMAXCODES]; //! This caches the physical number of element in the leaf or datamember.
95  Int_t fNcodes; // Number of leaves referenced in formula
96  Bool_t fHasCast; // Record whether the formula contain a cast operation or not
97  Int_t fMultiplicity; // Indicator of the variability of the formula
98  Int_t fNindex; // Size of fIndex
99  Int_t *fLookupType; //[fNindex] array indicating how each leaf should be looked-up
100  TObjArray fLeaves; //! List of leaf used in this formula.
101  TObjArray fDataMembers; //! List of leaf data members
102  TObjArray fMethods; //! List of leaf method calls
103  TObjArray fExternalCuts; //! List of TCutG and TEntryList used in the formula
104  TObjArray fAliases; //! List of TTreeFormula for each alias used.
105  TObjArray fLeafNames; // List of TNamed describing leaves
106  TObjArray fBranches; //! List of branches to read. Similar to fLeaces but duplicates are zeroed out.
107  Bool_t fQuickLoad; //! If true, branch GetEntry is only called when the entry number changes.
108  Bool_t fNeedLoading; //! If true, the current entry has not been loaded yet.
109 
110  Int_t fNdimensions[kMAXCODES]; //Number of array dimensions in each leaf
111  Int_t fFixedSizes[kMAXCODES][kMAXFORMDIM]; //Physical sizes of lower dimensions for each leaf
112  UChar_t fHasMultipleVarDim[kMAXCODES]; //True if the corresponding variable is an array with more than one variable dimension.
113 
114  //the next line should have a mutable in front. See GetNdata()
115  Int_t fCumulSizes[kMAXCODES][kMAXFORMDIM]; //Accumulated sizes of lower dimensions for each leaf after variable dimensions has been calculated
116  Int_t fIndexes[kMAXCODES][kMAXFORMDIM]; //Index of array selected by user for each leaf
117  TTreeFormula *fVarIndexes[kMAXCODES][kMAXFORMDIM]; //Pointer to a variable index.
118 
119  TAxis *fAxis; //! pointer to histogram axis if this is a string
120  Bool_t fDidBooleanOptimization; //! True if we executed one boolean optimization since the last time instance number 0 was evaluated
121  TTreeFormulaManager *fManager; //! The dimension coordinator.
122 
123  // Helper members and function used during the construction and parsing
124  TList *fDimensionSetup; //! list of dimension setups, for delayed creation of the dimension information.
125  std::vector<std::string> fAliasesUsed; //! List of aliases used during the parsing of the expression.
126 
127  LongDouble_t* fConstLD; // local version of fConsts able to store bigger numbers
128 
129  TTreeFormula(const char *name, const char *formula, TTree *tree, const std::vector<std::string>& aliases);
130  void Init(const char *name, const char *formula);
131  Bool_t BranchHasMethod(TLeaf* leaf, TBranch* branch, const char* method,const char* params, Long64_t readentry) const;
132  Int_t DefineAlternate(const char* expression);
133  void DefineDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * info, Int_t& virt_dim);
134  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);
135  TLeaf* GetLeafWithDatamember(const char* topchoice, const char* nextchice, Long64_t readentry) const;
136  Int_t ParseWithLeaf(TLeaf *leaf, const char *expression, Bool_t final, UInt_t paran_level, TObjArray &castqueue, Bool_t useLeafCollectionObject, const char *fullExpression);
137  Int_t RegisterDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * multidim = 0);
139  Int_t RegisterDimensions(Int_t code, TFormLeafInfo *info, TFormLeafInfo *maininfo, Bool_t useCollectionObject);
140  Int_t RegisterDimensions(Int_t code, TLeaf *leaf);
141  Int_t RegisterDimensions(const char *size, Int_t code);
142 
143  virtual Double_t GetValueFromMethod(Int_t i, TLeaf *leaf) const;
144  virtual void* GetValuePointerFromMethod(Int_t i, TLeaf *leaf) const;
145  Int_t GetRealInstance(Int_t instance, Int_t codeindex);
146 
147  void LoadBranches();
149  void ResetDimensions();
150 
151  virtual TClass* EvalClass(Int_t oper) const;
152  virtual Bool_t IsLeafInteger(Int_t code) const;
153  virtual Bool_t IsString(Int_t oper) const;
154  virtual Bool_t IsLeafString(Int_t code) const;
155  virtual Bool_t SwitchToFormLeafInfo(Int_t code);
156  virtual Bool_t StringToNumber(Int_t code);
157 
158  void Convert(UInt_t fromVersion);
159 
160 private:
161  // Not implemented yet
162  TTreeFormula(const TTreeFormula&);
164 
165  template<typename T> T GetConstant(Int_t k);
166 
167 public:
168  TTreeFormula();
169  TTreeFormula(const char *name,const char *formula, TTree *tree);
170  virtual ~TTreeFormula();
171 
172  virtual Int_t DefinedVariable(TString &variable, Int_t &action);
173  virtual TClass* EvalClass() const;
174 
175  template<typename T> T EvalInstance(Int_t i=0, const char *stringStack[]=0);
176  virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<Double_t>(i, stringStack); }
177  virtual Long64_t EvalInstance64(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<Long64_t>(i, stringStack); }
178  virtual LongDouble_t EvalInstanceLD(Int_t i=0, const char *stringStack[]=0) {return EvalInstance<LongDouble_t>(i, stringStack); }
179 
180  virtual const char *EvalStringInstance(Int_t i=0);
181  virtual void* EvalObject(Int_t i=0);
182  // EvalInstance should be const. See comment on GetNdata()
183  TFormLeafInfo *GetLeafInfo(Int_t code) const;
185  TMethodCall *GetMethodCall(Int_t code) const;
186  virtual Int_t GetMultiplicity() const {return fMultiplicity;}
187  virtual TLeaf *GetLeaf(Int_t n) const;
188  virtual Int_t GetNcodes() const {return fNcodes;}
189  virtual Int_t GetNdata();
190  //GetNdata should probably be const. However it need to cache some information about the actual dimension
191  //of arrays, so if GetNdata is const, the variables fUsedSizes and fCumulUsedSizes need to be declared
192  //mutable. We will be able to do that only when all the compilers supported for ROOT actually implemented
193  //the mutable keyword.
194  //NOTE: Also modify the code in PrintValue which current goes around this limitation :(
195  virtual Bool_t IsInteger(Bool_t fast=kTRUE) const;
196  Bool_t IsQuickLoad() const { return fQuickLoad; }
197  virtual Bool_t IsString() const;
198  virtual Bool_t Notify() { UpdateFormulaLeaves(); return kTRUE; }
199  virtual char *PrintValue(Int_t mode=0) const;
200  virtual char *PrintValue(Int_t mode, Int_t instance, const char *decform = "9.9") const;
201  virtual void SetAxis(TAxis *axis=0);
202  void SetQuickLoad(Bool_t quick) { fQuickLoad = quick; }
203  virtual void SetTree(TTree *tree) {fTree = tree;}
204  virtual void ResetLoading();
205  virtual TTree* GetTree() const {return fTree;}
206  virtual void UpdateFormulaLeaves();
207 
208  ClassDef(TTreeFormula,9) //The Tree formula
209 };
210 
211 #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
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:106
virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:176
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
TTreeFormulaManager * GetManager() const
Definition: TTreeFormula.h:184
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:35
virtual TLeaf * GetLeaf(Int_t n) const
Return leaf corresponding to serial number n.
#define BIT(n)
Definition: Rtypes.h:120
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:137
Int_t fNdimensions[kMAXCODES]
If true, the current entry has not been loaded yet.
Definition: TTreeFormula.h:110
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:97
virtual void SetTree(TTree *tree)
Definition: TTreeFormula.h:203
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:94
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:29
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:198
TTree * T
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:105
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:254
TObjArray fExternalCuts
List of leaf method calls.
Definition: TTreeFormula.h:103
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:37
virtual TClass * EvalClass() const
Evaluate the class of this treeformula.
Method or function calling interface.
Definition: TMethodCall.h:41
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:64
A doubly linked list.
Definition: TList.h:47
UChar_t fHasMultipleVarDim[kMAXCODES]
Definition: TTreeFormula.h:112
virtual Bool_t StringToNumber(Int_t code)
Try to 'demote' a string into an array bytes.
TObjArray fDataMembers
List of leaf used in this formula.
Definition: TTreeFormula.h:101
Class to manage histogram axis.
Definition: TAxis.h:36
const Int_t kMAXCODES
Definition: TTreeFormula.h:48
Int_t ParseWithLeaf(TLeaf *leaf, const char *expression, Bool_t final, UInt_t paran_level, TObjArray &castqueue, Bool_t useLeafCollectionObject, const char *fullExpression)
Decompose 'expression' 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:95
unsigned int UInt_t
Definition: RtypesCore.h:42
TObjArray fAliases
List of TCutG and TEntryList used in the formula.
Definition: TTreeFormula.h:104
virtual Int_t GetNcodes() const
Definition: TTreeFormula.h:188
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:115
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:125
A Branch for the case of an object.
virtual TTree * GetTree() const
Definition: TTreeFormula.h:205
TAxis * fAxis
Definition: TTreeFormula.h:119
Bool_t fHasCast
Definition: TTreeFormula.h:96
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...
tuple tree
Definition: tree.py:24
LongDouble_t * fConstLD
List of aliases used during the parsing of the expression.
Definition: TTreeFormula.h:127
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:100
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...
Bool_t fDidBooleanOptimization
pointer to histogram axis if this is a string
Definition: TTreeFormula.h:120
Int_t fIndexes[kMAXCODES][kMAXFORMDIM]
Definition: TTreeFormula.h:116
This class is a small helper class to implement reading a data member on an object stored in a TTree...
Definition: TFormLeafInfo.h:53
T EvalInstance(Int_t i=0, const char *stringStack[]=0)
Evaluate this treeformula.
#define name(a, b)
Definition: linkTestLib0.cpp:5
TTree * fTree
Definition: TTreeFormula.h:92
Bool_t fQuickLoad
List of branches to read. Similar to fLeaces but duplicates are zeroed out.
Definition: TTreeFormula.h:107
TTreeFormula * fVarIndexes[kMAXCODES][kMAXFORMDIM]
Definition: TTreeFormula.h:117
TTreeFormulaManager * fManager
True if we executed one boolean optimization since the last time instance number 0 was evaluated...
Definition: TTreeFormula.h:121
Bool_t axis
Definition: geodemo.C:37
virtual ~TTreeFormula()
Tree Formula default destructor.
Int_t * fLookupType
Definition: TTreeFormula.h:99
TList * fDimensionSetup
The dimension coordinator.
Definition: TTreeFormula.h:124
virtual Long64_t EvalInstance64(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:177
Bool_t IsQuickLoad() const
Definition: TTreeFormula.h:196
TObjArray fMethods
List of leaf data members.
Definition: TTreeFormula.h:102
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:98
virtual LongDouble_t EvalInstanceLD(Int_t i=0, const char *stringStack[]=0)
Definition: TTreeFormula.h:178
void SetQuickLoad(Bool_t quick)
Definition: TTreeFormula.h:202
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
virtual Int_t GetMultiplicity() const
Definition: TTreeFormula.h:186
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:111
Bool_t fNeedLoading
If true, branch GetEntry is only called when the entry number changes.
Definition: TTreeFormula.h:108
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:93
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).