CMS 3D CMS Logo

PrescaleService.cc
Go to the documentation of this file.
1 //
3 // PrescaleService
4 // ---------------
5 //
7 
14 
15 #include <iostream>
16 #include <set>
17 #include <algorithm>
18 
19 namespace edm {
20  namespace service {
21 
22  // constructor
24  : forceDefault_(iPS.getParameter<bool>("forceDefault")),
25  lvl1Labels_(iPS.getParameter<std::vector<std::string> >("lvl1Labels")),
26  lvl1Default_(findDefaultIndex(iPS.getParameter<std::string>("lvl1DefaultLabel"), lvl1Labels_)),
27  vpsetPrescales_(iPS.getParameterSetVector("prescaleTable")),
28  prescaleTable_() {
31 
32  // Sanity check
33  if (lvl1Default_ >= lvl1Labels_.size()) {
34  throw cms::Exception("InvalidLvl1Index")
35  << "lvl1Default_ '" << lvl1Default_ << "' exceeds number of prescale columns " << lvl1Labels_.size() << "!";
36  }
37 
38  // Check and store Prescale Table
39  for (unsigned int iVPSet = 0; iVPSet < vpsetPrescales_.size(); ++iVPSet) {
40  const ParameterSet& psetPrescales = vpsetPrescales_[iVPSet];
41  const std::string pathName = psetPrescales.getParameter<std::string>("pathName");
42  if (prescaleTable_.find(pathName) != prescaleTable_.end()) {
43  throw cms::Exception("PrescaleServiceConfigError") << " Path '" << pathName << "' found more than once!";
44  }
45  std::vector<unsigned int> prescales = psetPrescales.getParameter<std::vector<unsigned int> >("prescales");
46  if (prescales.size() != lvl1Labels_.size()) {
47  throw cms::Exception("PrescaleServiceConfigError")
48  << " Path '" << pathName << "' has " << prescales.size() << " prescales, instead of expected "
49  << lvl1Labels_.size() << "!";
50  }
52  }
53  }
54 
55  // destructor
57 
58  // member functions
59 
62  processParameterSetID_ = processContext.parameterSetID();
63  }
64  }
65 
67  // Acess to Process ParameterSet needed - can't be done in c'tor
69  // Label of HLTPrescaler on each path, keyed on pathName
70  std::map<std::string, std::string> path2module;
71  // Name of path for each HLTPrescaler, keyed on moduleLabel
72  std::map<std::string, std::string> module2path;
73 
74  // Check process config:
75  // * each path contains at most one HLTPrescaler instance
76  // * each HLTPrescaler instance is part of at most one path
77  // * each HLTPrescaler instance is part of at least one ptah
78 
79  // Find all HLTPrescaler instances
80  const std::vector<std::string> allModules = prcPS.getParameter<std::vector<std::string> >("@all_modules");
81  for (unsigned int i = 0; i < allModules.size(); ++i) {
82  ParameterSet const& pset = prcPS.getParameterSet(allModules[i]);
83  const std::string moduleLabel = pset.getParameter<std::string>("@module_label");
84  const std::string moduleType = pset.getParameter<std::string>("@module_type");
85  if (moduleType == "HLTPrescaler")
86  module2path[moduleLabel] = "";
87  }
88  // Check all modules on all paths
89  const std::vector<std::string> allPaths = prcPS.getParameter<std::vector<std::string> >("@paths");
90  for (unsigned int iP = 0; iP < allPaths.size(); ++iP) {
91  const std::string& pathName = allPaths[iP];
92  std::vector<std::string> modules = prcPS.getParameter<std::vector<std::string> >(pathName);
93  for (unsigned int iM = 0; iM < modules.size(); ++iM) {
94  const std::string& moduleLabel = modules[iM];
95  if (module2path.find(moduleLabel) != module2path.end()) {
96  if (path2module.find(pathName) == path2module.end()) {
97  path2module[pathName] = moduleLabel;
98  } else {
99  throw cms::Exception("PrescaleServiceConfigError")
100  << "Path '" << pathName << "' with (>1) HLTPrescalers: " << path2module[pathName] << "+"
101  << moduleLabel << "!";
102  }
103  if (module2path[moduleLabel].empty()) {
104  module2path[moduleLabel] = pathName;
105  } else {
106  throw cms::Exception("PrescaleServiceConfigError")
107  << " HLTPrescaler '" << moduleLabel << "' on (>1) Paths: " << module2path[moduleLabel] << "+"
108  << pathName << "!";
109  }
110  }
111  }
112  }
113  // Check all HLTPrescaler instances are on a path
114  for (std::map<std::string, std::string>::const_iterator it = module2path.begin(); it != module2path.end(); ++it) {
115  if (it->second.empty()) {
116  throw cms::Exception("PrescaleServiceConfigError")
117  << " HLTPrescaler '" << it->first << "' not found on any path!";
118  }
119  }
120 
121  // Check paths stored Prescale Table: each path is actually in the process config
122  for (std::map<std::string, std::vector<unsigned int> >::const_iterator it = prescaleTable_.begin();
123  it != prescaleTable_.end();
124  ++it) {
125  if (path2module.find(it->first) == path2module.end()) {
126  throw cms::Exception("PrescaleServiceConfigError")
127  << " Path '" << it->first << "' is unknown or does not contain any HLTPrescaler!";
128  }
129  }
130  }
131 
132  // const method
133  unsigned int PrescaleService::getPrescale(std::string const& prescaledPath) const {
134  return getPrescale(lvl1Default_, prescaledPath);
135  }
136 
137  // const method
138  unsigned int PrescaleService::getPrescale(unsigned int lvl1Index, std::string const& prescaledPath) const {
139  if (forceDefault_)
140  lvl1Index = lvl1Default_;
141 
142  if (lvl1Index >= lvl1Labels_.size()) {
143  throw cms::Exception("InvalidLvl1Index")
144  << "lvl1Index '" << lvl1Index << "' exceeds number of prescale columns " << lvl1Labels_.size() << "!";
145  }
146  PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
147  return (it == prescaleTable_.end()) ? 1 : it->second[lvl1Index];
148  }
149 
150  // static method
151  unsigned int PrescaleService::findDefaultIndex(std::string const& label, std::vector<std::string> const& labels) {
152  for (unsigned int i = 0; i < labels.size(); ++i) {
153  if (labels[i] == label) {
154  return i;
155  }
156  }
157  return labels.size();
158  }
159 
160  // static method
163 
164  std::vector<std::string> defaultVector;
165  defaultVector.push_back(std::string("default"));
166  desc.add<std::vector<std::string> >("lvl1Labels", defaultVector);
167 
168  // This default vector<ParameterSet> will be used when
169  // the configuration does not include this parameter and
170  // it also gets written into the generated cfi file.
171  std::vector<edm::ParameterSet> defaultVPSet;
172  edm::ParameterSet pset0;
173  pset0.addParameter<std::string>("pathName", std::string("HLTPath"));
174  std::vector<unsigned> defaultVectorU;
175  defaultVectorU.push_back(1u);
176  pset0.addParameter<std::vector<unsigned> >("prescales", defaultVectorU);
177  defaultVPSet.push_back(pset0);
178 
180  validator.add<std::string>("pathName");
181  validator.add<std::vector<unsigned int> >("prescales");
182 
183  desc.addVPSet("prescaleTable", validator, defaultVPSet);
184 
185  desc.add<std::string>("lvl1DefaultLabel", std::string("default"));
186  desc.add<bool>("forceDefault", false);
187 
188  descriptions.add("PrescaleService", desc);
189  }
190 
191  } // namespace service
192 } // namespace edm
ConfigurationDescriptions.h
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
service
Definition: service.py:1
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
edm::service::PrescaleService::postBeginJob
void postBeginJob()
Definition: PrescaleService.cc:66
edm::service::PrescaleService::processParameterSetID_
ParameterSetID processParameterSetID_
Definition: PrescaleService.h:60
mutracking_dqm_sourceclient-live_cfg.allPaths
allPaths
Definition: mutracking_dqm_sourceclient-live_cfg.py:181
edm::service::PrescaleService::getPrescale
unsigned int getPrescale(std::string const &prescaledPath) const
Definition: PrescaleService.cc:133
modules
Definition: MuonCleanerBySegments.cc:35
edm::service::PrescaleService::prescaleTable_
PrescaleTable_t prescaleTable_
Definition: PrescaleService.h:59
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ProcessContext
Definition: ProcessContext.h:27
edm::service::PrescaleService::vpsetPrescales_
const std::vector< ParameterSet > vpsetPrescales_
Definition: PrescaleService.h:58
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::service::PrescaleService::lvl1Default_
const unsigned int lvl1Default_
Definition: PrescaleService.h:57
PrescaleService.h
edm::service::PrescaleService::findDefaultIndex
static unsigned int findDefaultIndex(std::string const &label, std::vector< std::string > const &labels)
Definition: PrescaleService.cc:151
edm::service::PrescaleService::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PrescaleService.cc:161
edm::service::PrescaleService::preBeginJob
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
Definition: PrescaleService.cc:60
ActivityRegistry.h
edm::service::PrescaleService::PrescaleService
PrescaleService(ParameterSet const &, ActivityRegistry &)
Definition: PrescaleService.cc:23
edm::service::PrescaleService::lvl1Labels_
const VString_t lvl1Labels_
Definition: PrescaleService.h:56
edm::Hash::isValid
bool isValid() const
Definition: Hash.h:141
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
hltMonBTagIPClient_cfi.pathName
pathName
Definition: hltMonBTagIPClient_cfi.py:5
edm::ActivityRegistry::watchPreBeginJob
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
Definition: ActivityRegistry.h:151
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
edm::ActivityRegistry::watchPostBeginJob
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
Definition: ActivityRegistry.h:158
edm::ProcessContext::parameterSetID
ParameterSetID const & parameterSetID() const
Definition: ProcessContext.h:32
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::service::PrescaleService::forceDefault_
const bool forceDefault_
Definition: PrescaleService.h:55
edm::ParameterSet
Definition: ParameterSet.h:47
hltrates_dqm_sourceclient-live_cfg.prescales
prescales
Definition: hltrates_dqm_sourceclient-live_cfg.py:90
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
edm::service::PrescaleService::~PrescaleService
~PrescaleService()
Definition: PrescaleService.cc:56
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::getParameterSet
ParameterSet const & getParameterSet(ParameterSetID const &id)
Definition: ParameterSet.cc:862
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
edm::PathsAndConsumesOfModulesBase
Definition: PathsAndConsumesOfModulesBase.h:35
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:245
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edmTracerLogToSimpleConfig.allModules
allModules
Definition: edmTracerLogToSimpleConfig.py:131
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
ProcessContext.h
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::ParameterSet::getParameterSet
ParameterSet const & getParameterSet(std::string const &) const
Definition: ParameterSet.cc:2128
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27