CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
edm::service::PrescaleService Class Reference

#include <PrescaleService.h>

Inheritance diagram for edm::service::PrescaleService:
edm::serviceregistry::SaveConfiguration

Public Types

typedef std::map< std::string, std::vector< unsigned int > > PrescaleTable_t
 
typedef std::vector< std::string > VString_t
 

Public Member Functions

unsigned int getLvl1IndexDefault () const
 
const VString_tgetLvl1Labels () const
 
unsigned int getPrescale (std::string const &prescaledPath) const
 
unsigned int getPrescale (unsigned int lvl1Index, std::string const &prescaledPath) const
 
const PrescaleTable_tgetPrescaleTable () const
 
 PrescaleService (ParameterSet const &, ActivityRegistry &)
 
 ~PrescaleService ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static unsigned int findDefaultIndex (std::string const &label, std::vector< std::string > const &labels)
 

Private Member Functions

void postBeginJob ()
 
void preBeginJob (PathsAndConsumesOfModulesBase const &, ProcessContext const &)
 

Private Attributes

const bool forceDefault_
 
const unsigned int lvl1Default_
 
const VString_t lvl1Labels_
 
PrescaleTable_t prescaleTable_
 
ParameterSetID processParameterSetID_
 
const std::vector< ParameterSetvpsetPrescales_
 

Detailed Description

Definition at line 21 of file PrescaleService.h.

Member Typedef Documentation

typedef std::map<std::string, std::vector<unsigned int> > edm::service::PrescaleService::PrescaleTable_t

Definition at line 41 of file PrescaleService.h.

typedef std::vector<std::string> edm::service::PrescaleService::VString_t

Definition at line 40 of file PrescaleService.h.

Constructor & Destructor Documentation

edm::service::PrescaleService::PrescaleService ( ParameterSet const &  iPS,
ActivityRegistry iReg 
)

Definition at line 25 of file PrescaleService.cc.

References Exception, edm::ParameterSet::getParameter(), lvl1Default_, lvl1Labels_, postBeginJob(), preBeginJob(), prescaleTable_, AlCaHLTBitMon_QueryRunRegistry::string, vpsetPrescales_, edm::ActivityRegistry::watchPostBeginJob(), and edm::ActivityRegistry::watchPreBeginJob().

26  : forceDefault_(iPS.getParameter<bool>("forceDefault"))
27  , lvl1Labels_(iPS.getParameter<std::vector<std::string> >("lvl1Labels"))
28  , lvl1Default_(findDefaultIndex(iPS.getParameter<std::string>("lvl1DefaultLabel"), lvl1Labels_))
29  , vpsetPrescales_(iPS.getParameterSetVector("prescaleTable"))
30  , prescaleTable_()
31  {
32  iReg.watchPreBeginJob(this, &PrescaleService::preBeginJob);
33  iReg.watchPostBeginJob(this, &PrescaleService::postBeginJob);
34 
35  // Sanity check
36  if (lvl1Default_ >= lvl1Labels_.size()) {
37  throw cms::Exception("InvalidLvl1Index")
38  <<"lvl1Default_ '" << lvl1Default_ << "' exceeds number of prescale columns " << lvl1Labels_.size() << "!";
39  }
40 
41  // Check and store Prescale Table
42  for (unsigned int iVPSet=0; iVPSet < vpsetPrescales_.size(); ++iVPSet) {
43  const ParameterSet& psetPrescales = vpsetPrescales_[iVPSet];
44  const std::string pathName = psetPrescales.getParameter<std::string>("pathName");
45  if (prescaleTable_.find(pathName)!=prescaleTable_.end()) {
46  throw cms::Exception("PrescaleServiceConfigError")
47  << " Path '" << pathName << "' found more than once!";
48  }
49  std::vector<unsigned int> prescales = psetPrescales.getParameter<std::vector<unsigned int> >("prescales");
50  if (prescales.size()!=lvl1Labels_.size()) {
51  throw cms::Exception("PrescaleServiceConfigError")
52  << " Path '" << pathName << "' has " << prescales.size() << " prescales, instead of expected " << lvl1Labels_.size() << "!";
53  }
54  prescaleTable_[pathName] = prescales;
55  }
56 
57  }
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
const unsigned int lvl1Default_
const std::vector< ParameterSet > vpsetPrescales_
static unsigned int findDefaultIndex(std::string const &label, std::vector< std::string > const &labels)
edm::service::PrescaleService::~PrescaleService ( )

Definition at line 60 of file PrescaleService.cc.

60  {
61  }

Member Function Documentation

void edm::service::PrescaleService::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 165 of file PrescaleService.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSet::addParameter(), edm::ParameterSetDescription::addVPSet(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getPrescaleTable().

165  {
167 
168  std::vector<std::string> defaultVector;
169  defaultVector.push_back(std::string("default"));
170  desc.add<std::vector<std::string> >("lvl1Labels", defaultVector);
171 
172  // This default vector<ParameterSet> will be used when
173  // the configuration does not include this parameter and
174  // it also gets written into the generated cfi file.
175  std::vector<edm::ParameterSet> defaultVPSet;
176  edm::ParameterSet pset0;
177  pset0.addParameter<std::string>("pathName", std::string("HLTPath"));
178  std::vector<unsigned> defaultVectorU;
179  defaultVectorU.push_back(1u);
180  pset0.addParameter<std::vector<unsigned> >("prescales", defaultVectorU);
181  defaultVPSet.push_back(pset0);
182 
184  validator.add<std::string>("pathName");
185  validator.add<std::vector<unsigned int> >("prescales");
186 
187  desc.addVPSet("prescaleTable", validator, defaultVPSet);
188 
189  desc.add<std::string>("lvl1DefaultLabel", std::string("default"));
190  desc.add<bool> ("forceDefault", false);
191 
192  descriptions.add("PrescaleService", desc);
193  }
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
unsigned int edm::service::PrescaleService::findDefaultIndex ( std::string const &  label,
std::vector< std::string > const &  labels 
)
static

Definition at line 155 of file PrescaleService.cc.

References mps_fire::i.

Referenced by getPrescaleTable().

155  {
156  for (unsigned int i = 0; i < labels.size(); ++i) {
157  if (labels[i] == label) {
158  return i;
159  }
160  }
161  return labels.size();
162  }
unsigned int edm::service::PrescaleService::getLvl1IndexDefault ( ) const
inline

Definition at line 42 of file PrescaleService.h.

References lvl1Default_.

Referenced by HLTPrescaleRecorder::beginLuminosityBlock(), and HLTPrescaleRecorder::beginRun().

42 {return lvl1Default_;}
const unsigned int lvl1Default_
const VString_t& edm::service::PrescaleService::getLvl1Labels ( ) const
inline

Definition at line 43 of file PrescaleService.h.

References lvl1Labels_.

Referenced by HLTPrescaleRecorder::beginLuminosityBlock(), and HLTPrescaleRecorder::beginRun().

43 {return lvl1Labels_;}
unsigned int edm::service::PrescaleService::getPrescale ( std::string const &  prescaledPath) const

Definition at line 136 of file PrescaleService.cc.

References lvl1Default_.

Referenced by HLTPrescaler::filter().

137  {
138  return getPrescale(lvl1Default_, prescaledPath);
139  }
const unsigned int lvl1Default_
unsigned int getPrescale(std::string const &prescaledPath) const
unsigned int edm::service::PrescaleService::getPrescale ( unsigned int  lvl1Index,
std::string const &  prescaledPath 
) const

Definition at line 142 of file PrescaleService.cc.

References Exception, forceDefault_, lvl1Default_, lvl1Labels_, and prescaleTable_.

143  {
144  if (forceDefault_) lvl1Index = lvl1Default_;
145 
146  if (lvl1Index >= lvl1Labels_.size()) {
147  throw cms::Exception("InvalidLvl1Index")
148  << "lvl1Index '" << lvl1Index << "' exceeds number of prescale columns " << lvl1Labels_.size() << "!";
149  }
150  PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
151  return (it == prescaleTable_.end()) ? 1 : it->second[lvl1Index];
152  }
const unsigned int lvl1Default_
const PrescaleTable_t& edm::service::PrescaleService::getPrescaleTable ( ) const
inline
void edm::service::PrescaleService::postBeginJob ( )
private

Definition at line 72 of file PrescaleService.cc.

References Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::getParameterSet(), mps_fire::i, genParticles_cff::map, prescaleTable_, processParameterSetID_, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getPrescaleTable(), and PrescaleService().

72  {
73 
74  // Acess to Process ParameterSet needed - can't be done in c'tor
76  // Label of HLTPrescaler on each path, keyed on pathName
77  std::map<std::string,std::string> path2module;
78  // Name of path for each HLTPrescaler, keyed on moduleLabel
79  std::map<std::string,std::string> module2path;
80 
81  // Check process config:
82  // * each path contains at most one HLTPrescaler instance
83  // * each HLTPrescaler instance is part of at most one path
84  // * each HLTPrescaler instance is part of at least one ptah
85 
86  // Find all HLTPrescaler instances
87  const std::vector<std::string> allModules=prcPS.getParameter<std::vector<std::string> >("@all_modules");
88  for(unsigned int i = 0; i < allModules.size(); ++i) {
89  ParameterSet const& pset = prcPS.getParameterSet(allModules[i]);
90  const std::string moduleLabel = pset.getParameter<std::string>("@module_label");
91  const std::string moduleType = pset.getParameter<std::string>("@module_type");
92  if (moduleType == "HLTPrescaler") module2path[moduleLabel]="";
93  }
94  // Check all modules on all paths
95  const std::vector<std::string> allPaths = prcPS.getParameter<std::vector<std::string> >("@paths");
96  for (unsigned int iP = 0; iP < allPaths.size(); ++iP) {
97  const std::string& pathName = allPaths[iP];
98  std::vector<std::string> modules = prcPS.getParameter<std::vector<std::string> >(pathName);
99  for (unsigned int iM = 0; iM < modules.size(); ++iM) {
100  const std::string& moduleLabel = modules[iM];
101  if (module2path.find(moduleLabel)!=module2path.end()) {
102  if (path2module.find(pathName)==path2module.end()) {
103  path2module[pathName]=moduleLabel;
104  } else {
105  throw cms::Exception("PrescaleServiceConfigError")
106  << "Path '" << pathName << "' with (>1) HLTPrescalers: " << path2module[pathName] << "+" << moduleLabel << "!";
107  }
108  if (module2path[moduleLabel]=="") {
109  module2path[moduleLabel]=pathName;
110  } else {
111  throw cms::Exception("PrescaleServiceConfigError")
112  << " HLTPrescaler '" << moduleLabel << "' on (>1) Paths: " << module2path[moduleLabel] << "+" << pathName << "!";
113  }
114  }
115  }
116  }
117  // Check all HLTPrescaler instances are on a path
118  for (std::map<std::string,std::string>::const_iterator it = module2path.begin(); it!=module2path.end(); ++it) {
119  if (it->second=="") {
120  throw cms::Exception("PrescaleServiceConfigError")
121  << " HLTPrescaler '" << it->first << "' not found on any path!";
122  }
123  }
124 
125  // Check paths stored Prescale Table: each path is actually in the process config
126  for (std::map<std::string, std::vector<unsigned int> >::const_iterator it = prescaleTable_.begin(); it!=prescaleTable_.end(); ++it) {
127  if (path2module.find(it->first)==path2module.end()) {
128  throw cms::Exception("PrescaleServiceConfigError")
129  << " Path '"<< it->first << "' is unknown or does not contain any HLTPrescaler!";
130  }
131  }
132 
133  }
ParameterSet const & getParameterSet(ParameterSetID const &id)
ParameterSetID processParameterSetID_
void edm::service::PrescaleService::preBeginJob ( PathsAndConsumesOfModulesBase const &  ,
ProcessContext const &  processContext 
)
private

Definition at line 65 of file PrescaleService.cc.

References edm::Hash< I >::isValid(), edm::ProcessContext::parameterSetID(), and processParameterSetID_.

Referenced by getPrescaleTable(), and PrescaleService().

66  {
68  processParameterSetID_ = processContext.parameterSetID();
69  }
70  }
ParameterSetID processParameterSetID_
bool isValid() const
Definition: Hash.h:154

Member Data Documentation

const bool edm::service::PrescaleService::forceDefault_
private

Definition at line 59 of file PrescaleService.h.

Referenced by getPrescale().

const unsigned int edm::service::PrescaleService::lvl1Default_
private

Definition at line 61 of file PrescaleService.h.

Referenced by getLvl1IndexDefault(), getPrescale(), and PrescaleService().

const VString_t edm::service::PrescaleService::lvl1Labels_
private

Definition at line 60 of file PrescaleService.h.

Referenced by getLvl1Labels(), getPrescale(), and PrescaleService().

PrescaleTable_t edm::service::PrescaleService::prescaleTable_
private

Definition at line 63 of file PrescaleService.h.

Referenced by getPrescale(), getPrescaleTable(), postBeginJob(), and PrescaleService().

ParameterSetID edm::service::PrescaleService::processParameterSetID_
private

Definition at line 64 of file PrescaleService.h.

Referenced by postBeginJob(), and preBeginJob().

const std::vector<ParameterSet> edm::service::PrescaleService::vpsetPrescales_
private

Definition at line 62 of file PrescaleService.h.

Referenced by PrescaleService().