CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
dqmAuxFunctions.cc File Reference
#include "Validation/RecoTau/plugins/dqmAuxFunctions.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include <TH1.h>
#include <iostream>

Go to the source code of this file.

Functions

void dqmCopyRecursively (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 (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 ( DQMStore dqmStore,
const std::string &  inputDirectory,
const std::string &  outputDirectory,
double  scaleFactor,
int  mode,
bool  rmInputDirectory 
)

Definition at line 107 of file dqmAuxFunctions.cc.

References python.multivaluedict::append(), clone(), TrackerOfflineValidation_Dqm_cff::dirName, dqmCopyRecursively(), dqmDirectoryName(), dqmRegisterHistogram(), dqmSubDirectoryName_merged(), DQMStore::get(), DQMStore::getMEs(), DQMStore::getSubdirs(), MonitorElement::getTH1(), DQMStore::rmdir(), and DQMStore::setCurrentFolder().

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

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

Definition at line 55 of file dqmAuxFunctions.cc.

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

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

Definition at line 78 of file dqmAuxFunctions.cc.

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

Referenced by dqmCopyRecursively().

79 {
80  //std::cout << "<dqmRegisterHistogram>:" << std::endl;
81  //histogram->SetName(std::string(histogram->GetName()).append("_copied").data());
82  histogram->SetName(histogram->GetName());
83  if ( TH1F* h = dynamic_cast<TH1F*>(histogram) ) {
84  //std::cout << " --> calling DQMStore::book1D" << std::endl;
85  dqmStore.book1D(name, h);
86  } else if ( TH1S* h = dynamic_cast<TH1S*>(histogram) ) {
87  //std::cout << " --> calling DQMStore::book1@" << std::endl;
88  dqmStore.book1S(name, h);
89  } else if ( TH2F* h = dynamic_cast<TH2F*>(histogram) ) {
90  //std::cout << " --> calling DQMStore::book2D" << std::endl;
91  dqmStore.book2D(name, h);
92  } else if ( TH2S* h = dynamic_cast<TH2S*>(histogram) ) {
93  //std::cout << " --> calling DQMStore::book2S" << std::endl;
94  dqmStore.book2S(name, h);
95  } else if ( TH3F* h = dynamic_cast<TH3F*>(histogram) ) {
96  //std::cout << " --> calling DQMStore::book3D" << std::endl;
97  dqmStore.book3D(name, h);
98  } else if ( TProfile* h = dynamic_cast<TProfile*>(histogram) ) {
99  //std::cout << " --> calling DQMStore::bookProfile" << std::endl;
100  dqmStore.bookProfile(name, h);
101  } else if ( TProfile2D* h = dynamic_cast<TProfile2D*>(histogram) ) {
102  //std::cout << " --> calling DQMStore::bookProfile2D" << std::endl;
103  dqmStore.bookProfile2D(name, h);
104  }
105 }
MonitorElement * book2S(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2S histogram.
Definition: DQMStore.cc:867
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
MonitorElement * book3D(const char *name, const char *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:979
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1031
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
MonitorElement * book1S(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:733
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1175
std::string dqmSubDirectoryName_merged ( const std::string &  directory,
const std::string &  subdirectory 
)

Definition at line 64 of file dqmAuxFunctions.cc.

References dqmSeparator.

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

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

Definition at line 34 of file dqmAuxFunctions.cc.

References edm::numEntries().

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

35 {
36  std::ostringstream os;
37 
38  os << "{ ";
39 
40  unsigned numEntries = vs.size();
41  for ( unsigned iEntry = 0; iEntry < numEntries; ++iEntry ) {
42  os << vs[iEntry];
43  if ( iEntry < (numEntries - 1) ) os << ", ";
44  }
45 
46  os << " }";
47 
48  return os.str();
49 }
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 alcazmumu_cfi::src.

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

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

Definition at line 195 of file dqmAuxFunctions.cc.

References dqmRootDirectory, and dqmSeparator.

Referenced by TauDQMHistEffProducer::endRun().

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