Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
19class TBuffer;
20#else
21#include "TBuffer.h"
22#endif
23
24class TBrowser;
25class TDirectory;
26class TFile;
27
28class TKey : public TNamed {
29
30private:
33 kReproducible = BIT(15)
34 };
35 TKey(const TKey&) = delete; // TKey objects are not copiable.
36 TKey& operator=(const TKey&) = delete; // TKey objects are not copiable.
37
38protected:
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 Int_t Read(const char *name) override { return TObject::Read(name); }
55 virtual void Create(Int_t nbytes, TFile* f = nullptr);
56 void Build(TDirectory* motherDir, const char* classname, Long64_t filepos);
57 void Reset(); // Currently only for the use of TBasket.
58 virtual Int_t WriteFileKeepBuffer(TFile *f = nullptr);
59
60 public:
61 TKey();
62 TKey(TDirectory* motherDir);
63 TKey(TDirectory* motherDir, const TKey &orig, UShort_t pidOffset);
64 TKey(const char *name, const char *title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
65 TKey(const TString &name, const TString &title, const TClass *cl, Int_t nbytes, TDirectory* motherDir);
66 TKey(const TObject *obj, const char *name, Int_t bufsize, TDirectory* motherDir);
67 TKey(const void *obj, const TClass *cl, const char *name, Int_t bufsize, TDirectory* motherDir);
68 TKey(Long64_t pointer, Int_t nbytes, TDirectory* motherDir = nullptr);
69 ~TKey() override;
70
71 void Browse(TBrowser *b) override;
72 void Delete(Option_t *option="") override;
73 virtual void DeleteBuffer();
74 void FillBuffer(char *&buffer) override;
75 virtual const char *GetClassName() const {return fClassName.Data();}
76 const char *GetIconName() const override;
77 const char *GetTitle() const override;
78 virtual char *GetBuffer() const {return fBuffer+fKeylen;}
79 TBuffer *GetBufferRef() const {return fBufferRef;}
80 Short_t GetCycle() const;
81 const TDatime &GetDatime() const {return fDatime;}
82 TFile *GetFile() const;
83 Short_t GetKeep() const;
84 Int_t GetKeylen() const {return fKeylen;}
85 TDirectory* GetMotherDir() const { return fMotherDir; }
86 Int_t GetNbytes() const {return fNbytes;}
87 Int_t GetObjlen() const {return fObjlen;}
88 Int_t GetVersion() const {return fVersion;}
89 virtual Long64_t GetSeekKey() const {return fSeekKey;}
90 virtual Long64_t GetSeekPdir() const {return fSeekPdir;}
92 Bool_t IsFolder() const override;
93 virtual void Keep();
94 virtual void ls(Bool_t current) const;
95 void ls(Option_t *option="") const override;
96 void Print(Option_t *option="") const override;
97 virtual Int_t Read(TObject *obj);
98 virtual TObject *ReadObj();
99 virtual TObject *ReadObjWithBuffer(char *bufferRead);
100 /// To read an object (non deriving from TObject) from the file.
101 /// This is more user friendly version of TKey::ReadObjectAny.
102 /// See TKey::ReadObjectAny for more details.
103 template <typename T> T *ReadObject() {
104 return reinterpret_cast<T*>(ReadObjectAny(TClass::GetClass<T>()));
105 }
106 virtual void *ReadObjectAny(const TClass *expectedClass);
107 virtual void ReadBuffer(char *&buffer);
108 void ReadKeyBuffer(char *&buffer);
109 virtual Bool_t ReadFile();
110 virtual void SetBuffer() { DeleteBuffer(); fBuffer = new char[fNbytes];}
111 virtual void SetParent(const TObject *parent);
112 void SetMotherDir(TDirectory* dir) { fMotherDir = dir; }
113 Int_t Sizeof() const override;
114 virtual Int_t WriteFile(Int_t cycle = 1, TFile* f = nullptr);
115
116 ClassDefOverride(TKey,4); //Header description of a logical record on file.
117};
118
119#endif
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
bool Bool_t
Definition RtypesCore.h:63
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
short Short_t
Definition RtypesCore.h:39
long long Long64_t
Definition RtypesCore.h:80
const char Option_t
Definition RtypesCore.h:66
#define BIT(n)
Definition Rtypes.h:85
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
char name[80]
Definition TGX11.cxx:110
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
Describe directory structure in memory.
Definition TDirectory.h:45
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
const char * GetTitle() const override
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition TKey.cxx:1544
void Delete(Option_t *option="") override
Delete an object from the file.
Definition TKey.cxx:542
EStatusBits
Definition TKey.h:31
@ kReproducible
Definition TKey.h:33
@ kIsDirectoryFile
Definition TKey.h:32
virtual Long64_t GetSeekKey() const
Definition TKey.h:89
Int_t Sizeof() const override
Return the size in bytes of the key header structure.
Definition TKey.cxx:1348
TKey()
TKey default constructor.
Definition TKey.cxx:90
~TKey() override
TKey default destructor.
Definition TKey.cxx:529
TFile * GetFile() const
Returns file to which key belong.
Definition TKey.cxx:589
virtual void Keep()
Set the "KEEP" status.
Definition TKey.cxx:689
const char * GetIconName() const override
Title can keep 32x32 xpm thumbnail/icon of the parent object.
Definition TKey.cxx:1536
Int_t Read(const char *name) override
Read contents of object with specified name from the current directory.
Definition TKey.h:54
Int_t GetVersion() const
Definition TKey.h:88
Int_t GetKeylen() const
Definition TKey.h:84
TDatime fDatime
Date/Time of insertion in file.
Definition TKey.h:42
Int_t GetObjlen() const
Definition TKey.h:87
TBuffer * fBufferRef
Pointer to the TBuffer object.
Definition TKey.h:50
T * ReadObject()
To read an object (non deriving from TObject) from the file.
Definition TKey.h:103
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
Int_t GetNbytes() const
Definition TKey.h:86
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by 'offset'.
Definition TKey.cxx:654
Short_t GetKeep() const
Returns the "KEEP" status.
Definition TKey.cxx:597
Int_t fVersion
Key version identifier.
Definition TKey.h:39
Bool_t IsFolder() const override
Check if object referenced by the key is a folder.
Definition TKey.cxx:668
Int_t fLeft
Number of bytes left in current segment.
Definition TKey.h:48
virtual const char * GetClassName() const
Definition TKey.h:75
Short_t fKeylen
Number of bytes for the key itself.
Definition TKey.h:43
virtual Bool_t ReadFile()
Read the key structure from the file.
Definition TKey.cxx:1277
virtual void SetBuffer()
Definition TKey.h:110
TKey(const TKey &)=delete
const TDatime & GetDatime() const
Definition TKey.h:81
void Browse(TBrowser *b) override
Read object from disk and call its Browse() method.
Definition TKey.cxx:431
virtual Int_t WriteFileKeepBuffer(TFile *f=nullptr)
Write the encoded object supported by this key.
Definition TKey.cxx:1503
Long64_t fSeekKey
Location of object on file.
Definition TKey.h:45
void Build(TDirectory *motherDir, const char *classname, Long64_t filepos)
Method used in all TKey constructor to initialize basic data fields.
Definition TKey.cxx:393
char * fBuffer
Object buffer.
Definition TKey.h:49
Long64_t fSeekPdir
Location of parent directory on file.
Definition TKey.h:46
virtual void SetParent(const TObject *parent)
Set parent in key buffer.
Definition TKey.cxx:1306
virtual void * ReadObjectAny(const TClass *expectedClass)
To read an object (non deriving from TObject) from the file.
Definition TKey.cxx:1027
void ReadKeyBuffer(char *&buffer)
Decode input buffer.
Definition TKey.cxx:1234
Int_t fNbytes
Number of bytes for the object on file.
Definition TKey.h:40
Int_t fObjlen
Length of uncompressed object in bytes.
Definition TKey.h:41
void Reset()
Reset the key as it had not been 'filled' yet.
Definition TKey.cxx:1314
TKey & operator=(const TKey &)=delete
virtual Long64_t GetSeekPdir() const
Definition TKey.h:90
void SetMotherDir(TDirectory *dir)
Definition TKey.h:112
Short_t fCycle
Cycle number.
Definition TKey.h:44
virtual TObject * ReadObjWithBuffer(char *bufferRead)
To read a TObject* from bufferRead.
Definition TKey.cxx:896
virtual void ls(Bool_t current) const
List Key contents.
Definition TKey.cxx:698
TDirectory * GetMotherDir() const
Definition TKey.h:85
Short_t GetCycle() const
Return cycle number associated to this key.
Definition TKey.cxx:581
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:762
virtual void Create(Int_t nbytes, TFile *f=nullptr)
Create a TKey object of specified size.
Definition TKey.cxx:463
virtual void DeleteBuffer()
Delete key buffer(s).
Definition TKey.cxx:563
virtual Int_t WriteFile(Int_t cycle=1, TFile *f=nullptr)
Write the encoded object supported by this key.
Definition TKey.cxx:1462
virtual char * GetBuffer() const
Definition TKey.h:78
virtual void ReadBuffer(char *&buffer)
Decode input buffer.
Definition TKey.cxx:1222
TDirectory * fMotherDir
!pointer to mother directory
Definition TKey.h:52
TString fClassName
Object Class name.
Definition TKey.h:47
void Print(Option_t *option="") const override
Print key contents.
Definition TKey.cxx:718
void FillBuffer(char *&buffer) override
Encode key header into output buffer.
Definition TKey.cxx:605
TBuffer * GetBufferRef() const
Definition TKey.h:79
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition TObject.cxx:648
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376