Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // @(#)root/tree:$Id$
0002 // Author: Rene Brun   14/01/2001
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 
0012 #ifndef ROOT_TBranchElement
0013 #define ROOT_TBranchElement
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TBranchElement                                                       //
0019 //                                                                      //
0020 // A Branch for the case of an object.                                  //
0021 //////////////////////////////////////////////////////////////////////////
0022 
0023 
0024 #include "TBranch.h"
0025 
0026 #include "TClassRef.h"
0027 
0028 #include "TTree.h"
0029 
0030 class TFolder;
0031 class TStreamerInfo;
0032 class TVirtualCollectionProxy;
0033 class TVirtualCollectionIterators;
0034 class TVirtualCollectionPtrIterators;
0035 class TVirtualArray;
0036 
0037 #include "TStreamerInfoActions.h"
0038 
0039 class TBranchElement : public TBranch {
0040 
0041 // Friends
0042    friend class TTreeCloner;
0043    friend class TLeafElement;
0044 
0045 /// Types
0046 protected:
0047    enum EStatusBits {
0048       kBranchFolder  = BIT(14),
0049       kDeleteObject  = BIT(16), ///<  We are the owner of fObject.
0050       kCache         = BIT(18), ///<  Need to pushd/pop fOnfileObject.
0051       kOwnOnfileObj  = BIT(19), ///<  We are the owner of fOnfileObject.
0052       kAddressSet    = BIT(20), ///<  The addressing set have been called for this branch
0053       kMakeClass     = BIT(21), ///<  This branch has been switched to using the MakeClass Mode
0054       kDecomposedObj = BIT(21)  ///<  More explicit alias for kMakeClass.
0055    };
0056 
0057 
0058 // Data Members
0059 protected:
0060    TString                  fClassName;     ///<  Class name of referenced object
0061    TString                  fParentName;    ///<  Name of parent class
0062    TString                  fClonesName;    ///<  Name of class in TClonesArray (if any)
0063    TVirtualCollectionProxy *fCollProxy;     ///<! collection interface (if any)
0064    UInt_t                   fCheckSum;      ///<  CheckSum of class
0065    Version_t                fClassVersion;  ///<  Version number of class
0066    Int_t                    fID;            ///<  element serial number in fInfo
0067    Int_t                    fType;          ///<  Branch type
0068                                             ///<
0069                                             ///<  Note on fType values:
0070                                             ///<  * -1 unsplit object with custom streamer at time of writing
0071                                             ///<  * 0 unsplit object with default streamer at time of writing
0072                                             ///<      OR simple data member of split object (fID==-1 for the former)
0073                                             ///<  * 1 base class of a split object.
0074                                             ///<  * 2 class typed data member of a split object
0075                                             ///<  * 3 branch count of a split TClonesArray
0076                                             ///<  * 31 data member of the content of a split TClonesArray
0077                                             ///<  * 4 branch count of a split STL Collection.
0078                                             ///<  * 41 data member of the content of a split STL collection
0079    Int_t                    fStreamerType;  ///<  branch streamer type
0080    Int_t                    fMaximum;       ///<  Maximum entries for a TClonesArray or variable array
0081    Int_t                    fSTLtype;       ///<! STL container type
0082    Int_t                    fNdata;         ///<! Number of data in this branch
0083    TBranchElement          *fBranchCount;   ///<  pointer to primary branchcount branch
0084    TBranchElement          *fBranchCount2;  ///<  pointer to secondary branchcount branch
0085    TStreamerInfo           *fInfo;          ///<! Pointer to StreamerInfo
0086    char                    *fObject;        ///<! Pointer to object at *fAddress
0087    TVirtualArray           *fOnfileObject;  ///<! Place holder for the onfile representation of data members.
0088    bool                     fInit : 1;      ///<! Initialization flag for branch assignment
0089    bool                     fInInitInfo : 1;///<! True during the 2nd part of InitInfo (cut recursion).
0090    bool                     fInitOffsets: 1;///<! Initialization flag to not endlessly recalculate offsets
0091    TClassRef                fTargetClass;   ///<! Reference to the target in-memory class
0092    TClassRef                fCurrentClass;  ///<! Reference to current (transient) class definition
0093    TClassRef                fParentClass;   ///<! Reference to class definition in fParentName
0094    TClassRef                fBranchClass;   ///<! Reference to class definition in fClassName
0095    TClassRef                fClonesClass;   ///<! Reference to class definition in fClonesName
0096    Int_t                   *fBranchOffset;  ///<! Sub-Branch offsets with respect to current transient class
0097    Int_t                    fBranchID;      ///<! ID number assigned by a TRefTable.
0098    TStreamerInfoActions::TIDs fNewIDs; ///<! Nested List of the serial number of all the StreamerInfo to be used.
0099    TStreamerInfoActions::TActionSequence *fReadActionSequence;  ///<! Set of actions to be executed to extract the data from the basket.
0100    TStreamerInfoActions::TActionSequence *fFillActionSequence;  ///<! Set of actions to be executed to write the data to the basket.
0101    TVirtualCollectionIterators           *fIterators;      ///<! holds the iterators when the branch is of fType==4.
0102    TVirtualCollectionIterators           *fWriteIterators; ///<! holds the read (non-staging) iterators when the branch is of fType==4 and associative containers.
0103    TVirtualCollectionPtrIterators        *fPtrIterators;   ///<! holds the iterators when the branch is of fType==4 and it is a split collection of pointers.
0104 
0105 // Not implemented
0106 private:
0107    TBranchElement(const TBranchElement&) = delete;
0108    TBranchElement& operator=(const TBranchElement&) = delete;
0109 
0110    static void SwitchContainer(TObjArray *);
0111 
0112 // Implementation use only functions.
0113 protected:
0114    void                     BuildTitle(const char* name);
0115    virtual void             InitializeOffsets();
0116    virtual void             InitInfo();
0117    bool                     IsMissingCollection() const;
0118    TStreamerInfo           *FindOnfileInfo(TClass *valueClass, const TObjArray &branches) const;
0119    TClass                  *GetParentClass(); // Class referenced by fParentName
0120    TStreamerInfo           *GetInfoImp() const;
0121    void                     ReleaseObject();
0122    void                     SetupInfo();
0123    void                     SetBranchCount(TBranchElement* bre);
0124    void                     SetBranchCount2(TBranchElement* bre) { fBranchCount2 = bre; }
0125    Int_t                    Unroll(const char* name, TClass* cltop, TClass* cl, char* ptr, Int_t basketsize, Int_t splitlevel, Int_t btype);
0126    inline void              ValidateAddress() const;
0127 
0128    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);
0129    void Init(TTree *tree, TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
0130    void Init(TTree *tree, TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
0131 
0132    void SetActionSequence(TClass *originalClass, TStreamerInfo *localInfo, TStreamerInfoActions::TActionSequence::SequenceGetter_t create, TStreamerInfoActions::TActionSequence *&actionSequence);
0133    void ReadLeavesImpl(TBuffer& b);
0134    void ReadLeavesMakeClass(TBuffer& b);
0135    void ReadLeavesCollection(TBuffer& b);
0136    void ReadLeavesCollectionSplitPtrMember(TBuffer& b);
0137    void ReadLeavesCollectionSplitVectorPtrMember(TBuffer& b);
0138    void ReadLeavesCollectionMember(TBuffer& b);
0139    void ReadLeavesClones(TBuffer& b);
0140    void ReadLeavesClonesMember(TBuffer& b);
0141    void ReadLeavesCustomStreamer(TBuffer& b);
0142    void ReadLeavesMember(TBuffer& b);
0143    void ReadLeavesMemberBranchCount(TBuffer& b);
0144    void ReadLeavesMemberCounter(TBuffer& b);
0145    void SetReadLeavesPtr();
0146    void SetReadActionSequence();
0147    void SetupAddressesImpl();
0148    void SetAddressImpl(void *addr, bool implied) override;
0149 
0150    void FillLeavesImpl(TBuffer& b);
0151    void FillLeavesMakeClass(TBuffer& b);
0152    void FillLeavesCollection(TBuffer& b);
0153    void FillLeavesCollectionSplitVectorPtrMember(TBuffer& b);
0154    void FillLeavesCollectionSplitPtrMember(TBuffer& b);
0155    void FillLeavesCollectionMember(TBuffer& b);
0156    void FillLeavesAssociativeCollectionMember(TBuffer& b);
0157    void FillLeavesClones(TBuffer& b);
0158    void FillLeavesClonesMember(TBuffer& b);
0159    void FillLeavesCustomStreamer(TBuffer& b);
0160    void FillLeavesMemberBranchCount(TBuffer& b);
0161    void FillLeavesMemberCounter(TBuffer& b);
0162    void FillLeavesMember(TBuffer& b);
0163    void SetFillLeavesPtr();
0164    void SetFillActionSequence();
0165 
0166 // Public Interface.
0167 public:
0168    TBranchElement();
0169    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);
0170    TBranchElement(TTree *tree, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
0171    TBranchElement(TTree *tree, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
0172    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);
0173    TBranchElement(TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
0174    TBranchElement(TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
0175 
0176                     ~TBranchElement() override;
0177 
0178            void             Browse(TBrowser* b) override;
0179            TBranch         *FindBranch(const char *name) override;
0180            TLeaf           *FindLeaf(const char *name) override;
0181            char            *GetAddress() const override;
0182            TBranchElement  *GetBranchCount() const { return fBranchCount; }
0183            TBranchElement  *GetBranchCount2() const { return fBranchCount2; }
0184            Int_t           *GetBranchOffset() const { return fBranchOffset; }
0185            UInt_t           GetCheckSum() { return fCheckSum; }
0186            const char      *GetClassName() const override { return fClassName.Data(); }
0187    virtual TClass          *GetClass() const { return fBranchClass; }
0188    virtual const char      *GetClonesName() const { return fClonesName.Data(); }
0189    TVirtualCollectionProxy *GetCollectionProxy();
0190    TClass                  *GetCurrentClass(); // Class referenced by transient description
0191            Int_t            GetEntry(Long64_t entry = 0, Int_t getall = 0) override;
0192            Int_t            GetExpectedType(TClass *&clptr,EDataType &type) override;
0193            TString          GetFullName() const override;
0194            const char      *GetIconName() const override;
0195            Int_t            GetID() const { return fID; }
0196            TStreamerInfo   *GetInfo() const;
0197            bool             GetMakeClass() const override;
0198            char            *GetObject() const;
0199            TVirtualArray   *GetOnfileObject() const { return fOnfileObject; }
0200    virtual const char      *GetParentName() const { return fParentName.Data(); }
0201    virtual Int_t            GetMaximum() const;
0202            Int_t            GetNdata() const { return fNdata; }
0203            Int_t            GetType() const { return fType; }
0204            Int_t            GetStreamerType() const { return fStreamerType; }
0205    virtual TClass          *GetTargetClass() { return fTargetClass; }
0206    virtual const char      *GetTypeName() const;
0207            Double_t         GetValue(Int_t i, Int_t len, bool subarr = false) const { return GetTypedValue<Double_t>(i, len, subarr); }
0208    template<typename T > T  GetTypedValue(Int_t i, Int_t len, bool subarr = false) const;
0209    virtual void            *GetValuePointer() const;
0210            Int_t            GetClassVersion() { return fClassVersion; }
0211            bool             IsBranchFolder() const { return TestBit(kBranchFolder); }
0212            bool             IsFolder() const override;
0213    virtual bool             IsObjectOwner() const { return TestBit(kDeleteObject); }
0214            bool             Notify() override { if (fAddress) { ResetAddress(); } return true; }
0215            void             Print(Option_t* option = "") const override;
0216            void             PrintValue(Int_t i) const;
0217            void             Reset(Option_t* option = "") override;
0218            void             ResetAfterMerge(TFileMergeInfo *) override;
0219            void             ResetAddress() override;
0220    virtual void             ResetDeleteObject();
0221    virtual void             ResetInitInfo(bool recurse);
0222            void             SetAddress(void* addobj) override;
0223            bool             SetMakeClass(bool decomposeObj = true) override;
0224            void             SetObject(void *objadd) override;
0225            void             SetBasketSize(Int_t buffsize) override;
0226    virtual void             SetBranchFolder() { SetBit(kBranchFolder); }
0227    virtual void             SetClassName(const char* name) { fClassName = name; }
0228            void             SetOffset(Int_t offset) override;
0229    virtual void             SetMissing();
0230    inline  void             SetParentClass(TClass* clparent);
0231    virtual void             SetParentName(const char* name) { fParentName = name; }
0232    virtual void             SetTargetClass(const char *name);
0233            void             SetupAddresses() override;
0234    virtual void             SetType(Int_t btype) { fType = btype; }
0235            void             UpdateFile() override;
0236            void             Unroll(const char *name, TClass *cl, TStreamerInfo *sinfo, char* objptr, Int_t bufsize, Int_t splitlevel);
0237 
0238    enum EBranchElementType {
0239       kLeafNode = 0,
0240       kBaseClassNode = 1,  // -- We are a base class element.
0241                            // Note: This does not include an STL container class which is
0242                            //        being used as a base class because the streamer element
0243                            //        in that case is not the base streamer element it is the
0244                            //        STL streamer element.
0245       kObjectNode = 2,
0246       kClonesNode = 3,
0247       kSTLNode = 4,
0248       kClonesMemberNode = 31,
0249       kSTLMemberNode = 41
0250    };
0251 
0252 private:
0253    Int_t            FillImpl(ROOT::Internal::TBranchIMTHelper *) override;
0254 
0255    ClassDefOverride(TBranchElement,10)  // Branch in case of an object
0256 };
0257 
0258 inline void TBranchElement::SetParentClass(TClass* clparent)
0259 {
0260    fParentClass = clparent;
0261    fParentName = clparent ? clparent->GetName() : "";
0262 }
0263 
0264 inline void TBranchElement::ValidateAddress() const
0265 {
0266    // Check to see if the user changed the object pointer without telling us.
0267 
0268    if (fID < 0) {
0269       // We are a top-level branch.
0270       if (!fTree->GetMakeClass() && fAddress && (*((char**) fAddress) != fObject)) {
0271          // The semantics of fAddress and fObject are violated.
0272          // Assume the user changed the pointer on us.
0273          // Note: The cast is here because we want to be able to
0274          //       be called from the constant get functions.
0275 
0276          // FIXME: Disable the check/warning TTree until we add a missing interface.
0277          if (TestBit(kDeleteObject)) {
0278             // This should never happen!
0279             Error("ValidateAddress", "We owned an object whose address changed!  our ptr: %p  new ptr: %p",
0280                   (void*)fObject, (void*)*((char**) fAddress));
0281             const_cast<TBranchElement*>(this)->ResetBit(kDeleteObject);
0282          }
0283          const_cast<TBranchElement*>(this)->SetAddress(fAddress);
0284       }
0285    }
0286 }
0287 
0288 #endif // ROOT_TBranchElement