test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrescaleService.cc
Go to the documentation of this file.
1 //
3 // PrescaleService
4 // ---------------
5 //
7 
8 
15 
16 #include <iostream>
17 #include <set>
18 #include <algorithm>
19 
20 
21 namespace edm {
22  namespace service {
23 
24  // constructor
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  {
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  }
55  }
56 
57  }
58 
59  // destructor
61  }
62 
63  // member functions
64 
66  ProcessContext const& processContext) {
68  processParameterSetID_ = processContext.parameterSetID();
69  }
70  }
71 
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  }
134 
135  // const method
136  unsigned int PrescaleService::getPrescale(std::string const& prescaledPath) const
137  {
138  return getPrescale(lvl1Default_, prescaledPath);
139  }
140 
141  // const method
142  unsigned int PrescaleService::getPrescale(unsigned int lvl1Index, std::string const& prescaledPath) const
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  }
153 
154  // static method
155  unsigned int PrescaleService::findDefaultIndex(std::string const & label, std::vector<std::string> const & labels) {
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  }
163 
164  // static method
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  }
194 
195  } // namespace service
196 } // namespace edm
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
const unsigned int lvl1Default_
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterSet const & getParameterSet(ParameterSetID const &id)
ParameterSetID const & parameterSetID() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
ParameterDescriptionBase * add(U const &iLabel, T const &value)
PrescaleService(ParameterSet const &, ActivityRegistry &)
ParameterSet const & getParameterSet(std::string const &) const
unsigned int getPrescale(std::string const &prescaledPath) const
const std::vector< ParameterSet > vpsetPrescales_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
ParameterSetID processParameterSetID_
bool isValid() const
Definition: Hash.h:150
static unsigned int findDefaultIndex(std::string const &label, std::vector< std::string > const &labels)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal