ROOTANA
Loading...
Searching...
No Matches
TDirectory-example.h
Go to the documentation of this file.
1// @(#)root/base:$Name: v5-14-00f $:$Id: TDirectory.h,v 1.37 2006/06/20 18:17:34 pcanal Exp $
2// Author: Rene Brun 28/11/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_TDirectory
13#define ROOT_TDirectory
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TDirectory //
19// //
20// Describe directory structure in memory. //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#ifndef ROOT_TNamed
25#include "TNamed.h"
26#endif
27#ifndef ROOT_TList
28#include "TList.h"
29#endif
30#ifndef ROOT_TDatime
31#include "TDatime.h"
32#endif
33#ifndef ROOT_TUUID
34#include "TUUID.h"
35#endif
36
37class TBrowser;
38class TKey;
39class TFile;
40
42
43class TDirectory : public TNamed {
44
45protected:
46 Bool_t fModified; //true if directory has been modified
47 Bool_t fWritable; //true if directory is writable
48 TDatime fDatimeC; //Date and time when directory is created
49 TDatime fDatimeM; //Date and time of last modification
50 Int_t fNbytesKeys; //Number of bytes for the keys
51 Int_t fNbytesName; //Number of bytes in TNamed at creation time
52 Int_t fBufferSize; //Default buffer size to create new TKeys
53 Long64_t fSeekDir; //Location of directory on file
54 Long64_t fSeekParent; //Location of parent directory on file
55 Long64_t fSeekKeys; //Location of Keys record on file
56 TFile *fFile; //pointer to current file in memory
57 TObject *fMother; //pointer to mother of the directory
58 TList *fList; //Pointer to objects list in memory
59 TList *fKeys; //Pointer to keys list in memory
60 TUUID fUUID; //Unique identifier
61 TString fPathBuffer; //!Buffer for GetPath() function
62
63 Bool_t cd1(const char *path);
64 static Bool_t Cd1(const char *path);
65
66 void FillFullPath(TString& buf) const;
67
68private:
69 TDirectory(const TDirectory &directory); //Directories cannot be copied
70 void operator=(const TDirectory &); //Directorise cannot be copied
71
72public:
73 // TDirectory status bits
74 enum { kCloseDirectory = BIT(7) };
75
76 /** @class Context
77 *
78 * Small helper to keep current directory context.
79 * Automatically reverts to "old" directory
80 */
81 class TContext {
82 private:
83 TDirectory* fPrevious; // Pointer to the previous current directory.
86 void CdNull();
87 public:
88 TContext(TDirectory* previous, TDirectory* newCurrent)
89 : fPrevious(previous)
90 {
91 // Store the current directory so we can restore it
92 // later and cd to the new directory.
93 if ( newCurrent ) newCurrent->cd();
94 }
96 {
97 // Store the current directory so we can restore it
98 // later and cd to the new directory.
99 if ( newCurrent ) newCurrent->cd();
100 }
102 {
103 // Destructor. Reset the current directory to its
104 // previous state.
105 if ( fPrevious ) fPrevious->cd();
106 else CdNull();
107 }
108 };
109
111 TDirectory(const char *name, const char *title, Option_t *option="", TDirectory* motherDir = 0);
112 virtual ~TDirectory();
113 virtual void Append(TObject *obj);
114 void Add(TObject *obj) { Append(obj); }
115 Int_t AppendKey(TKey *key);
116 virtual void Browse(TBrowser *b);
117 void Build(TFile* motherFile = 0, TDirectory* motherDir = 0);
118 virtual void Clear(Option_t *option="");
119 virtual void Close(Option_t *option="");
120 virtual void Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
121 virtual Bool_t cd(const char *path = 0);
122 virtual void DeleteAll(Option_t *option="");
123 virtual void Delete(const char *namecycle="");
124 virtual void Draw(Option_t *option="");
125 virtual void FillBuffer(char *&buffer);
126 virtual TKey *FindKey(const char *keyname) const;
127 virtual TKey *FindKeyAny(const char *keyname) const;
128 virtual TObject *FindObject(const char *name) const;
129 virtual TObject *FindObject(const TObject *obj) const;
130 virtual TObject *FindObjectAny(const char *name) const;
131 virtual TObject *Get(const char *namecycle);
132 virtual TDirectory *GetDirectory(const char *namecycle, Bool_t printError = false, const char *funcname = "GetDirectory");
133 template <class T> inline void GetObject(const char* namecycle, T*& ptr) // See TDirectory::Get for information
134 {
135 ptr = (T*)GetObjectChecked(namecycle,TBuffer::GetClass(typeid(T)));
136 }
137 virtual void *GetObjectChecked(const char *namecycle, const char* classname);
138 virtual void *GetObjectChecked(const char *namecycle, const TClass* cl);
139 virtual void *GetObjectUnchecked(const char *namecycle);
140 virtual Int_t GetBufferSize() const;
141 const TDatime &GetCreationDate() const { return fDatimeC; }
142 virtual TFile *GetFile() const { return fFile; }
143 virtual TKey *GetKey(const char *name, Short_t cycle=9999) const;
144 virtual TList *GetList() const { return fList; }
145 virtual TList *GetListOfKeys() const { return fKeys; }
146 const TDatime &GetModificationDate() const { return fDatimeM; }
147 TObject *GetMother() const { return fMother; }
148 TDirectory *GetMotherDir() const { return fMother==0 ? 0 : dynamic_cast<TDirectory*>(fMother); }
149 virtual Int_t GetNbytesKeys() const { return fNbytesKeys; }
150 virtual Int_t GetNkeys() const { return fKeys->GetSize(); }
151 virtual Long64_t GetSeekDir() const { return fSeekDir; }
152 virtual Long64_t GetSeekParent() const { return fSeekParent; }
153 virtual Long64_t GetSeekKeys() const { return fSeekKeys; }
154 virtual const char *GetPathStatic() const;
155 virtual const char *GetPath() const;
156 TUUID GetUUID() const {return fUUID;}
157 Bool_t IsFolder() const { return kTRUE; }
158 Bool_t IsModified() const { return fModified; }
159 Bool_t IsWritable() const { return fWritable; }
160 virtual void ls(Option_t *option="") const;
161 virtual TDirectory *mkdir(const char *name, const char *title="");
162 virtual void Paint(Option_t *option="");
163 virtual void Print(Option_t *option="") const;
164 virtual void Purge(Short_t nkeep=1);
165 virtual void pwd() const;
166 virtual void ReadAll(Option_t *option="");
167 virtual Int_t ReadKeys();
168 virtual void RecursiveRemove(TObject *obj);
169 virtual void rmdir(const char *name);
170 virtual void Save();
171 virtual void SaveSelf(Bool_t force = kFALSE);
172 virtual void SetBufferSize(Int_t bufsize);
173 void SetModified() {fModified = kTRUE;}
174 void SetMother(const TObject *mother) {fMother = (TObject*)mother;}
175 virtual void SetName(const char* newname);
176 void SetSeekDir(Long64_t v) { fSeekDir = v; }
177 void SetWritable(Bool_t writable=kTRUE);
178 virtual Int_t Sizeof() const;
179 virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0);
180 virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0) const ;
181 virtual Int_t WriteTObject(const TObject *obj, const char *name=0, Option_t *option="");
182 template <class T> inline Int_t WriteObject(const T* obj, const char* name, Option_t *option="") // see TDirectory::WriteObject or TDirectoryWriteObjectAny for explanation
183 {
184 return WriteObjectAny(obj,TBuffer::GetClass(typeid(T)),name,option);
185 }
186 virtual Int_t WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="");
187 virtual Int_t WriteObjectAny(const void *obj, const TClass *cl, const char *name, Option_t *option="");
188 virtual void WriteDirHeader();
189 virtual void WriteKeys();
190
191 static Bool_t Cd(const char *path);
192 static void DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle);
193 static void EncodeNameCycle(char *buffer, const char *name, Short_t cycle);
194
195 ClassDef(TDirectory,4) //Describe directory structure in memory
196};
197
198#endif
199
R__EXTERN TDirectory * gDirectory
TContext(TDirectory *previous, TDirectory *newCurrent)
TContext & operator=(TContext &)
TContext(TDirectory *newCurrent)
TContext(TContext &)
virtual Long64_t GetSeekDir() const
virtual Int_t ReadKeys()
Bool_t cd1(const char *path)
Buffer for GetPath() function.
void SetWritable(Bool_t writable=kTRUE)
static Bool_t Cd(const char *path)
virtual void Save()
virtual TList * GetList() const
Int_t AppendKey(TKey *key)
virtual void Purge(Short_t nkeep=1)
virtual void Close(Option_t *option="")
virtual Int_t Sizeof() const
virtual TKey * FindKey(const char *keyname) const
virtual TDirectory * mkdir(const char *name, const char *title="")
virtual void Append(TObject *obj)
virtual TObject * FindObject(const TObject *obj) const
Bool_t IsModified() const
virtual Int_t GetNkeys() const
virtual void WriteKeys()
virtual Int_t GetNbytesKeys() const
virtual void * GetObjectChecked(const char *namecycle, const TClass *cl)
virtual void ls(Option_t *option="") const
virtual void Copy(TObject &) const
virtual Int_t WriteObjectAny(const void *obj, const TClass *cl, const char *name, Option_t *option="")
virtual void * GetObjectChecked(const char *namecycle, const char *classname)
virtual void SaveSelf(Bool_t force=kFALSE)
void FillFullPath(TString &buf) const
virtual void FillBuffer(char *&buffer)
virtual void Browse(TBrowser *b)
Int_t WriteObject(const T *obj, const char *name, Option_t *option="")
virtual void WriteDirHeader()
virtual void Paint(Option_t *option="")
void Add(TObject *obj)
virtual void Draw(Option_t *option="")
virtual Int_t WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="")
const TDatime & GetModificationDate() const
virtual TObject * Get(const char *namecycle)
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
virtual void * GetObjectUnchecked(const char *namecycle)
static void DecodeNameCycle(const char *namecycle, char *name, Short_t &cycle)
virtual Int_t WriteTObject(const TObject *obj, const char *name=0, Option_t *option="")
virtual TFile * GetFile() const
virtual TKey * GetKey(const char *name, Short_t cycle=9999) const
void SetSeekDir(Long64_t v)
virtual void Print(Option_t *option="") const
virtual TKey * FindKeyAny(const char *keyname) const
TDirectory(const char *name, const char *title, Option_t *option="", TDirectory *motherDir=0)
static Bool_t Cd1(const char *path)
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
virtual void Clear(Option_t *option="")
virtual void SetBufferSize(Int_t bufsize)
Long64_t fSeekParent
virtual void DeleteAll(Option_t *option="")
virtual TObject * FindObject(const char *name) const
virtual Int_t GetBufferSize() const
virtual TObject * FindObjectAny(const char *name) const
virtual void pwd() const
virtual Long64_t GetSeekParent() const
virtual const char * GetPathStatic() const
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0) const
virtual Long64_t GetSeekKeys() const
virtual TList * GetListOfKeys() const
void SetMother(const TObject *mother)
TUUID GetUUID() const
Bool_t IsWritable() const
TDirectory * GetMotherDir() const
void Build(TFile *motherFile=0, TDirectory *motherDir=0)
virtual const char * GetPath() const
virtual void RecursiveRemove(TObject *obj)
TDirectory(const TDirectory &directory)
virtual Bool_t cd(const char *path=0)
TObject * GetMother() const
virtual void rmdir(const char *name)
Bool_t IsFolder() const
TObject * fMother
static void EncodeNameCycle(char *buffer, const char *name, Short_t cycle)
virtual void ReadAll(Option_t *option="")
void operator=(const TDirectory &)
void GetObject(const char *namecycle, T *&ptr)
virtual void SetName(const char *newname)
virtual ~TDirectory()
virtual void Delete(const char *namecycle="")
const TDatime & GetCreationDate() const