Logo ROOT  
Reference Guide
TKey.h
Go to the documentation of this file.
1 // @(#)root/io
2 // Author: Rene Brun 28/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TKey
13 #define ROOT_TKey
14 
15 #include "TNamed.h"
16 #include "TDatime.h"
17 #include "TClass.h"
18 #ifdef R__LESS_INCLUDES
19 class TBuffer;
20 #else
21 #include "TBuffer.h"
22 #endif
23 
24 class TBrowser;
25 class TDirectory;
26 class TFile;
27 
28 class TKey : public TNamed {
29 
30 private:
31  enum EStatusBits {
34  };
35  TKey(const TKey&) = delete; // TKey objects are not copiable.
36  TKey& operator=(const TKey&) = delete; // TKey objects are not copiable.
37 
38 protected:
39  Int_t fVersion; ///< Key version identifier
40  Int_t fNbytes; ///< Number of bytes for the object on file
41  Int_t fObjlen; ///< Length of uncompressed object in bytes
42  TDatime fDatime; ///< Date/Time of insertion in file
43  Short_t fKeylen; ///< Number of bytes for the key itself
44  Short_t fCycle; ///< Cycle number
45  Long64_t fSeekKey; ///< Location of object on file
46  Long64_t fSeekPdir; ///< Location of parent directory on file
47  TString fClassName; ///< Object Class name
48  Int_t fLeft; ///< Number of bytes left in current segment
49  char *fBuffer; ///< Object buffer
50  TBuffer *fBufferRef; ///< Pointer to the TBuffer object
51  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
52  TDirectory *fMotherDir; ///<!pointer to mother directory
53 
54  virtual Int_t Read(const char *name) { return TObject::Read(name); }
55  virtual void Create(Int_t nbytes, TFile* f = 0);
56  void Build(TDirectory* motherDir, const char* classname, Long64_t filepos);
57  virtual void Reset(); // Currently only for the use of TBasket.
58  virtual Int_t WriteFileKeepBuffer(TFile *f = 0);
59 
60 
61  public:
62  TKey();
63  TKey(TDirectory* motherDir);
64  TKey(TDirectory* motherDir, const TKey &orig, UShort_t pidOffset);
65  TKey(const char *name, const char *title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
66  TKey(const TString &name, const TString &title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
67  TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* motherDir);
68  TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, TDirectory* motherDir);
69  TKey(Long64_t pointer, Int_t nbytes, TDirectory* motherDir = 0);
70  virtual ~TKey();
71 
72  virtual void Browse(TBrowser *b);
73  virtual void Delete(Option_t *option="");
74  virtual void DeleteBuffer();
75  virtual void FillBuffer(char *&buffer);
76  virtual const char *GetClassName() const {return fClassName.Data();}
77  virtual const char *GetIconName() const;
78  virtual const char *GetTitle() const;
79  virtual char *GetBuffer() const {return fBuffer+fKeylen;}
80  TBuffer *GetBufferRef() const {return fBufferRef;}
81  Short_t GetCycle() const;
82  const TDatime &GetDatime() const {return fDatime;}
83  TFile *GetFile() const;
84  Short_t GetKeep() const;
85  Int_t GetKeylen() const {return fKeylen;}
86  TDirectory* GetMotherDir() const { return fMotherDir; }
87  Int_t GetNbytes() const {return fNbytes;}
88  Int_t GetObjlen() const {return fObjlen;}
89  Int_t GetVersion() const {return fVersion;}
90  virtual Long64_t GetSeekKey() const {return fSeekKey;}
91  virtual Long64_t GetSeekPdir() const {return fSeekPdir;}
92  virtual void IncrementPidOffset(UShort_t offset);
93  Bool_t IsFolder() const;
94  virtual void Keep();
95  virtual void ls(Bool_t current) const;
96  virtual void ls(Option_t *option="") const;
97  virtual void Print(Option_t *option="") const;
98  virtual Int_t Read(TObject *obj);
99  virtual TObject *ReadObj();
100  virtual TObject *ReadObjWithBuffer(char *bufferRead);
101  /// To read an object (non deriving from TObject) from the file.
102  /// This is more user friendly version of TKey::ReadObjectAny.
103  /// See TKey::ReadObjectAny for more details.
104  template <typename T> T *ReadObject() {
105  return reinterpret_cast<T*>(ReadObjectAny(TClass::GetClass<T>()));
106  }
107  virtual void *ReadObjectAny(const TClass *expectedClass);
108  virtual void ReadBuffer(char *&buffer);
109  void ReadKeyBuffer(char *&buffer);
110  virtual Bool_t ReadFile();
111  virtual void SetBuffer() { DeleteBuffer(); fBuffer = new char[fNbytes];}
112  virtual void SetParent(const TObject *parent);
113  void SetMotherDir(TDirectory* dir) { fMotherDir = dir; }
114  virtual Int_t Sizeof() const;
115  virtual Int_t WriteFile(Int_t cycle=1, TFile* f = 0);
116 
117  ClassDef(TKey,4); //Header description of a logical record on file.
118 };
119 
120 #endif
TKey::GetKeylen
Int_t GetKeylen() const
Definition: TKey.h:85
TBrowser
Definition: TBrowser.h:37
TKey::fLeft
Int_t fLeft
Number of bytes left in current segment.
Definition: TKey.h:48
TKey::ls
virtual void ls(Bool_t current) const
List Key contents.
Definition: TKey.cxx:694
f
#define f(i)
Definition: RSha256.hxx:122
TKey::GetVersion
Int_t GetVersion() const
Definition: TKey.h:89
TKey::GetKeep
Short_t GetKeep() const
Returns the "KEEP" status.
Definition: TKey.cxx:593
UShort_t
unsigned short UShort_t
Definition: RtypesCore.h:40
TKey::fVersion
Int_t fVersion
Key version identifier.
Definition: TKey.h:39
TString::Data
const char * Data() const
Definition: TString.h:369
TKey::ReadObjectAny
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
Definition: TKey.cxx:1015
TKey::GetMotherDir
TDirectory * GetMotherDir() const
Definition: TKey.h:86
TKey::GetBuffer
virtual char * GetBuffer() const
Definition: TKey.h:79
TKey::fPidOffset
UShort_t fPidOffset
!Offset to be added to the pid index in this key/buffer. This is actually saved in the high bits of f...
Definition: TKey.h:51
TKey::TKey
TKey()
TKey default constructor.
Definition: TKey.cxx:90
TDatime.h
TKey::DeleteBuffer
virtual void DeleteBuffer()
Delete key buffer(s).
Definition: TKey.cxx:559
TNamed.h
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TKey::SetBuffer
virtual void SetBuffer()
Definition: TKey.h:111
TKey::fSeekPdir
Long64_t fSeekPdir
Location of parent directory on file.
Definition: TKey.h:46
TKey::GetObjlen
Int_t GetObjlen() const
Definition: TKey.h:88
Int_t
int Int_t
Definition: RtypesCore.h:45
TKey::WriteFile
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
Write the encoded object supported by this key.
Definition: TKey.cxx:1450
TClass.h
TKey::fMotherDir
TDirectory * fMotherDir
!pointer to mother directory
Definition: TKey.h:52
TKey::fBuffer
char * fBuffer
Object buffer.
Definition: TKey.h:49
TBuffer
Definition: TBuffer.h:43
TKey::FillBuffer
virtual void FillBuffer(char *&buffer)
Encode key header into output buffer.
Definition: TKey.cxx:601
TKey::GetBufferRef
TBuffer * GetBufferRef() const
Definition: TKey.h:80
TKey::fBufferRef
TBuffer * fBufferRef
Pointer to the TBuffer object.
Definition: TKey.h:50
TKey::Browse
virtual void Browse(TBrowser *b)
Read object from disk and call its Browse() method.
Definition: TKey.cxx:427
TKey::GetSeekPdir
virtual Long64_t GetSeekPdir() const
Definition: TKey.h:91
TKey::Build
void Build(TDirectory *motherDir, const char *classname, Long64_t filepos)
Method used in all TKey constructor to initialize basic data fields.
Definition: TKey.cxx:389
TString
Definition: TString.h:136
TKey::ReadFile
virtual Bool_t ReadFile()
Read the key structure from the file.
Definition: TKey.cxx:1265
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
b
#define b(i)
Definition: RSha256.hxx:118
TKey::Print
virtual void Print(Option_t *option="") const
Print key contents.
Definition: TKey.cxx:714
TKey::kReproducible
@ kReproducible
Definition: TKey.h:33
TKey::Sizeof
virtual Int_t Sizeof() const
Return the size in bytes of the key header structure.
Definition: TKey.cxx:1336
TKey::SetMotherDir
void SetMotherDir(TDirectory *dir)
Definition: TKey.h:113
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TBuffer.h
TKey::operator=
TKey & operator=(const TKey &)=delete
TKey::GetClassName
virtual const char * GetClassName() const
Definition: TKey.h:76
TKey::ReadBuffer
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
Definition: TKey.cxx:1210
TKey::GetFile
TFile * GetFile() const
Returns file to which key belong.
Definition: TKey.cxx:585
TNamed
Definition: TNamed.h:29
TKey::fClassName
TString fClassName
Object Class name.
Definition: TKey.h:47
TKey::Delete
virtual void Delete(Option_t *option="")
Delete an object from the file.
Definition: TKey.cxx:538
BIT
#define BIT(n)
Definition: Rtypes.h:85
TKey::IsFolder
Bool_t IsFolder() const
Check if object referenced by the key is a folder.
Definition: TKey.cxx:664
Short_t
short Short_t
Definition: RtypesCore.h:39
TKey::IncrementPidOffset
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by 'offset'.
Definition: TKey.cxx:650
TObject::Read
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:564
TFile
Definition: TFile.h:54
TKey::ReadObjWithBuffer
virtual TObject * ReadObjWithBuffer(char *bufferRead)
To read a TObject* from bufferRead.
Definition: TKey.cxx:884
TKey::fKeylen
Short_t fKeylen
Number of bytes for the key itself.
Definition: TKey.h:43
TKey::SetParent
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
Definition: TKey.cxx:1294
TKey::GetIconName
virtual const char * GetIconName() const
Title can keep 32x32 xpm thumbnail/icon of the parent object.
Definition: TKey.cxx:1524
TKey
Definition: TKey.h:28
TKey::GetSeekKey
virtual Long64_t GetSeekKey() const
Definition: TKey.h:90
TKey::ReadObj
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:750
TKey::fDatime
TDatime fDatime
Date/Time of insertion in file.
Definition: TKey.h:42
TKey::fCycle
Short_t fCycle
Cycle number.
Definition: TKey.h:44
TKey::WriteFileKeepBuffer
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
Definition: TKey.cxx:1491
TKey::Reset
virtual void Reset()
Reset the key as it had not been 'filled' yet.
Definition: TKey.cxx:1302
TKey::ReadObject
T * ReadObject()
To read an object (non deriving from TObject) from the file.
Definition: TKey.h:104
TKey::GetDatime
const TDatime & GetDatime() const
Definition: TKey.h:82
TKey::fNbytes
Int_t fNbytes
Number of bytes for the object on file.
Definition: TKey.h:40
TKey::~TKey
virtual ~TKey()
TKey default destructor.
Definition: TKey.cxx:525
TClass
Definition: TClass.h:80
TObject
Definition: TObject.h:37
TKey::GetCycle
Short_t GetCycle() const
Return cycle number associated to this key.
Definition: TKey.cxx:577
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TKey::fObjlen
Int_t fObjlen
Length of uncompressed object in bytes.
Definition: TKey.h:41
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
TDirectory
Definition: TDirectory.h:40
TKey::GetTitle
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition: TKey.cxx:1532
TDatime
Definition: TDatime.h:37
TKey::Keep
virtual void Keep()
Set the "KEEP" status.
Definition: TKey.cxx:685
TKey::Read
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TKey.h:54
TKey::fSeekKey
Long64_t fSeekKey
Location of object on file.
Definition: TKey.h:45
TKey::Create
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
Definition: TKey.cxx:459
TKey::kIsDirectoryFile
@ kIsDirectoryFile
Definition: TKey.h:32
TKey::ReadKeyBuffer
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
Definition: TKey.cxx:1222
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
int
TKey::GetNbytes
Int_t GetNbytes() const
Definition: TKey.h:87