CMS 3D CMS Logo

Functions
dqmAuxFunctions.cc File Reference
#include "Validation/RecoTau/plugins/dqmAuxFunctions.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include <TH1.h>
#include <iostream>

Go to the source code of this file.

Functions

void dqmCopyRecursively (dqm::legacy::DQMStore &dqmStore, const std::string &inputDirectory, const std::string &outputDirectory, double scaleFactor, int mode, bool rmInputDirectory)
 
std::string dqmDirectoryName (const std::string &directory)
 
void dqmRegisterHistogram (dqm::legacy::DQMStore &dqmStore, TH1 *histogram, const std::string &name)
 
std::string dqmSubDirectoryName_merged (const std::string &directory, const std::string &subdirectory)
 
std::string format_vstring (const std::vector< std::string > &vs)
 
std::string replace_string (const std::string &src, const std::string &keyword, const std::string &parameter, unsigned minReplacements, unsigned maxReplacements, int &errorFlag)
 
void separateHistogramFromDirectoryName (const std::string &histogramAndDirectoryName, std::string &histogramName, std::string &directoryName)
 

Function Documentation

void dqmCopyRecursively ( dqm::legacy::DQMStore dqmStore,
const std::string &  inputDirectory,
const std::string &  outputDirectory,
double  scaleFactor,
int  mode,
bool  rmInputDirectory 
)

Definition at line 109 of file dqmAuxFunctions.cc.

References mps_setup::append, clone(), TrackerOfflineValidation_Dqm_cff::dirName, dqmCopyRecursively(), dqmDirectoryName(), dqmRegisterHistogram(), dqmSubDirectoryName_merged(), dqm::dqmstoreimpl::DQMStore::get(), dqm::dqmstoreimpl::DQMStore::getMEs(), dqm::dqmstoreimpl::DQMStore::getSubdirs(), dqm::legacy::MonitorElement::getTH1(), multiplicitycorr_cfi::scaleFactor, dqm::dqmstoreimpl::DQMStore::setCurrentFolder(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by dqmCopyRecursively(), TauDQMFileLoader::endRun(), and readCfgParameter().

114  {
115  //std::cout << "<copyRecursively>:" << std::endl;
116  //std::cout << " inputDirectory = " << inputDirectory << std::endl;
117  //std::cout << " outputDirectory = " << outputDirectory << std::endl;
118  //std::cout << " rmInputDirectory = " << rmInputDirectory << std::endl;
119 
120  //--- copy all monitor elements in current inputDirectory to the outputDirectory
121  dqmStore.setCurrentFolder(inputDirectory);
122  std::vector<std::string> meNames = dqmStore.getMEs();
123  for (std::vector<std::string>::const_iterator meName = meNames.begin(); meName != meNames.end(); ++meName) {
124  std::string meName_full = dqmDirectoryName(inputDirectory).append(*meName);
125  //std::cout << " meName_full = " << meName_full << std::endl;
126 
127  dqmStore.setCurrentFolder(inputDirectory);
128  dqm::legacy::MonitorElement* meInput = dqmStore.get(meName_full);
129  //std::cout << " meInput = " << meInput << std::endl;
130  if (!meInput) {
131  edm::LogError("copyRecursively") << " Failed to access meName = " << (*meName) << " in DQMStore"
132  << " --> skipping !!";
133  continue;
134  }
135 
136  TH1* histogram = meInput->getTH1();
137  //std::cout << " histogram = " << histogram << std::endl;
138  if (!histogram) {
139  edm::LogError("copyRecursively") << " Failed to access histogram associated to meName = " << (*meName)
140  << " in DQMStore"
141  << " --> skipping !!";
142  continue;
143  }
144 
145  std::unique_ptr<TH1> clone(dynamic_cast<TH1*>(histogram->Clone()));
146  clone->Scale(scaleFactor);
147 
148  dqmStore.setCurrentFolder(outputDirectory);
149  dqm::legacy::MonitorElement* meOutput = dqmStore.get(dqmDirectoryName(outputDirectory).append(*meName));
150  //std::cout << " meOutput = " << meOutput << std::endl;
151  //--- check if outputHistogram does already exist
152  if (meOutput) {
153  switch (mode) {
154  case 1: // print error message
155  edm::LogError("copyRecursively")
156  << " meName = " << (*meName) << " already exists in outputDirectory = " << outputDirectory
157  << " --> skipping !!";
158  break;
159  case 2: // overwrite outputHistogram
160  dqmRegisterHistogram(dqmStore, clone.release(), *meName);
161  break;
162  case 3: // add histogram to outputHistogram
163  meOutput->getTH1()->Add(clone.get(), scaleFactor);
164  }
165  } else {
166  dqmRegisterHistogram(dqmStore, clone.release(), *meName);
167  }
168  }
169 
170  //--- call function recursively for all sub-directories
171  dqmStore.setCurrentFolder(inputDirectory);
172  std::vector<std::string> dirNames = dqmStore.getSubdirs();
173  for (std::vector<std::string>::const_iterator dirName = dirNames.begin(); dirName != dirNames.end(); ++dirName) {
174  std::string subDirName = dqmSubDirectoryName_merged(inputDirectory, *dirName);
175  //std::cout << " subDirName = " << subDirName << std::endl;
176 
177  std::string inputDirName_full = dqmDirectoryName(inputDirectory).append(subDirName);
178  //std::cout << " inputDirName_full = " << inputDirName_full << std::endl;
179 
180  std::string outputDirName_full = dqmDirectoryName(outputDirectory).append(subDirName);
181  //std::cout << " outputDirName_full = " << outputDirName_full << std::endl;
182 
183  dqmCopyRecursively(dqmStore, inputDirName_full, outputDirName_full, scaleFactor, mode, rmInputDirectory);
184  }
185 }
std::vector< std::string > getMEs() const
get list of (non-dir) MEs of current directory
Definition: DQMStore.cc:1487
void dqmRegisterHistogram(dqm::legacy::DQMStore &dqmStore, TH1 *histogram, const std::string &name)
std::string dqmSubDirectoryName_merged(const std::string &directory, const std::string &subdirectory)
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
void dqmCopyRecursively(dqm::legacy::DQMStore &dqmStore, const std::string &inputDirectory, const std::string &outputDirectory, double scaleFactor, int mode, bool rmInputDirectory)
std::string dqmDirectoryName(const std::string &directory)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:1466
virtual TH1 * getTH1() const
std::string dqmDirectoryName ( const std::string &  directory)

Definition at line 57 of file dqmAuxFunctions.cc.

References createBeamHaloJobs::directory, TrackerOfflineValidation_Dqm_cff::dirName, dqmSeparator, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by dqmCopyRecursively(), and readCfgParameter().

57  {
59  //if ( dirName == "" || dirName.find_last_of(dqmSeparator) != (dirName.length() - 1) ) dirName.append(dqmSeparator);
60  //--- add tailing '/'
61  if (!dirName.empty() && dirName.find_last_of(dqmSeparator) != (dirName.length() - 1))
62  dirName.append(dqmSeparator);
63  return dirName;
64 }
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8
void dqmRegisterHistogram ( dqm::legacy::DQMStore dqmStore,
TH1 *  histogram,
const std::string &  name 
)

Definition at line 81 of file dqmAuxFunctions.cc.

References dqm::dqmstoreimpl::DQMStore::book1D(), dqm::dqmstoreimpl::DQMStore::book1S(), dqm::dqmstoreimpl::DQMStore::book2D(), dqm::dqmstoreimpl::DQMStore::book2S(), dqm::dqmstoreimpl::DQMStore::book3D(), dqm::dqmstoreimpl::DQMStore::bookProfile(), dqm::dqmstoreimpl::DQMStore::bookProfile2D(), and h.

Referenced by dqmCopyRecursively().

81  {
82  //std::cout << "<dqmRegisterHistogram>:" << std::endl;
83  //histogram->SetName(std::string(histogram->GetName()).append("_copied").data());
84  histogram->SetName(histogram->GetName());
85  if (TH1F* h = dynamic_cast<TH1F*>(histogram)) {
86  //std::cout << " --> calling DQMStore::book1D" << std::endl;
87  dqmStore.book1D(name, h);
88  } else if (TH1S* h = dynamic_cast<TH1S*>(histogram)) {
89  //std::cout << " --> calling DQMStore::book1@" << std::endl;
90  dqmStore.book1S(name, h);
91  } else if (TH2F* h = dynamic_cast<TH2F*>(histogram)) {
92  //std::cout << " --> calling DQMStore::book2D" << std::endl;
93  dqmStore.book2D(name, h);
94  } else if (TH2S* h = dynamic_cast<TH2S*>(histogram)) {
95  //std::cout << " --> calling DQMStore::book2S" << std::endl;
96  dqmStore.book2S(name, h);
97  } else if (TH3F* h = dynamic_cast<TH3F*>(histogram)) {
98  //std::cout << " --> calling DQMStore::book3D" << std::endl;
99  dqmStore.book3D(name, h);
100  } else if (TProfile* h = dynamic_cast<TProfile*>(histogram)) {
101  //std::cout << " --> calling DQMStore::bookProfile" << std::endl;
102  dqmStore.bookProfile(name, h);
103  } else if (TProfile2D* h = dynamic_cast<TProfile2D*>(histogram)) {
104  //std::cout << " --> calling DQMStore::bookProfile2D" << std::endl;
105  dqmStore.bookProfile2D(name, h);
106  }
107 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
MonitorElement * book2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1178
MonitorElement * book1S(char_string const &name, char_string const &title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:1127
MonitorElement * book3D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ)
Book 3D histogram.
Definition: DQMStore.cc:1255
MonitorElement * bookProfile2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s")
Definition: DQMStore.cc:1369
MonitorElement * bookProfile(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:1283
MonitorElement * book2S(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2S histogram.
Definition: DQMStore.cc:1190
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1121
std::string dqmSubDirectoryName_merged ( const std::string &  directory,
const std::string &  subdirectory 
)

Definition at line 66 of file dqmAuxFunctions.cc.

References dqmSeparator, AlCaHLTBitMon_QueryRunRegistry::string, and personalPlayback::subdirectory.

Referenced by dqmCopyRecursively(), TauDQMFileLoader::endRun(), and readCfgParameter().

66  {
67  std::string subDirName = subdirectory;
68  //--- remove characters specifying directory part from name of subdirectory
69  if (subDirName.find(directory) <= 1)
70  subDirName.replace(subDirName.find(directory), directory.length(), "");
71  //--- remove tailing '/'s
72  while (subDirName.find(dqmSeparator) == 0)
73  subDirName.replace(subDirName.find(dqmSeparator), dqmSeparator.length(), "");
74  return subDirName;
75 }
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8
std::string format_vstring ( const std::vector< std::string > &  vs)

Definition at line 36 of file dqmAuxFunctions.cc.

References edm::numEntries().

Referenced by PATJetCorrExtractor::operator()(), TauDQMFileLoader::cfgEntryFileSet::print(), TauDQMHistPlotter::cfgEntryLabel::print(), and TauDQMHistPlotter::cfgEntryDrawJob::print().

36  {
37  std::ostringstream os;
38 
39  os << "{ ";
40 
41  unsigned numEntries = vs.size();
42  for (unsigned iEntry = 0; iEntry < numEntries; ++iEntry) {
43  os << vs[iEntry];
44  if (iEntry < (numEntries - 1))
45  os << ", ";
46  }
47 
48  os << " }";
49 
50  return os.str();
51 }
Long64_t numEntries(TFile *hdl, std::string const &trname)
Definition: CollUtil.cc:50
std::string replace_string ( const std::string &  src,
const std::string &  keyword,
const std::string &  parameter,
unsigned  minReplacements,
unsigned  maxReplacements,
int &  errorFlag 
)

Definition at line 11 of file dqmAuxFunctions.cc.

References pfMETsysShiftCorrections_cfi::parameter, TrackRefitter_38T_cff::src, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TauDQMHistPlotter::endRun(), TauDQMHistEffProducer::TauDQMHistEffProducer(), and TauDQMHistPlotter::TauDQMHistPlotter().

16  {
17  std::string modSrc = src;
18  unsigned numReplacements = 0;
19  while (modSrc.find(keyword) != std::string::npos) {
20  modSrc.replace(modSrc.find(keyword), keyword.length(), parameter);
21  ++numReplacements;
22  }
23  if ((numReplacements < minReplacements) || (numReplacements > maxReplacements)) {
24  edm::LogError("replace_string") << " Failed to replace parameter = " << parameter << " in src = " << src << ","
25  << " numReplacements = " << numReplacements << " (min = " << minReplacements
26  << ", max = " << maxReplacements << ") !!";
27  errorFlag = 1;
28  }
29  return modSrc;
30 }
void separateHistogramFromDirectoryName ( const std::string &  histogramAndDirectoryName,
std::string &  histogramName,
std::string &  directoryName 
)

Definition at line 191 of file dqmAuxFunctions.cc.

References dqmRootDirectory, dqmSeparator, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TauDQMHistEffProducer::dqmEndJob().

193  {
194  //std::cout << "<separateHistogramFromDirectoryName>:" << std::endl;
195 
196  std::string tempName = histogramAndDirectoryName;
197 
198  //--- remove DQM root directory from histogram name
199  std::string::size_type dqmRootDirectoryPos = tempName.find(dqmRootDirectory);
200  if (dqmRootDirectoryPos != std::string::npos) {
201  tempName.replace(dqmRootDirectoryPos, dqmRootDirectory.size(), "");
202  }
203 
204  //std::cout << " tempName = " << tempName << std::endl;
205 
206  //--- extract directory from histogram name
207  std::string::size_type lastPos;
208  std::string::size_type nextPos = tempName.find(dqmSeparator);
209  do {
210  lastPos = nextPos;
211  nextPos = tempName.find(dqmSeparator, lastPos + 1);
212  } while (nextPos != std::string::npos);
213 
214  histogramName = (lastPos != std::string::npos) ? std::string(tempName, lastPos + 1, tempName.length()) : tempName;
215  directoryName = (lastPos != std::string::npos) ? std::string(tempName, 0, lastPos) : "";
216 
217  //std::cout << " histogramName = " << histogramName << std::endl;
218  //std::cout << " directoryName = " << directoryName << std::endl;
219 }
uint16_t size_type
const std::string dqmRootDirectory
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8