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