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  , forceDefault_(iPS.getParameter<bool>("forceDefault"))
32  , lvl1Labels_(iPS.getParameter<std::vector<std::string> >("lvl1Labels"))
33  , nLvl1Index_(lvl1Labels_.size())
34  , iLvl1IndexDefault_(findDefaultIndex(iPS.getParameter<std::string>("lvl1DefaultLabel"), lvl1Labels_))
35  , vpsetPrescales_(iPS.getParameterSetVector("prescaleTable"))
36  , prescaleTable_()
37  {
40 
43 
46  }
47 
48  //______________________________________________________________________________
50  }
51 
53  // implementation of member functions
55 
57  vpsetPrescales_.clear();
58  prescaleTable_.clear();
59  lvl1Labels_ = iPS.getParameter<std::vector<std::string> >("lvl1Labels");
60  nLvl1Index_ = lvl1Labels_.size();
61  iLvl1IndexDefault_ = findDefaultIndex(iPS.getParameter<std::string>("lvl1DefaultLabel"), lvl1Labels_);
62  vpsetPrescales_ = iPS.getParameterSetVector("prescaleTable");
63  configure();
64  }
65 
67  if (!configured_) {
68  configure();
69  }
70  }
71 
72  //______________________________________________________________________________
74  {
75  configured_ = true;
76 
78 
79  // find all HLTPrescaler modules
80  std::set<std::string> prescalerModules;
81  std::vector<std::string> allModules=prcPS.getParameter<std::vector<std::string> >("@all_modules");
82  for(unsigned int i = 0; i < allModules.size(); ++i) {
83  ParameterSet const& pset = prcPS.getParameterSet(allModules[i]);
84  std::string moduleLabel = pset.getParameter<std::string>("@module_label");
85  std::string moduleType = pset.getParameter<std::string>("@module_type");
86  if (moduleType == "HLTPrescaler") prescalerModules.insert(moduleLabel);
87  }
88 
89  // find all paths with an HLTPrescaler and check for <=1
90  std::set<std::string> prescaledPathSet;
91  std::vector<std::string> allPaths = prcPS.getParameter<std::vector<std::string> >("@paths");
92  for (unsigned int iP = 0; iP < allPaths.size(); ++iP) {
93  std::string pathName = allPaths[iP];
94  std::vector<std::string> modules = prcPS.getParameter<std::vector<std::string> >(pathName);
95  for (unsigned int iM = 0; iM < modules.size(); ++iM) {
96  std::string moduleLabel = modules[iM];
97  if (prescalerModules.erase(moduleLabel)>0) {
98  std::set<std::string>::const_iterator itPath=prescaledPathSet.find(pathName);
99  if (itPath==prescaledPathSet.end()) {
100  prescaledPathSet.insert(pathName);
101  } else {
102  throw cms::Exception("DuplicatePrescaler")
103  <<"path '"<<pathName<<"' has more than one HLTPrescaler!";
104  }
105  }
106  }
107  }
108 
109  std::vector<std::string> prescaledPaths;
110  for (unsigned int iVPSet=0; iVPSet < vpsetPrescales_.size(); ++iVPSet) {
111  ParameterSet psetPrescales = vpsetPrescales_[iVPSet];
112  std::string pathName = psetPrescales.getParameter<std::string>("pathName");
113  if (prescaledPathSet.erase(pathName) > 0) {
114  std::vector<unsigned int> prescales =
115  psetPrescales.getParameter<std::vector<unsigned int> >("prescales");
116  if (prescales.size()!=nLvl1Index_) {
117  throw cms::Exception("PrescaleTableMismatch")
118  << "path '" << pathName << "' has unexpected number of prescales";
119  }
121  }
122  else {
123  throw cms::Exception("PrescaleTableUnknownPath")
124  <<"path '"<<pathName<<"' is invalid or does not "
125  <<"contain any HLTPrescaler";
126  }
127  }
128  }
129 
130  //______________________________________________________________________________
131  unsigned int PrescaleService::getPrescale(std::string const& prescaledPath)
132  {
133  return getPrescale(iLvl1IndexDefault_, prescaledPath);
134  }
135 
136  //______________________________________________________________________________
137  unsigned int PrescaleService::getPrescale(unsigned int lvl1Index,
138  std::string const& prescaledPath)
139  {
140  if (forceDefault_)
141  lvl1Index = iLvl1IndexDefault_;
142 
143  if (lvl1Index >= nLvl1Index_) {
144  throw cms::Exception("InvalidLvl1Index")
145  <<"lvl1Index '"<<lvl1Index<<"' exceeds number of prescale columns";
146  }
147 
148  if (!configured_) {
149  configure();
150  }
151 
152  PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
153  return (it == prescaleTable_.end()) ? 1 : it->second[lvl1Index];
154  }
155 
156  //______________________________________________________________________________
157  unsigned int PrescaleService::findDefaultIndex(std::string const & label, std::vector<std::string> const & labels) {
158  for (unsigned int i = 0; i < labels.size(); ++i) {
159  if (labels[i] == label) {
160  return i;
161  }
162  }
163  // FIXME add a LogWarning if the default is not found ?
164  return 0;
165  }
166 
167  //______________________________________________________________________________
170 
171  std::vector<std::string> defaultVector;
172  defaultVector.push_back(std::string("default"));
173  desc.add<std::vector<std::string> >("lvl1Labels", defaultVector);
174 
175  // This default vector<ParameterSet> will be used when
176  // the configuration does not include this parameter and
177  // it also gets written into the generated cfi file.
178  std::vector<edm::ParameterSet> defaultVPSet;
179  edm::ParameterSet pset0;
180  pset0.addParameter<std::string>("pathName", std::string("HLTPath"));
181  std::vector<unsigned> defaultVectorU;
182  defaultVectorU.push_back(1u);
183  pset0.addParameter<std::vector<unsigned> >("prescales", defaultVectorU);
184  defaultVPSet.push_back(pset0);
185 
187  validator.add<std::string>("pathName");
188  validator.add<std::vector<unsigned int> >("prescales");
189 
190  desc.addVPSet("prescaleTable", validator, defaultVPSet);
191 
192  desc.add<std::string>("lvl1DefaultLabel", std::string("default"));
193  desc.add<bool> ("forceDefault", false);
194 
195  descriptions.add("PrescaleService", desc);
196  }
197 
198  } // namespace service
199 } // namespace edm
T getParameter(std::string 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)
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)
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:145
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.
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
unsigned int getPrescale(unsigned int lvl1Index, std::string const &prescaledPath)