Logo ROOT   6.21/01
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 "TBuffer.h"
18 #include "TClass.h"
19 
20 class TBrowser;
21 class TDirectory;
22 class TFile;
23 
24 class TKey : public TNamed {
25 
26 private:
27  enum EStatusBits {
30  };
31  TKey(const TKey&) = delete; // TKey objects are not copiable.
32  TKey& operator=(const TKey&) = delete; // TKey objects are not copiable.
33 
34 protected:
35  Int_t fVersion; ///< Key version identifier
36  Int_t fNbytes; ///< Number of bytes for the object on file
37  Int_t fObjlen; ///< Length of uncompressed object in bytes
38  TDatime fDatime; ///< Date/Time of insertion in file
39  Short_t fKeylen; ///< Number of bytes for the key itself
40  Short_t fCycle; ///< Cycle number
41  Long64_t fSeekKey; ///< Location of object on file
42  Long64_t fSeekPdir; ///< Location of parent directory on file
43  TString fClassName; ///< Object Class name
44  Int_t fLeft; ///< Number of bytes left in current segment
45  char *fBuffer; ///< Object buffer
46  TBuffer *fBufferRef; ///< Pointer to the TBuffer object
47  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
48  TDirectory *fMotherDir; ///<!pointer to mother directory
49 
50  virtual Int_t Read(const char *name) { return TObject::Read(name); }
51  virtual void Create(Int_t nbytes, TFile* f = 0);
52  void Build(TDirectory* motherDir, const char* classname, Long64_t filepos);
53  virtual void Reset(); // Currently only for the use of TBasket.
54  virtual Int_t WriteFileKeepBuffer(TFile *f = 0);
55 
56 
57  public:
58  TKey();
59  TKey(TDirectory* motherDir);
60  TKey(TDirectory* motherDir, const TKey &orig, UShort_t pidOffset);
61  TKey(const char *name, const char *title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
62  TKey(const TString &name, const TString &title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
63  TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* motherDir);
64  TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, TDirectory* motherDir);
65  TKey(Long64_t pointer, Int_t nbytes, TDirectory* motherDir = 0);
66  virtual ~TKey();
67 
68  virtual void Browse(TBrowser *b);
69  virtual void Delete(Option_t *option="");
70  virtual void DeleteBuffer();
71  virtual void FillBuffer(char *&buffer);
72  virtual const char *GetClassName() const {return fClassName.Data();}
73  virtual const char *GetIconName() const;
74  virtual const char *GetTitle() const;
75  virtual char *GetBuffer() const {return fBuffer+fKeylen;}
76  TBuffer *GetBufferRef() const {return fBufferRef;}
77  Short_t GetCycle() const;
78  const TDatime &GetDatime() const {return fDatime;}
79  TFile *GetFile() const;
80  Short_t GetKeep() const;
81  Int_t GetKeylen() const {return fKeylen;}
82  TDirectory* GetMotherDir() const { return fMotherDir; }
83  Int_t GetNbytes() const {return fNbytes;}
84  Int_t GetObjlen() const {return fObjlen;}
85  Int_t GetVersion() const {return fVersion;}
86  virtual Long64_t GetSeekKey() const {return fSeekKey;}
87  virtual Long64_t GetSeekPdir() const {return fSeekPdir;}
88  virtual void IncrementPidOffset(UShort_t offset);
89  Bool_t IsFolder() const;
90  virtual void Keep();
91  virtual void ls(Option_t *option="") const;
92  virtual void Print(Option_t *option="") const;
93  virtual Int_t Read(TObject *obj);
94  virtual TObject *ReadObj();
95  virtual TObject *ReadObjWithBuffer(char *bufferRead);
96  /// To read an object (non deriving from TObject) from the file.
97  /// This is more user friendly version of TKey::ReadObjectAny.
98  /// See TKey::ReadObjectAny for more details.
99  template <typename T> T *ReadObject() {
100  return reinterpret_cast<T*>(ReadObjectAny(TClass::GetClass<T>()));
101  }
102  virtual void *ReadObjectAny(const TClass *expectedClass);
103  virtual void ReadBuffer(char *&buffer);
104  void ReadKeyBuffer(char *&buffer);
105  virtual Bool_t ReadFile();
106  virtual void SetBuffer() { DeleteBuffer(); fBuffer = new char[fNbytes];}
107  virtual void SetParent(const TObject *parent);
108  void SetMotherDir(TDirectory* dir) { fMotherDir = dir; }
109  virtual Int_t Sizeof() const;
110  virtual Int_t WriteFile(Int_t cycle=1, TFile* f = 0);
111 
112  ClassDef(TKey,4); //Header description of a logical record on file.
113 };
114 
115 #endif
Int_t fVersion
Key version identifier.
Definition: TKey.h:35
T * ReadObject()
To read an object (non deriving from TObject) from the file.
Definition: TKey.h:99
Int_t fLeft
Number of bytes left in current segment.
Definition: TKey.h:44
virtual const char * GetIconName() const
Title can keep 32x32 xpm thumbnail/icon of the parent object.
Definition: TKey.cxx:1522
long long Long64_t
Definition: RtypesCore.h:69
const char Option_t
Definition: RtypesCore.h:62
double T(double x)
Definition: ChebyshevPol.h:34
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:47
virtual char * GetBuffer() const
Definition: TKey.h:75
unsigned short UShort_t
Definition: RtypesCore.h:36
virtual const char * GetClassName() const
Definition: TKey.h:72
#define BIT(n)
Definition: Rtypes.h:83
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:48
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
Definition: TKey.cxx:1010
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TKey()
TKey default constructor.
Definition: TKey.cxx:92
virtual void Browse(TBrowser *b)
Read object from disk and call its Browse() method.
Definition: TKey.cxx:429
void Build(TDirectory *motherDir, const char *classname, Long64_t filepos)
Method used in all TKey constructor to initialize basic data fields.
Definition: TKey.cxx:391
Basic string class.
Definition: TString.h:131
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TKey & operator=(const TKey &)=delete
char * fBuffer
Object buffer.
Definition: TKey.h:45
virtual void FillBuffer(char *&buffer)
Encode key header into output buffer.
Definition: TKey.cxx:595
TDirectory * GetMotherDir() const
Definition: TKey.h:82
TDirectory * fMotherDir
!pointer to mother directory
Definition: TKey.h:48
TBuffer * GetBufferRef() const
Definition: TKey.h:76
virtual Int_t Sizeof() const
Return the size in bytes of the key header structure.
Definition: TKey.cxx:1334
virtual void ls(Option_t *option="") const
List Key contents.
Definition: TKey.cxx:687
#define ClassDef(name, id)
Definition: Rtypes.h:326
Long64_t fSeekPdir
Location of parent directory on file.
Definition: TKey.h:42
virtual void Print(Option_t *option="") const
Print key contents.
Definition: TKey.cxx:696
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Short_t GetKeep() const
Returns the "KEEP" status.
Definition: TKey.cxx:587
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
Write the encoded object supported by this key.
Definition: TKey.cxx:1448
Short_t fKeylen
Number of bytes for the key itself.
Definition: TKey.h:39
TString fClassName
Object Class name.
Definition: TKey.h:43
virtual ~TKey()
TKey default destructor.
Definition: TKey.cxx:527
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:562
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
virtual void Delete(Option_t *option="")
Delete an object from the file.
Definition: TKey.cxx:541
TDatime fDatime
Date/Time of insertion in file.
Definition: TKey.h:38
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
Definition: TKey.cxx:1489
Int_t GetObjlen() const
Definition: TKey.h:84
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by &#39;offset&#39;.
Definition: TKey.cxx:644
virtual void Keep()
Set the "KEEP" status.
Definition: TKey.cxx:679
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
Definition: TKey.cxx:1208
TFile * GetFile() const
Returns file to which key belong.
Definition: TKey.cxx:579
virtual Bool_t ReadFile()
Read the key structure from the file.
Definition: TKey.cxx:1263
virtual Long64_t GetSeekPdir() const
Definition: TKey.h:87
short Short_t
Definition: RtypesCore.h:35
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
virtual void Reset()
Reset the key as it had not been &#39;filled&#39; yet.
Definition: TKey.cxx:1300
virtual TObject * ReadObjWithBuffer(char *bufferRead)
To read a TObject* from bufferRead.
Definition: TKey.cxx:874
TBuffer * fBufferRef
Pointer to the TBuffer object.
Definition: TKey.h:46
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
Definition: TKey.cxx:1292
Long64_t fSeekKey
Location of object on file.
Definition: TKey.h:41
void SetMotherDir(TDirectory *dir)
Definition: TKey.h:108
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
Definition: TKey.cxx:1220
Short_t fCycle
Cycle number.
Definition: TKey.h:40
virtual Long64_t GetSeekKey() const
Definition: TKey.h:86
Describe directory structure in memory.
Definition: TDirectory.h:34
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition: TKey.cxx:1530
EStatusBits
Definition: TObject.h:57
Int_t GetNbytes() const
Definition: TKey.h:83
Int_t GetVersion() const
Definition: TKey.h:85
Int_t GetKeylen() const
Definition: TKey.h:81
Int_t fObjlen
Length of uncompressed object in bytes.
Definition: TKey.h:37
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
Definition: TKey.cxx:461
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:732
virtual void DeleteBuffer()
Delete key buffer(s).
Definition: TKey.cxx:553
virtual void SetBuffer()
Definition: TKey.h:106
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Int_t fNbytes
Number of bytes for the object on file.
Definition: TKey.h:36
const TDatime & GetDatime() const
Definition: TKey.h:78
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TKey.h:50
Short_t GetCycle() const
Return cycle number associated to this key.
Definition: TKey.cxx:571
Bool_t IsFolder() const
Check if object referenced by the key is a folder.
Definition: TKey.cxx:658
char name[80]
Definition: TGX11.cxx:109
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
const char * Data() const
Definition: TString.h:364