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 //
6 // 04/25/2008 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
9 
16 
17 #include <set>
18 #include <algorithm>
19 
20 
21 namespace edm {
22  namespace service {
23 
25  // construction/destruction
27 
28  //______________________________________________________________________________
30  : configured_(false)
31  , lvl1Labels_(iPS.getParameter<std::vector<std::string> >("lvl1Labels"))
32  , nLvl1Index_(lvl1Labels_.size())
33  , iLvl1IndexDefault_(0)
34  , vpsetPrescales_(iPS.getParameterSetVector("prescaleTable"))
35  , prescaleTable_()
36  {
37  std::string lvl1DefaultLabel=
38  iPS.getUntrackedParameter<std::string>("lvl1DefaultLabel","");
39  for (unsigned int i = 0; i < lvl1Labels_.size(); ++i) {
40  if (lvl1Labels_[i] == lvl1DefaultLabel) iLvl1IndexDefault_ = i;
41  }
42 
45 
48 
51  }
52 
53  //______________________________________________________________________________
55  }
56 
58  // implementation of member functions
60 
62  vpsetPrescales_.clear();
63  prescaleTable_.clear();
65  lvl1Labels_ = iPS.getParameter<std::vector<std::string> >("lvl1Labels");
66  nLvl1Index_ = lvl1Labels_.size();
67  vpsetPrescales_ = iPS.getParameterSetVector("prescaleTable");
68  std::string lvl1DefaultLabel=
69  iPS.getUntrackedParameter<std::string>("lvl1DefaultLabel");
70  for (unsigned int i=0; i < lvl1Labels_.size(); ++i) {
71  if (lvl1Labels_[i] == lvl1DefaultLabel) iLvl1IndexDefault_ = i;
72  }
73  configure();
74  }
75 
77  if (!configured_) {
78  configure();
79  }
80  }
81 
82  //______________________________________________________________________________
84  {
85  configured_ = true;
86 
88 
89  // find all HLTPrescaler modules
90  std::set<std::string> prescalerModules;
91  std::vector<std::string> allModules=prcPS.getParameter<std::vector<std::string> >("@all_modules");
92  for(unsigned int i = 0; i < allModules.size(); ++i) {
93  ParameterSet const& pset = prcPS.getParameterSet(allModules[i]);
94  std::string moduleLabel = pset.getParameter<std::string>("@module_label");
95  std::string moduleType = pset.getParameter<std::string>("@module_type");
96  if (moduleType == "HLTPrescaler") prescalerModules.insert(moduleLabel);
97  }
98 
99  // find all paths with an HLTPrescaler and check for <=1
100  std::set<std::string> prescaledPathSet;
101  std::vector<std::string> allPaths = prcPS.getParameter<std::vector<std::string> >("@paths");
102  for (unsigned int iP = 0; iP < allPaths.size(); ++iP) {
103  std::string pathName = allPaths[iP];
104  std::vector<std::string> modules = prcPS.getParameter<std::vector<std::string> >(pathName);
105  for (unsigned int iM = 0; iM < modules.size(); ++iM) {
106  std::string moduleLabel = modules[iM];
107  if (prescalerModules.erase(moduleLabel)>0) {
108  std::set<std::string>::const_iterator itPath=prescaledPathSet.find(pathName);
109  if (itPath==prescaledPathSet.end()) {
110  prescaledPathSet.insert(pathName);
111  } else {
112  throw cms::Exception("DuplicatePrescaler")
113  <<"path '"<<pathName<<"' has more than one HLTPrescaler!";
114  }
115  }
116  }
117  }
118 
119  std::vector<std::string> prescaledPaths;
120  for (unsigned int iVPSet=0; iVPSet < vpsetPrescales_.size(); ++iVPSet) {
121  ParameterSet psetPrescales = vpsetPrescales_[iVPSet];
122  std::string pathName = psetPrescales.getParameter<std::string>("pathName");
123  if (prescaledPathSet.erase(pathName) > 0) {
124  std::vector<unsigned int> prescales =
125  psetPrescales.getParameter<std::vector<unsigned int> >("prescales");
126  if (prescales.size()!=nLvl1Index_) {
127  throw cms::Exception("PrescaleTableMismatch")
128  << "path '" << pathName << "' has unexpected number of prescales";
129  }
131  }
132  else {
133  throw cms::Exception("PrescaleTableUnknownPath")
134  <<"path '"<<pathName<<"' is invalid or does not "
135  <<"contain any HLTPrescaler";
136  }
137  }
138  }
139 
140  //______________________________________________________________________________
141  unsigned int PrescaleService::getPrescale(std::string const& prescaledPath)
142  {
143  return getPrescale(iLvl1IndexDefault_, prescaledPath);
144  }
145 
146  //______________________________________________________________________________
147  unsigned int PrescaleService::getPrescale(unsigned int lvl1Index,
148  std::string const& prescaledPath)
149  {
150  if (lvl1Index >= nLvl1Index_) {
151  throw cms::Exception("InvalidLvl1Index")
152  <<"lvl1Index '"<<lvl1Index<<"' exceeds number of prescale columns";
153  }
154 
155  if (!configured_) {
156  configure();
157  }
158 
159  PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
160  return (it == prescaleTable_.end()) ? 1 : it->second[lvl1Index];
161  }
162 
163  //______________________________________________________________________________
166 
167  std::vector<std::string> defaultVector;
168  defaultVector.push_back(std::string("default"));
169  desc.add<std::vector<std::string> >("lvl1Labels", defaultVector);
170 
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.addUntracked<std::string>("lvl1DefaultLabel", std::string("default"));
190 
191  descriptions.add("PrescaleService", desc);
192  }
193 
194  } // namespace service
195 } // namespace edm
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< ParameterSet > vpsetPrescales_
VParameterSet const & getParameterSetVector(std::string const &name) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
void watchPreModule(PreModule::slot_type const &iSlot)
const std::string * pathName() const
Definition: HLTadd.h:31
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:139
void reconfigure(ParameterSet const &ps)
void preEventProcessing(EventID const &, Timestamp const &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void postModule(ModuleDescription const &)
PrescaleService(ParameterSet const &, ActivityRegistry &)
ParameterSet const & getProcessParameterSet()
Definition: Registry.cc:34
ParameterSet const & getParameterSet(std::string const &) const
void postEventProcessing(Event const &, EventSetup const &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void preModule(ModuleDescription const &)
tuple size
Write out results.
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
const std::string * moduleLabel() const
Definition: HLTadd.h:40
unsigned int getPrescale(unsigned int lvl1Index, std::string const &prescaledPath)