Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-02 09:24:40

0001 // @(#)root/io:$Id$
0002 // Author: Rene Brun   12/10/2000
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_TStreamerInfo
0013 #define ROOT_TStreamerInfo
0014 
0015 #include <atomic>
0016 #include <vector>
0017 
0018 #include "TVirtualStreamerInfo.h"
0019 
0020 #include "TVirtualCollectionProxy.h"
0021 
0022 #include "TObjArray.h"
0023 
0024 
0025 class TFile;
0026 class TClass;
0027 class TClonesArray;
0028 class TDataMember;
0029 class TMemberStreamer;
0030 class TStreamerElement;
0031 class TStreamerBasicType;
0032 class TClassStreamer;
0033 class TVirtualArray;
0034 namespace ROOT { namespace Detail { class TCollectionProxyInfo; } }
0035 namespace ROOT { class TSchemaRule; }
0036 
0037 namespace TStreamerInfoActions { class TActionSequence; }
0038 
0039 class TStreamerInfo : public TVirtualStreamerInfo {
0040 
0041    class TCompInfo {
0042    // Class used to cache information (see fComp)
0043    private:
0044       // TCompInfo(const TCompInfo&) = default;
0045       // TCompInfo& operator=(const TCompInfo&) = default;
0046    public:
0047       Int_t             fType;
0048       Int_t             fNewType;
0049       Int_t             fOffset;
0050       Int_t             fLength;
0051       TStreamerElement *fElem;     ///< Not Owned
0052       ULongptr_t        fMethod;
0053       TClass           *fClass;    ///< Not Owned
0054       TClass           *fNewClass; ///< Not Owned
0055       TString           fClassName;
0056       TMemberStreamer  *fStreamer; ///< Not Owned
0057       TCompInfo() : fType(-1), fNewType(0), fOffset(0), fLength(0), fElem(nullptr), fMethod(0),
0058                     fClass(nullptr), fNewClass(nullptr), fClassName(), fStreamer(nullptr) {}
0059       ~TCompInfo() {}
0060       void Update(const TClass *oldcl, TClass *newcl);
0061    };
0062    friend class TStreamerInfoActions::TActionSequence;
0063 
0064 public:
0065    // make the opaque pointer public.
0066    typedef TCompInfo TCompInfo_t;
0067 
0068 protected:
0069    //---------------------------------------------------------------------------
0070    // Adapter class used to handle streaming collection of pointers
0071    //---------------------------------------------------------------------------
0072    class TPointerCollectionAdapter
0073    {
0074    public:
0075       TPointerCollectionAdapter( TVirtualCollectionProxy *proxy ):
0076          fProxy( proxy ) {}
0077 
0078       char* operator[]( UInt_t idx ) const
0079       {
0080          char **el = (char**)fProxy->At(idx);
0081          return *el;
0082       }
0083    private:
0084       TVirtualCollectionProxy *fProxy;
0085    };
0086 
0087 private:
0088    UInt_t            fCheckSum;          ///<Checksum of original class
0089    Int_t             fClassVersion;      ///<Class version identifier
0090    Int_t             fOnFileClassVersion;///<!Class version identifier as stored on file.
0091    Int_t             fNumber;            ///<!Unique identifier
0092    Int_t             fSize;              ///<!size of the persistent class
0093    size_t            fAlignment;         ///<!alignment of the memory representation of the class
0094    Int_t             fNdata;             ///<!number of optimized elements
0095    Int_t             fNfulldata;         ///<!number of elements
0096    Int_t             fNslots;            ///<!total number of slots in fComp.
0097    TCompInfo        *fComp;              ///<![fNslots with less than fElements->GetEntries()*1.5 used] Compiled info
0098    TCompInfo       **fCompOpt;           ///<![fNdata]
0099    TCompInfo       **fCompFull;          ///<![fElements->GetEntries()]
0100    TClass           *fClass;             ///<!pointer to class
0101    TObjArray        *fElements;          ///<Array of TStreamerElements
0102    Version_t         fOldVersion;        ///<! Version of the TStreamerInfo object read from the file
0103    Int_t             fNVirtualInfoLoc;   ///<! Number of virtual info location to update.
0104    ULong_t          *fVirtualInfoLoc;    ///<![fNVirtualInfoLoc] Location of the pointer to the TStreamerInfo inside the object (when emulated)
0105    TStreamerInfoActions::TActionSequence *fReadObjectWise;        ///<! List of read action resulting from the compilation.
0106    TStreamerInfoActions::TActionSequence *fReadMemberWise;        ///<! List of read action resulting from the compilation for use in member wise streaming.
0107    TStreamerInfoActions::TActionSequence *fReadMemberWiseVecPtr;  ///<! List of read action resulting from the compilation for use in member wise streaming.
0108    TStreamerInfoActions::TActionSequence *fReadText;              ///<! List of text read action resulting from the compilation, used for JSON.
0109    TStreamerInfoActions::TActionSequence *fWriteObjectWise;       ///<! List of write action resulting from the compilation.
0110    TStreamerInfoActions::TActionSequence *fWriteMemberWise;       ///<! List of write action resulting from the compilation for use in member wise streaming.
0111    TStreamerInfoActions::TActionSequence *fWriteMemberWiseVecPtr; ///<! List of write action resulting from the compilation for use in member wise streaming.
0112    TStreamerInfoActions::TActionSequence *fWriteText;             ///<! List of text write action resulting for the compilation, used for JSON.
0113 
0114    static std::atomic<Int_t>             fgCount;     ///<Number of TStreamerInfo instances
0115 
0116    template <typename T> static T GetTypedValueAux(Int_t type, void *ladd, int k, Int_t len);
0117    static void       PrintValueAux(char *ladd, Int_t atype, TStreamerElement * aElement, Int_t aleng, Int_t *count);
0118 
0119    UInt_t            GenerateIncludes(FILE *fp, char *inclist, const TList *extrainfos);
0120    void              GenerateDeclaration(FILE *fp, FILE *sfp, const TList *subClasses, Bool_t top = kTRUE);
0121    void              InsertArtificialElements(std::vector<const ROOT::TSchemaRule*> &rules);
0122    void              DestructorImpl(void* p, Bool_t dtorOnly);
0123 
0124 private:
0125    TStreamerInfo(const TStreamerInfo&) = delete;            // TStreamerInfo are not copiable.  Not Implemented.
0126    TStreamerInfo& operator=(const TStreamerInfo&) = delete; // TStreamerInfo are not copiable.  Not Implemented.
0127    void AddReadAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
0128    void AddWriteAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
0129    void AddReadTextAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
0130    void AddWriteTextAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
0131    void AddReadMemberWiseVecPtrAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
0132    void AddWriteMemberWiseVecPtrAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
0133 
0134 public:
0135 
0136    /// Status bits
0137    /// See TVirtualStreamerInfo::EStatusBits for the values.
0138 
0139    /// EReadWrite Enumerator
0140    /// See TVirtualStreamerInfo::EReadWrite for documentation and values.
0141 
0142    TStreamerInfo();
0143    TStreamerInfo(TClass *cl);
0144               ~TStreamerInfo() override;
0145    void                Build(Bool_t isTransient = kFALSE) override;
0146    void                BuildCheck(TFile *file = nullptr, Bool_t load = kTRUE) override;
0147    void                BuildEmulated(TFile *file) override;
0148    void                BuildOld() override;
0149    Bool_t              BuildFor( const TClass *cl ) override;
0150    void                CallShowMembers(const void* obj, TMemberInspector &insp, Bool_t isTransient) const override;
0151    void                Clear(Option_t * = "") override;
0152    TObject            *Clone(const char *newname = "") const override;
0153    Bool_t              CompareContent(TClass *cl,TVirtualStreamerInfo *info, Bool_t warn, Bool_t complete, TFile *file) override;
0154    void                Compile() override;
0155    void                ComputeSize();
0156    void                ForceWriteInfo(TFile *file, Bool_t force = kFALSE) override;
0157    Int_t               GenerateHeaderFile(const char *dirname, const TList *subClasses = nullptr, const TList *extrainfos = nullptr) override;
0158    TClass             *GetActualClass(const void *obj) const override;
0159    size_t              GetClassAlignment() const override { return fAlignment; }
0160    TClass             *GetClass() const override { return fClass; }
0161    UInt_t              GetCheckSum() const override { return fCheckSum; }
0162    UInt_t              GetCheckSum(TClass::ECheckSum code) const;
0163    Int_t               GetClassVersion() const override { return fClassVersion; }
0164    Int_t               GetDataMemberOffset(TDataMember *dm, TMemberStreamer *&streamer) const;
0165    TObjArray          *GetElements() const override {return fElements;}
0166    TStreamerElement   *GetElem(Int_t id) const override { return fComp[id].fElem; }  // Return the element for the list of optimized elements (max GetNdata())
0167    TStreamerElement   *GetElement(Int_t id) const override {return (TStreamerElement*)fElements->At(id);} // Return the element for the complete list of elements (max GetElements()->GetEntries())
0168    Int_t               GetElementOffset(Int_t id) const override {return fCompFull[id]->fOffset;}
0169    TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Bool_t forCollection) { return forCollection ? fReadMemberWiseVecPtr : fReadMemberWise; }
0170    TStreamerInfoActions::TActionSequence *GetReadObjectWiseActions() { return fReadObjectWise; }
0171    TStreamerInfoActions::TActionSequence *GetReadTextActions() { return fReadText; }
0172    TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions(Bool_t forCollection) { return forCollection ? fWriteMemberWiseVecPtr : fWriteMemberWise; }
0173    TStreamerInfoActions::TActionSequence *GetWriteObjectWiseActions() { return fWriteObjectWise; }
0174    TStreamerInfoActions::TActionSequence *GetWriteTextActions() { return fWriteText; }
0175    Int_t               GetNdata()   const {return fNdata;}
0176    Int_t               GetNelement() const { return fElements->GetEntriesFast(); }
0177    Int_t               GetNumber()  const override { return fNumber; }
0178    Int_t               GetLength(Int_t id) const {return fComp[id].fLength;}
0179    ULongptr_t          GetMethod(Int_t id) const {return fComp[id].fMethod;}
0180    Int_t               GetNewType(Int_t id) const {return fComp[id].fNewType;}
0181    Int_t               GetOffset(const char *) const override;
0182    Int_t               GetOffset(Int_t id) const override {return fComp[id].fOffset;}
0183    Version_t           GetOldVersion() const override {return fOldVersion;}
0184    Int_t               GetOnFileClassVersion() const override {return fOnFileClassVersion;}
0185    Int_t               GetSize() const override;
0186    Int_t               GetSizeElements() const;
0187    TStreamerElement   *GetStreamerElement(const char*datamember, Int_t& offset) const  override;
0188    TStreamerElement   *GetStreamerElementReal(Int_t i, Int_t j) const;
0189    Int_t               GetType(Int_t id)   const {return fComp[id].fType;}
0190    template <typename T> T GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const;
0191    template <typename T> T GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
0192    template <typename T> T GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
0193    template <typename T> T GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
0194    Double_t            GetValue(char *pointer, Int_t i, Int_t j, Int_t len) const { return GetTypedValue<Double_t>(pointer, i, j, len); }
0195    Double_t            GetValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const { return GetTypedValueClones<Double_t>(clones, i, j, k, eoffset); }
0196    Double_t            GetValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const { return GetTypedValueSTL<Double_t>(cont, i, j, k, eoffset); }
0197    Double_t            GetValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const { return GetTypedValueSTLP<Double_t>(cont, i, j, k, eoffset); }
0198    void                ls(Option_t *option="") const override;
0199    Bool_t              MatchLegacyCheckSum(UInt_t checksum) const;
0200    TVirtualStreamerInfo *NewInfo(TClass *cl) override { return new TStreamerInfo(cl); }
0201    void               *New(void *obj = nullptr) override;
0202    void               *NewArray(Long_t nElements, void* ary = nullptr) override;
0203    void                Destructor(void* p, Bool_t dtorOnly = kFALSE) override;
0204    void                DeleteArray(void* p, Bool_t dtorOnly = kFALSE) override;
0205    void                PrintValue(const char *name, char *pointer, Int_t i, Int_t len, Int_t lenmax=1000) const;
0206    void                PrintValueClones(const char *name, TClonesArray *clones, Int_t i, Int_t eoffset, Int_t lenmax=1000) const;
0207    void                PrintValueSTL(const char *name, TVirtualCollectionProxy *cont, Int_t i, Int_t eoffset, Int_t lenmax=1000) const;
0208 
0209    template <class T>
0210    Int_t               ReadBuffer(TBuffer &b, const T &arrptr, TCompInfo *const*const compinfo, Int_t first, Int_t last, Int_t narr=1,Int_t eoffset=0,Int_t mode=0);
0211    template <class T>
0212    Int_t               ReadBufferSkip(TBuffer &b, const T &arrptr, const TCompInfo *compinfo,Int_t kase, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
0213    template <class T>
0214    Int_t               ReadBufferConv(TBuffer &b, const T &arrptr, const TCompInfo *compinfo,Int_t kase, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
0215    template <class T>
0216    Int_t               ReadBufferArtificial(TBuffer &b, const T &arrptr, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
0217 
0218    Int_t               ReadBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset);
0219    Int_t               ReadBufferSTL(TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t eoffset, Bool_t v7 = kTRUE );
0220    void                SetCheckSum(UInt_t checksum) override { fCheckSum = checksum; }
0221    void                SetClass(TClass *cl) override;
0222    void                SetClassVersion(Int_t vers) override { fClassVersion = vers; }
0223    void                SetOnFileClassVersion(Int_t vers) { fOnFileClassVersion = vers; }
0224    void                TagFile(TFile *fFile) override;
0225 private:
0226    // Try to remove those functions from the public interface.
0227    Int_t               WriteBuffer(TBuffer &b, char *pointer, Int_t first);
0228    Int_t               WriteBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset);
0229    Int_t               WriteBufferSTL   (TBuffer &b, TVirtualCollectionProxy *cont,   Int_t nc);
0230    Int_t               WriteBufferSTLPtrs( TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t first, Int_t eoffset);
0231 public:
0232    void                Update(const TClass *oldClass, TClass *newClass) override;
0233 
0234    /// \brief Generate the TClass and TStreamerInfo for the requested pair.
0235    /// This creates a TVirtualStreamerInfo for the pair and trigger the BuildCheck/Old to
0236    /// provokes the creation of the corresponding TClass.  This relies on the dictionary for
0237    /// std::pair<const int, int> to already exist (or the interpreter information being available)
0238    /// as it is used as a template.
0239    /// \note The returned object is owned by the caller.
0240    TVirtualStreamerInfo *GenerateInfoForPair(const std::string &pairclassname, bool silent, size_t hint_pair_offset, size_t hint_pair_size) override;
0241    TVirtualStreamerInfo *GenerateInfoForPair(const std::string &firstname, const std::string &secondname, bool silent, size_t hint_pair_offset, size_t hint_pair_size) override;
0242 
0243    TVirtualCollectionProxy *GenEmulatedProxy(const char* class_name, Bool_t silent) override;
0244    TClassStreamer *GenEmulatedClassStreamer(const char* class_name, Bool_t silent) override;
0245    TVirtualCollectionProxy *GenExplicitProxy(const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl) override;
0246    TClassStreamer *GenExplicitClassStreamer(const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl) override;
0247 
0248    static TStreamerElement   *GetCurrentElement();
0249 
0250 public:
0251    // For access by the StreamerInfoActions.
0252    template <class T>
0253    Int_t               WriteBufferAux      (TBuffer &b, const T &arr, TCompInfo *const*const compinfo, Int_t first, Int_t last, Int_t narr,Int_t eoffset,Int_t mode);
0254 
0255    //WARNING this class version must be the same as TVirtualStreamerInfo
0256    ClassDefOverride(TStreamerInfo, 10) // Streamer information for one class version
0257 };
0258 
0259 
0260 #endif