Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 {
28  kIsDirectoryFile = BIT(14),
29  kReproducible = BIT(15)
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() { 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