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 24 of file TH1Store.h.

typedef SSMap::const_iterator TH1Store::SSMapConstIter

Definition at line 26 of file TH1Store.h.

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

Definition at line 25 of file TH1Store.h.

typedef STH1PtrMap::const_iterator TH1Store::STH1PtrMapConstIter

Definition at line 28 of file TH1Store.h.

typedef STH1PtrMap::iterator TH1Store::STH1PtrMapIter

Definition at line 27 of file TH1Store.h.

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

Definition at line 23 of file TH1Store.h.

Constructor & Destructor Documentation

TH1Store::TH1Store ( )

Definition at line 21 of file TH1Store.cc.

21  : m_deleteOnDestruction (false)
22 {
23 }
bool m_deleteOnDestruction
Definition: TH1Store.h:105
TH1Store::~TH1Store ( )

Definition at line 25 of file TH1Store.cc.

References m_deleteOnDestruction, and m_ptrMap.

26 {
28  {
29  for (STH1PtrMapIter iter = m_ptrMap.begin();
30  m_ptrMap.end() != iter;
31  ++iter)
32  {
33  delete iter->second;
34  } // for iter
35  } // if destroying pointers
36 }
bool m_deleteOnDestruction
Definition: TH1Store.h:105
STH1PtrMap m_ptrMap
Definition: TH1Store.h:106
STH1PtrMap::iterator STH1PtrMapIter
Definition: TH1Store.h:27

Member Function Documentation

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

Definition at line 131 of file TH1Store.cc.

References TrackerOfflineValidation_Dqm_cff::dirName, and matches.

Referenced by setVerbose(), and write().

132 {
133  // do we have this one already
134  TDirectory *dirPtr = filePtr->GetDirectory (dirName.c_str());
135  if (dirPtr)
136  {
137  dirPtr->cd();
138  return dirPtr;
139  }
140  // if we're here, then this directory doesn't exist. Is this
141  // directory a subdirectory?
142  const boost::regex subdirRE ("(.+?)/([^/]+)");
143  boost::smatch matches;
144  TDirectory *parentDir = 0;
145  string useName = dirName;
146  if( boost::regex_match (dirName, matches, subdirRE) )
147  {
148  parentDir = _createDir (matches[1], filePtr);
149  useName = matches[2];
150  } else {
151  // This is not a subdirectory, so we're golden
152  parentDir = filePtr;
153  }
154  dirPtr = parentDir->mkdir (useName.c_str());
155  dirPtr->cd();
156  return dirPtr;
157 }
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:131
void TH1Store::add ( TH1 *  histPtr,
const std::string &  directory = "" 
)

Definition at line 39 of file TH1Store.cc.

References MessageLogger_cfi::cerr, gather_cfg::cout, createBeamHaloJobs::directory, corrVsCorr::filename, hist(), m_nameDirMap, m_ptrMap, dataset::name, sm_verbose, and write().

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

40 {
41  // Do we have a histogram with this name already?
42  string name = histPtr->GetName();
43  if (m_ptrMap.end() != m_ptrMap.find (name))
44  {
45  // D'oh
46  cerr << "TH1Store::add() Error: '" << name
47  << "' already exists. Aborting." << endl;
48  assert (0);
49  } // if already exists
50  if (sm_verbose)
51  {
52  cout << "THStore::add() : Adding " << name << endl;
53  }
54  m_ptrMap[name] = histPtr;
55  histPtr->SetDirectory(0);
56  if (directory.length())
57  {
59  }
60 }
SSMap m_nameDirMap
Definition: TH1Store.h:107
static bool sm_verbose
Definition: TH1Store.h:113
STH1PtrMap m_ptrMap
Definition: TH1Store.h:106
TH1* TH1Store::hist ( const std::string &  name)
TH1* TH1Store::hist ( const char *  name)
inline

Definition at line 68 of file TH1Store.h.

References hist(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 70 of file TH1Store.h.

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

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

Definition at line 56 of file TH1Store.h.

References add(), createBeamHaloJobs::directory, hist(), m_deleteOnDestruction, dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

57  { m_deleteOnDestruction = deleteOnDestruction; }
bool m_deleteOnDestruction
Definition: TH1Store.h:105
static void TH1Store::setVerbose ( bool  verbose = true)
inlinestatic

Definition at line 87 of file TH1Store.h.

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

88  { sm_verbose = verbose; }
bool verbose
static bool sm_verbose
Definition: TH1Store.h:113
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 93 of file TH1Store.cc.

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

96 {
97  filePtr->cd();
98  // write out all histograms
99  for (STH1PtrMapConstIter iter = m_ptrMap.begin();
100  m_ptrMap.end() != iter;
101  ++iter)
102  {
103  SSMapConstIter nameDirIter = m_nameDirMap.find (iter->first);
104  if (m_nameDirMap.end() != nameDirIter)
105  {
106  // we want a subdirectory for this one
107  _createDir (nameDirIter->second, filePtr);
108  } else {
109  // we don't need a subdirectory, just save this in the main
110  // directory.
111  filePtr->cd();
112  }
113  iter->second->Write();
114  } // for iter
115  // Write out command line arguments. Save information in directory
116  // called provenance.
117  TDirectory *dir = _createDir ("args", filePtr);
118  if (argsVec.size())
119  {
120  dir->WriteObject (&argsVec, "argsVec");
121  }
122  if (inputFilesVec.size())
123  {
124  dir->WriteObject (&inputFilesVec, "inputFiles");
125  }
126  cout << "TH1Store::write(): Successfully written to '"
127  << filePtr->GetName() << "'." << endl;
128 }
SSMap m_nameDirMap
Definition: TH1Store.h:107
TDirectory * _createDir(const std::string &dirname, TFile *filePtr) const
Definition: TH1Store.cc:131
STH1PtrMap::const_iterator STH1PtrMapConstIter
Definition: TH1Store.h:28
STH1PtrMap m_ptrMap
Definition: TH1Store.h:106
SSMap::const_iterator SSMapConstIter
Definition: TH1Store.h:26
dbl *** dir
Definition: mlp_gen.cc:35

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 30 of file TH1Store.h.

bool TH1Store::m_deleteOnDestruction
private

Definition at line 105 of file TH1Store.h.

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

SSMap TH1Store::m_nameDirMap
private

Definition at line 107 of file TH1Store.h.

Referenced by add(), and write().

STH1PtrMap TH1Store::m_ptrMap
private

Definition at line 106 of file TH1Store.h.

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

bool TH1Store::sm_verbose = false
staticprivate

Definition at line 113 of file TH1Store.h.

Referenced by add(), and setVerbose().