Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:22

0001 // -*- C++ -*-
0002 
0003 #if !defined(TH1Store_H)
0004 #define TH1Store_H
0005 
0006 #include <map>
0007 #include <string>
0008 #include <set>
0009 
0010 #include "TH1.h"
0011 #include "TFile.h"
0012 #include "TString.h"
0013 #include "TDirectory.h"
0014 
0015 class TH1Store {
0016 public:
0017   //////////////////////
0018   // Public Constants //
0019   //////////////////////
0020 
0021   typedef std::vector<std::string> SVec;
0022   typedef std::map<std::string, std::string> SSMap;
0023   typedef std::map<std::string, TH1 *> STH1PtrMap;
0024   typedef SSMap::const_iterator SSMapConstIter;
0025   typedef STH1PtrMap::iterator STH1PtrMapIter;
0026   typedef STH1PtrMap::const_iterator STH1PtrMapConstIter;
0027 
0028   static const SVec kEmptyVec;
0029 
0030   /////////////
0031   // friends //
0032   /////////////
0033   // tells particle data how to print itself out
0034   friend std::ostream &operator<<(std::ostream &o_stream, const TH1Store &rhs);
0035 
0036   //////////////////////////
0037   //            _         //
0038   // |\/|      |_         //
0039   // |  |EMBER | UNCTIONS //
0040   //                      //
0041   //////////////////////////
0042 
0043   /////////////////////////////////
0044   // Constructors and Destructor //
0045   /////////////////////////////////
0046   TH1Store();
0047   ~TH1Store();
0048 
0049   ////////////////
0050   // One Liners //
0051   ////////////////
0052   // Whether or not to delete histogram pointers on destruction
0053   void setDeleteOnDestruction(bool deleteOnDestruction = true) { m_deleteOnDestruction = deleteOnDestruction; }
0054 
0055   //////////////////////////////
0056   // Regular Member Functions //
0057   //////////////////////////////
0058 
0059   // adds a histogram pointer to the map
0060   void add(TH1 *histPtr, const std::string &directory = "");
0061 
0062   // given a string, returns corresponding histogram pointer
0063   TH1 *hist(const std::string &name);
0064   TH1 *hist(const char *name) { return hist((const std::string)name); }
0065   TH1 *hist(const TString &name) { return hist((const char *)name); }
0066 
0067   // write all histograms to a root file
0068   void write(const std::string &filename, const SVec &argsVec = kEmptyVec, const SVec &inputFilesVec = kEmptyVec) const;
0069   void write(TFile *filePtr, const SVec &argsVec = kEmptyVec, const SVec &inputFilesVec = kEmptyVec) const;
0070 
0071   /////////////////////////////
0072   // Static Member Functions //
0073   /////////////////////////////
0074 
0075   // turn on verbose messages (e.g., printing out histogram names
0076   // when being made)
0077   static void setVerbose(bool verbose = true) { sm_verbose = verbose; }
0078 
0079 private:
0080   //////////////////////////////
0081   // Private Member Functions //
0082   //////////////////////////////
0083 
0084   // creates directory and all parent directories as needed
0085   // (equivalent to unix 'mkdir -p') and then changes (cd's) to
0086   // that directory.  Returns TDirectory of pointing to dirname.
0087   TDirectory *_createDir(const std::string &dirname, TFile *filePtr) const;
0088 
0089   /////////////////////////
0090   // Private Member Data //
0091   /////////////////////////
0092 
0093   bool m_deleteOnDestruction;
0094   STH1PtrMap m_ptrMap;
0095   SSMap m_nameDirMap;
0096 
0097   ////////////////////////////////
0098   // Private Static Member Data //
0099   ////////////////////////////////
0100 
0101   static bool sm_verbose;
0102 };
0103 
0104 #endif  // TH1Store_H