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