TFormLeafInfo.h

Go to the documentation of this file.
00001 // @(#)root/treeplayer:$Id: TFormLeafInfo.h 34885 2010-08-20 13:33:08Z pcanal $
00002 // Author: Philippe Canal 01/06/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers and al.        *
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 
00012 #ifndef ROOT_TFormLeafInfo
00013 #define ROOT_TFormLeafInfo
00014 
00015 #ifndef ROOT_TObject
00016 #include "TObject.h"
00017 #endif
00018 
00019 #ifndef ROOT_TLeafElement
00020 #include "TLeafElement.h"
00021 #endif
00022 
00023 #include "TArrayI.h"
00024 #include "TDataType.h"
00025 #include "TStreamerInfo.h"
00026 #include "TStreamerElement.h"
00027 
00028 
00029 class TFormLeafInfo : public TObject {
00030 public:
00031    // Constructors
00032    TFormLeafInfo(TClass* classptr = 0, Long_t offset = 0,
00033                  TStreamerElement* element = 0);
00034    TFormLeafInfo(const TFormLeafInfo& orig);
00035    virtual TFormLeafInfo* DeepCopy() const;
00036    virtual ~TFormLeafInfo();
00037 
00038    // Data Members
00039    TClass           *fClass;   //! This is the class of the data pointed to
00040    //   TStreamerInfo    *fInfo;    //! == fClass->GetStreamerInfo()
00041    Long_t            fOffset;  //! Offset of the data pointed inside the class fClass
00042    TStreamerElement *fElement; //! Descriptor of the data pointed to.
00043          //Warning, the offset in fElement is NOT correct because it does not take into
00044          //account base classes and nested objects (which fOffset does).
00045    TFormLeafInfo    *fCounter;
00046    TFormLeafInfo    *fNext;    // follow this to grab the inside information
00047    TString fClassName;
00048    TString fElementName;
00049 
00050 protected:
00051    Int_t fMultiplicity;
00052 public:
00053 
00054    virtual void AddOffset(Int_t offset, TStreamerElement* element);
00055 
00056    virtual Int_t GetArrayLength();
00057    virtual TClass*   GetClass() const;
00058    virtual Int_t     GetCounterValue(TLeaf* leaf);
00059    virtual Int_t     ReadCounterValue(char *where);
00060 
00061    char* GetObjectAddress(TLeafElement* leaf, Int_t &instance);
00062 
00063    Int_t GetMultiplicity();
00064 
00065    // Currently only implemented in TFormLeafInfoCast
00066    Int_t GetNdata(TLeaf* leaf);
00067    virtual Int_t GetNdata();
00068 
00069    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00070 
00071    virtual void     *GetValuePointer(TLeaf *leaf, Int_t instance = 0);
00072    virtual void     *GetValuePointer(char  *from, Int_t instance = 0);
00073    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00074    virtual void     *GetLocalValuePointer( char *from, Int_t instance = 0);
00075 
00076    virtual Bool_t    HasCounter() const;
00077    virtual Bool_t    IsString() const;
00078 
00079    virtual Bool_t    IsInteger() const;
00080    virtual Bool_t    IsReference() const  {  return kFALSE; }
00081 
00082    // Method for multiple variable dimensions.
00083    virtual Int_t GetPrimaryIndex();
00084    virtual Int_t GetVarDim();
00085    virtual Int_t GetVirtVarDim();
00086    virtual Int_t GetSize(Int_t index);
00087    virtual Int_t GetSumOfSizes();
00088    virtual void  LoadSizes(TBranch* branch);
00089    virtual void  SetPrimaryIndex(Int_t index);
00090    virtual void  SetSecondaryIndex(Int_t index);
00091    virtual void  SetSize(Int_t index, Int_t val);
00092    virtual void  SetBranch(TBranch* br)  { if ( fNext ) fNext->SetBranch(br); }
00093    virtual void  UpdateSizes(TArrayI *garr);
00094 
00095    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00096 
00097    virtual Bool_t    Update();
00098 };
00099 
00100 //______________________________________________________________________________
00101 //
00102 // TFormLeafInfoDirect is a small helper class to implement reading a data
00103 // member on an object stored in a TTree.
00104 
00105 class TFormLeafInfoDirect : public TFormLeafInfo {
00106 public:
00107    TFormLeafInfoDirect(TBranchElement * from);
00108    TFormLeafInfoDirect(const TFormLeafInfoDirect& orig);
00109    virtual TFormLeafInfo* DeepCopy() const;
00110    virtual ~TFormLeafInfoDirect();
00111 
00112    virtual Double_t  ReadValue(char * /*where*/, Int_t /*instance*/= 0);
00113    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00114    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00115    virtual void     *GetLocalValuePointer(char *thisobj, Int_t instance = 0);
00116 };
00117 
00118 
00119 //______________________________________________________________________________
00120 //
00121 // TFormLeafInfoNumerical is a small helper class to implement reading a
00122 // numerical value inside a collection
00123 
00124 class TFormLeafInfoNumerical : public TFormLeafInfo {
00125 public:
00126    EDataType fKind;
00127    Bool_t fIsBool;
00128    TFormLeafInfoNumerical(TVirtualCollectionProxy *holder_of);
00129    TFormLeafInfoNumerical(EDataType kind);
00130    TFormLeafInfoNumerical(const TFormLeafInfoNumerical& orig);
00131    virtual TFormLeafInfo* DeepCopy() const;
00132    virtual ~TFormLeafInfoNumerical();
00133    virtual Bool_t    IsString() const;
00134    virtual Bool_t    Update();
00135 };
00136 
00137 //______________________________________________________________________________
00138 //
00139 // TFormLeafInfoCollectionObject
00140 // This class is used when we are interested by the collection it self and
00141 // it is split.
00142 
00143 class TFormLeafInfoCollectionObject : public TFormLeafInfo {
00144    Bool_t fTop;  //If true, it indicates that the branch itself contains
00145 public:
00146    TFormLeafInfoCollectionObject(TClass* classptr = 0, Bool_t fTop = kTRUE);
00147 
00148    virtual TFormLeafInfo* DeepCopy() const {
00149       return new TFormLeafInfoCollectionObject(*this);
00150    }
00151 
00152    virtual Int_t     GetCounterValue(TLeaf* leaf);
00153    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00154    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00155    virtual void     *GetValuePointer(TLeaf *leaf, Int_t instance = 0);
00156    virtual void     *GetValuePointer(char  *thisobj, Int_t instance = 0);
00157    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00158    virtual void     *GetLocalValuePointer(char  *thisobj, Int_t instance = 0);
00159 };
00160 
00161 //______________________________________________________________________________
00162 //
00163 // TFormLeafInfoClones is a small helper class to implement reading a data
00164 // member on a TClonesArray object stored in a TTree.
00165 
00166 class TFormLeafInfoClones : public TFormLeafInfo {
00167 public:
00168    Bool_t fTop;  //If true, it indicates that the branch itself contains
00169    //either the clonesArrays or something inside the clonesArray
00170    TFormLeafInfoClones(TClass* classptr = 0, Long_t offset = 0);
00171    TFormLeafInfoClones(TClass* classptr, Long_t offset, Bool_t top);
00172    TFormLeafInfoClones(TClass* classptr, Long_t offset, TStreamerElement* element,
00173                        Bool_t top = kFALSE);
00174    virtual TFormLeafInfo* DeepCopy() const {
00175       return new TFormLeafInfoClones(*this);
00176    }
00177 
00178    virtual Int_t     GetCounterValue(TLeaf* leaf);
00179    virtual Int_t     ReadCounterValue(char *where);
00180    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00181    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00182    virtual void     *GetValuePointer(TLeaf *leaf, Int_t instance = 0);
00183    virtual void     *GetValuePointer(char  *thisobj, Int_t instance = 0);
00184    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00185    virtual void     *GetLocalValuePointer(char  *thisobj, Int_t instance = 0);
00186 };
00187 
00188 
00189 //______________________________________________________________________________
00190 //
00191 // TFormLeafInfoCollection is a small helper class to implement reading a data member
00192 // on a generic collection object stored in a TTree.
00193 
00194 class TFormLeafInfoCollection : public TFormLeafInfo {
00195 public:
00196    Bool_t fTop;  //If true, it indicates that the branch itself contains
00197                  //either the clonesArrays or something inside the clonesArray
00198    TClass                  *fCollClass;
00199    TString                  fCollClassName;
00200    TVirtualCollectionProxy *fCollProxy;
00201    TStreamerElement        *fLocalElement;
00202 
00203    TFormLeafInfoCollection(TClass* classptr,
00204                            Long_t offset,
00205                            TStreamerElement* element,
00206                            Bool_t top = kFALSE);
00207 
00208    TFormLeafInfoCollection(TClass* motherclassptr,
00209                            Long_t offset = 0,
00210                            TClass* elementclassptr = 0,
00211                            Bool_t top = kFALSE);
00212 
00213    TFormLeafInfoCollection();
00214    TFormLeafInfoCollection(const TFormLeafInfoCollection& orig);
00215 
00216    ~TFormLeafInfoCollection();
00217 
00218    virtual TFormLeafInfo* DeepCopy() const;
00219 
00220    virtual Bool_t    Update();
00221 
00222    virtual Int_t     GetCounterValue(TLeaf* leaf);
00223    virtual Int_t     ReadCounterValue(char* where);
00224    virtual Int_t     GetCounterValue(TLeaf* leaf, Int_t instance);
00225    virtual Bool_t    HasCounter() const;
00226    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00227    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00228    virtual void     *GetValuePointer(TLeaf *leaf, Int_t instance = 0);
00229    virtual void     *GetValuePointer(char  *thisobj, Int_t instance = 0);
00230    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00231    virtual void     *GetLocalValuePointer(char  *thisobj, Int_t instance = 0);
00232 };
00233 
00234 //______________________________________________________________________________
00235 //
00236 // TFormLeafInfoCollectionSize is used to return the size of a collection
00237 //
00238 class TFormLeafInfoCollectionSize : public TFormLeafInfo {
00239    TClass                  *fCollClass;
00240    TString                  fCollClassName;
00241    TVirtualCollectionProxy *fCollProxy;
00242 public:
00243    TFormLeafInfoCollectionSize(TClass*);
00244    TFormLeafInfoCollectionSize(TClass* classptr,Long_t offset,TStreamerElement* element);
00245    TFormLeafInfoCollectionSize();
00246    TFormLeafInfoCollectionSize(const TFormLeafInfoCollectionSize& orig);
00247 
00248    ~TFormLeafInfoCollectionSize();
00249 
00250    virtual TFormLeafInfo* DeepCopy() const;
00251 
00252    virtual Bool_t    Update();
00253 
00254    virtual void     *GetValuePointer(TLeaf *leaf, Int_t instance = 0);
00255    virtual void     *GetValuePointer(char  *from, Int_t instance = 0);
00256    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00257    virtual void     *GetLocalValuePointer( char *from, Int_t instance = 0);
00258    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00259 };
00260 
00261 //______________________________________________________________________________
00262 //
00263 // TFormLeafInfoPointer is a small helper class to implement reading a data
00264 // member by following a pointer inside a branch of TTree.
00265 
00266 class TFormLeafInfoPointer : public TFormLeafInfo {
00267 public:
00268    TFormLeafInfoPointer(TClass* classptr = 0, Long_t offset = 0,
00269                         TStreamerElement* element = 0);
00270    TFormLeafInfoPointer(const TFormLeafInfoPointer& orig);
00271 
00272    virtual TFormLeafInfo* DeepCopy() const;
00273 
00274    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00275    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00276 };
00277 
00278 //______________________________________________________________________________
00279 //
00280 // TFormLeafInfoMethod is a small helper class to implement executing a method
00281 // of an object stored in a TTree
00282 
00283 class TFormLeafInfoMethod : public TFormLeafInfo {
00284 
00285    TMethodCall *fMethod;
00286    TString fMethodName;
00287    TString fParams;
00288    Double_t fResult;
00289    TString  fCopyFormat;
00290    TString  fDeleteFormat;
00291    void    *fValuePointer;
00292    Bool_t   fIsByValue;
00293 
00294 public:
00295 
00296    TFormLeafInfoMethod(TClass* classptr = 0, TMethodCall *method = 0);
00297    TFormLeafInfoMethod(const TFormLeafInfoMethod& orig);
00298    ~TFormLeafInfoMethod();
00299 
00300    virtual TFormLeafInfo* DeepCopy() const;
00301 
00302    virtual TClass*  GetClass() const;
00303    virtual void    *GetLocalValuePointer( TLeaf *from, Int_t instance = 0);
00304    virtual void    *GetLocalValuePointer(char *from, Int_t instance = 0);
00305    virtual Bool_t   IsInteger() const;
00306    virtual Bool_t   IsString() const;
00307    virtual Double_t ReadValue(char *where, Int_t instance = 0);
00308    virtual Bool_t   Update();
00309 };
00310 
00311 //______________________________________________________________________________
00312 //
00313 // TFormLeafInfoMultiVarDim is a small helper class to implement reading a
00314 // data member on a variable size array inside a TClonesArray object stored in
00315 // a TTree.  This is the version used when the data member is inside a
00316 // non-splitted object.
00317 
00318 class TFormLeafInfoMultiVarDim : public TFormLeafInfo {
00319 public:
00320    Int_t fNsize;
00321    TArrayI fSizes;           // Array of sizes of the variable dimension
00322    TFormLeafInfo *fCounter2; // Information on how to read the secondary dimensions
00323    Int_t fSumOfSizes;        // Sum of the content of fSizes
00324    Int_t fDim;               // physical number of the dimension that is variable
00325    Int_t fVirtDim;           // number of the virtual dimension to which this object correspond.
00326    Int_t fPrimaryIndex;      // Index of the dimensions that is indexing the second dimension's size
00327    Int_t fSecondaryIndex;    // Index of the second dimension
00328    
00329 protected:
00330    TFormLeafInfoMultiVarDim(TClass* classptr, Long_t offset,
00331                             TStreamerElement* element) : TFormLeafInfo(classptr,offset,element),fNsize(0),fSizes(),fCounter2(0),fSumOfSizes(0),fDim(0),fVirtDim(0),fPrimaryIndex(-1),fSecondaryIndex(-1) {}
00332 
00333 public:
00334    TFormLeafInfoMultiVarDim(TClass* classptr, Long_t offset,
00335                             TStreamerElement* element, TFormLeafInfo* parent);
00336    TFormLeafInfoMultiVarDim();
00337    TFormLeafInfoMultiVarDim(const TFormLeafInfoMultiVarDim& orig);
00338    ~TFormLeafInfoMultiVarDim();
00339    
00340    virtual TFormLeafInfo* DeepCopy() const;
00341    
00342 
00343    /* The proper indexing and unwinding of index is done by prior leafinfo in the chain. */
00344    //virtual Double_t  ReadValue(char *where, Int_t instance = 0) {
00345    //   return TFormLeafInfo::ReadValue(where,instance);
00346    //}
00347    
00348    virtual void     LoadSizes(TBranch* branch);
00349    virtual Int_t    GetPrimaryIndex();
00350    virtual void     SetPrimaryIndex(Int_t index);
00351    virtual void     SetSecondaryIndex(Int_t index);
00352    virtual void     SetSize(Int_t index, Int_t val);
00353    virtual Int_t    GetSize(Int_t index);
00354    virtual Int_t    GetSumOfSizes();
00355    virtual Double_t GetValue(TLeaf * /*leaf*/, Int_t /*instance*/ = 0);
00356    virtual Int_t    GetVarDim();
00357    virtual Int_t    GetVirtVarDim();
00358    virtual Bool_t   Update();
00359    virtual void     UpdateSizes(TArrayI *garr);
00360 };
00361 
00362 //______________________________________________________________________________
00363 //
00364 // TFormLeafInfoMultiVarDimDirect is a small helper class to implement reading
00365 // a data member on a variable size array inside a TClonesArray object stored
00366 // in a TTree.  This is the version used for split access
00367 
00368 class TFormLeafInfoMultiVarDimDirect : public TFormLeafInfoMultiVarDim {
00369 public:
00370    TFormLeafInfoMultiVarDimDirect();
00371    TFormLeafInfoMultiVarDimDirect(const TFormLeafInfoMultiVarDimDirect& orig);
00372 
00373    virtual TFormLeafInfo* DeepCopy() const;
00374 
00375    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00376    virtual Double_t  ReadValue(char * /*where*/, Int_t /*instance*/ = 0);
00377 };
00378 
00379 //______________________________________________________________________________
00380 //
00381 // TFormLeafInfoMultiVarDimCollection is a small helper class to implement reading
00382 // a data member which is a collection inside a TClonesArray or collection object 
00383 // stored in a TTree.  This is the version used for split access
00384 //
00385 class TFormLeafInfoMultiVarDimCollection : public TFormLeafInfoMultiVarDim {
00386 public:
00387    TFormLeafInfoMultiVarDimCollection(TClass* motherclassptr, Long_t offset,
00388       TClass* elementclassptr, TFormLeafInfo *parent);
00389    TFormLeafInfoMultiVarDimCollection(TClass* classptr, Long_t offset,
00390       TStreamerElement* element, TFormLeafInfo* parent);
00391    TFormLeafInfoMultiVarDimCollection();
00392    TFormLeafInfoMultiVarDimCollection(const TFormLeafInfoMultiVarDimCollection& orig);
00393 
00394    virtual TFormLeafInfo* DeepCopy() const;
00395 
00396    virtual Int_t GetArrayLength() { return 0; }
00397    virtual void      LoadSizes(TBranch* branch);
00398    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00399    virtual Double_t  ReadValue(char * /*where*/, Int_t /*instance*/ = 0);
00400 };
00401 
00402 //______________________________________________________________________________
00403 //
00404 // TFormLeafInfoMultiVarDimClones is a small helper class to implement reading
00405 // a data member which is a TClonesArray inside a TClonesArray or collection object 
00406 // stored in a TTree.  This is the version used for split access
00407 //
00408 class TFormLeafInfoMultiVarDimClones : public TFormLeafInfoMultiVarDim {
00409 public:
00410    TFormLeafInfoMultiVarDimClones(TClass* motherclassptr, Long_t offset,
00411       TClass* elementclassptr, TFormLeafInfo *parent);
00412    TFormLeafInfoMultiVarDimClones(TClass* classptr, Long_t offset,
00413       TStreamerElement* element, TFormLeafInfo* parent);
00414    TFormLeafInfoMultiVarDimClones();
00415    TFormLeafInfoMultiVarDimClones(const TFormLeafInfoMultiVarDimClones& orig);
00416 
00417    virtual TFormLeafInfo* DeepCopy() const;
00418 
00419    virtual Int_t GetArrayLength() { return 0; }
00420    virtual void      LoadSizes(TBranch* branch);
00421    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00422    virtual Double_t  ReadValue(char * /*where*/, Int_t /*instance*/ = 0);
00423 };
00424 
00425 //______________________________________________________________________________
00426 //
00427 // TFormLeafInfoCast is a small helper class to implement casting an object to
00428 // a different type (equivalent to dynamic_cast)
00429 
00430 class TFormLeafInfoCast : public TFormLeafInfo {
00431 public:
00432    TClass *fCasted;     //! Pointer to the class we are trying to case to
00433    TString fCastedName; //! Name of the class we are casting to.
00434    Bool_t  fGoodCast;   //! Marked by ReadValue.
00435    Bool_t  fIsTObject;  //! Indicated whether the fClass inherits from TObject.
00436 
00437    TFormLeafInfoCast(TClass* classptr = 0, TClass* casted = 0);
00438    TFormLeafInfoCast(const TFormLeafInfoCast& orig);
00439    virtual ~TFormLeafInfoCast();
00440 
00441    virtual TFormLeafInfo* DeepCopy() const;
00442 
00443    // Currently only implemented in TFormLeafInfoCast
00444    virtual Int_t GetNdata();
00445    virtual Double_t  ReadValue(char *where, Int_t instance = 0);
00446    virtual Bool_t    Update();
00447 };
00448 
00449 //______________________________________________________________________________
00450 //
00451 // TFormLeafTTree is a small helper class to implement reading 
00452 // from the containing TTree object itself.
00453 
00454 class TFormLeafInfoTTree : public TFormLeafInfo {
00455    TTree   *fTree;
00456    TTree   *fCurrent;
00457    TString  fAlias;
00458 
00459 public:
00460    TFormLeafInfoTTree(TTree *tree = 0, const char *alias = 0, TTree *current = 0);
00461    TFormLeafInfoTTree(const TFormLeafInfoTTree& orig);
00462    ~TFormLeafInfoTTree();
00463 
00464    virtual TFormLeafInfo* DeepCopy() const;
00465 
00466    using TFormLeafInfo::GetLocalValuePointer;
00467    using TFormLeafInfo::GetValue;
00468 
00469    virtual void     *GetLocalValuePointer(TLeaf *leaf, Int_t instance = 0);
00470    virtual Double_t  GetValue(TLeaf *leaf, Int_t instance = 0);
00471    virtual Double_t  ReadValue(char *thisobj, Int_t instance);
00472    virtual Bool_t    Update();
00473 };
00474 
00475 
00476 #endif /* ROOT_TFormLeafInfo */
00477 

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