Back to home page

EIC code displayed by LXR

 
 

    


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

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    Int_t             fNdata;             ///<!number of optimized elements
0094    Int_t             fNfulldata;         ///<!number of elements
0095    Int_t             fNslots;            ///<!total number of slots in fComp.
0096    TCompInfo        *fComp;              ///<![fNslots with less than fElements->GetEntries()*1.5 used] Compiled info
0097    TCompInfo       **fCompOpt;           ///<![fNdata]
0098    TCompInfo       **fCompFull;          ///<![fElements->GetEntries()]
0099    TClass           *fClass;             ///<!pointer to class
0100    TObjArray        *fElements;          ///<Array of TStreamerElements
0101    Version_t         fOldVersion;        ///<! Version of the TStreamerInfo object read from the file
0102    Int_t             fNVirtualInfoLoc;   ///<! Number of virtual info location to update.
0103    ULong_t          *fVirtualInfoLoc;    ///<![fNVirtualInfoLoc] Location of the pointer to the TStreamerInfo inside the object (when emulated)
0104    TStreamerInfoActions::TActionSequence *fReadObjectWise;        ///<! List of read action resulting from the compilation.
0105    TStreamerInfoActions::TActionSequence *fReadMemberWise;        ///<! List of read action resulting from the compilation for use in member wise streaming.
0106    TStreamerInfoActions::TActionSequence *fReadMemberWiseVecPtr;  ///<! List of read action resulting from the compilation for use in member wise streaming.
0107    TStreamerInfoActions::TActionSequence *fReadText;              ///<! List of text read action resulting from the compilation, used for JSON.
0108    TStreamerInfoActions::TActionSequence *fWriteObjectWise;       ///<! List of write action resulting from the compilation.
0109    TStreamerInfoActions::TActionSequence *fWriteMemberWise;       ///<! List of write action resulting from the compilation for use in member wise streaming.
0110    TStreamerInfoActions::TActionSequence *fWriteMemberWiseVecPtr; ///<! List of write action resulting from the compilation for use in member wise streaming.
0111    TStreamerInfoActions::TActionSequence *fWriteText;             ///<! List of text write action resulting for the compilation, used for JSON.
0112 
0113    static std::atomic<Int_t>             fgCount;     ///<Number of TStreamerInfo instances
0114 
0115    template <typename T> static T GetTypedValueAux(Int_t type, void *ladd, int k, Int_t len);
0116    static void       PrintValueAux(char *ladd, Int_t atype, TStreamerElement * aElement, Int_t aleng, Int_t *count);
0117 
0118    UInt_t            GenerateIncludes(FILE *fp, char *inclist, const TList *extrainfos);
0119    void              GenerateDeclaration(FILE *fp, FILE *sfp, const TList *subClasses, Bool_t top = kTRUE);
0120    void              InsertArtificialElements(std::vector<const ROOT::TSchemaRule*> &rules);
0121    void              DestructorImpl(void* p, Bool_t dtorOnly);
0122 
0123 private:
0124    TStreamerInfo(const TStreamerInfo&) = delete;            // TStreamerInfo are not copiable.  Not Implemented.
0125    TStreamerInfo& operator=(const TStreamerInfo&) = delete; // TStreamerInfo are not copiable.  Not Implemented.
0126    void AddReadAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
0127    void AddWriteAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
0128    void AddReadTextAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
0129    void AddWriteTextAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
0130    void AddReadMemberWiseVecPtrAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
0131    void AddWriteMemberWiseVecPtrAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
0132 
0133 public:
0134 
0135    /// Status bits
0136    /// See TVirtualStreamerInfo::EStatusBits for the values.
0137 
0138    /// EReadWrite Enumerator
0139    /// | Enum Constant | Description   |
0140    /// |-------------|--------------------|
0141    /// | kBase       | Base class element |
0142    /// | kOffsetL    | Fixed size array |
0143    /// | kOffsetP    | Pointer to object |
0144    /// | kCounter    | Counter for array size |
0145    /// | kCharStar   | Pointer to array of char |
0146    /// | kLegacyChar | Equal to TDataType's kchar |
0147    /// | kBits       | TObject::fBits in case of a referenced object |
0148    /// | kObject     | Class  derived from TObject, or for TStreamerSTL::fCtype non-pointer elements |
0149    /// | kObjectp    | Class* derived from TObject and with    comment field //->Class, or for TStreamerSTL::fCtype: pointer elements |
0150    /// | kObjectP    | Class* derived from TObject and with NO comment field //->Class |
0151    /// | kAny        | Class  not derived from TObject |
0152    /// | kAnyp       | Class* not derived from TObject with    comment field //->Class |
0153    /// | kAnyP       | Class* not derived from TObject with NO comment field //->Class |
0154    /// | kAnyPnoVT   | Class* not derived from TObject with NO comment field //->Class and Class has NO virtual table |
0155    /// | kSTLp       | Pointer to STL container |
0156    /// | kTString    | TString, special case |
0157    /// | kTObject    | TObject, special case |
0158    /// | kTNamed     | TNamed , special case |
0159    /// | kCache      | Cache the value in memory than is not part of the object but is accessible via a SchemaRule |
0160    enum EReadWrite {
0161       kBase        =  0,  kOffsetL = 20,  kOffsetP = 40,  kCounter =  6,  kCharStar = 7,
0162       kChar        =  1,  kShort   =  2,  kInt     =  3,  kLong    =  4,  kFloat    = 5,
0163       kDouble      =  8,  kDouble32=  9,
0164       kLegacyChar  = 10, /// Equal to TDataType's kchar
0165       kUChar       = 11,  kUShort  = 12,  kUInt    = 13,  kULong   = 14,  kBits     = 15,
0166       kLong64      = 16,  kULong64 = 17,  kBool    = 18,  kFloat16 = 19,
0167       kObject      = 61,  kAny     = 62,  kObjectp = 63,  kObjectP = 64,  kTString  = 65,
0168       kTObject     = 66,  kTNamed  = 67,  kAnyp    = 68,  kAnyP    = 69,  kAnyPnoVT = 70,
0169       kSTLp        = 71,
0170       kSkip        = 100, kSkipL = 120, kSkipP   = 140,
0171       kConv        = 200, kConvL = 220, kConvP   = 240,
0172       kSTL         = 300, kSTLstring = 365,
0173       kStreamer    = 500, kStreamLoop = 501,
0174       kCache       = 600,  /// Cache the value in memory than is not part of the object but is accessible via a SchemaRule
0175       kArtificial  = 1000,
0176       kCacheNew    = 1001,
0177       kCacheDelete = 1002,
0178       kNeedObjectForVirtualBaseClass = 99997,
0179       kMissing     = 99999
0180    };
0181 
0182    TStreamerInfo();
0183    TStreamerInfo(TClass *cl);
0184               ~TStreamerInfo() override;
0185    void                Build(Bool_t isTransient = kFALSE) override;
0186    void                BuildCheck(TFile *file = nullptr, Bool_t load = kTRUE) override;
0187    void                BuildEmulated(TFile *file) override;
0188    void                BuildOld() override;
0189    Bool_t              BuildFor( const TClass *cl ) override;
0190    void                CallShowMembers(const void* obj, TMemberInspector &insp, Bool_t isTransient) const override;
0191    void                Clear(Option_t * = "") override;
0192    TObject            *Clone(const char *newname = "") const override;
0193    Bool_t              CompareContent(TClass *cl,TVirtualStreamerInfo *info, Bool_t warn, Bool_t complete, TFile *file) override;
0194    void                Compile() override;
0195    void                ComputeSize();
0196    void                ForceWriteInfo(TFile *file, Bool_t force = kFALSE) override;
0197    Int_t               GenerateHeaderFile(const char *dirname, const TList *subClasses = nullptr, const TList *extrainfos = nullptr) override;
0198    TClass             *GetActualClass(const void *obj) const override;
0199    TClass             *GetClass() const override { return fClass; }
0200    UInt_t              GetCheckSum() const override { return fCheckSum; }
0201    UInt_t              GetCheckSum(TClass::ECheckSum code) const;
0202    Int_t               GetClassVersion() const override { return fClassVersion; }
0203    Int_t               GetDataMemberOffset(TDataMember *dm, TMemberStreamer *&streamer) const;
0204    TObjArray          *GetElements() const override {return fElements;}
0205    TStreamerElement   *GetElem(Int_t id) const override { return fComp[id].fElem; }  // Return the element for the list of optimized elements (max GetNdata())
0206    TStreamerElement   *GetElement(Int_t id) const override {return (TStreamerElement*)fElements->At(id);} // Return the element for the complete list of elements (max GetElements()->GetEntries())
0207    Int_t               GetElementOffset(Int_t id) const override {return fCompFull[id]->fOffset;}
0208    TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Bool_t forCollection) { return forCollection ? fReadMemberWiseVecPtr : fReadMemberWise; }
0209    TStreamerInfoActions::TActionSequence *GetReadObjectWiseActions() { return fReadObjectWise; }
0210    TStreamerInfoActions::TActionSequence *GetReadTextActions() { return fReadText; }
0211    TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions(Bool_t forCollection) { return forCollection ? fWriteMemberWiseVecPtr : fWriteMemberWise; }
0212    TStreamerInfoActions::TActionSequence *GetWriteObjectWiseActions() { return fWriteObjectWise; }
0213    TStreamerInfoActions::TActionSequence *GetWriteTextActions() { return fWriteText; }
0214    Int_t               GetNdata()   const {return fNdata;}
0215    Int_t               GetNelement() const { return fElements->GetEntriesFast(); }
0216    Int_t               GetNumber()  const override { return fNumber; }
0217    Int_t               GetLength(Int_t id) const {return fComp[id].fLength;}
0218    ULongptr_t          GetMethod(Int_t id) const {return fComp[id].fMethod;}
0219    Int_t               GetNewType(Int_t id) const {return fComp[id].fNewType;}
0220    Int_t               GetOffset(const char *) const override;
0221    Int_t               GetOffset(Int_t id) const override {return fComp[id].fOffset;}
0222    Version_t           GetOldVersion() const override {return fOldVersion;}
0223    Int_t               GetOnFileClassVersion() const override {return fOnFileClassVersion;}
0224    Int_t               GetSize() const override;
0225    Int_t               GetSizeElements() const;
0226    TStreamerElement   *GetStreamerElement(const char*datamember, Int_t& offset) const  override;
0227    TStreamerElement   *GetStreamerElementReal(Int_t i, Int_t j) const;
0228    Int_t               GetType(Int_t id)   const {return fComp[id].fType;}
0229    template <typename T> T GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const;
0230    template <typename T> T GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
0231    template <typename T> T GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
0232    template <typename T> T GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
0233    Double_t            GetValue(char *pointer, Int_t i, Int_t j, Int_t len) const { return GetTypedValue<Double_t>(pointer, i, j, len); }
0234    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); }
0235    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); }
0236    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); }
0237    void                ls(Option_t *option="") const override;
0238    Bool_t              MatchLegacyCheckSum(UInt_t checksum) const;
0239    TVirtualStreamerInfo *NewInfo(TClass *cl) override { return new TStreamerInfo(cl); }
0240    void               *New(void *obj = nullptr) override;
0241    void               *NewArray(Long_t nElements, void* ary = nullptr) override;
0242    void                Destructor(void* p, Bool_t dtorOnly = kFALSE) override;
0243    void                DeleteArray(void* p, Bool_t dtorOnly = kFALSE) override;
0244    void                PrintValue(const char *name, char *pointer, Int_t i, Int_t len, Int_t lenmax=1000) const;
0245    void                PrintValueClones(const char *name, TClonesArray *clones, Int_t i, Int_t eoffset, Int_t lenmax=1000) const;
0246    void                PrintValueSTL(const char *name, TVirtualCollectionProxy *cont, Int_t i, Int_t eoffset, Int_t lenmax=1000) const;
0247 
0248    template <class T>
0249    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);
0250    template <class T>
0251    Int_t               ReadBufferSkip(TBuffer &b, const T &arrptr, const TCompInfo *compinfo,Int_t kase, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
0252    template <class T>
0253    Int_t               ReadBufferConv(TBuffer &b, const T &arrptr, const TCompInfo *compinfo,Int_t kase, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
0254    template <class T>
0255    Int_t               ReadBufferArtificial(TBuffer &b, const T &arrptr, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
0256 
0257    Int_t               ReadBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset);
0258    Int_t               ReadBufferSTL(TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t eoffset, Bool_t v7 = kTRUE );
0259    void                SetCheckSum(UInt_t checksum) override { fCheckSum = checksum; }
0260    void                SetClass(TClass *cl) override;
0261    void                SetClassVersion(Int_t vers) override { fClassVersion = vers; }
0262    void                SetOnFileClassVersion(Int_t vers) { fOnFileClassVersion = vers; }
0263    void                TagFile(TFile *fFile) override;
0264 private:
0265    // Try to remove those functions from the public interface.
0266    Int_t               WriteBuffer(TBuffer &b, char *pointer, Int_t first);
0267    Int_t               WriteBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset);
0268    Int_t               WriteBufferSTL   (TBuffer &b, TVirtualCollectionProxy *cont,   Int_t nc);
0269    Int_t               WriteBufferSTLPtrs( TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t first, Int_t eoffset);
0270 public:
0271    void                Update(const TClass *oldClass, TClass *newClass) override;
0272 
0273    /// \brief Generate the TClass and TStreamerInfo for the requested pair.
0274    /// This creates a TVirtualStreamerInfo for the pair and trigger the BuildCheck/Old to
0275    /// provokes the creation of the corresponding TClass.  This relies on the dictionary for
0276    /// std::pair<const int, int> to already exist (or the interpreter information being available)
0277    /// as it is used as a template.
0278    /// \note The returned object is owned by the caller.
0279    TVirtualStreamerInfo *GenerateInfoForPair(const std::string &pairclassname, bool silent, size_t hint_pair_offset, size_t hint_pair_size) override;
0280    TVirtualStreamerInfo *GenerateInfoForPair(const std::string &firstname, const std::string &secondname, bool silent, size_t hint_pair_offset, size_t hint_pair_size) override;
0281 
0282    TVirtualCollectionProxy *GenEmulatedProxy(const char* class_name, Bool_t silent) override;
0283    TClassStreamer *GenEmulatedClassStreamer(const char* class_name, Bool_t silent) override;
0284    TVirtualCollectionProxy *GenExplicitProxy(const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl) override;
0285    TClassStreamer *GenExplicitClassStreamer(const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl) override;
0286 
0287    static TStreamerElement   *GetCurrentElement();
0288 
0289 public:
0290    // For access by the StreamerInfoActions.
0291    template <class T>
0292    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);
0293 
0294    //WARNING this class version must be the same as TVirtualStreamerInfo
0295    ClassDefOverride(TStreamerInfo,9)  //Streamer information for one class version
0296 };
0297 
0298 
0299 #endif