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 char *name)
 
TH1 * hist (const std::string &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

◆ SSMap

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

Definition at line 22 of file TH1Store.h.

◆ SSMapConstIter

typedef SSMap::const_iterator TH1Store::SSMapConstIter

Definition at line 24 of file TH1Store.h.

◆ STH1PtrMap

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

Definition at line 23 of file TH1Store.h.

◆ STH1PtrMapConstIter

typedef STH1PtrMap::const_iterator TH1Store::STH1PtrMapConstIter

Definition at line 26 of file TH1Store.h.

◆ STH1PtrMapIter

typedef STH1PtrMap::iterator TH1Store::STH1PtrMapIter

Definition at line 25 of file TH1Store.h.

◆ SVec

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

Definition at line 21 of file TH1Store.h.

Constructor & Destructor Documentation

◆ TH1Store()

TH1Store::TH1Store ( )

Definition at line 20 of file TH1Store.cc.

20 : m_deleteOnDestruction(false) {}

◆ ~TH1Store()

TH1Store::~TH1Store ( )

Definition at line 22 of file TH1Store.cc.

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 }

References m_deleteOnDestruction, and m_ptrMap.

Member Function Documentation

◆ _createDir()

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

Definition at line 95 of file TH1Store.cc.

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 }

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

Referenced by write().

◆ add()

void TH1Store::add ( TH1 *  histPtr,
const std::string &  directory = "" 
)

Definition at line 30 of file TH1Store.cc.

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 }

References cms::cuda::assert(), EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, gather_cfg::cout, createBeamHaloJobs::directory, m_nameDirMap, m_ptrMap, Skims_PA_cff::name, and sm_verbose.

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

◆ hist() [1/3]

TH1* TH1Store::hist ( const char *  name)
inline

Definition at line 64 of file TH1Store.h.

64 { return hist((const std::string)name); }

References hist(), Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by hist().

◆ hist() [2/3]

TH1* TH1Store::hist ( const std::string &  name)

◆ hist() [3/3]

TH1* TH1Store::hist ( const TString &  name)
inline

Definition at line 65 of file TH1Store.h.

65 { return hist((const char *)name); }

References hist(), and Skims_PA_cff::name.

Referenced by hist().

◆ setDeleteOnDestruction()

void TH1Store::setDeleteOnDestruction ( bool  deleteOnDestruction = true)
inline

Definition at line 53 of file TH1Store.h.

53 { m_deleteOnDestruction = deleteOnDestruction; }

References m_deleteOnDestruction.

◆ setVerbose()

static void TH1Store::setVerbose ( bool  verbose = true)
inlinestatic

Definition at line 77 of file TH1Store.h.

77 { sm_verbose = verbose; }

References sm_verbose, and verbose.

◆ write() [1/2]

void TH1Store::write ( const std::string &  filename,
const SVec argsVec = kEmptyVec,
const SVec inputFilesVec = kEmptyVec 
) const

◆ write() [2/2]

void TH1Store::write ( TFile *  filePtr,
const SVec argsVec = kEmptyVec,
const SVec inputFilesVec = kEmptyVec 
) const

Definition at line 68 of file TH1Store.cc.

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 }

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

Friends And Related Function Documentation

◆ operator<<

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

Member Data Documentation

◆ kEmptyVec

const TH1Store::SVec TH1Store::kEmptyVec
static

Definition at line 28 of file TH1Store.h.

◆ m_deleteOnDestruction

bool TH1Store::m_deleteOnDestruction
private

Definition at line 93 of file TH1Store.h.

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

◆ m_nameDirMap

SSMap TH1Store::m_nameDirMap
private

Definition at line 95 of file TH1Store.h.

Referenced by add(), and write().

◆ m_ptrMap

STH1PtrMap TH1Store::m_ptrMap
private

Definition at line 94 of file TH1Store.h.

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

◆ sm_verbose

bool TH1Store::sm_verbose = false
staticprivate

Definition at line 101 of file TH1Store.h.

Referenced by add(), and setVerbose().

TH1Store::sm_verbose
static bool sm_verbose
Definition: TH1Store.h:101
TH1Store::m_ptrMap
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
gather_cfg.cout
cout
Definition: gather_cfg.py:144
oniaPATMuonsWithTrigger_cff.matches
matches
Definition: oniaPATMuonsWithTrigger_cff.py:77
cms::cuda::assert
assert(be >=bs)
TH1Store::hist
TH1 * hist(const std::string &name)
TH1Store::STH1PtrMapConstIter
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:26
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
TH1Store::STH1PtrMapIter
STH1PtrMap::iterator STH1PtrMapIter
Definition: TH1Store.h:25
TH1Store::m_deleteOnDestruction
bool m_deleteOnDestruction
Definition: TH1Store.h:93
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TH1Store::SSMapConstIter
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:24
createBeamHaloJobs.directory
string directory
Definition: createBeamHaloJobs.py:211
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23