CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/PhysicsTools/FWLite/interface/TH1Store.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #if !defined(TH1Store_H)
00004 #define TH1Store_H
00005 
00006 #include <map>
00007 #include <string>
00008 #include <set>
00009 
00010 #include "TH1.h"
00011 #include "TFile.h"
00012 #include "TString.h"
00013 #include "TDirectory.h"
00014 
00015 class TH1Store
00016 {
00017    public:
00018 
00020       // Public Constants //
00022 
00023       typedef std::vector< std::string >            SVec;
00024       typedef std::map< std::string, std::string >  SSMap;
00025       typedef std::map< std::string, TH1* >         STH1PtrMap;
00026       typedef SSMap::const_iterator                 SSMapConstIter;
00027       typedef STH1PtrMap::iterator                  STH1PtrMapIter;
00028       typedef STH1PtrMap::const_iterator            STH1PtrMapConstIter;
00029 
00030       static const SVec kEmptyVec;
00031 
00033       // friends //
00035       // tells particle data how to print itself out
00036       friend std::ostream& operator<< (std::ostream& o_stream, 
00037                                        const TH1Store &rhs);
00038 
00040       //            _         //
00041       // |\/|      |_         //
00042       // |  |EMBER | UNCTIONS //
00043       //                      //
00045 
00047       // Constructors and Destructor //
00049       TH1Store();
00050       ~TH1Store();
00051 
00053       // One Liners //
00055       // Whether or not to delete histogram pointers on destruction
00056       void setDeleteOnDestruction (bool deleteOnDestruction = true) 
00057       { m_deleteOnDestruction = deleteOnDestruction; }
00058 
00060       // Regular Member Functions //
00062 
00063       // adds a histogram pointer to the map
00064       void add (TH1 *histPtr, const std::string &directory = "");
00065 
00066       // given a string, returns corresponding histogram pointer
00067       TH1* hist (const std::string &name);
00068       TH1* hist (const char* name)    
00069       { return hist( (const std::string) name ); }
00070       TH1* hist (const TString &name) 
00071       { return hist( (const char*) name ); }
00072 
00073       // write all histograms to a root file
00074       void write (const std::string &filename, 
00075                   const SVec &argsVec = kEmptyVec, 
00076                   const SVec &inputFilesVec = kEmptyVec) const;
00077       void write (TFile *filePtr, 
00078                   const SVec &argsVec = kEmptyVec, 
00079                   const SVec &inputFilesVec = kEmptyVec) const;
00080 
00082       // Static Member Functions //
00084 
00085       // turn on verbose messages (e.g., printing out histogram names
00086       // when being made)
00087       static void setVerbose (bool verbose = true)
00088       { sm_verbose = verbose; }
00089 
00090   private:
00091 
00093       // Private Member Functions //
00095 
00096       // creates directory and all parent directories as needed
00097       // (equivalent to unix 'mkdir -p') and then changes (cd's) to
00098       // that directory.  Returns TDirectory of pointing to dirname.
00099       TDirectory* _createDir (const std::string &dirname, TFile *filePtr) const;
00100 
00102       // Private Member Data //
00104 
00105       bool       m_deleteOnDestruction;
00106       STH1PtrMap m_ptrMap;
00107       SSMap      m_nameDirMap;
00108       
00110       // Private Static Member Data //
00112 
00113       static bool sm_verbose;      
00114 
00115 };
00116 
00117 
00118 #endif // TH1Store_H