ROOT  6.06/09
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 #ifndef ROOT_TNamed
16 #include "TNamed.h"
17 #endif
18 #ifndef ROOT_TDatime
19 #include "TDatime.h"
20 #endif
21 #ifndef ROOT_TBuffer
22 #include "TBuffer.h"
23 #endif
24 
25 class TClass;
26 class TBrowser;
27 class TDirectory;
28 class TFile;
29 
30 class TKey : public TNamed {
31 
32 private:
33  enum EStatusBits {
35  };
36  TKey(const TKey&); // TKey objects are not copiable.
37  TKey& operator=(const TKey&); // TKey objects are not copiable.
38 
39 protected:
40  Int_t fVersion; ///< Key version identifier
41  Int_t fNbytes; ///< Number of bytes for the object on file
42  Int_t fObjlen; ///< Length of uncompressed object in bytes
43  TDatime fDatime; ///< Date/Time of insertion in file
44  Short_t fKeylen; ///< Number of bytes for the key itself
45  Short_t fCycle; ///< Cycle number
46  Long64_t fSeekKey; ///< Location of object on file
47  Long64_t fSeekPdir; ///< Location of parent directory on file
48  TString fClassName; ///< Object Class name
49  Int_t fLeft; ///< Number of bytes left in current segment
50  char *fBuffer; ///< Object buffer
51  TBuffer *fBufferRef; ///< Pointer to the TBuffer object
52  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
53  TDirectory *fMotherDir; ///<!pointer to mother directory
54 
55  virtual Int_t Read(const char *name) { return TObject::Read(name); }
56  virtual void Create(Int_t nbytes, TFile* f = 0);
57  void Build(TDirectory* motherDir, const char* classname, Long64_t filepos);
58  virtual void Reset(); // Currently only for the use of TBasket.
59  virtual Int_t WriteFileKeepBuffer(TFile *f = 0);
60 
61 
62  public:
63  TKey();
64  TKey(TDirectory* motherDir);
65  TKey(TDirectory* motherDir, const TKey &orig, UShort_t pidOffset);
66  TKey(const char *name, const char *title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
67  TKey(const TString &name, const TString &title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
68  TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* motherDir);
69  TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, TDirectory* motherDir);
70  TKey(Long64_t pointer, Int_t nbytes, TDirectory* motherDir = 0);
71  virtual ~TKey();
72 
73  virtual void Browse(TBrowser *b);
74  virtual void Delete(Option_t *option="");
75  virtual void DeleteBuffer();
76  virtual void FillBuffer(char *&buffer);
77  virtual const char *GetClassName() const {return fClassName.Data();}
78  virtual const char *GetIconName() const;
79  virtual const char *GetTitle() const;
80  virtual char *GetBuffer() const {return fBuffer+fKeylen;}
81  TBuffer *GetBufferRef() const {return fBufferRef;}
82  Short_t GetCycle() const;
83  const TDatime &GetDatime() const {return fDatime;}
84  TFile *GetFile() const;
85  Short_t GetKeep() const;
86  Int_t GetKeylen() const {return fKeylen;}
87  TDirectory* GetMotherDir() const { return fMotherDir; }
88  Int_t GetNbytes() const {return fNbytes;}
89  Int_t GetObjlen() const {return fObjlen;}
90  Int_t GetVersion() const {return fVersion;}
91  virtual Long64_t GetSeekKey() const {return fSeekKey;}
92  virtual Long64_t GetSeekPdir() const {return fSeekPdir;}
93  virtual ULong_t Hash() const;
94  virtual void IncrementPidOffset(UShort_t offset);
95  Bool_t IsFolder() const;
96  virtual void Keep();
97  virtual void ls(Option_t *option="") const;
98  virtual void Print(Option_t *option="") const;
99  virtual Int_t Read(TObject *obj);
100  virtual TObject *ReadObj();
101  virtual TObject *ReadObjWithBuffer(char *bufferRead);
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() { 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:40
Int_t fLeft
Number of bytes left in current segment.
Definition: TKey.h:49
Bool_t IsFolder() const
Check if object referenced by the key is a folder.
Definition: TKey.cxx:653
long long Long64_t
Definition: RtypesCore.h:69
TDirectory * GetMotherDir() const
Definition: TKey.h:87
virtual void ls(Option_t *option="") const
List Key contents.
Definition: TKey.cxx:682
const char Option_t
Definition: RtypesCore.h:62
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:52
virtual void Print(Option_t *option="") const
Print key contents.
Definition: TKey.cxx:691
unsigned short UShort_t
Definition: RtypesCore.h:36
#define BIT(n)
Definition: Rtypes.h:120
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
Definition: TKey.cxx:1005
Short_t GetCycle() const
Return cycle number associated to this key.
Definition: TKey.cxx:561
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Long64_t GetSeekPdir() const
Definition: TKey.h:92
virtual void Browse(TBrowser *b)
Read object from disk and call its Browse() method.
Definition: TKey.cxx:426
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:137
virtual const char * GetIconName() const
Title can keep 32x32 xpm thumbnail/icon of the parent object.
Definition: TKey.cxx:1514
TFile * GetFile() const
Returns file to which key belong.
Definition: TKey.cxx:569
virtual const char * GetClassName() const
Definition: TKey.h:77
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
char * fBuffer
Object buffer.
Definition: TKey.h:50
virtual void FillBuffer(char *&buffer)
Encode key header into output buffer.
Definition: TKey.cxx:585
TDirectory * fMotherDir
!pointer to mother directory
Definition: TKey.h:53
virtual Long64_t GetSeekKey() const
Definition: TKey.h:91
virtual char * GetBuffer() const
Definition: TKey.h:80
const char * Data() const
Definition: TString.h:349
Long64_t fSeekPdir
Location of parent directory on file.
Definition: TKey.h:47
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Int_t GetNbytes() const
Definition: TKey.h:88
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=0)
Write the encoded object supported by this key.
Definition: TKey.cxx:1440
ClassDef(TKey, 4)
Short_t fKeylen
Number of bytes for the key itself.
Definition: TKey.h:44
TString fClassName
Object Class name.
Definition: TKey.h:48
virtual ~TKey()
TKey default destructor.
Definition: TKey.cxx:517
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:606
virtual Int_t Sizeof() const
Return the size in bytes of the key header structure.
Definition: TKey.cxx:1329
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void Delete(Option_t *option="")
Delete an object from the file.
Definition: TKey.cxx:531
TDatime fDatime
Date/Time of insertion in file.
Definition: TKey.h:43
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition: TKey.cxx:1522
virtual Int_t WriteFileKeepBuffer(TFile *f=0)
Write the encoded object supported by this key.
Definition: TKey.cxx:1481
TBuffer * GetBufferRef() const
Definition: TKey.h:81
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by 'offset'.
Definition: TKey.cxx:639
virtual void Keep()
Set the "KEEP" status.
Definition: TKey.cxx:674
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
Definition: TKey.cxx:1203
virtual Bool_t ReadFile()
Read the key structure from the file.
Definition: TKey.cxx:1258
short Short_t
Definition: RtypesCore.h:35
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void Reset()
Reset the key as it had not been 'filled' yet.
Definition: TKey.cxx:1295
virtual TObject * ReadObjWithBuffer(char *bufferRead)
To read a TObject* from bufferRead.
Definition: TKey.cxx:869
TBuffer * fBufferRef
Pointer to the TBuffer object.
Definition: TKey.h:51
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
Definition: TKey.cxx:1287
Long64_t fSeekKey
Location of object on file.
Definition: TKey.h:46
void SetMotherDir(TDirectory *dir)
Definition: TKey.h:108
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
Definition: TKey.cxx:1215
Short_t fCycle
Cycle number.
Definition: TKey.h:45
double f(double x)
Describe directory structure in memory.
Definition: TDirectory.h:41
EStatusBits
Definition: TObject.h:76
unsigned long ULong_t
Definition: RtypesCore.h:51
Int_t GetObjlen() const
Definition: TKey.h:89
Int_t GetKeylen() const
Definition: TKey.h:86
Int_t GetVersion() const
Definition: TKey.h:90
#define name(a, b)
Definition: linkTestLib0.cpp:5
Int_t fObjlen
Length of uncompressed object in bytes.
Definition: TKey.h:42
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Create(Int_t nbytes, TFile *f=0)
Create a TKey object of specified size.
Definition: TKey.cxx:458
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:727
virtual void DeleteBuffer()
Delete key buffer(s).
Definition: TKey.cxx:543
virtual void SetBuffer()
Definition: TKey.h:106
Int_t fNbytes
Number of bytes for the object on file.
Definition: TKey.h:41
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TKey.h:55
virtual ULong_t Hash() const
This Hash function should redefine the default from TNamed.
Definition: TKey.cxx:624
const TDatime & GetDatime() const
Definition: TKey.h:83
TObject * obj
Short_t GetKeep() const
Returns the "KEEP" status.
Definition: TKey.cxx:577
TKey & operator=(const TKey &)
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39