Logo ROOT  
Reference Guide
TDirectoryFile.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Rene Brun 22/01/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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_TDirectoryFile
13 #define ROOT_TDirectoryFile
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TDirectoryFile //
19 // //
20 // Describe directory structure in a ROOT file. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "Compression.h"
25 #include "TDirectory.h"
26 #include "TDatime.h"
27 #include "TList.h"
28 
29 class TKey;
30 class TFile;
31 
32 class TDirectoryFile : public TDirectory {
33 
34 protected:
35  Bool_t fModified{kFALSE}; ///< True if directory has been modified
36  Bool_t fWritable{kFALSE}; ///< True if directory is writable
37  TDatime fDatimeC; ///< Date and time when directory is created
38  TDatime fDatimeM; ///< Date and time of last modification
39  Int_t fNbytesKeys{0}; ///< Number of bytes for the keys
40  Int_t fNbytesName{0}; ///< Number of bytes in TNamed at creation time
41  Int_t fBufferSize{0}; ///< Default buffer size to create new TKeys
42  Long64_t fSeekDir{0}; ///< Location of directory on file
43  Long64_t fSeekParent{0}; ///< Location of parent directory on file
44  Long64_t fSeekKeys{0}; ///< Location of Keys record on file
45  TFile *fFile{nullptr}; ///< Pointer to current file in memory
46  TList *fKeys{nullptr}; ///< Pointer to keys list in memory
47 
48  void CleanTargets();
49  void InitDirectoryFile(TClass *cl = nullptr);
50  void BuildDirectoryFile(TFile* motherFile, TDirectory* motherDir);
51 
52 private:
53  TDirectoryFile(const TDirectoryFile &directory) = delete; //Directories cannot be copied
54  void operator=(const TDirectoryFile &) = delete; //Directories cannot be copied
55 
56 public:
57  // TDirectory status bits
58  enum EStatusBits { kCloseDirectory = BIT(7) }; // Unused in ROOT, never set. Maybe only in external code.
59 
61  TDirectoryFile(const char *name, const char *title, Option_t *option="", TDirectory* motherDir = nullptr);
62  virtual ~TDirectoryFile();
63 
64  void Append(TObject *obj, Bool_t replace = kFALSE) override;
65  void Add(TObject *obj, Bool_t replace = kFALSE) override { Append(obj,replace); }
66  Int_t AppendKey(TKey *key) override;
67  void Browse(TBrowser *b) override;
68  void Build(TFile* motherFile = nullptr, TDirectory* motherDir = nullptr) override { BuildDirectoryFile(motherFile, motherDir); }
69  TObject *CloneObject(const TObject *obj, Bool_t autoadd = kTRUE) override;
70  void Close(Option_t *option="") override;
71  void Copy(TObject &) const override { MayNotUse("Copy(TObject &)"); }
72  Bool_t cd(const char *path = nullptr) override;
73  void Delete(const char *namecycle="") override;
74  void FillBuffer(char *&buffer) override;
75  TKey *FindKey(const char *keyname) const override;
76  TKey *FindKeyAny(const char *keyname) const override;
77  TObject *FindObjectAny(const char *name) const override;
78  TObject *FindObjectAnyFile(const char *name) const override;
79  TObject *Get(const char *namecycle) override;
80  /// See documentation of TDirectoryFile::Get(const char *namecycle)
81  template <class T> inline T* Get(const char* namecycle)
82  {
83  return TDirectory::Get<T>(namecycle);
84  }
85  TDirectory *GetDirectory(const char *apath, Bool_t printError = false, const char *funcname = "GetDirectory") override;
86  void *GetObjectChecked(const char *namecycle, const char* classname) override;
87  void *GetObjectChecked(const char *namecycle, const TClass* cl) override;
88  void *GetObjectUnchecked(const char *namecycle) override;
89  Int_t GetBufferSize() const override;
90  const TDatime &GetCreationDate() const { return fDatimeC; }
91  TFile *GetFile() const override { return fFile; }
92  TKey *GetKey(const char *name, Short_t cycle=9999) const override;
93  TList *GetListOfKeys() const override { return fKeys; }
94  const TDatime &GetModificationDate() const { return fDatimeM; }
95  Int_t GetNbytesKeys() const override { return fNbytesKeys; }
96  Int_t GetNkeys() const override { return fKeys->GetSize(); }
97  Long64_t GetSeekDir() const override { return fSeekDir; }
98  Long64_t GetSeekParent() const override { return fSeekParent; }
99  Long64_t GetSeekKeys() const override { return fSeekKeys; }
100  Bool_t IsModified() const override { return fModified; }
101  Bool_t IsWritable() const override { return fWritable; }
102  void ls(Option_t *option="") const override;
103  TDirectory *mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory = kFALSE) override;
104  TFile *OpenFile(const char *name, Option_t *option= "",
105  const char *ftitle = "", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault,
106  Int_t netopt = 0) override;
107  void Purge(Short_t nkeep=1) override;
108  void ReadAll(Option_t *option="") override;
109  Int_t ReadKeys(Bool_t forceRead=kTRUE) override;
110  Int_t ReadTObject(TObject *obj, const char *keyname) override;
111  virtual void ResetAfterMerge(TFileMergeInfo *);
112  void rmdir(const char *name) override;
113  void Save() override;
114  void SaveSelf(Bool_t force = kFALSE) override;
115  Int_t SaveObjectAs(const TObject *obj, const char *filename="", Option_t *option="") const override;
116  void SetBufferSize(Int_t bufsize) override;
117  void SetModified() override {fModified = kTRUE;}
118  void SetSeekDir(Long64_t v) override { fSeekDir = v; }
119  void SetTRefAction(TObject *ref, TObject *parent) override;
120  void SetWritable(Bool_t writable=kTRUE) override;
121  Int_t Sizeof() const override;
122  Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override;
123  Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) const override;
124  Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *option="", Int_t bufsize=0) override;
125  Int_t WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="", Int_t bufsize=0) override;
126  Int_t WriteObjectAny(const void *obj, const TClass *cl, const char *name, Option_t *option="", Int_t bufsize=0) override;
127  void WriteDirHeader() override;
128  void WriteKeys() override;
129 
130  ClassDefOverride(TDirectoryFile,5) //Describe directory structure in a ROOT file
131 };
132 
133 #endif
TDirectoryFile::ReadKeys
Int_t ReadKeys(Bool_t forceRead=kTRUE) override
Read the linked list of keys.
Definition: TDirectoryFile.cxx:1337
Compression.h
TDirectoryFile::GetObjectChecked
void * GetObjectChecked(const char *namecycle, const char *classname) override
See documentation of TDirectoryFile::GetObjectCheck(const char *namecycle, const TClass *cl)
Definition: TDirectoryFile.cxx:986
TFileMergeInfo
Definition: TFileMergeInfo.h:42
TBrowser
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TDirectoryFile::Add
void Add(TObject *obj, Bool_t replace=kFALSE) override
Definition: TDirectoryFile.h:65
TDirectoryFile::SetModified
void SetModified() override
Definition: TDirectoryFile.h:117
TDirectoryFile::CleanTargets
void CleanTargets()
Clean the pointers to this object (gDirectory, TContext, etc.)
Definition: TDirectoryFile.cxx:350
TDirectory.h
Option_t
const char Option_t
Definition: RtypesCore.h:66
TDirectoryFile::Copy
void Copy(TObject &) const override
Copy this to obj.
Definition: TDirectoryFile.h:71
ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault
@ kUseCompiledDefault
Use the compile-time default setting.
Definition: Compression.h:50
TDirectoryFile::Save
void Save() override
Save recursively all directory keys and headers.
Definition: TDirectoryFile.cxx:1503
TDirectoryFile::GetKey
TKey * GetKey(const char *name, Short_t cycle=9999) const override
Return pointer to key with name,cycle.
Definition: TDirectoryFile.cxx:1101
TDirectoryFile::ResetAfterMerge
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset the TDirectory after its content has been merged into another Directory.
Definition: TDirectoryFile.cxx:1445
TDirectoryFile::SetTRefAction
void SetTRefAction(TObject *ref, TObject *parent) override
Find the action to be executed in the dictionary of the parent class and store the corresponding exec...
Definition: TDirectoryFile.cxx:1613
TDirectoryFile::fDatimeM
TDatime fDatimeM
Date and time of last modification.
Definition: TDirectoryFile.h:38
TDatime.h
TDirectoryFile::Append
void Append(TObject *obj, Bool_t replace=kFALSE) override
Append object to this directory.
Definition: TDirectoryFile.cxx:209
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TDirectoryFile::Write
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write all objects in memory to disk.
Definition: TDirectoryFile.cxx:1786
TDirectoryFile::fNbytesName
Int_t fNbytesName
Number of bytes in TNamed at creation time.
Definition: TDirectoryFile.h:40
TDirectoryFile::TDirectoryFile
TDirectoryFile(const TDirectoryFile &directory)=delete
Int_t
int Int_t
Definition: RtypesCore.h:45
TDirectoryFile::cd
Bool_t cd(const char *path=nullptr) override
Change current directory to "this" directory.
Definition: TDirectoryFile.cxx:340
TDirectoryFile::fDatimeC
TDatime fDatimeC
Date and time when directory is created.
Definition: TDirectoryFile.h:37
TList.h
TDirectoryFile::SaveSelf
void SaveSelf(Bool_t force=kFALSE) override
Save Directory keys and header.
Definition: TDirectoryFile.cxx:1577
TObject::MayNotUse
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:943
TDirectoryFile::fFile
TFile * fFile
Pointer to current file in memory.
Definition: TDirectoryFile.h:45
TDirectoryFile::SetBufferSize
void SetBufferSize(Int_t bufsize) override
Set the default buffer size when creating new TKeys.
Definition: TDirectoryFile.cxx:1598
TDirectoryFile::OpenFile
TFile * OpenFile(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0) override
Interface to TFile::Open.
Definition: TDirectoryFile.cxx:1191
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
TDirectoryFile::Delete
void Delete(const char *namecycle="") override
Delete Objects or/and keys in a directory.
Definition: TDirectoryFile.cxx:618
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TDirectoryFile::Sizeof
Int_t Sizeof() const override
Return the size in bytes of the directory header.
Definition: TDirectoryFile.cxx:1655
v
@ v
Definition: rootcling_impl.cxx:3635
TDirectoryFile::IsModified
Bool_t IsModified() const override
Definition: TDirectoryFile.h:100
TDirectoryFile::GetCreationDate
const TDatime & GetCreationDate() const
Definition: TDirectoryFile.h:90
b
#define b(i)
Definition: RSha256.hxx:100
bool
TDirectoryFile::fModified
Bool_t fModified
True if directory has been modified.
Definition: TDirectoryFile.h:35
TDirectoryFile::GetFile
TFile * GetFile() const override
Definition: TDirectoryFile.h:91
TDirectoryFile::Get
T * Get(const char *namecycle)
See documentation of TDirectoryFile::Get(const char *namecycle)
Definition: TDirectoryFile.h:81
TDirectoryFile::GetObjectUnchecked
void * GetObjectUnchecked(const char *namecycle) override
Return pointer to object identified by namecycle.
Definition: TDirectoryFile.cxx:978
TDirectoryFile::GetNbytesKeys
Int_t GetNbytesKeys() const override
Definition: TDirectoryFile.h:95
TDirectoryFile::WriteTObject
Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *option="", Int_t bufsize=0) override
Write object obj to this directory.
Definition: TDirectoryFile.cxx:1856
TDirectoryFile::Close
void Close(Option_t *option="") override
Delete all objects from memory and directory structure itself.
Definition: TDirectoryFile.cxx:547
TDirectoryFile::GetListOfKeys
TList * GetListOfKeys() const override
Definition: TDirectoryFile.h:93
TDirectoryFile::~TDirectoryFile
virtual ~TDirectoryFile()
Destructor.
Definition: TDirectoryFile.cxx:177
TDirectoryFile::Get
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
Definition: TDirectoryFile.cxx:909
TDirectoryFile::FindKeyAny
TKey * FindKeyAny(const char *keyname) const override
Find key with name keyname in the current directory or its subdirectories.
Definition: TDirectoryFile.cxx:782
TDirectoryFile::fKeys
TList * fKeys
Pointer to keys list in memory.
Definition: TDirectoryFile.h:46
TDirectoryFile::Browse
void Browse(TBrowser *b) override
Browse the content of the directory.
Definition: TDirectoryFile.cxx:260
TDirectoryFile::CloneObject
TObject * CloneObject(const TObject *obj, Bool_t autoadd=kTRUE) override
Make a clone of an object using the Streamer facility.
Definition: TDirectoryFile.cxx:373
TDirectoryFile::fBufferSize
Int_t fBufferSize
Default buffer size to create new TKeys.
Definition: TDirectoryFile.h:41
TDirectoryFile::operator=
void operator=(const TDirectoryFile &)=delete
TDirectoryFile::WriteObjectAny
Int_t WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="", Int_t bufsize=0) override
Write object from pointer of class classname in this directory.
Definition: TDirectoryFile.cxx:1969
TDirectoryFile::AppendKey
Int_t AppendKey(TKey *key) override
Insert key in the linked list of keys of this directory.
Definition: TDirectoryFile.cxx:225
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TDirectoryFile::Build
void Build(TFile *motherFile=nullptr, TDirectory *motherDir=nullptr) override
Definition: TDirectoryFile.h:68
TDirectoryFile::TDirectoryFile
TDirectoryFile()
Default TDirectoryFile constructor.
Definition: TDirectoryFile.cxx:60
TDirectoryFile::SaveObjectAs
Int_t SaveObjectAs(const TObject *obj, const char *filename="", Option_t *option="") const override
Save object in filename.
Definition: TDirectoryFile.cxx:1536
BIT
#define BIT(n)
Definition: Rtypes.h:85
TDirectoryFile::GetModificationDate
const TDatime & GetModificationDate() const
Definition: TDirectoryFile.h:94
TDirectoryFile::Purge
void Purge(Short_t nkeep=1) override
Purge lowest key cycles in a directory.
Definition: TDirectoryFile.cxx:1248
Short_t
short Short_t
Definition: RtypesCore.h:39
TDirectoryFile::GetSeekParent
Long64_t GetSeekParent() const override
Definition: TDirectoryFile.h:98
TDirectoryFile::ReadTObject
Int_t ReadTObject(TObject *obj, const char *keyname) override
Read object with keyname from the current directory.
Definition: TDirectoryFile.cxx:1423
TDirectoryFile::fSeekKeys
Long64_t fSeekKeys
Location of Keys record on file.
Definition: TDirectoryFile.h:44
TDirectoryFile::IsWritable
Bool_t IsWritable() const override
Definition: TDirectoryFile.h:101
TDirectoryFile::GetSeekDir
Long64_t GetSeekDir() const override
Definition: TDirectoryFile.h:97
TDirectoryFile::GetSeekKeys
Long64_t GetSeekKeys() const override
Definition: TDirectoryFile.h:99
TDirectoryFile::FindKey
TKey * FindKey(const char *keyname) const override
Find key with name keyname in the current directory.
Definition: TDirectoryFile.cxx:766
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TDirectoryFile::kCloseDirectory
@ kCloseDirectory
Definition: TDirectoryFile.h:58
TDirectoryFile::ls
void ls(Option_t *option="") const override
List Directory contents.
Definition: TDirectoryFile.cxx:1132
TKey
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:28
TDirectoryFile::GetDirectory
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
Definition: TDirectoryFile.cxx:458
TDirectoryFile::fSeekParent
Long64_t fSeekParent
Location of parent directory on file.
Definition: TDirectoryFile.h:43
TDirectoryFile::FindObjectAnyFile
TObject * FindObjectAnyFile(const char *name) const override
Scan the memory lists of all files for an object with name.
Definition: TDirectoryFile.cxx:431
TDirectoryFile::FindObjectAny
TObject * FindObjectAny(const char *name) const override
Find object by name in the list of memory objects of the current directory or its sub-directories.
Definition: TDirectoryFile.cxx:822
TDirectoryFile::GetNkeys
Int_t GetNkeys() const override
Definition: TDirectoryFile.h:96
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TDirectoryFile::fWritable
Bool_t fWritable
True if directory is writable.
Definition: TDirectoryFile.h:36
TDirectoryFile::FillBuffer
void FillBuffer(char *&buffer) override
Encode directory header into output buffer.
Definition: TDirectoryFile.cxx:722
TDirectoryFile::WriteDirHeader
void WriteDirHeader() override
Overwrite the Directory header record.
Definition: TDirectoryFile.cxx:2088
TDirectoryFile::SetSeekDir
void SetSeekDir(Long64_t v) override
Definition: TDirectoryFile.h:118
TDirectoryFile::fNbytesKeys
Int_t fNbytesKeys
Number of bytes for the keys.
Definition: TDirectoryFile.h:39
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TDirectoryFile::rmdir
void rmdir(const char *name) override
Removes subdirectory from the directory.
Definition: TDirectoryFile.cxx:1491
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:40
TDirectoryFile::SetWritable
void SetWritable(Bool_t writable=kTRUE) override
Set the new value of fWritable recursively.
Definition: TDirectoryFile.cxx:1632
TDirectoryFile::GetBufferSize
Int_t GetBufferSize() const override
Return the buffer size to create new TKeys.
Definition: TDirectoryFile.cxx:1089
TDatime
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
TDirectoryFile::fSeekDir
Long64_t fSeekDir
Location of directory on file.
Definition: TDirectoryFile.h:42
TDirectoryFile::BuildDirectoryFile
void BuildDirectoryFile(TFile *motherFile, TDirectory *motherDir)
Initialise directory to defaults.
Definition: TDirectoryFile.cxx:305
TDirectoryFile
A ROOT file is structured in Directories (like a file system).
Definition: TDirectoryFile.h:32
TDirectoryFile::InitDirectoryFile
void InitDirectoryFile(TClass *cl=nullptr)
Initialize the key associated with this directory (and the related data members.
Definition: TDirectoryFile.cxx:147
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
TDirectoryFile::WriteKeys
void WriteKeys() override
Write Keys linked list on the file.
Definition: TDirectoryFile.cxx:2117
TList
A doubly linked list.
Definition: TList.h:44
TDirectoryFile::mkdir
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
Definition: TDirectoryFile.cxx:1207
int
TDirectoryFile::ReadAll
void ReadAll(Option_t *option="") override
Read objects from a ROOT file directory into memory.
Definition: TDirectoryFile.cxx:1284