Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:11

0001 // @(#)root/io
0002 // Author: Rene Brun   28/12/94
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_TKey
0013 #define ROOT_TKey
0014 
0015 #include "TNamed.h"
0016 #include "TDatime.h"
0017 #include "TClass.h"
0018 #ifdef R__LESS_INCLUDES
0019 class TBuffer;
0020 #else
0021 #include "TBuffer.h"
0022 #endif
0023 
0024 class TBrowser;
0025 class TDirectory;
0026 class TFile;
0027 
0028 class TKey : public TNamed {
0029 
0030 private:
0031    enum EStatusBits {
0032       kIsDirectoryFile = BIT(14),
0033       kReproducible = BIT(15)
0034    };
0035    TKey(const TKey&) = delete;            // TKey objects are not copiable.
0036    TKey& operator=(const TKey&) = delete; // TKey objects are not copiable.
0037 
0038 protected:
0039    Int_t       fVersion;     ///< Key version identifier
0040    Int_t       fNbytes;      ///< Number of bytes for the object on file
0041    Int_t       fObjlen;      ///< Length of uncompressed object in bytes
0042    TDatime     fDatime;      ///< Date/Time of insertion in file
0043    Short_t     fKeylen;      ///< Number of bytes for the key itself
0044    Short_t     fCycle;       ///< Cycle number
0045    Long64_t    fSeekKey;     ///< Location of object on file
0046    Long64_t    fSeekPdir;    ///< Location of parent directory on file
0047    TString     fClassName;   ///< Object Class name
0048    Int_t       fLeft;        ///< Number of bytes left in current segment
0049    char       *fBuffer;      ///< Object buffer
0050    TBuffer    *fBufferRef;   ///< Pointer to the TBuffer object
0051    UShort_t    fPidOffset;   ///<!Offset to be added to the pid index in this key/buffer.  This is actually saved in the high bits of fSeekPdir
0052    TDirectory *fMotherDir;   ///<!pointer to mother directory
0053 
0054            Int_t    Read(const char *name) override { return TObject::Read(name); }
0055    virtual void     Create(Int_t nbytes, TFile* f = nullptr);
0056            void     Build(TDirectory* motherDir, const char* classname, Long64_t filepos);
0057            void     Reset(); // Currently only for the use of TBasket.
0058    virtual Int_t    WriteFileKeepBuffer(TFile *f = nullptr);
0059 
0060  public:
0061    TKey();
0062    TKey(TDirectory* motherDir);
0063    TKey(TDirectory* motherDir, const TKey &orig, UShort_t pidOffset);
0064    TKey(const char *name, const char *title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
0065    TKey(const TString &name, const TString &title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
0066    TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* motherDir);
0067    TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, TDirectory* motherDir);
0068    TKey(Long64_t pointer, Int_t nbytes, TDirectory* motherDir = nullptr);
0069    ~TKey() override;
0070 
0071            void        Browse(TBrowser *b) override;
0072            void        Delete(Option_t *option="") override;
0073    virtual void        DeleteBuffer();
0074            void        FillBuffer(char *&buffer) override;
0075    virtual const char *GetClassName() const {return fClassName.Data();}
0076            const char *GetIconName() const override;
0077            const char *GetTitle() const override;
0078    virtual char       *GetBuffer() const {return fBuffer+fKeylen;}
0079            TBuffer    *GetBufferRef() const {return fBufferRef;}
0080            Short_t     GetCycle() const;
0081    const   TDatime    &GetDatime() const   {return fDatime;}
0082            TFile      *GetFile() const;
0083            Short_t     GetKeep() const;
0084            Int_t       GetKeylen() const   {return fKeylen;}
0085            TDirectory* GetMotherDir() const { return fMotherDir; }
0086            Int_t       GetNbytes() const   {return fNbytes;}
0087            Int_t       GetObjlen() const   {return fObjlen;}
0088            Int_t       GetVersion() const  {return fVersion;}
0089    virtual Long64_t    GetSeekKey() const  {return fSeekKey;}
0090    virtual Long64_t    GetSeekPdir() const {return fSeekPdir;}
0091    virtual void        IncrementPidOffset(UShort_t offset);
0092            Bool_t      IsFolder() const override;
0093    virtual void        Keep();
0094    virtual void        ls(Bool_t current) const;
0095            void        ls(Option_t *option="") const override;
0096            void        Print(Option_t *option="") const override;
0097    virtual Int_t       Read(TObject *obj);
0098    virtual TObject    *ReadObj();
0099    virtual TObject    *ReadObjWithBuffer(char *bufferRead);
0100    /// To read an object (non deriving from TObject) from the file.
0101    /// This is more user friendly version of TKey::ReadObjectAny.
0102    /// See TKey::ReadObjectAny for more details.
0103    template <typename T> T *ReadObject() {
0104       return reinterpret_cast<T*>(ReadObjectAny(TClass::GetClass<T>()));
0105    }
0106    virtual void       *ReadObjectAny(const TClass *expectedClass);
0107    virtual void        ReadBuffer(char *&buffer);
0108            void        ReadKeyBuffer(char *&buffer);
0109    virtual Bool_t      ReadFile();
0110    virtual void        SetBuffer() { DeleteBuffer(); fBuffer = new char[fNbytes];}
0111    virtual void        SetParent(const TObject *parent);
0112            void        SetMotherDir(TDirectory* dir) { fMotherDir = dir; }
0113            Int_t       Sizeof() const override;
0114    virtual Int_t       WriteFile(Int_t cycle = 1, TFile* f = nullptr);
0115 
0116    ClassDefOverride(TKey,4); //Header description of a logical record on file.
0117 };
0118 
0119 #endif