TTreeFormula.h

Go to the documentation of this file.
00001 // @(#)root/treeplayer:$Id: TTreeFormula.h 30176 2009-09-15 15:42:11Z pcanal $
00002 // Author: Rene Brun   19/01/96
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 // ---------------------------------- TreeFormula.h
00012 
00013 #ifndef ROOT_TTreeFormula
00014 #define ROOT_TTreeFormula
00015 
00016 
00017 
00018 //////////////////////////////////////////////////////////////////////////
00019 //                                                                      //
00020 // TTreeFormula                                                         //
00021 //                                                                      //
00022 // The Tree formula class                                               //
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; // must be the same as kMAXFOUND in TFormula
00049 const Int_t kMAXFORMDIM = 5; // Maximum number of array dimensions support in TTreeFormula
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), // true if some of the needed leaves are missing in the current TTree
00072       kIsInteger   = BIT(17), // true if the branch contains an integer variable
00073       kNeedEntries = BIT(18)  // true if the formula uses Entries$
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;            //! pointer to Tree
00093    Short_t     fCodes[kMAXCODES]; //  List of leaf numbers referenced in formula
00094    Int_t       fNdata[kMAXCODES]; //! This caches the physical number of element in the leaf or datamember.
00095    Int_t       fNcodes;           //  Number of leaves referenced in formula
00096    Bool_t      fHasCast;          //  Record whether the formula contain a cast operation or not
00097    Int_t       fMultiplicity;     //  Indicator of the variability of the formula
00098    Int_t       fNindex;           //  Size of fIndex
00099    Int_t      *fLookupType;       //[fNindex] array indicating how each leaf should be looked-up
00100    TObjArray   fLeaves;           //!  List of leaf used in this formula.
00101    TObjArray   fDataMembers;      //!  List of leaf data members
00102    TObjArray   fMethods;          //!  List of leaf method calls
00103    TObjArray   fExternalCuts;     //!  List of TCutG and TEntryList used in the formula
00104    TObjArray   fAliases;          //!  List of TTreeFormula for each alias used.
00105    TObjArray   fLeafNames;        //   List of TNamed describing leaves
00106    TObjArray   fBranches;         //!  List of branches to read.  Similar to fLeaces but duplicates are zeroed out.
00107    Bool_t      fQuickLoad;        //!  If true, branch GetEntry is only called when the entry number changes.
00108    Bool_t      fNeedLoading;      //!  If true, the current entry has not been loaded yet.
00109 
00110    Int_t       fNdimensions[kMAXCODES];              //Number of array dimensions in each leaf
00111    Int_t       fFixedSizes[kMAXCODES][kMAXFORMDIM];  //Physical sizes of lower dimensions for each leaf
00112    UChar_t     fHasMultipleVarDim[kMAXCODES];        //True if the corresponding variable is an array with more than one variable dimension.
00113 
00114    //the next line should have a mutable in front. See GetNdata()
00115    Int_t       fCumulSizes[kMAXCODES][kMAXFORMDIM];  //Accumulated sizes of lower dimensions for each leaf after variable dimensions has been calculated
00116    Int_t       fIndexes[kMAXCODES][kMAXFORMDIM];     //Index of array selected by user for each leaf
00117    TTreeFormula *fVarIndexes[kMAXCODES][kMAXFORMDIM];  //Pointer to a variable index.
00118 
00119    TAxis                    *fAxis;           //! pointer to histogram axis if this is a string
00120    Bool_t                    fDidBooleanOptimization;  //! True if we executed one boolean optimization since the last time instance number 0 was evaluated
00121    TTreeFormulaManager      *fManager;        //! The dimension coordinator.
00122 
00123    // Helper members and function used during the construction and parsing
00124    TList                    *fDimensionSetup; //! list of dimension setups, for delayed creation of the dimension information.
00125    std::vector<std::string>  fAliasesUsed;    //! List of aliases used during the parsing of the expression.
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 &paran_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    // Not implemented yet
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    // EvalInstance should be const.  See comment on GetNdata()
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    //GetNdata should probably be const.  However it need to cache some information about the actual dimension
00182    //of arrays, so if GetNdata is const, the variables fUsedSizes and fCumulUsedSizes need to be declared
00183    //mutable.  We will be able to do that only when all the compilers supported for ROOT actually implemented
00184    //the mutable keyword.
00185    //NOTE: Also modify the code in PrintValue which current goes around this limitation :(
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)  //The Tree formula
00200 };
00201 
00202 #endif

Generated on Tue Jul 5 14:28:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1