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

◆ 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) {}
bool m_deleteOnDestruction
Definition: TH1Store.h:93

◆ ~TH1Store()

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

◆ _createDir()

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 oniaPATMuonsWithTrigger_cff::matches.

Referenced by 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

◆ add()

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

Definition at line 30 of file TH1Store.cc.

References cms::cuda::assert(), DMR_cfg::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().

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
assert(be >=bs)
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94

◆ hist() [1/3]

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

◆ hist() [2/3]

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

Definition at line 64 of file TH1Store.h.

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

Referenced by hist().

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

◆ hist() [3/3]

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

Definition at line 65 of file TH1Store.h.

References hist(), and Skims_PA_cff::name.

Referenced by hist().

65 { return hist((const char *)name); }
TH1 * hist(const std::string &name)

◆ setDeleteOnDestruction()

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

Definition at line 53 of file TH1Store.h.

References m_deleteOnDestruction.

53 { m_deleteOnDestruction = deleteOnDestruction; }
bool m_deleteOnDestruction
Definition: TH1Store.h:93

◆ setVerbose()

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

Definition at line 77 of file TH1Store.h.

References sm_verbose, and verbose.

77 { sm_verbose = verbose; }
bool verbose
static bool sm_verbose
Definition: TH1Store.h:101

◆ 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.

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
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:26
STH1PtrMap m_ptrMap
Definition: TH1Store.h:94
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:95
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:24

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().