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 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
TH1Store::setVerbose
static void setVerbose(bool verbose=true)
Definition: TH1Store.h:77
TH1Store::TH1Store
TH1Store()
Definition: TH1Store.cc:20
TH1Store::sm_verbose
static bool sm_verbose
Definition: TH1Store.h:101
TH1Store::SVec
std::vector< std::string > SVec
Definition: TH1Store.h:21
TH1Store::operator<<
friend std::ostream & operator<<(std::ostream &o_stream, const TH1Store &rhs)
TH1Store::setDeleteOnDestruction
void setDeleteOnDestruction(bool deleteOnDestruction=true)
Definition: TH1Store.h:53
TH1Store::m_ptrMap
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
TH1Store::hist
TH1 * hist(const char *name)
Definition: TH1Store.h:64
BTVHLTOfflineSource_cfi.dirname
dirname
Definition: BTVHLTOfflineSource_cfi.py:7
TH1Store::hist
TH1 * hist(const std::string &name)
TH1Store::STH1PtrMapConstIter
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:26
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
TH1Store
Definition: TH1Store.h:15
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
TH1Store::~TH1Store
~TH1Store()
Definition: TH1Store.cc:22
TH1Store::STH1PtrMapIter
STH1PtrMap::iterator STH1PtrMapIter
Definition: TH1Store.h:25
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TH1Store::m_deleteOnDestruction
bool m_deleteOnDestruction
Definition: TH1Store.h:93
TH1Store::STH1PtrMap
std::map< std::string, TH1 * > STH1PtrMap
Definition: TH1Store.h:23
TH1Store::_createDir
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:95
TH1Store::m_nameDirMap
SSMap m_nameDirMap
Definition: TH1Store.h:95
TH1Store::hist
TH1 * hist(const TString &name)
Definition: TH1Store.h:65
TH1Store::kEmptyVec
static const SVec kEmptyVec
Definition: TH1Store.h:28
TH1Store::write
void write(const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
TH1Store::SSMapConstIter
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:24
createBeamHaloJobs.directory
string directory
Definition: createBeamHaloJobs.py:211
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
TH1Store::add
void add(TH1 *histPtr, const std::string &directory="")
Definition: TH1Store.cc:30
TH1Store::SSMap
std::map< std::string, std::string > SSMap
Definition: TH1Store.h:22