test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 (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

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

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(), DQMStore::setCurrentFolder(), and AlCaHLTBitMon_QueryRunRegistry::string.

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::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)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void dqmCopyRecursively(DQMStore &dqmStore, const std::string &inputDirectory, const std::string &outputDirectory, double scaleFactor, int mode, bool rmInputDirectory)
std::string dqmDirectoryName ( const std::string &  )

Definition at line 55 of file dqmAuxFunctions.cc.

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

56 {
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
std::string dqmSubDirectoryName_merged ( const std::string &  ,
const std::string &   
)

Definition at line 64 of file dqmAuxFunctions.cc.

References dqmSeparator, and AlCaHLTBitMon_QueryRunRegistry::string.

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
template<class T >
void readCfgParameter ( const edm::ParameterSet cfgParSet,
std::map< std::string, T > &  def 
)

Definition at line 22 of file dqmAuxFunctions.h.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), and edm::ParameterSet::insert().

23 {
24  std::vector<std::string> cfgParNames = cfgParSet.getParameterNamesForType<edm::ParameterSet>();
25  for ( std::vector<std::string>::const_iterator cfgParName = cfgParNames.begin();
26  cfgParName != cfgParNames.end(); ++cfgParName ) {
27  edm::ParameterSet cfgParDef = cfgParSet.getParameter<edm::ParameterSet>(*cfgParName);
28 
29  def.insert(std::pair<std::string, T>(*cfgParName, T(*cfgParName, cfgParDef)));
30  }
31 }
T getParameter(std::string const &) const
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:192
long double T
JetCorrectorParameters::Definitions def
Definition: classes.h:6
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 alcazmumu_cfi::src, and AlCaHLTBitMon_QueryRunRegistry::string.

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 &  ,
std::string &  ,
std::string &   
)

Definition at line 195 of file dqmAuxFunctions.cc.

References dqmRootDirectory, dqmSeparator, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Variable Documentation

const std::string dqmRootDirectory = ""
const std::string dqmSeparator = "/"

Definition at line 37 of file dqmAuxFunctions.h.

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

Definition at line 13 of file dqmAuxFunctions.h.

Referenced by TauDQMHistPlotter::endRun().

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

Definition at line 15 of file dqmAuxFunctions.h.

Referenced by TauDQMHistPlotter::TauDQMHistPlotter().

const std::string rangeKeyword = "#RANGE"