// TupleManager.h #ifndef TupleManager_H #define TupleManager_H // TupleManager manages a file containing ntuples and histograms. // // If the FNAL package HepTuple is present, this class makes use of // the HepTuple file HepHbookFileManager. If not, it makes use of the // CLHEP class HBookFile. The interface is similar to either of these // except that only one instance of this class may exist and TRF++ histograms // and ntuples are accessed through static methods. This instance is // created automatically when the first histogram or ntuple is accessed. // A method open() may be added to allow the user to do this and specify // the file name. // // Also, the file is automatically written to disk after the main // program exits. If the need arises to close the file earlier, // the interface can be expanded to add method close. // #include #include #include "Tuple.h" #include "Hist1D.h" #include "ptr/Ptr.h" #include "ptr/NullPolicy.h" #include "ptr/DeletePolicy.h" #ifndef NO_HEPTUPLE class HepFileManager; #else #include "CLHEP/Hist/HBookFile.h" #endif class TupleManager { public: // typedefs // Tuple pointer. #ifndef NO_HEPTUPLE typedef Ptr TuplePtr; typedef Ptr Hist1DPtr; #else typedef Ptr TuplePtr; #endif // Map of tuples indexed by string. typedef std::map > TupleMap; #ifndef NO_HEPTUPLE // Map of 1D histograms indexed by string title. typedef std::map > Hist1DMap; #endif private: // static attributes // The only instance of this class. static Ptr _pthis; private: // attributes // The real manager. #ifndef NO_HEPTUPLE Ptr _pmgr; #else Ptr _pmgr; #endif // map of tuples indexed by name TupleMap _tuples; #ifndef NO_HEPTUPLE // map of 1D histograms indexed by name Hist1DMap _hist1ds; #endif public: // static methods // Fetch an ntuple. // If the ntuple does not exist, it is created. static Tuple& tuple(const char* name); static Tuple& tuple(std::string name); // Check and see if a tuple has been defined. static bool is_tuple(std::string name); #ifndef NO_HEPTUPLE // Create a 1D histogram static Hist1D& hist1d(std::string title, int nbins, float low, float high); // Fetch an already existing 1D histogram. static Hist1D& hist1d(std::string title); // Check if the specified 1D histogram has been defined. static bool is_hist1d(std::string title); #endif // Fetch a 2D histogram // static Histogram& histogram(const char* title, // int nBinsX, float lowX, float highX, // int nBinsY, float lowY, float highY); // Open the ntuple file. // Return nonzero for error. // Returns error if a file is already open. // int open(); // Close and write out the present ntuples. // Return nonzero for error. // void close(); private: // methods // Hide constructor TupleManager(); public: // methods // Destructor. ~TupleManager(); }; #endif