00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_TTreeFormula
00014 #define ROOT_TTreeFormula
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef ROOT_TFormula
00027 #include "TFormula.h"
00028 #endif
00029
00030 #ifndef ROOT_TLeaf
00031 #include "TLeaf.h"
00032 #endif
00033
00034 #ifndef ROOT_TObjArray
00035 #include "TObjArray.h"
00036 #endif
00037
00038 #include <string>
00039 #include <vector>
00040
00041 #ifdef R__OLDHPACC
00042 namespace std {
00043 using ::string;
00044 using ::vector;
00045 }
00046 #endif
00047
00048 const Int_t kMAXCODES = kMAXFOUND;
00049 const Int_t kMAXFORMDIM = 5;
00050
00051 class TTree;
00052 class TArrayI;
00053 class TMethodCall;
00054 class TLeafObject;
00055 class TDataMember;
00056 class TStreamerElement;
00057 class TFormLeafInfoMultiVarDim;
00058 class TFormLeafInfo;
00059 class TBranchElement;
00060 class TAxis;
00061 class TTreeFormulaManager;
00062
00063
00064 class TTreeFormula : public TFormula {
00065
00066 friend class TTreeFormulaManager;
00067
00068 protected:
00069 enum {
00070 kIsCharacter = BIT(12),
00071 kMissingLeaf = BIT(15),
00072 kIsInteger = BIT(17),
00073 kNeedEntries = BIT(18)
00074 };
00075 enum {
00076 kDirect, kDataMember, kMethod,
00077 kIndexOfEntry, kEntries, kLength, kIteration, kLengthFunc, kSum, kEntryList,
00078 kTreeMember,
00079 kIndexOfLocalEntry,
00080 kMin, kMax
00081
00082 };
00083 enum {
00084 kAlias = 200,
00085 kAliasString = 201,
00086 kAlternate = 202,
00087 kAlternateString = 203,
00088 kMinIf = 204,
00089 kMaxIf = 205
00090 };
00091
00092 TTree *fTree;
00093 Short_t fCodes[kMAXCODES];
00094 Int_t fNdata[kMAXCODES];
00095 Int_t fNcodes;
00096 Bool_t fHasCast;
00097 Int_t fMultiplicity;
00098 Int_t fNindex;
00099 Int_t *fLookupType;
00100 TObjArray fLeaves;
00101 TObjArray fDataMembers;
00102 TObjArray fMethods;
00103 TObjArray fExternalCuts;
00104 TObjArray fAliases;
00105 TObjArray fLeafNames;
00106 TObjArray fBranches;
00107 Bool_t fQuickLoad;
00108 Bool_t fNeedLoading;
00109
00110 Int_t fNdimensions[kMAXCODES];
00111 Int_t fFixedSizes[kMAXCODES][kMAXFORMDIM];
00112 UChar_t fHasMultipleVarDim[kMAXCODES];
00113
00114
00115 Int_t fCumulSizes[kMAXCODES][kMAXFORMDIM];
00116 Int_t fIndexes[kMAXCODES][kMAXFORMDIM];
00117 TTreeFormula *fVarIndexes[kMAXCODES][kMAXFORMDIM];
00118
00119 TAxis *fAxis;
00120 Bool_t fDidBooleanOptimization;
00121 TTreeFormulaManager *fManager;
00122
00123
00124 TList *fDimensionSetup;
00125 std::vector<std::string> fAliasesUsed;
00126
00127 TTreeFormula(const char *name, const char *formula, TTree *tree, const std::vector<std::string>& aliases);
00128 void Init(const char *name, const char *formula);
00129 Bool_t BranchHasMethod(TLeaf* leaf, TBranch* branch, const char* method,const char* params, Long64_t readentry) const;
00130 Int_t DefineAlternate(const char* expression);
00131 void DefineDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * info, Int_t& virt_dim);
00132 Int_t FindLeafForExpression(const char* expression, TLeaf *&leaf, TString &leftover, Bool_t &final, UInt_t ¶n_level, TObjArray &castqueue, std::vector<std::string>& aliasUsed, Bool_t &useLeafCollectionObject, const char *fullExpression);
00133 TLeaf* GetLeafWithDatamember(const char* topchoice, const char* nextchice, Long64_t readentry) const;
00134 Int_t ParseWithLeaf(TLeaf *leaf, const char *expression, Bool_t final, UInt_t paran_level, TObjArray &castqueue, Bool_t useLeafCollectionObject, const char *fullExpression);
00135 Int_t RegisterDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * multidim = 0);
00136 Int_t RegisterDimensions(Int_t code, TBranchElement *branch);
00137 Int_t RegisterDimensions(Int_t code, TFormLeafInfo *info, TFormLeafInfo *maininfo, Bool_t useCollectionObject);
00138 Int_t RegisterDimensions(Int_t code, TLeaf *leaf);
00139 Int_t RegisterDimensions(const char *size, Int_t code);
00140
00141 virtual Double_t GetValueFromMethod(Int_t i, TLeaf *leaf) const;
00142 virtual void* GetValuePointerFromMethod(Int_t i, TLeaf *leaf) const;
00143 Int_t GetRealInstance(Int_t instance, Int_t codeindex);
00144
00145 void LoadBranches();
00146 Bool_t LoadCurrentDim();
00147 void ResetDimensions();
00148
00149 virtual TClass* EvalClass(Int_t oper) const;
00150 virtual Bool_t IsLeafInteger(Int_t code) const;
00151 virtual Bool_t IsString(Int_t oper) const;
00152 virtual Bool_t IsLeafString(Int_t code) const;
00153 virtual Bool_t SwitchToFormLeafInfo(Int_t code);
00154 virtual Bool_t StringToNumber(Int_t code);
00155
00156 void Convert(UInt_t fromVersion);
00157
00158 private:
00159
00160 TTreeFormula(const TTreeFormula&);
00161 TTreeFormula& operator=(const TTreeFormula&);
00162
00163 public:
00164 TTreeFormula();
00165 TTreeFormula(const char *name,const char *formula, TTree *tree);
00166 virtual ~TTreeFormula();
00167
00168 virtual Int_t DefinedVariable(TString &variable, Int_t &action);
00169 virtual TClass* EvalClass() const;
00170 virtual Double_t EvalInstance(Int_t i=0, const char *stringStack[]=0);
00171 virtual const char *EvalStringInstance(Int_t i=0);
00172 virtual void* EvalObject(Int_t i=0);
00173
00174 TFormLeafInfo *GetLeafInfo(Int_t code) const;
00175 TTreeFormulaManager*GetManager() const { return fManager; }
00176 TMethodCall *GetMethodCall(Int_t code) const;
00177 virtual Int_t GetMultiplicity() const {return fMultiplicity;}
00178 virtual TLeaf *GetLeaf(Int_t n) const;
00179 virtual Int_t GetNcodes() const {return fNcodes;}
00180 virtual Int_t GetNdata();
00181
00182
00183
00184
00185
00186 virtual Bool_t IsInteger(Bool_t fast=kTRUE) const;
00187 Bool_t IsQuickLoad() const { return fQuickLoad; }
00188 virtual Bool_t IsString() const;
00189 virtual Bool_t Notify() { UpdateFormulaLeaves(); return kTRUE; }
00190 virtual char *PrintValue(Int_t mode=0) const;
00191 virtual char *PrintValue(Int_t mode, Int_t instance, const char *decform = "9.9") const;
00192 virtual void SetAxis(TAxis *axis=0);
00193 void SetQuickLoad(Bool_t quick) { fQuickLoad = quick; }
00194 virtual void SetTree(TTree *tree) {fTree = tree;}
00195 virtual void ResetLoading();
00196 virtual TTree* GetTree() const {return fTree;}
00197 virtual void UpdateFormulaLeaves();
00198
00199 ClassDef(TTreeFormula,9)
00200 };
00201
00202 #endif