CMS 3D CMS Logo

Functions | Variables

/data/refman/pasoursint/CMSSW_5_3_6/src/Validation/RecoTau/plugins/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(), and DQMStore::setCurrentFolder().

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

{
  //std::cout << "<copyRecursively>:" << std::endl;
  //std::cout << " inputDirectory = " << inputDirectory << std::endl;
  //std::cout << " outputDirectory = " << outputDirectory << std::endl;
  //std::cout << " rmInputDirectory = " << rmInputDirectory << std::endl;

  bool meInput_copied = false;

//--- copy all monitor elements in current inputDirectory to the outputDirectory
  dqmStore.setCurrentFolder(inputDirectory);
  std::vector<std::string> meNames = dqmStore.getMEs();
  for ( std::vector<std::string>::const_iterator meName = meNames.begin();
        meName != meNames.end(); ++meName ) {
    std::string meName_full = dqmDirectoryName(inputDirectory).append(*meName);
    //std::cout << " meName_full = " <<  meName_full << std::endl;

    dqmStore.setCurrentFolder(inputDirectory);
    MonitorElement* meInput = dqmStore.get(meName_full);
    //std::cout << " meInput = " << meInput << std::endl;
    if ( !meInput ) {
      edm::LogError ("copyRecursively") << " Failed to access meName = " << (*meName) << " in DQMStore" 
                                        << " --> skipping !!";
      continue;
    }

    TH1* histogram = meInput->getTH1();
    //std::cout << " histogram = " << histogram << std::endl;
    if ( !histogram ) {
      edm::LogError ("copyRecursively") << " Failed to access histogram associated to meName = " << (*meName) << " in DQMStore" 
                                        << " --> skipping !!";
      continue;
    }

    std::auto_ptr<TH1> clone(dynamic_cast<TH1*>(histogram->Clone()));
    clone->Scale(scaleFactor);

    dqmStore.setCurrentFolder(outputDirectory);   
    MonitorElement* meOutput = dqmStore.get(dqmDirectoryName(outputDirectory).append(*meName));
    //std::cout << " meOutput = " << meOutput << std::endl;
//--- check if outputHistogram does already exist
    if ( meOutput ) {
      switch ( mode ) {
      case 1: // print error message 
        edm::LogError ("copyRecursively") << " meName = " << (*meName) << " already exists in outputDirectory = " << outputDirectory 
                                          << " --> skipping !!";
        break;
      case 2: // overwrite outputHistogram
        dqmRegisterHistogram(dqmStore, clone.release(), *meName);
        break;
      case 3: // add histogram to outputHistogram
        meOutput->getTH1()->Add(clone.get(), scaleFactor);
      }
    } else {
      dqmRegisterHistogram(dqmStore, clone.release(), *meName);
    }

    meInput_copied = true;
  }

//--- call function recursively for all sub-directories
  dqmStore.setCurrentFolder(inputDirectory);
  std::vector<std::string> dirNames = dqmStore.getSubdirs();
  for ( std::vector<std::string>::const_iterator dirName = dirNames.begin();
        dirName != dirNames.end(); ++dirName ) {
    std::string subDirName = dqmSubDirectoryName_merged(inputDirectory, *dirName);
    //std::cout << " subDirName = " << subDirName << std::endl;

    std::string inputDirName_full = dqmDirectoryName(inputDirectory).append(subDirName);
    //std::cout << " inputDirName_full = " << inputDirName_full << std::endl;

    std::string outputDirName_full = dqmDirectoryName(outputDirectory).append(subDirName);
    //std::cout << " outputDirName_full = " << outputDirName_full << std::endl;

    dqmCopyRecursively(dqmStore, inputDirName_full, outputDirName_full, scaleFactor, mode, rmInputDirectory);
  }

//--- delete inputDirectory 
//    (if requested to do so and inputDirectory is **not empty**;
//     otherwise, common parent directories of inputDirectory and outputDirectory might get deleted !!)
  if ( rmInputDirectory && meInput_copied ) dqmStore.rmdir(inputDirectory);
}
std::string dqmDirectoryName ( const std::string &  )

Definition at line 55 of file dqmAuxFunctions.cc.

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

{
  std::string dirName = directory;
  //if ( dirName == "" || dirName.find_last_of(dqmSeparator) != (dirName.length() - 1) )  dirName.append(dqmSeparator);
//--- add tailing '/'
  if ( dirName != "" && dirName.find_last_of(dqmSeparator) != (dirName.length() - 1) )  dirName.append(dqmSeparator);
  return dirName;
}
std::string dqmSubDirectoryName_merged ( const std::string &  ,
const std::string &   
)

Definition at line 64 of file dqmAuxFunctions.cc.

References dqmSeparator.

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

{ 
  std::string subDirName = subdirectory;
//--- remove characters specifying directory part from name of subdirectory
  if ( subDirName.find(directory) <= 1 ) subDirName.replace(subDirName.find(directory), directory.length(), "");
//--- remove tailing '/'s
  while ( subDirName.find(dqmSeparator) == 0 ) subDirName.replace(subDirName.find(dqmSeparator), dqmSeparator.length(), "");
  return subDirName;
}
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::cfgEntryDrawJob::print(), and TauDQMHistPlotter::cfgEntryLabel::print().

{
  std::ostringstream os;
  
  os << "{ ";

  unsigned numEntries = vs.size();
  for ( unsigned iEntry = 0; iEntry < numEntries; ++iEntry ) {
    os << vs[iEntry];
    if ( iEntry < (numEntries - 1) ) os << ", ";
  }

  os << " }";
  
  return os.str();
}
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().

{
  std::vector<std::string> cfgParNames = cfgParSet.getParameterNamesForType<edm::ParameterSet>();
  for ( std::vector<std::string>::const_iterator cfgParName = cfgParNames.begin(); 
        cfgParName != cfgParNames.end(); ++cfgParName ) {
    edm::ParameterSet cfgParDef = cfgParSet.getParameter<edm::ParameterSet>(*cfgParName);
    
    def.insert(std::pair<std::string, T>(*cfgParName, T(*cfgParName, cfgParDef)));
  }
}
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.

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

{
  std::string modSrc = src;
  unsigned numReplacements = 0;
  while ( modSrc.find(keyword) != std::string::npos ) {
    modSrc.replace(modSrc.find(keyword), keyword.length(), parameter);
    ++numReplacements;
  }
  if ( (numReplacements < minReplacements) ||
       (numReplacements > maxReplacements) ) {
    edm::LogError ("replace_string") << " Failed to replace parameter = " << parameter << " in src = " << src << ","
                                     << " numReplacements = " << numReplacements 
                                     << " (min = " << minReplacements << ", max = " << maxReplacements << ") !!";
    errorFlag = 1;
  }
  return modSrc;
}
void separateHistogramFromDirectoryName ( const std::string &  ,
std::string &  ,
std::string &   
)

Definition at line 195 of file dqmAuxFunctions.cc.

References dqmRootDirectory, and dqmSeparator.

Referenced by TauDQMHistEffProducer::endRun().

{
  //std::cout << "<separateHistogramFromDirectoryName>:" << std::endl;

  std::string tempName = histogramAndDirectoryName;

//--- remove DQM root directory from histogram name
  std::string::size_type dqmRootDirectoryPos = tempName.find(dqmRootDirectory);
  if ( dqmRootDirectoryPos != std::string::npos ) {  
    tempName.replace(dqmRootDirectoryPos, dqmRootDirectory.size(), "");  
  }  

  //std::cout << " tempName = " << tempName << std::endl;

//--- extract directory from histogram name
  std::string::size_type lastPos;
  std::string::size_type nextPos = tempName.find(dqmSeparator);  
  do {
    lastPos = nextPos;
    nextPos = tempName.find(dqmSeparator, lastPos + 1);
  } while ( nextPos != std::string::npos );

  histogramName = ( lastPos != std::string::npos ) ? std::string(tempName, lastPos + 1, tempName.length()) : tempName;
  directoryName = ( lastPos != std::string::npos ) ? std::string(tempName, 0, lastPos) : "";

  //std::cout << " histogramName = " << histogramName << std::endl;
  //std::cout << " directoryName = " << directoryName << std::endl;
}

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"