ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFileIter.h
Go to the documentation of this file.
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 01/03/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2001 [BNL] Brookhaven National Laboratory. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TFileIter
14 #define ROOT_TFileIter
15 
16 ///////////////////////////////////////////////////////////////////////////
17 // //
18 // Class to iterate (read / write ) the events written to /from TFile. //
19 // //
20 // - set the current internal cursor directly by different means //
21 // - set the current cursor to the "next" position if available //
22 // - gain extra information of the TKey object at the current position //
23 // - read TObject object from the TFile defined by TKey at the current //
24 // position //
25 // //
26 // - Read "next" object from the file //
27 // - n-th object from the file //
28 // - object that is in n object on the file //
29 // - read current object //
30 // - return the name of the key of the current object //
31 // - return the current position //
32 // - set the current position by the absolute position number //
33 // - set the current position by relative position number //
34 // - get the number of keys in the file //
35 // //
36 // The event is supposed to assign an unique ID in form of //
37 // //
38 // TKey name ::= event Id ::= eventName "." run_number "." event_number //
39 // //
40 // //
41 // and stored as the TKey name of the object written //
42 // //
43 // author Valeri Fine //
44 // //
45 ///////////////////////////////////////////////////////////////////////////
46 
47 #ifndef ROOT_TString
48 #include "TString.h"
49 #endif
50 #ifndef ROOT_TIterator
51 #include "TIterator.h"
52 #endif
53 #ifndef ROOT_TList
54 #include "TList.h"
55 #endif
56 #ifndef ROOT_TFile
57 #include "TFile.h"
58 #endif
59 
60 
61 class TFileIter : public TListIter {
62 
63 private:
64 
65  TFileIter *fNestedIterator; //! The inner TFidrectory interator;
66 
67  virtual TIterator &operator=(const TIterator &) { return *this; }
68  virtual Bool_t operator!=(const TIterator &it) const { return TListIter::operator!=(it);}
69 
70 protected:
71  TDirectory *fRootFile; // TDirectory/TFile to be iterated over
72  TString fEventName; // current key name
73  UInt_t fRunNumber; // current "run number"
74  UInt_t fEventNumber; // current "event number"
75  Int_t fCursorPosition; // the position of the current key in the sorted TKey list
76  Bool_t fOwnTFile; // Bit whether this classs creates TFile on its own to delete
77 
78  void Initialize();
79  TObject *ReadObj(const TKey *key) const;
80  TKey *NextEventKey(UInt_t eventNumber=UInt_t(-1), UInt_t runNumber=UInt_t(-1), const char *name="*");
81 
82 public:
83 
84  TFileIter(const char *name, Option_t *option = "",
85  const char *ftitle = "", Int_t compress = 1,
86  Int_t netopt = 0);
87  TFileIter(TFile *file=0);
88  TFileIter(TDirectory *directory);
89  TFileIter(const TFileIter &);
90  virtual ~TFileIter();
91 // --- draft !!! virtual Int_t Copy(TFile *destFile);
93  virtual const TFile *GetTFile() const;
94  virtual const TDirectory *GetTDirectory() const;
95  static TString MapName(const char *name, const char *localSystemKey = 0
96  , const char *mountedFileSystemKey = 0);
97  static const char *GetResourceName();
98  static const char *GetDefaultMapFileName();
99  static const char *GetLocalFileNameKey();
100  static const char *GetForeignFileSystemKey();
101  static void PurgeKeys(TList *listOfKeys);
102  virtual Bool_t IsOpen() const;
103  virtual TObject *NextEventGet(UInt_t eventNumber=UInt_t(-1), UInt_t runNumber=UInt_t(-1), const char *name="*");
104  virtual Int_t NextEventPut(TObject *obj, UInt_t eventNum, UInt_t runNumber, const char *name=0);
105  void SetCursorPosition(Int_t cursorPosition);
106  void SetCursorPosition(const char *keyNameToFind);
107  Int_t GetObjlen() const;
108  virtual Int_t TotalKeys() const;
109  virtual TKey *SkipObjects(Int_t nSkip=1);
110  virtual TObject *GetObject() const;
111  virtual Int_t GetDepth() const;
112 
113  TKey *GetCurrentKey() const;
114  const char *GetKeyName() const;
115 
116  TFileIter &operator=(Int_t cursorPosition);
117  TFileIter &operator=(const char *keyNameToFind);
118  TFileIter &operator+=(Int_t shift);
119  TFileIter &operator-=(Int_t shift);
122 
123  TObject *operator*() const;
124  operator const char *() const;
125  operator const TFile *() const;
126  operator const TDirectory *() const;
127  operator int () const;
128  int operator==(const char *name) const;
129  int operator!=(const char *name) const;
130 
131 public: // abstract TIterator methods implementations:
132 
133  virtual TObject *Next();
134  virtual TObject *Next(Int_t nSkip);
135  virtual void Reset();
136  virtual void Rewind();
137  TObject *operator()(Int_t nSkip);
138  TObject *operator()();
139 
140  ClassDef(TFileIter,0) // TFile class iterator
141 };
142 
143 //__________________________________________________________________________
144 inline const char *TFileIter::GetResourceName() {return "ForeignFileMap";}
145 //__________________________________________________________________________
146 inline const char *TFileIter::GetDefaultMapFileName() {return "io.config";}
147 //__________________________________________________________________________
148 inline const char *TFileIter::GetLocalFileNameKey() {return "LocalFileSystem";}
149 //__________________________________________________________________________
150 inline const char *TFileIter::GetForeignFileSystemKey(){return "MountedFileSystem";}
151 
152 //__________________________________________________________________________
154 {
155  // return the current
157 }
158 
159 //__________________________________________________________________________
160 inline const TFile *TFileIter::GetTFile() const { return GetTDirectory()->GetFile(); }
161 //__________________________________________________________________________
164 
165 //__________________________________________________________________________
167 {
168  // Make 1 step over the file objects and returns its pointer
169  // or 0, if there is no object left in the container
170  return Next(1);
171 }
172 
173 //__________________________________________________________________________
174 inline void TFileIter::Rewind()
175 {
176  // Alias for "Reset" method
177  Reset();
178 }
179 //__________________________________________________________________________
180 inline void TFileIter::SetCursorPosition(Int_t cursorPosition)
181 {
182  // Make <cursorPosition> steps (>0 - forward) over the file
183  // objects to skip it
184  if (fNestedIterator)
185  fNestedIterator->SetCursorPosition(cursorPosition);
186  else
187  SkipObjects(cursorPosition - fCursorPosition);
188 }
189 
190 //__________________________________________________________________________
191 inline TFileIter &TFileIter::operator=(const char *keyNameToFind)
192 {
193  // Iterate unless the name of the object matches <keyNameToFind>
194  SetCursorPosition(keyNameToFind); return *this;}
195 
196 //__________________________________________________________________________
197 inline TFileIter &TFileIter::operator=(Int_t cursorPosition)
198 {
199  // Iterate over <cursorPosition>
200  SetCursorPosition(cursorPosition);
201  return *this;
202 }
203 //__________________________________________________________________________
204 inline TFileIter::operator const TDirectory *() const
205 { return GetTDirectory(); }
206 
207 //__________________________________________________________________________
208 inline TFileIter::operator const TFile *() const
209 { return GetTFile (); }
210 //__________________________________________________________________________
212 { SkipObjects(shift); return *this;}
213 //__________________________________________________________________________
215 { return operator+=(-shift);}
216 //__________________________________________________________________________
218 { SkipObjects( 1); return *this;}
219 //__________________________________________________________________________
221 { SkipObjects(-1); return *this;}
222 //__________________________________________________________________________
224 { return GetObject();}
225 //__________________________________________________________________________
226 inline TFileIter::operator int () const
227 { return CurrentCursorPosition(); }
228 //__________________________________________________________________________
229 inline TFileIter::operator const char *() const
230 {
231  // return the current key name
232  return GetKeyName();
233 }
234 //__________________________________________________________________________
235 inline int TFileIter::operator==(const char *name) const
236 { return name ? !strcmp(name,GetKeyName()):0;}
237 
238 //__________________________________________________________________________
239 inline int TFileIter::operator!=(const char *name) const
240 { return !(operator==(name)); }
241 
242 //__________________________________________________________________________
243 inline TObject *TFileIter::operator()(){ return Next(); }
244 //__________________________________________________________________________
245 inline TObject *TFileIter::operator()(Int_t nSkip){ return Next(nSkip);}
246 
247 #endif
UInt_t fRunNumber
Definition: TFileIter.h:73
TFileIter * fNestedIterator
Definition: TFileIter.h:65
virtual ~TFileIter()
TFileIter dtor.
Definition: TFileIter.cxx:196
UInt_t fEventNumber
Definition: TFileIter.h:74
Int_t CurrentCursorPosition() const
Definition: TFileIter.h:153
virtual const TFile * GetTFile() const
Definition: TFileIter.h:160
virtual TIterator & operator=(const TIterator &)
The inner TFidrectory interator;.
Definition: TFileIter.h:67
static const char * GetDefaultMapFileName()
Definition: TFileIter.h:146
Bool_t fOwnTFile
Definition: TFileIter.h:76
const char Option_t
Definition: RtypesCore.h:62
Int_t fCursorPosition
Definition: TFileIter.h:75
virtual Int_t GetDepth() const
return the current number of the nested subdirectroies; = 0 - means there is no subdirectories ...
Definition: TFileIter.cxx:248
TObject * operator()()
Definition: TFileIter.h:243
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
void SetCursorPosition(Int_t cursorPosition)
Definition: TFileIter.h:180
const char * GetKeyName() const
return the name of the current TKey
Definition: TFileIter.cxx:256
Basic string class.
Definition: TString.h:137
static const char * GetLocalFileNameKey()
Definition: TFileIter.h:148
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
static const char * GetResourceName()
Definition: TFileIter.h:144
TKey * GetCurrentKey() const
return the pointer to the current TKey
Definition: TFileIter.cxx:240
TObject * ReadObj(const TKey *key) const
Read the next TObject from for the TDirectory by TKey provided.
Definition: TFileIter.cxx:495
Iterator abstract base class.
Definition: TIterator.h:32
Iterator of linked list.
Definition: TList.h:187
virtual Bool_t operator!=(const TIterator &it) const
This operator compares two TIterator objects.
Definition: TFileIter.h:68
#define ClassDef(name, id)
Definition: Rtypes.h:254
TDirectory * fRootFile
Definition: TFileIter.h:71
TString fEventName
Definition: TFileIter.h:72
virtual TObject * NextEventGet(UInt_t eventNumber=UInt_t(-1), UInt_t runNumber=UInt_t(-1), const char *name="*")
reads, creates and returns the object by TKey name that matches the "name" .
Definition: TFileIter.cxx:487
static TString MapName(const char *name, const char *localSystemKey=0, const char *mountedFileSystemKey=0)
MapName(const char *name, const char *localSystemKey,const char *mountedFileSystemKey) Substitute th...
Definition: TFileIter.cxx:547
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
TFileIter & operator++()
Definition: TFileIter.h:217
virtual Int_t NextEventPut(TObject *obj, UInt_t eventNum, UInt_t runNumber, const char *name=0)
Create a special TKey name with obj provided and write it out.
Definition: TFileIter.cxx:515
virtual const TDirectory * GetTDirectory() const
Definition: TFileIter.h:162
A doubly linked list.
Definition: TList.h:47
virtual TFile * GetFile() const
Definition: TDirectory.h:155
TFileIter & operator--()
Definition: TFileIter.h:220
virtual TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
Definition: TFileIter.h:166
int operator==(const char *name) const
Definition: TFileIter.h:235
virtual TObject * GetObject() const
read the object from TFile defined by the current TKey
Definition: TFileIter.cxx:273
void Initialize()
to be documented
Definition: TFileIter.cxx:211
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Bool_t IsOpen() const
Check whether the associated ROOT TFile was open and TFile object is healthy.
Definition: TFileIter.cxx:226
virtual Int_t TotalKeys() const
The total number of the TKey keys in the current TDirectory only Usually this means the total number ...
Definition: TFileIter.cxx:294
virtual void Reset()
Reset the status of the iterator.
Definition: TFileIter.cxx:356
static const char * GetForeignFileSystemKey()
Definition: TFileIter.h:150
virtual void Rewind()
Definition: TFileIter.h:174
Bool_t operator!=(const TIterator &aIter) const
This operator compares two TIterator objects.
Definition: TList.cxx:985
tuple file
Definition: fildir.py:20
Describe directory structure in memory.
Definition: TDirectory.h:44
TObject * operator*() const
Return current object or nullptr.
Definition: TFileIter.h:223
virtual TKey * SkipObjects(Int_t nSkip=1)
Returns the TKey pointer to the nSkip TKey object from the current one nSkip = 0; the state of the it...
Definition: TFileIter.cxx:401
TFileIter & operator+=(Int_t shift)
Definition: TFileIter.h:211
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
TFileIter & operator-=(Int_t shift)
Definition: TFileIter.h:214
TFileIter(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Open ROOT TFile by the name provided; This TFile is to be deleted by the TFileIter alone...
Definition: TFileIter.cxx:149
TObject * obj
static void PurgeKeys(TList *listOfKeys)
Remove the TKey duplication, leave the keys with highest cycle number only Sort if first...
Definition: TFileIter.cxx:316
Int_t GetObjlen() const
Returns the uncompressed length of the current object.
Definition: TFileIter.cxx:280
TKey * NextEventKey(UInt_t eventNumber=UInt_t(-1), UInt_t runNumber=UInt_t(-1), const char *name="*")
Definition: TFileIter.cxx:443