Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TTreeFormula.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/treeplayer:$Id$
0002 // Author: Rene Brun   19/01/96
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 // ---------------------------------- TreeFormula.h
0012 
0013 #ifndef ROOT_TTreeFormula
0014 #define ROOT_TTreeFormula
0015 
0016 
0017 
0018 //////////////////////////////////////////////////////////////////////////
0019 //                                                                      //
0020 // TTreeFormula                                                         //
0021 //                                                                      //
0022 // The Tree formula class                                               //
0023 //                                                                      //
0024 //////////////////////////////////////////////////////////////////////////
0025 
0026 #include "v5/TFormula.h"
0027 
0028 #include "TLeaf.h"
0029 
0030 #include "TObjArray.h"
0031 
0032 #include <string>
0033 #include <vector>
0034 
0035 #ifdef R__OLDHPACC
0036 namespace std {
0037    using ::string;
0038    using ::vector;
0039 }
0040 #endif
0041 
0042 const Int_t kMAXCODES = kMAXFOUND; // must be the same as kMAXFOUND in TFormulaOld
0043 const Int_t kMAXFORMDIM = 5; // Maximum number of array dimensions support in TTreeFormula
0044 
0045 class TTree;
0046 class TArrayI;
0047 class TMethodCall;
0048 class TLeafObject;
0049 class TDataMember;
0050 class TStreamerElement;
0051 class TFormLeafInfoMultiVarDim;
0052 class TFormLeafInfo;
0053 class TBranchElement;
0054 class TAxis;
0055 class TTreeFormulaManager;
0056 
0057 
0058 class TTreeFormula : public ROOT::v5::TFormula {
0059 
0060 friend class TTreeFormulaManager;
0061 
0062 protected:
0063    enum EStatusBits {
0064       kIsCharacter = BIT(12),
0065       kMissingLeaf = BIT(15), // true if some of the needed leaves are missing in the current TTree
0066       kIsInteger   = BIT(17), // true if the branch contains an integer variable
0067       kNeedEntries = BIT(18)  // true if the formula uses Entries$
0068    };
0069    enum {
0070       kDirect, kDataMember, kMethod,
0071       kIndexOfEntry, kEntries, kLength, kIteration, kLengthFunc, kSum, kEntryList,
0072       kTreeMember,
0073       kIndexOfLocalEntry,
0074       kMin, kMax,
0075       kLocalEntries
0076 
0077    };
0078    enum {
0079       kAlias           = 200,
0080       kAliasString     = 201,
0081       kAlternate       = 202,
0082       kAlternateString = 203,
0083       kMinIf           = 204,
0084       kMaxIf           = 205
0085    };
0086 
0087    // Helper struct to hold a cache
0088    // that can accelerate calculation of the RealIndex.
0089    struct RealInstanceCache {
0090       Int_t fInstanceCache = 0;
0091       Int_t fLocalIndexCache = 0;
0092       Int_t fVirtAccumCache = 0;
0093    };
0094 
0095    TTree      *fTree;             ///<! Pointer to Tree
0096    Int_t       fCodes[kMAXCODES]; ///<  List of leaf numbers referenced in formula
0097    Int_t       fNdata[kMAXCODES]; ///<! This caches the physical number of element in the leaf or data member.
0098    Int_t       fNcodes;           ///<  Number of leaves referenced in formula
0099    bool        fHasCast;          ///<  Record whether the formula contain a cast operation or not
0100    Int_t       fMultiplicity;     ///<  Indicator of the variability of the formula
0101    Int_t       fNindex;           ///<  Size of fIndex
0102    Int_t      *fLookupType;       ///<[fNindex] Array indicating how each leaf should be looked-up
0103    TObjArray   fLeaves;           ///<!  List of leaf used in this formula.
0104    TObjArray   fDataMembers;      ///<!  List of leaf data members
0105    TObjArray   fMethods;          ///<!  List of leaf method calls
0106    TObjArray   fExternalCuts;     ///<!  List of TCutG and TEntryList used in the formula
0107    TObjArray   fAliases;          ///<!  List of TTreeFormula for each alias used.
0108    TObjArray   fLeafNames;        ///<   List of TNamed describing leaves
0109    TObjArray   fBranches;         ///<!  List of branches to read.  Similar to fLeaves but duplicates are zeroed out.
0110    bool        fQuickLoad;        ///<!  If true, branch GetEntry is only called when the entry number changes.
0111    bool        fNeedLoading;      ///<!  If true, the current entry has not been loaded yet.
0112 
0113    Int_t       fNdimensions[kMAXCODES];               ///< Number of array dimensions in each leaf
0114    Int_t       fFixedSizes[kMAXCODES][kMAXFORMDIM];   ///< Physical sizes of lower dimensions for each leaf
0115    UChar_t     fHasMultipleVarDim[kMAXCODES];         ///< True if the corresponding variable is an array with more than one variable dimension.
0116 
0117    //the next line should have a mutable in front. See GetNdata()
0118    Int_t       fCumulSizes[kMAXCODES][kMAXFORMDIM];   ///< Accumulated sizes of lower dimensions for each leaf after variable dimensions has been calculated
0119    Int_t       fIndexes[kMAXCODES][kMAXFORMDIM];      ///< Index of array selected by user for each leaf
0120    TTreeFormula *fVarIndexes[kMAXCODES][kMAXFORMDIM]; ///< Pointer to a variable index.
0121 
0122    TAxis                    *fAxis;                   ///<! pointer to histogram axis if this is a string
0123    bool                      fDidBooleanOptimization; ///<! True if we executed one boolean optimization since the last time instance number 0 was evaluated
0124    TTreeFormulaManager      *fManager;                ///<! The dimension coordinator.
0125 
0126    // Helper members and function used during the construction and parsing
0127    TList                    *fDimensionSetup;         ///<! list of dimension setups, for delayed creation of the dimension information.
0128    std::vector<std::string>  fAliasesUsed;            ///<! List of aliases used during the parsing of the expression.
0129 
0130    LongDouble_t*        fConstLD;                     ///<! local version of fConsts able to store bigger numbers
0131 
0132    RealInstanceCache fRealInstanceCache;              ///<! Cache accelerating the GetRealInstance function
0133 
0134    TTreeFormula(const char *name, const char *formula, TTree *tree, const std::vector<std::string>& aliases);
0135    void Init(const char *name, const char *formula);
0136    bool        BranchHasMethod(TLeaf* leaf, TBranch* branch, const char* method,const char* params, Long64_t readentry) const;
0137    Int_t       DefineAlternate(const char* expression);
0138    void        DefineDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim * info, Int_t& virt_dim);
0139    Int_t       FindLeafForExpression(const char* expression, TLeaf *&leaf, TString &leftover, bool &final, UInt_t &paran_level, TObjArray &castqueue, std::vector<std::string>& aliasUsed, bool &useLeafCollectionObject, const char *fullExpression);
0140    TLeaf*      GetLeafWithDatamember(const char* topchoice, const char* nextchice, Long64_t readentry) const;
0141    Int_t       ParseWithLeaf(TLeaf *leaf, const char *expression, bool final, UInt_t paran_level, TObjArray &castqueue, bool useLeafCollectionObject, const char *fullExpression);
0142    Int_t       RegisterDimensions(Int_t code, Int_t size, TFormLeafInfoMultiVarDim *multidim = nullptr);
0143    Int_t       RegisterDimensions(Int_t code, TBranchElement *branch);
0144    Int_t       RegisterDimensions(Int_t code, TFormLeafInfo *info, TFormLeafInfo *maininfo, bool useCollectionObject);
0145    Int_t       RegisterDimensions(Int_t code, TLeaf *leaf);
0146    Int_t       RegisterDimensions(const char *size, Int_t code);
0147 
0148    virtual Double_t  GetValueFromMethod(Int_t i, TLeaf *leaf) const;
0149    virtual void*     GetValuePointerFromMethod(Int_t i, TLeaf *leaf) const;
0150    Int_t             GetRealInstance(Int_t instance, Int_t codeindex);
0151 
0152    void              LoadBranches();
0153    bool              LoadCurrentDim();
0154    void              ResetDimensions();
0155 
0156    virtual TClass*   EvalClass(Int_t oper) const;
0157    virtual bool      IsLeafInteger(Int_t code) const;
0158    bool      IsString(Int_t oper) const override;
0159    virtual bool      IsLeafString(Int_t code) const;
0160    virtual bool      SwitchToFormLeafInfo(Int_t code);
0161    bool      StringToNumber(Int_t code) override;
0162 
0163    void              Convert(UInt_t fromVersion) override;
0164    Bool_t            AnalyzePrimitive(TString &chain, TObjArray &args, Int_t &err, Int_t offset) override;
0165    void              Optimize() override;
0166 
0167 private:
0168    // Not implemented yet
0169    TTreeFormula(const TTreeFormula&) = delete;
0170    TTreeFormula& operator=(const TTreeFormula&) = delete;
0171 
0172    template<typename T> T GetConstant(Int_t k);
0173 
0174 public:
0175    TTreeFormula() = delete;
0176    TTreeFormula(TRootIOCtor*);
0177    TTreeFormula(const char *name,const char *formula, TTree *tree);
0178      ~TTreeFormula() override;
0179 
0180    Int_t       DefinedVariable(TString &variable, Int_t &action) override;
0181    virtual TClass*     EvalClass() const;
0182 
0183    template<typename T> T EvalInstance(Int_t i=0, const char *stringStack[] = nullptr);
0184    /// \brief Double_t template specialization of EvalInstance
0185    virtual Double_t       EvalInstance(Int_t i=0, const char *stringStack[] = nullptr) {return EvalInstance<Double_t>(i, stringStack); }
0186    /// \brief Long64_t template specialization of EvalInstance
0187    virtual Long64_t       EvalInstance64(Int_t i=0, const char *stringStack[] = nullptr) {return EvalInstance<Long64_t>(i, stringStack); }
0188    /// \brief LongDouble_t template specialization of EvalInstance
0189    virtual LongDouble_t   EvalInstanceLD(Int_t i=0, const char *stringStack[] = nullptr) {return EvalInstance<LongDouble_t>(i, stringStack); }
0190 
0191    virtual const char *EvalStringInstance(Int_t i=0);
0192    virtual void*       EvalObject(Int_t i=0);
0193    // EvalInstance should be const.  See comment on GetNdata()
0194    TFormLeafInfo      *GetLeafInfo(Int_t code) const;
0195    TTreeFormulaManager*GetManager() const { return fManager; }
0196    TMethodCall        *GetMethodCall(Int_t code) const;
0197    virtual Int_t       GetMultiplicity() const {return fMultiplicity;}
0198    virtual TLeaf      *GetLeaf(Int_t n) const;
0199    virtual Int_t       GetNcodes() const {return fNcodes;}
0200    virtual Int_t       GetNdata();
0201    //GetNdata should probably be const.  However it need to cache some information about the actual dimension
0202    //of arrays, so if GetNdata is const, the variables fUsedSizes and fCumulUsedSizes need to be declared
0203    //mutable.  We will be able to do that only when all the compilers supported for ROOT actually implemented
0204    //the mutable keyword.
0205    //NOTE: Also modify the code in PrintValue which current goes around this limitation :(
0206    virtual bool        IsInteger(bool fast=true) const;
0207            bool        IsQuickLoad() const { return fQuickLoad; }
0208    virtual bool        IsString() const;
0209    bool        Notify() override { UpdateFormulaLeaves(); return true; }
0210    virtual char       *PrintValue(Int_t mode=0) const;
0211    virtual char       *PrintValue(Int_t mode, Int_t instance, const char *decform = "9.9") const;
0212    virtual void        SetAxis(TAxis *axis = nullptr);
0213            void        SetQuickLoad(bool quick) { fQuickLoad = quick; }
0214    virtual void        SetTree(TTree *tree) {fTree = tree;}
0215    virtual void        ResetLoading();
0216    virtual TTree*      GetTree() const {return fTree;}
0217    virtual void        UpdateFormulaLeaves();
0218 
0219    ClassDefOverride(TTreeFormula, 10);  //The Tree formula
0220 };
0221 
0222 #endif