CMS 3D CMS Logo

Functions | Variables
dqmAuxFunctions.h File Reference
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include <string>
#include <vector>
#include <map>

Go to the source code of this file.

Functions

void dqmCopyRecursively (dqm::legacy::DQMStore &, const std::string &, const std::string &, double, int, bool)
 
std::string dqmDirectoryName (const std::string &)
 
std::string dqmSubDirectoryName_merged (const std::string &, const std::string &)
 
std::string format_vstring (const std::vector< std::string > &vs)
 
template<class T >
void readCfgParameter (const edm::ParameterSet &cfgParSet, std::map< std::string, T > &def)
 
std::string replace_string (const std::string &, const std::string &, const std::string &, unsigned, unsigned, int &)
 
void separateHistogramFromDirectoryName (const std::string &, std::string &, std::string &)
 

Variables

const std::string dqmRootDirectory = ""
 
const std::string dqmSeparator = "/"
 
const std::string parKeyword = "#PAR#"
 
const std::string plotKeyword = "#PLOT#"
 
const std::string processDirKeyword = "#PROCESSDIR#"
 
const std::string rangeKeyword = "#RANGE"
 

Function Documentation

◆ dqmCopyRecursively()

void dqmCopyRecursively ( dqm::legacy::DQMStore ,
const std::string &  ,
const std::string &  ,
double  ,
int  ,
bool   
)

Definition at line 109 of file dqmAuxFunctions.cc.

References mps_setup::append, clone(), TrackerOfflineValidation_Dqm_cff::dirName, dqmCopyRecursively(), dqmDirectoryName(), dqmRegisterHistogram(), L1TBPTX_cfi::dqmStore, dqmSubDirectoryName_merged(), dqm::legacy::MonitorElement::getTH1(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, scaleFactor, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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 }
void dqmRegisterHistogram(dqm::legacy::DQMStore &dqmStore, TH1 *histogram, const std::string &name)
Log< level::Error, false > LogError
std::string dqmSubDirectoryName_merged(const std::string &directory, const std::string &subdirectory)
constexpr G4double scaleFactor
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
virtual TH1 * getTH1() const

◆ dqmDirectoryName()

std::string dqmDirectoryName ( const std::string &  )

Definition at line 57 of file dqmAuxFunctions.cc.

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

Referenced by dqmCopyRecursively().

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

◆ dqmSubDirectoryName_merged()

std::string dqmSubDirectoryName_merged ( const std::string &  ,
const std::string &   
)

Definition at line 66 of file dqmAuxFunctions.cc.

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

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

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

◆ format_vstring()

std::string format_vstring ( const std::vector< std::string > &  vs)

Definition at line 36 of file dqmAuxFunctions.cc.

References edm::numEntries().

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

◆ readCfgParameter()

template<class T >
void readCfgParameter ( const edm::ParameterSet cfgParSet,
std::map< std::string, T > &  def 
)

Definition at line 22 of file dqmAuxFunctions.h.

References spu::def(), edm::ParameterSet::getParameter(), and edm::ParameterSet::getParameterNamesForType().

22  {
23  std::vector<std::string> cfgParNames = cfgParSet.getParameterNamesForType<edm::ParameterSet>();
24  for (std::vector<std::string>::const_iterator cfgParName = cfgParNames.begin(); cfgParName != cfgParNames.end();
25  ++cfgParName) {
26  edm::ParameterSet cfgParDef = cfgParSet.getParameter<edm::ParameterSet>(*cfgParName);
27 
28  def.insert(std::pair<std::string, T>(*cfgParName, T(*cfgParName, cfgParDef)));
29  }
30 }
int def(FILE *, FILE *, int)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:180
long double T

◆ replace_string()

std::string replace_string ( const std::string &  ,
const std::string &  ,
const std::string &  ,
unsigned  ,
unsigned  ,
int &   
)

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 }
Log< level::Error, false > LogError

◆ separateHistogramFromDirectoryName()

void separateHistogramFromDirectoryName ( const std::string &  ,
std::string &  ,
std::string &   
)

Definition at line 191 of file dqmAuxFunctions.cc.

References dqmRootDirectory, dqmSeparator, ECALResponse_cfi::histogramName, 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

Variable Documentation

◆ dqmRootDirectory

const std::string dqmRootDirectory = ""

◆ dqmSeparator

const std::string dqmSeparator = "/"

Definition at line 36 of file dqmAuxFunctions.h.

◆ parKeyword

const std::string parKeyword = "#PAR#"

◆ plotKeyword

const std::string plotKeyword = "#PLOT#"

Definition at line 13 of file dqmAuxFunctions.h.

Referenced by TauDQMHistPlotter::endRun().

◆ processDirKeyword

const std::string processDirKeyword = "#PROCESSDIR#"

Definition at line 15 of file dqmAuxFunctions.h.

Referenced by TauDQMHistPlotter::TauDQMHistPlotter().

◆ rangeKeyword

const std::string rangeKeyword = "#RANGE"