CMS 3D CMS Logo

TH1Store.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #if !defined(TH1Store_H)
4 #define TH1Store_H
5 
6 #include <map>
7 #include <string>
8 #include <set>
9 
10 #include "TH1.h"
11 #include "TFile.h"
12 #include "TString.h"
13 #include "TDirectory.h"
14 
15 class TH1Store
16 {
17  public:
18 
20  // Public Constants //
22 
23  typedef std::vector< std::string > SVec;
24  typedef std::map< std::string, std::string > SSMap;
25  typedef std::map< std::string, TH1* > STH1PtrMap;
26  typedef SSMap::const_iterator SSMapConstIter;
27  typedef STH1PtrMap::iterator STH1PtrMapIter;
28  typedef STH1PtrMap::const_iterator STH1PtrMapConstIter;
29 
30  static const SVec kEmptyVec;
31 
33  // friends //
35  // tells particle data how to print itself out
36  friend std::ostream& operator<< (std::ostream& o_stream,
37  const TH1Store &rhs);
38 
40  // _ //
41  // |\/| |_ //
42  // | |EMBER | UNCTIONS //
43  // //
45 
47  // Constructors and Destructor //
49  TH1Store();
50  ~TH1Store();
51 
53  // One Liners //
55  // Whether or not to delete histogram pointers on destruction
56  void setDeleteOnDestruction (bool deleteOnDestruction = true)
57  { m_deleteOnDestruction = deleteOnDestruction; }
58 
60  // Regular Member Functions //
62 
63  // adds a histogram pointer to the map
64  void add (TH1 *histPtr, const std::string &directory = "");
65 
66  // given a string, returns corresponding histogram pointer
67  TH1* hist (const std::string &name);
68  TH1* hist (const char* name)
69  { return hist( (const std::string) name ); }
70  TH1* hist (const TString &name)
71  { return hist( (const char*) name ); }
72 
73  // write all histograms to a root file
74  void write (const std::string &filename,
75  const SVec &argsVec = kEmptyVec,
76  const SVec &inputFilesVec = kEmptyVec) const;
77  void write (TFile *filePtr,
78  const SVec &argsVec = kEmptyVec,
79  const SVec &inputFilesVec = kEmptyVec) const;
80 
82  // Static Member Functions //
84 
85  // turn on verbose messages (e.g., printing out histogram names
86  // when being made)
87  static void setVerbose (bool verbose = true)
88  { sm_verbose = verbose; }
89 
90  private:
91 
93  // Private Member Functions //
95 
96  // creates directory and all parent directories as needed
97  // (equivalent to unix 'mkdir -p') and then changes (cd's) to
98  // that directory. Returns TDirectory of pointing to dirname.
99  TDirectory* _createDir (const std::string &dirname, TFile *filePtr) const;
100 
102  // Private Member Data //
104 
106  STH1PtrMap m_ptrMap;
108 
110  // Private Static Member Data //
112 
113  static bool sm_verbose;
114 
115 };
116 
117 
118 #endif // TH1Store_H
static void setVerbose(bool verbose=true)
Definition: TH1Store.h:87
bool m_deleteOnDestruction
Definition: TH1Store.h:105
SSMap m_nameDirMap
Definition: TH1Store.h:107
void add(TH1 *histPtr, const std::string &directory="")
Definition: TH1Store.cc:39
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:131
static bool sm_verbose
Definition: TH1Store.h:113
void setDeleteOnDestruction(bool deleteOnDestruction=true)
Definition: TH1Store.h:56
~TH1Store()
Definition: TH1Store.cc:25
static const SVec kEmptyVec
Definition: TH1Store.h:30
void write(const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
std::map< std::string, TH1 * > STH1PtrMap
Definition: TH1Store.h:25
static int verbose
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:28
STH1PtrMap m_ptrMap
Definition: TH1Store.h:106
friend std::ostream & operator<<(std::ostream &o_stream, const TH1Store &rhs)
std::vector< std::string > SVec
Definition: TH1Store.h:23
STH1PtrMap::iterator STH1PtrMapIter
Definition: TH1Store.h:27
std::map< std::string, std::string > SSMap
Definition: TH1Store.h:24
TH1 * hist(const char *name)
Definition: TH1Store.h:68
TH1Store()
Definition: TH1Store.cc:21
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:26
TH1 * hist(const std::string &name)
TH1 * hist(const TString &name)
Definition: TH1Store.h:70