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

◆ dqmCopyRecursively()

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.

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 }

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

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

◆ dqmDirectoryName()

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

Definition at line 57 of file dqmAuxFunctions.cc.

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 }

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

Referenced by dqmCopyRecursively().

◆ dqmRegisterHistogram()

void dqmRegisterHistogram ( dqm::legacy::DQMStore dqmStore,
TH1 *  histogram,
const std::string &  name 
)

Definition at line 81 of file dqmAuxFunctions.cc.

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 }

References L1TBPTX_cfi::dqmStore, and Skims_PA_cff::name.

Referenced by dqmCopyRecursively().

◆ dqmSubDirectoryName_merged()

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

Definition at line 66 of file dqmAuxFunctions.cc.

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 }

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

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

◆ format_vstring()

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

Definition at line 36 of file dqmAuxFunctions.cc.

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 }

References edm::numEntries().

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

◆ replace_string()

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.

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 }

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

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

◆ separateHistogramFromDirectoryName()

void separateHistogramFromDirectoryName ( const std::string &  histogramAndDirectoryName,
std::string &  histogramName,
std::string &  directoryName 
)

Definition at line 191 of file dqmAuxFunctions.cc.

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 }

References dqmRootDirectory, dqmSeparator, ECALResponse_cfi::histogramName, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TauDQMHistEffProducer::dqmEndJob().

dqmRegisterHistogram
void dqmRegisterHistogram(dqm::legacy::DQMStore &dqmStore, TH1 *histogram, const std::string &name)
Definition: dqmAuxFunctions.cc:81
pfMETsysShiftCorrections_cfi.parameter
parameter
Definition: pfMETsysShiftCorrections_cfi.py:118
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
ECALResponse_cfi.histogramName
histogramName
Definition: ECALResponse_cfi.py:6
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
parameter
Definition: vlib.h:168
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
dqmSubDirectoryName_merged
std::string dqmSubDirectoryName_merged(const std::string &directory, const std::string &subdirectory)
Definition: dqmAuxFunctions.cc:66
dqmRootDirectory
const std::string dqmRootDirectory
Definition: dqmAuxFunctions.h:38
h
dqmDirectoryName
std::string dqmDirectoryName(const std::string &directory)
Definition: dqmAuxFunctions.cc:57
dqm::legacy::MonitorElement::getTH1
virtual TH1 * getTH1() const
Definition: MonitorElement.h:474
L1TBPTX_cfi.dqmStore
dqmStore
Definition: L1TBPTX_cfi.py:6
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::numEntries
Long64_t numEntries(TFile *hdl, std::string const &trname)
Definition: CollUtil.cc:50
edm::LogError
Definition: MessageLogger.h:183
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
dqmCopyRecursively
void dqmCopyRecursively(dqm::legacy::DQMStore &dqmStore, const std::string &inputDirectory, const std::string &outputDirectory, double scaleFactor, int mode, bool rmInputDirectory)
Definition: dqmAuxFunctions.cc:109
personalPlayback.subdirectory
subdirectory
Definition: personalPlayback.py:461
mps_setup.append
append
Definition: mps_setup.py:85
createBeamHaloJobs.directory
string directory
Definition: createBeamHaloJobs.py:211
multiplicitycorr_cfi.scaleFactor
scaleFactor
Definition: multiplicitycorr_cfi.py:7
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
dqmSeparator
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8