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