CDF II
CDF KITS
source navigation ]
diff markup ]
identifier search ]
freetext search ]
file search ]
 
Architecture: i386 ]
Version: 4.10.4 ] [ 4.10.5 ] [ 4.8.4 ] [ 4.8.4l3s ] [ 4.8.5 ] [ 4.9.0 ] [ 4.9.1 ] [ 4.9.1.hpt3 ] [ 4.9.1hpt3 ] [ 4.9.1top1 ] [ 5.0.0 ] [ 5.1.0 ] [ 5.1.0beamonly ] [ 5.1.1 ] [ 5.2.0 ] [ 5.3.0 ] [ 5.3.1 ] [ 5.3.1dsp ] [ 5.3.3 ] [ 5.3.3_nt ] [ 5.3.4 ] [ 6.1.1 ] [ 6.1.1b ] [ 6.1.2 ] [ 6.1.3 ] [ 6.1.4 ] [ 6.1.4int3 ] [ 6.1.4mc ] [ 6.1.4mc_a ] [ 6.1.6 ] [ development ]

001 #ifndef HEPFILEMANAGER_H
002 #define HEPFILEMANAGER_H
003 
004 
005 // ----------------------------------------------------------------------
006 //
007 // HepFileManager.h - header file for abstract base class providing
008 //   interface to any concrete histogram/Ntuple file manager
009 //
010 // HepFileManager objects are never instantiated directly.  Instead, use
011 // the derived class for the manager that is to be used (e.g.,
012 // HepHbookFileManager, HepHippoFileManager, etc.).  Refer to those
013 // class header files for usage.
014 //
015 // When creating a histogram/Ntuple manager or writing a wrapper for an
016 // existing manager, the manager class should be derived from this one.
017 //
018 //
019 // History:
020 //   ??-Jul-1994  Paul Rensing     Original draft
021 //   ??-Aug-1994  Bob Jacobsen     Added histogram support
022 //   26-Apr-1997  John Marraffino  Added directory functionality
023 //   20-May-1997  Walter Brown     General cleanup
024 //   29-May-1997  Jason Luther     Added comments
025 //   19-Jun-1997  Walter Brown     Restructured to handle cwd and the
026 //     ALists here; added findHist()s
027 //   27-Jun-1997  Walter Brown  Replaced HepString by standard string
028 //   18-Jul-1997  Philippe Canal   Added HepNtuple constructor
029 //   28-July-1997 Walter Brown     Added support for a list of managed
030 //     HepNtuple objects
031 //   05-Aug-1997  Walter Brown     Added writeOne()
032 //   08-Aug-1997  Walter Brown     Added isDirty(); granted friendship
033 //     to HepNtuple
034 //   12-Aug-1997  Walter Brown     Added root directory provisions
035 //   14-Aug-1997  Walter Brown     Added release()
036 //   21-Aug-1997  Walter Brown     Renamed newX() to makeX() and oldX()
037 //     to retrieveX(); changed return values from pointers to references;
038 //     added retrieveNtuple() prototype
039 //   27-Aug-1997  Walter Brown     Renamed makeX() to x() per committee
040 //   31-Oct-1997  Philippe Canal   Add dummy object creator for use after
041 //                                 an ignored exceptions
042 //   03-Nov-1997  Walter Brown     Added deadHepObj()
043 //   27-Jul-1998  Philippe Canal   Added actual object directory listing,
044 //                                 directory HepObj and utilities routines
045 //   19-Mar-2001  Mark Fischler    Added hepFileFormat method
046 //
047 // ----------------------------------------------------------------------
048 
049 #ifndef ZMENVIRONMENT_H
050   #include "ZMutility/ZMenvironment.h"
051 #endif
052 
053 #include <string>
054 #include <utility>
055 
056 #include <vector>
057 
058 #include "HepTuple/Exceptions.h"
059 #include "HepTuple/hepTupleFileType.h"
060 
061 ZM_USING_NAMESPACE( zmex )
062 
063 ZM_BEGIN_NAMESPACE( zmht )      /*  namespace zmht  {  */
064 
065 class HepHist;
066 class HepHist1D;
067 class HepHist2D;
068 class HepHistProf;
069 class HepHist1DArray;
070 class HepHist2DArray;
071 class HepHistProfArray;
072 class HepNtuple;
073 class HepDir;
074 class HepObj;
075 class HepID;
076 
077 class HepHistCombiner;
078 class GatherProxy;
079 class HepFileSwitch;
080 
081 class HepFileManager  {
082 
083   friend class HepObj;
084   friend class HepHist;
085   friend class HepHist1D;
086   friend class HepHist2D;
087   friend class HepHistProf;
088   friend class HepHist1DArray;
089   friend class HepHist2DArray;
090   friend class HepHistProfArray;
091   friend class HepNtuple;
092   friend class HepDir;
093 
094 public:
095 
096   // usefull constant
097   static const std::string absStart; // start of an absolute path ('//')
098   static const std::string dirSep;   // directory separator ('/')
099 
100   // constructor/destructor:
101   HepFileManager(
102     const std::string& fileName
103   , const std::string& rootDirName
104   );
105   // Enum to request a file opening mode 
106   // HEP_REFRESH means that the file is open for update
107   // but (for the manager that supports it) insure that
108   // each modified objects is over-written rather than 
109   // versioned (see ROOT).
110   // HEP_REMOVE means that any existing file with the
111   // specified name will be removed.   DANGEROUS!!!
112   // HEP_RENAME means that any existing file with the
113   // specified name will be renamed.
114   typedef enum mode_ { HEP_READONLY=1, HEP_UPDATE=2, HEP_REFRESH=4,
115                        HEP_REMOVE=8,   HEP_RENAME=16 } mode;
116 
117   virtual ~HepFileManager();
118 
119   // Optional protections
120   bool forReadOnly();      // Set the manager as read only
121   bool forUpdate();        // Verify that the file can be updated
122 
123   // accessors:
124   inline std::string  fileName() const;
125   inline std::string  rootDir() const;
126   std::string         pwd() const;
127   inline bool         isReadOnly() const;
128   virtual HepTupleFileFormat hepFileFormat() const = 0;
129 
130   // directory manipulation functions:
131   virtual void cd( const std::string & path = "" );
132 
133   virtual void mkdir( const std::string & path );
134 
135   virtual std::string ls(const std::string & path = "", 
136                          const std::string & opts = "" )  const;
137 
138   class Item {
139   public:
140     HepFileManager * mgr;         // pointer to desired manager
141     std::string      title;       // object's title
142     int              id;          // optional unique object ident
143     std::string      dir;         // object's directory
144     char             type;        // object type identification
145     Item(const HepObj&);
146     Item();                     
147   };
148   friend class HepFileManager::Item;
149   typedef std::vector<Item> ItemList;
150   virtual ItemList list( const std::string & path = "", 
151                          const std::string & opts = ""  )  const;
152 
153   virtual void rm( int hid = 0 );
154   virtual void rm( const std::string & title );
155 
156   virtual void rmdir( const std::string & path, bool recursive = false );
157   //  virtual void rmdir( const HepDir & dir, bool recursive = false );
158 
159   // create histograms and Ntuples:
160   static HepObj * deadHepObj();      // for erroneous situations
161 
162   virtual HepHist1D & hist1D(        // 1-D
163     const std::string& title,
164     const int nBins, const float low, const float high,
165     const int hid = 0
166   );
167   virtual HepHist1DArray& hist1DArray(   // Array of 1-D Histograms 
168     const int size,
169     const std::string& title_prefix,
170     const int nBins, const float low, const float high,
171     const int hid = 0
172   );
173   virtual HepHist2D & hist2D(        // 2-D
174     const std::string& title,
175     const int nBinsX, const float lowX, const float highX,
176     const int nBinsY, const float lowY, const float highY,
177     const int hid = 0
178   );
179   virtual HepHist2DArray& hist2DArray(   // Array of 2-D Histograms 
180     const int size,
181     const std::string& title_prefix,
182     const int nBinsX, const float lowX, const float highX,
183     const int nBinsY, const float lowY, const float highY,
184     const int hid = 0
185   );
186   virtual HepHistProf & histProf(    // profile plot
187     const std::string& title,
188     const int nBinsX, const float lowX, const float highX,
189     const float lowY, const float highY,
190     const std::string& chopt,
191     const int hid = 0
192   );
193   virtual HepHistProf & histProf(    // profile plot
194     const std::string& title,
195     const int nBinsX, const float lowX, const float highX,
196     const float lowY, const float highY,
197     const int hid = 0
198   );
199   virtual HepHistProfArray & histProfArray(    // Array of profile plot
200     const int size,
201     const std::string& title_prefix,
202     const int nBinsX, const float lowX, const float highX,
203     const float lowY, const float highY,
204     const std::string& chopt,
205     const int hid = 0
206   );
207   virtual HepHistProfArray & histProfArray(    // Array of profile plot
208     const int size,
209     const std::string& title_prefix,
210     const int nBinsX, const float lowX, const float highX,
211     const float lowY, const float highY,
212     const int hid = 0
213   );
214   virtual HepNtuple & ntuple(        // Ntuple
215     const std::string& title,
216     const int hid = 0
217   );
218 
219 
220   // attach to existing histograms and Ntuples:
221   HepObj * retrieveHepObj(                   // generic retrieval logic:
222     const std::string& title
223   , const int hid
224   , const char objType
225   ) const;
226 
227   HepObj * retrieveHepObj(                   // generic retrieval logic:
228     const std::string& title
229   , const int hid
230   , const char objType
231   , const std::string& path
232   ) const;
233 
234   virtual HepHist1D & retrieveHist1D(        // 1-D
235     const std::string& title,
236     const int hid = 0
237   );
238   virtual HepHist2D & retrieveHist2D(        // 2-D
239     const std::string& title,
240     const int hid = 0
241   );
242   virtual HepHistProf & retrieveHistProf(    // profile plot
243     const std::string& title,
244     const int hid = 0
245   );
246   virtual HepHist1DArray & retrieveHist1DArray(        // Array of 1-D
247     const int size,
248     const std::string& title,
249     const int hid = 0
250   );
251   virtual HepHist2DArray & retrieveHist2DArray(        // Array of 2-D
252     const int size,
253     const std::string& title,
254     const int hid = 0
255   );
256   virtual HepHistProfArray & retrieveHistProfArray(    // Array of profile plot
257     const int size,
258     const std::string& title,
259     const int hid = 0
260   );
261   virtual HepNtuple & retrieveNtuple(        // Ntuple
262     const std::string& title,
263     const int hid = 0
264   );
265 
266   // user is finished with the indicated object
267   virtual void release( HepObj & me );
268 
269   // write the Ntuples/histograms into the file, returning success status:
270   // non-0 otherwise.
271   virtual int write() = 0;
272 
273   // write this directory's Ntuples/histograms into the file
274   virtual void writeDirectory() = 0;
275 
276   // Call dumpData() or clearData() for all managed tuples
277   virtual void dumpAllData();
278   virtual void clearAllData();
279 
280   // Create a object of that a clone or copy of the argument in the current
281   // directory. A Copy in an exact replication of the argument. A clone is an
282   // object of the same type and characteristic (e.g number of bins) but
283   // without any data entered.
284 
285   virtual HepObj& makeClone( const HepObj& original, const std::string& new_title, int new_id = 0 ); 
286   virtual HepObj& makeEmpty( const HepObj& original, const std::string& new_title, int new_id = 0 ); 
287 
288   // Clone all the objects in the current (specified) directory of the original manager.
289   // options are the same as for list and ls.  Cloned items have the same title and id
290   // as the originals.
291   virtual bool copyClone( HepFileManager* original, const std::string& options = "" );
292   virtual bool copyClone( HepFileManager* original, const std::string& path,
293                           const std::string& options);
294   virtual bool copyEmpty( HepFileManager* original, const std::string& options = "" );
295   virtual bool copyEmpty( HepFileManager* original, const std::string& path,
296                           const std::string& options);
297 
298   // Merge, except for ntuples, all the objects in this and sourceManager
299   HepFileManager & combine( HepFileManager* sourceManager );
300 
301   // Merge, except for ntuples, all the objects in this and sourceManager
302   // according to the recipe provided by the user in his/her
303   // HepHistCombiner::usercomb object.
304   HepFileManager & combine( HepFileManager* sourceManager,
305                             HepHistCombiner & usercomb );
306 
307   // Same operation as combine except expressed as an operator overload.
308   HepFileManager & operator+= ( HepFileManager& b );
309 
310   // Transparently switch output from current file to newFileName with
311   // optional resetting of all histogram objects.  Root manager only.
312   virtual bool switchFile( const std::string& newFileName,
313                            const bool resetHists );
314 
315   // Transparently switch output from current file to newFileName with
316   // optional resetting of all histogram objects.  Root manager only.
317   virtual bool switchFile( const std::string& newFileName,
318                            const bool resetHists,
319                            HepFileSwitch& userHandler );
320 
321 #ifdef BABAR
322 
323 // ************************************************************************* //
324 // define accessor that return pointers instead of reference to ease         //
325 // babar's transition                                                        //
326 
327   HepHist1D* newHist1D ( 
328     const char title[],
329     const int nBins, const float low, const float high,
330     const int hid = 0
331     );
332   HepHist2D* newHist2D(        // 2-D
333     const char title[],
334     const int nBinsX, const float lowX, const float highX,
335     const int nBinsY, const float lowY, const float highY,
336     const int hid = 0
337   );
338   HepHistProf* newHistProf(    // profile plot
339     const char title[],
340     const int nBinsX, const float lowX, const float highX,
341     const float lowY, const float highY,
342     const char chopt[],
343     const int hid = 0
344   );
345   HepHistProf* newHistProf(    // profile plot
346     const char title[],
347     const int nBinsX, const float lowX, const float highX,
348     const float lowY, const float highY,
349     const int hid = 0
350   );
351   HepNtuple* newNtuple(        // Ntuple
352     const char title[],
353     const int hid = 0
354   );
355 
356 #endif
357 
358 protected:
359   // Function check what is the actual mode of a file
360   typedef enum filemode_ { HEP_ABSENT, HEP_NONE, 
361                            HEP_READ, HEP_WRITE, HEP_ALL } filemode;
362   static filemode checkFile ( const std::string & filename );
363 
364   // Check if the title is valid (at least not '/' in it)
365   virtual bool checkTitle( const std::string& title) const;
366 
367   // set the read only flag and return the old value.  NO CHECK is performed.
368   // use forReadOnly() and forUpdate() for checked operations.
369   bool setReadOnly ( bool );
370 
371   // Return the highest id in the current directory.
372   int GetHighestId(const std::string& path = "") const;
373 
374   // Created the internal representation of the directory.
375   // It will NOT create it in the actual manager.
376   HepDir* mkdir_( const std::string & path );
377 
378   // Return the HepDir node corresponding to the path
379   HepDir* getdir(const std::string& path) const;
380 
381   HepObj * retrieveHepObj(         // generic retrieval logic
382     const std::string& title       // called by other retrieve functions
383     , const int hid
384     , const char objType
385     , const HepDir* dir 
386   ) const;
387 
388   // update the list with the content of dir.  Do dir's sub-directory
389   // it opts containt the letter 'r'
390   void list_(const HepDir&,HepFileManager::ItemList&,const std::string& opts) const;
391 
392   // Actual copyClone and copyEmpty member functions.
393 
394   virtual bool copyClone_( const HepDir& original, const std::string& options );
395   virtual bool copyEmpty_( const HepDir& original, const std::string& options );
396 
397   // id generator: Provide the next available ID, or honor the req
398   HepID nextID( const int req = 0 ); 
399      // call next one with empty string (emulate default 1st argument.)
400   virtual HepID nextID( const std::string& s = "", const int req = 0 ); 
401 
402   // save individual histograms and Ntuples:
403   virtual void writeOne( HepObj * thisObj  );
404 
405   typedef std::vector<HepObj *> HepObjList;
406   HepObjList   objList_;      // list of (ptrs to) all HepObj's in this file
407   HepObjList   deadObjList_;  // list of deleted HepObj's in this file
408                               // (an object makes it to this list if it is
409                               // delete while the users MAY have a reference 
410                               // to it.  It will be actually delete when 
411                               // the manager is deleted.
412 
413   // list inspection & maintenance:
414   HepObjList::const_iterator  findObj( const std::string & title ) const;
415   HepObjList::const_iterator  findObj( const int id ) const;
416   void signIn( HepObj * thisObj );
417 
418   void isInUse( HepObj * h, const bool isIt );
419   void isDirty( HepObj * h, const bool isIt );
420   void isCreated( HepObj * h, const bool isIt );
421 
422   // Dead Object creator
423   virtual HepNtuple& deadNtuple() const;
424   virtual HepHist1D& deadHist1D() const;
425   virtual HepHist2D& deadHist2D() const;
426   virtual HepHistProf& deadHistProf() const;
427 
428   static HepHist1DArray& deadHist1DArray();
429   static HepHist2DArray& deadHist2DArray();
430   static HepHistProfArray& deadHistProfArray();
431 
432   static void copyToItem(const HepObj&,Item&); 
433   // used by Item constructor to read HepObj eventhough Item is not a friend
434   // of HepObj and HepObj data members are not available publicly when the
435   // user does not have the object.  
436 
437   // Helper functions for the public HepFileManager::combine function
438 
439 typedef std::vector<std::string>                svector;
440 
441   void reconcileDirs( HepFileManager* sourceManager, 
442                       GatherProxy& satchel );
443 
444   void gatherHists( HepFileManager* sourceManager, 
445                     GatherProxy& satchel );
446 
447   void scanTree( HepFileManager* Manager, svector& Dirs, svector& Keys );
448 
449 private:
450 
451   std::string fileName_;        // the file name
452   const std::string rootDir_;   // the name of this file's root directory
453   HepDir*      topDir_;         // The upmost directory
454   HepDir*      cwd_;            // the current working directory
455   int          lastID_;         // the last largest id number used
456   bool         isReadOnly_;     // Fist set as the opening status of the file
457                                 // which may be later changed by the user
458                                 // see forReadOnly()
459 
460   HepFileManager( const HepFileManager & );              // forbidden
461   HepFileManager & operator=( const HepFileManager & );  // forbidden
462 
463 };  // HepFileManager
464 
465 
466 typedef HepFileManager HepTupleManager; // preserve classname compatibility
467 
468 
469 ZM_END_NAMESPACE( zmht )        /*  }  // namespace zmht  */
470 
471 
472 #include "HepFileManager.icc"
473 
474 
475 #endif  // HEPFILEMANAGER_H
476 

source navigation ] diff markup ] identifier search ] freetext search ] file search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!

Send problems or questions to cdfcode@fnal.gov