TBranchElement.h

Go to the documentation of this file.
00001 // @(#)root/tree:$Id: TBranchElement.h 38191 2011-02-22 22:06:56Z rdm $
00002 // Author: Rene Brun   14/01/2001
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 
00012 #ifndef ROOT_TBranchElement
00013 #define ROOT_TBranchElement
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TBranchElement                                                       //
00019 //                                                                      //
00020 // A Branch for the case of an object.                                  //
00021 //////////////////////////////////////////////////////////////////////////
00022 
00023 
00024 #ifndef ROOT_TBranch
00025 #include "TBranch.h"
00026 #endif
00027 
00028 #ifndef ROOT_TClassRef
00029 #include "TClassRef.h"
00030 #endif
00031 
00032 #ifndef ROOT_TTree
00033 #include "TTree.h"
00034 #endif
00035 
00036 #ifndef ROOT_TError
00037 #include "TError.h"
00038 #endif
00039 
00040 #include <vector>
00041 
00042 class TFolder;
00043 class TStreamerInfo;
00044 class TVirtualCollectionProxy;
00045 class TVirtualCollectionIterators;
00046 class TVirtualCollectionPtrIterators;
00047 class TVirtualArray;
00048 
00049 namespace TStreamerInfoActions { class TActionSequence; }
00050 
00051 
00052 class TBranchElement : public TBranch {
00053 
00054 // Friends
00055    friend class TTreeCloner;
00056 
00057 // Types
00058 protected:
00059    enum {
00060       kBranchFolder = BIT(14),
00061       kDeleteObject = BIT(16),  //  We are the owner of fObject.
00062       kCache        = BIT(18),  //  Need to pushd/pop fOnfileObject.
00063       kOwnOnfileObj = BIT(19),  //  We are the owner of fOnfileObject.
00064       kAddressSet   = BIT(20),  //  The addressing set have been called for this branch
00065       kMakeClass    = BIT(21),  //  This branch has been switched to using the MakeClass Mode
00066       kDecomposedObj= BIT(21)   //  More explicit alias for kMakeClass.
00067    };
00068 
00069 // Data Members
00070 protected:
00071    TString                  fClassName;     //  Class name of referenced object
00072    TString                  fParentName;    //  Name of parent class
00073    TString                  fClonesName;    //  Name of class in TClonesArray (if any)
00074    TVirtualCollectionProxy *fCollProxy;     //! collection interface (if any)
00075    UInt_t                   fCheckSum;      //  CheckSum of class
00076    Int_t                    fClassVersion;  //  Version number of class
00077    Int_t                    fID;            //  element serial number in fInfo
00078    Int_t                    fType;          //  branch type
00079    Int_t                    fStreamerType;  //  branch streamer type
00080    Int_t                    fMaximum;       //  Maximum entries for a TClonesArray or variable array
00081    Int_t                    fSTLtype;       //! STL container type
00082    Int_t                    fNdata;         //! Number of data in this branch
00083    TBranchElement          *fBranchCount;   //  pointer to primary branchcount branch
00084    TBranchElement          *fBranchCount2;  //  pointer to secondary branchcount branch
00085    TStreamerInfo           *fInfo;          //! Pointer to StreamerInfo
00086    char                    *fObject;        //! Pointer to object at *fAddress
00087    TVirtualArray           *fOnfileObject;  //! Place holder for the onfile representation of data members.
00088    Bool_t                   fInit;          //! Initialization flag for branch assignment
00089    Bool_t                   fInitOffsets;   //! Initialization flag to not endlessly recalculate offsets
00090    TClassRef                fTargetClass;   //! Reference to the target in-memory class
00091    TClassRef                fCurrentClass;  //! Reference to current (transient) class definition
00092    TClassRef                fParentClass;   //! Reference to class definition in fParentName
00093    TClassRef                fBranchClass;   //! Reference to class definition in fClassName
00094    Int_t                   *fBranchOffset;  //! Sub-Branch offsets with respect to current transient class
00095    Int_t                    fBranchID;      //! ID number assigned by a TRefTable.
00096    std::vector<Int_t>       fIDs;           //! List of the serial number of all the StreamerInfo to be used.   
00097    TStreamerInfoActions::TActionSequence *fReadActionSequence;  //! Set of actions to be executed to extract the data from the basket.
00098    TVirtualCollectionIterators           *fIterators;     //! holds the iterators when the branch is of fType==4.
00099    TVirtualCollectionPtrIterators        *fPtrIterators;  //! holds the iterators when the branch is of fType==4 and it is a split collection of pointers.
00100 
00101 // Not implemented
00102 private:
00103    TBranchElement(const TBranchElement&);            // not implemented
00104    TBranchElement& operator=(const TBranchElement&); // not implemented
00105 
00106    static void SwitchContainer(TObjArray *); 
00107 
00108 // Implementation use only functions.
00109 protected:
00110    void                     BuildTitle(const char* name);
00111    virtual void             InitializeOffsets();
00112    virtual void             InitInfo();
00113    Bool_t                   IsMissingCollection() const;
00114    TClass                  *GetCurrentClass(); // Class referenced by transient description
00115    TClass                  *GetParentClass(); // Class referenced by fParentName
00116    TStreamerInfo           *GetInfoImp() const;
00117    void                     ReleaseObject();
00118    void                     SetBranchCount(TBranchElement* bre);
00119    void                     SetBranchCount2(TBranchElement* bre) { fBranchCount2 = bre; }
00120    Int_t                    Unroll(const char* name, TClass* cltop, TClass* cl, char* ptr, Int_t basketsize, Int_t splitlevel, Int_t btype);
00121    inline void              ValidateAddress() const;
00122 
00123    void Init(TTree *tree, TBranch *parent, const char* name, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t btype = 0);
00124    void Init(TTree *tree, TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
00125    void Init(TTree *tree, TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
00126 
00127    void ReadLeavesImpl(TBuffer& b);
00128    void ReadLeavesMakeClass(TBuffer& b);
00129    void ReadLeavesCollection(TBuffer& b);
00130    void ReadLeavesCollectionSplitPtrMember(TBuffer& b);
00131    void ReadLeavesCollectionSplitVectorPtrMember(TBuffer& b);
00132    void ReadLeavesCollectionMember(TBuffer& b);
00133    void ReadLeavesClones(TBuffer& b);
00134    void ReadLeavesClonesMember(TBuffer& b);
00135    void ReadLeavesCustomStreamer(TBuffer& b);
00136    void ReadLeavesMember(TBuffer& b);
00137    void ReadLeavesMemberBranchCount(TBuffer& b);
00138    void ReadLeavesMemberCounter(TBuffer& b);
00139    void SetReadLeavesPtr();
00140    void SetReadActionSequence();
00141 
00142 // Public Interface.
00143 public:
00144    TBranchElement();
00145    TBranchElement(TTree *tree, const char* name, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t btype = 0);
00146    TBranchElement(TTree *tree, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
00147    TBranchElement(TTree *tree, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
00148    TBranchElement(TBranch *parent, const char* name, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t btype = 0);
00149    TBranchElement(TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
00150    TBranchElement(TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
00151 
00152    virtual                  ~TBranchElement();
00153 
00154    virtual void             Browse(TBrowser* b);
00155    virtual Int_t            Fill();
00156    virtual void             FillLeaves(TBuffer& b);
00157    virtual TBranch         *FindBranch(const char *name);
00158    virtual TLeaf           *FindLeaf(const char *name);
00159    virtual char            *GetAddress() const;
00160            TBranchElement  *GetBranchCount() const { return fBranchCount; }
00161            TBranchElement  *GetBranchCount2() const { return fBranchCount2; }
00162            Int_t           *GetBranchOffset() const { return fBranchOffset; }
00163            UInt_t           GetCheckSum() { return fCheckSum; }
00164    virtual const char      *GetClassName() const { return fClassName.Data(); }
00165    virtual TClass          *GetClass() const { return fBranchClass; }
00166    virtual const char      *GetClonesName() const { return fClonesName.Data(); }
00167    TVirtualCollectionProxy *GetCollectionProxy();
00168    virtual Int_t            GetEntry(Long64_t entry = 0, Int_t getall = 0);
00169    virtual Int_t            GetExpectedType(TClass *&clptr,EDataType &type);
00170            const char      *GetIconName() const;
00171            Int_t            GetID() const { return fID; }
00172            TStreamerInfo   *GetInfo() const;
00173            Bool_t           GetMakeClass() const;
00174            char            *GetObject() const;
00175    virtual const char      *GetParentName() const { return fParentName.Data(); }
00176    virtual Int_t            GetMaximum() const;
00177            Int_t            GetNdata() const { return fNdata; }
00178            Int_t            GetType() const { return fType; }
00179            Int_t            GetStreamerType() const { return fStreamerType; }
00180    virtual TClass          *GetTargetClass() { return fTargetClass; }
00181    virtual const char      *GetTypeName() const;
00182            Double_t         GetValue(Int_t i, Int_t len, Bool_t subarr = kFALSE) const;
00183    virtual void            *GetValuePointer() const;
00184            Int_t            GetClassVersion() { return fClassVersion; }
00185            Bool_t           IsBranchFolder() const { return TestBit(kBranchFolder); }
00186            Bool_t           IsFolder() const;
00187    virtual Bool_t           IsObjectOwner() const { return TestBit(kDeleteObject); }
00188    virtual Bool_t           Notify() { if (fAddress) { ResetAddress(); } return 1; }
00189    virtual void             Print(Option_t* option = "") const;
00190            void             PrintValue(Int_t i) const;
00191    virtual void             Reset(Option_t* option = "");
00192    virtual void             ResetAddress();
00193    virtual void             ResetDeleteObject();
00194    virtual void             SetAddress(void* addobj);
00195    virtual Bool_t           SetMakeClass(Bool_t decomposeObj = kTRUE);
00196    virtual void             SetObject(void *objadd);
00197    virtual void             SetBasketSize(Int_t buffsize);
00198    virtual void             SetBranchFolder() { SetBit(kBranchFolder); }
00199    virtual void             SetClassName(const char* name) { fClassName = name; }
00200    virtual void             SetOffset(Int_t offset);
00201    inline  void             SetParentClass(TClass* clparent);
00202    virtual void             SetParentName(const char* name) { fParentName = name; }
00203    virtual void             SetTargetClass(const char *name);
00204    virtual void             SetupAddresses();
00205    virtual void             SetType(Int_t btype) { fType = btype; }
00206    virtual void             UpdateFile();
00207 
00208    ClassDef(TBranchElement,9)  // Branch in case of an object
00209 };
00210 
00211 inline void TBranchElement::SetParentClass(TClass* clparent)
00212 {
00213    fParentClass = clparent;
00214    fParentName = clparent ? clparent->GetName() : "";
00215 }
00216 
00217 inline void TBranchElement::ValidateAddress() const
00218 {
00219    // Check to see if the user changed the object pointer without telling us.
00220 
00221    if (fID < 0) {
00222       // We are a top-level branch.
00223       if (!fTree->GetMakeClass() && fAddress && (*((char**) fAddress) != fObject)) {
00224          // The semantics of fAddress and fObject are violated.
00225          // Assume the user changed the pointer on us.
00226          // Note: The cast is here because we want to be able to
00227          //       be called from the constant get functions.
00228 
00229          // FIXME: Disable the check/warning TTree until we add a missing interface.
00230          if (TestBit(kDeleteObject)) {
00231             // This should never happen!
00232             Error("ValidateAddress", "We owned an object whose address changed!  our ptr: %p  new ptr: %p", fObject, *((char**) fAddress));
00233             const_cast<TBranchElement*>(this)->ResetBit(kDeleteObject);
00234          }
00235          const_cast<TBranchElement*>(this)->SetAddress(fAddress);
00236       }
00237    }
00238 }
00239 
00240 #endif // ROOT_TBranchElement

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