CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 public:
18  // Public Constants //
20 
21  typedef std::vector<std::string> SVec;
22  typedef std::map<std::string, std::string> SSMap;
23  typedef std::map<std::string, TH1 *> STH1PtrMap;
24  typedef SSMap::const_iterator SSMapConstIter;
25  typedef STH1PtrMap::iterator STH1PtrMapIter;
26  typedef STH1PtrMap::const_iterator STH1PtrMapConstIter;
27 
28  static const SVec kEmptyVec;
29 
31  // friends //
33  // tells particle data how to print itself out
34  friend std::ostream &operator<<(std::ostream &o_stream, const TH1Store &rhs);
35 
37  // _ //
38  // |\/| |_ //
39  // | |EMBER | UNCTIONS //
40  // //
42 
44  // Constructors and Destructor //
46  TH1Store();
47  ~TH1Store();
48 
50  // One Liners //
52  // Whether or not to delete histogram pointers on destruction
53  void setDeleteOnDestruction(bool deleteOnDestruction = true) { m_deleteOnDestruction = deleteOnDestruction; }
54 
56  // Regular Member Functions //
58 
59  // adds a histogram pointer to the map
60  void add(TH1 *histPtr, const std::string &directory = "");
61 
62  // given a string, returns corresponding histogram pointer
63  TH1 *hist(const std::string &name);
64  TH1 *hist(const char *name) { return hist((const std::string)name); }
65  TH1 *hist(const TString &name) { return hist((const char *)name); }
66 
67  // write all histograms to a root file
68  void write(const std::string &filename, const SVec &argsVec = kEmptyVec, const SVec &inputFilesVec = kEmptyVec) const;
69  void write(TFile *filePtr, const SVec &argsVec = kEmptyVec, const SVec &inputFilesVec = kEmptyVec) const;
70 
72  // Static Member Functions //
74 
75  // turn on verbose messages (e.g., printing out histogram names
76  // when being made)
77  static void setVerbose(bool verbose = true) { sm_verbose = verbose; }
78 
79 private:
81  // Private Member Functions //
83 
84  // creates directory and all parent directories as needed
85  // (equivalent to unix 'mkdir -p') and then changes (cd's) to
86  // that directory. Returns TDirectory of pointing to dirname.
87  TDirectory *_createDir(const std::string &dirname, TFile *filePtr) const;
88 
90  // Private Member Data //
92 
96 
98  // Private Static Member Data //
100 
101  static bool sm_verbose;
102 };
103 
104 #endif // TH1Store_H
static void setVerbose(bool verbose=true)
Definition: TH1Store.h:77
bool m_deleteOnDestruction
Definition: TH1Store.h:93
SSMap m_nameDirMap
Definition: TH1Store.h:95
void add(TH1 *histPtr, const std::string &directory="")
Definition: TH1Store.cc:30
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:95
static bool sm_verbose
Definition: TH1Store.h:101
void setDeleteOnDestruction(bool deleteOnDestruction=true)
Definition: TH1Store.h:53
~TH1Store()
Definition: TH1Store.cc:22
static const SVec kEmptyVec
Definition: TH1Store.h:28
void write(const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
static constexpr int verbose
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:26
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
friend std::ostream & operator<<(std::ostream &o_stream, const TH1Store &rhs)
std::map< std::string, TH1 * > STH1PtrMap
Definition: TH1Store.h:23
STH1PtrMap::iterator STH1PtrMapIter
Definition: TH1Store.h:25
TH1 * hist(const char *name)
Definition: TH1Store.h:64
std::vector< std::string > SVec
Definition: TH1Store.h:21
TH1Store()
Definition: TH1Store.cc:20
std::map< std::string, std::string > SSMap
Definition: TH1Store.h:22
tuple filename
Definition: lut2db_cfg.py:20
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:24
TH1 * hist(const std::string &name)
TH1 * hist(const TString &name)
Definition: TH1Store.h:65