CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends
TH1Store Class Reference

#include <TH1Store.h>

Public Types

typedef std::map< std::string, std::string > SSMap
 
typedef SSMap::const_iterator SSMapConstIter
 
typedef std::map< std::string, TH1 * > STH1PtrMap
 
typedef STH1PtrMap::const_iterator STH1PtrMapConstIter
 
typedef STH1PtrMap::iterator STH1PtrMapIter
 
typedef std::vector< std::string > SVec
 

Public Member Functions

void add (TH1 *histPtr, const std::string &directory="")
 
TH1 * hist (const std::string &name)
 
TH1 * hist (const char *name)
 
TH1 * hist (const TString &name)
 
void setDeleteOnDestruction (bool deleteOnDestruction=true)
 
 TH1Store ()
 
void write (const std::string &filename, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
 
void write (TFile *filePtr, const SVec &argsVec=kEmptyVec, const SVec &inputFilesVec=kEmptyVec) const
 
 ~TH1Store ()
 

Static Public Member Functions

static void setVerbose (bool verbose=true)
 

Static Public Attributes

static const SVec kEmptyVec
 

Private Member Functions

TDirectory * _createDir (const std::string &dirname, TFile *filePtr) const
 

Private Attributes

bool m_deleteOnDestruction
 
SSMap m_nameDirMap
 
STH1PtrMap m_ptrMap
 

Static Private Attributes

static bool sm_verbose = false
 

Friends

std::ostream & operator<< (std::ostream &o_stream, const TH1Store &rhs)
 

Detailed Description

Definition at line 15 of file TH1Store.h.

Member Typedef Documentation

typedef std::map<std::string, std::string> TH1Store::SSMap

Definition at line 22 of file TH1Store.h.

typedef SSMap::const_iterator TH1Store::SSMapConstIter

Definition at line 24 of file TH1Store.h.

typedef std::map<std::string, TH1 *> TH1Store::STH1PtrMap

Definition at line 23 of file TH1Store.h.

typedef STH1PtrMap::const_iterator TH1Store::STH1PtrMapConstIter

Definition at line 26 of file TH1Store.h.

typedef STH1PtrMap::iterator TH1Store::STH1PtrMapIter

Definition at line 25 of file TH1Store.h.

typedef std::vector<std::string> TH1Store::SVec

Definition at line 21 of file TH1Store.h.

Constructor & Destructor Documentation

TH1Store::TH1Store ( )

Definition at line 20 of file TH1Store.cc.

20 : m_deleteOnDestruction(false) {}
bool m_deleteOnDestruction
Definition: TH1Store.h:93
TH1Store::~TH1Store ( )

Definition at line 22 of file TH1Store.cc.

References m_deleteOnDestruction, and m_ptrMap.

22  {
24  for (STH1PtrMapIter iter = m_ptrMap.begin(); m_ptrMap.end() != iter; ++iter) {
25  delete iter->second;
26  } // for iter
27  } // if destroying pointers
28 }
bool m_deleteOnDestruction
Definition: TH1Store.h:93
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
STH1PtrMap::iterator STH1PtrMapIter
Definition: TH1Store.h:25

Member Function Documentation

TDirectory * TH1Store::_createDir ( const std::string &  dirname,
TFile *  filePtr 
) const
private

Definition at line 95 of file TH1Store.cc.

References TrackerOfflineValidation_Dqm_cff::dirName, and patCandidatesForDimuonsSequences_cff::matches.

Referenced by setVerbose(), and write().

95  {
96  // do we have this one already
97  TDirectory *dirPtr = filePtr->GetDirectory(dirName.c_str());
98  if (dirPtr) {
99  dirPtr->cd();
100  return dirPtr;
101  }
102  // if we're here, then this directory doesn't exist. Is this
103  // directory a subdirectory?
104  const boost::regex subdirRE("(.+?)/([^/]+)");
105  boost::smatch matches;
106  TDirectory *parentDir = nullptr;
107  string useName = dirName;
108  if (boost::regex_match(dirName, matches, subdirRE)) {
109  parentDir = _createDir(matches[1], filePtr);
110  useName = matches[2];
111  } else {
112  // This is not a subdirectory, so we're golden
113  parentDir = filePtr;
114  }
115  dirPtr = parentDir->mkdir(useName.c_str());
116  dirPtr->cd();
117  return dirPtr;
118 }
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:95
void TH1Store::add ( TH1 *  histPtr,
const std::string &  directory = "" 
)

Definition at line 30 of file TH1Store.cc.

References beam_dqm_sourceclient-live_cfg::cerr, gather_cfg::cout, createBeamHaloJobs::directory, corrVsCorr::filename, hist(), m_nameDirMap, m_ptrMap, Skims_PA_cff::name, sm_verbose, and write().

Referenced by fwlite::EventContainer::add(), counter.Counter::register(), and setDeleteOnDestruction().

30  {
31  // Do we have a histogram with this name already?
32  string name = histPtr->GetName();
33  if (m_ptrMap.end() != m_ptrMap.find(name)) {
34  // D'oh
35  cerr << "TH1Store::add() Error: '" << name << "' already exists. Aborting." << endl;
36  assert(0);
37  } // if already exists
38  if (sm_verbose) {
39  cout << "THStore::add() : Adding " << name << endl;
40  }
41  m_ptrMap[name] = histPtr;
42  histPtr->SetDirectory(nullptr);
43  if (directory.length()) {
45  }
46 }
SSMap m_nameDirMap
Definition: TH1Store.h:95
static bool sm_verbose
Definition: TH1Store.h:101
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
TH1* TH1Store::hist ( const std::string &  name)
TH1* TH1Store::hist ( const char *  name)
inline

Definition at line 64 of file TH1Store.h.

References hist(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by hist().

64 { return hist((const std::string)name); }
TH1 * hist(const std::string &name)
TH1* TH1Store::hist ( const TString &  name)
inline

Definition at line 65 of file TH1Store.h.

References corrVsCorr::filename, hist(), AlCaHLTBitMon_QueryRunRegistry::string, and write().

Referenced by hist().

65 { return hist((const char *)name); }
TH1 * hist(const std::string &name)
void TH1Store::setDeleteOnDestruction ( bool  deleteOnDestruction = true)
inline
static void TH1Store::setVerbose ( bool  verbose = true)
inlinestatic

Definition at line 77 of file TH1Store.h.

References _createDir(), BTVHLTOfflineSource_cfi::dirname, sm_verbose, AlCaHLTBitMon_QueryRunRegistry::string, and verbose.

77 { sm_verbose = verbose; }
static bool sm_verbose
Definition: TH1Store.h:101
static int verbose
void TH1Store::write ( const std::string &  filename,
const SVec argsVec = kEmptyVec,
const SVec inputFilesVec = kEmptyVec 
) const
void TH1Store::write ( TFile *  filePtr,
const SVec argsVec = kEmptyVec,
const SVec inputFilesVec = kEmptyVec 
) const

Definition at line 68 of file TH1Store.cc.

References _createDir(), gather_cfg::cout, DeadROC_duringRun::dir, m_nameDirMap, and m_ptrMap.

68  {
69  filePtr->cd();
70  // write out all histograms
71  for (STH1PtrMapConstIter iter = m_ptrMap.begin(); m_ptrMap.end() != iter; ++iter) {
72  SSMapConstIter nameDirIter = m_nameDirMap.find(iter->first);
73  if (m_nameDirMap.end() != nameDirIter) {
74  // we want a subdirectory for this one
75  _createDir(nameDirIter->second, filePtr);
76  } else {
77  // we don't need a subdirectory, just save this in the main
78  // directory.
79  filePtr->cd();
80  }
81  iter->second->Write();
82  } // for iter
83  // Write out command line arguments. Save information in directory
84  // called provenance.
85  TDirectory *dir = _createDir("args", filePtr);
86  if (!argsVec.empty()) {
87  dir->WriteObject(&argsVec, "argsVec");
88  }
89  if (!inputFilesVec.empty()) {
90  dir->WriteObject(&inputFilesVec, "inputFiles");
91  }
92  cout << "TH1Store::write(): Successfully written to '" << filePtr->GetName() << "'." << endl;
93 }
SSMap m_nameDirMap
Definition: TH1Store.h:95
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:95
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:26
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:24

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o_stream,
const TH1Store rhs 
)
friend

Member Data Documentation

const TH1Store::SVec TH1Store::kEmptyVec
static

Definition at line 28 of file TH1Store.h.

bool TH1Store::m_deleteOnDestruction
private

Definition at line 93 of file TH1Store.h.

Referenced by setDeleteOnDestruction(), and ~TH1Store().

SSMap TH1Store::m_nameDirMap
private

Definition at line 95 of file TH1Store.h.

Referenced by add(), and write().

STH1PtrMap TH1Store::m_ptrMap
private

Definition at line 94 of file TH1Store.h.

Referenced by add(), write(), and ~TH1Store().

bool TH1Store::sm_verbose = false
staticprivate

Definition at line 101 of file TH1Store.h.

Referenced by add(), and setVerbose().