CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 

Private Attributes

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

Detailed Description

Definition at line 18 of file PrescaleService.h.

Member Typedef Documentation

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

Definition at line 38 of file PrescaleService.h.

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

Definition at line 37 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_, EgammaValidation_cff::pathName, postBeginJob(), makeHLTPrescaleTable::prescales, prescaleTable_, AlCaHLTBitMon_QueryRunRegistry::string, vpsetPrescales_, and edm::ActivityRegistry::watchPostBeginJob().

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.watchPostBeginJob(this, &PrescaleService::postBeginJob);
33 
34  // Sanity check
35  if (lvl1Default_ >= lvl1Labels_.size()) {
36  throw cms::Exception("InvalidLvl1Index")
37  <<"lvl1Default_ '" << lvl1Default_ << "' exceeds number of prescale columns " << lvl1Labels_.size() << "!";
38  }
39 
40  // Check and store Prescale Table
41  for (unsigned int iVPSet=0; iVPSet < vpsetPrescales_.size(); ++iVPSet) {
42  const ParameterSet& psetPrescales = vpsetPrescales_[iVPSet];
43  const std::string pathName = psetPrescales.getParameter<std::string>("pathName");
44  if (prescaleTable_.find(pathName)!=prescaleTable_.end()) {
45  throw cms::Exception("PrescaleServiceConfigError")
46  << " Path '" << pathName << "' found more than once!";
47  }
48  std::vector<unsigned int> prescales = psetPrescales.getParameter<std::vector<unsigned int> >("prescales");
49  if (prescales.size()!=lvl1Labels_.size()) {
50  throw cms::Exception("PrescaleServiceConfigError")
51  << " Path '" << pathName << "' has " << prescales.size() << " prescales, instead of expected " << lvl1Labels_.size() << "!";
52  }
54  }
55 
56  }
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 59 of file PrescaleService.cc.

59  {
60  }

Member Function Documentation

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

Definition at line 158 of file PrescaleService.cc.

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

158  {
160 
161  std::vector<std::string> defaultVector;
162  defaultVector.push_back(std::string("default"));
163  desc.add<std::vector<std::string> >("lvl1Labels", defaultVector);
164 
165  // This default vector<ParameterSet> will be used when
166  // the configuration does not include this parameter and
167  // it also gets written into the generated cfi file.
168  std::vector<edm::ParameterSet> defaultVPSet;
169  edm::ParameterSet pset0;
170  pset0.addParameter<std::string>("pathName", std::string("HLTPath"));
171  std::vector<unsigned> defaultVectorU;
172  defaultVectorU.push_back(1u);
173  pset0.addParameter<std::vector<unsigned> >("prescales", defaultVectorU);
174  defaultVPSet.push_back(pset0);
175 
177  validator.add<std::string>("pathName");
178  validator.add<std::vector<unsigned int> >("prescales");
179 
180  desc.addVPSet("prescaleTable", validator, defaultVPSet);
181 
182  desc.add<std::string>("lvl1DefaultLabel", std::string("default"));
183  desc.add<bool> ("forceDefault", false);
184 
185  descriptions.add("PrescaleService", desc);
186  }
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:143
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 148 of file PrescaleService.cc.

References i.

148  {
149  for (unsigned int i = 0; i < labels.size(); ++i) {
150  if (labels[i] == label) {
151  return i;
152  }
153  }
154  return labels.size();
155  }
int i
Definition: DBlmapReader.cc:9
unsigned int edm::service::PrescaleService::getLvl1IndexDefault ( ) const
inline

Definition at line 39 of file PrescaleService.h.

References lvl1Default_.

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

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

Definition at line 40 of file PrescaleService.h.

References lvl1Labels_.

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

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

Definition at line 129 of file PrescaleService.cc.

References lvl1Default_.

Referenced by HLTPrescaler::filter().

130  {
131  return getPrescale(lvl1Default_, prescaledPath);
132  }
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 135 of file PrescaleService.cc.

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

136  {
137  if (forceDefault_) lvl1Index = lvl1Default_;
138 
139  if (lvl1Index >= lvl1Labels_.size()) {
140  throw cms::Exception("InvalidLvl1Index")
141  << "lvl1Index '" << lvl1Index << "' exceeds number of prescale columns " << lvl1Labels_.size() << "!";
142  }
143  PrescaleTable_t::const_iterator it = prescaleTable_.find(prescaledPath);
144  return (it == prescaleTable_.end()) ? 1 : it->second[lvl1Index];
145  }
const unsigned int lvl1Default_
const PrescaleTable_t& edm::service::PrescaleService::getPrescaleTable ( ) const
inline

Definition at line 41 of file PrescaleService.h.

References prescaleTable_.

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

41 {return prescaleTable_;}
void edm::service::PrescaleService::postBeginJob ( )
private

Definition at line 64 of file PrescaleService.cc.

References Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::getProcessParameterSet(), i, python.multivaluedict::map(), edmConvertToStreamModule::modules, EgammaValidation_cff::pathName, prescaleTable_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by PrescaleService().

64  {
65 
66  // Acesss to Process ParameterSet needed - can't be done in c'tor
67  const ParameterSet prcPS = getProcessParameterSet();
68 
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") module2path[moduleLabel]="";
86  }
87  // Check all modules on all paths
88  const std::vector<std::string> allPaths = prcPS.getParameter<std::vector<std::string> >("@paths");
89  for (unsigned int iP = 0; iP < allPaths.size(); ++iP) {
90  const std::string& pathName = allPaths[iP];
91  std::vector<std::string> modules = prcPS.getParameter<std::vector<std::string> >(pathName);
92  for (unsigned int iM = 0; iM < modules.size(); ++iM) {
93  const std::string& moduleLabel = modules[iM];
94  if (module2path.find(moduleLabel)!=module2path.end()) {
95  if (path2module.find(pathName)==path2module.end()) {
96  path2module[pathName]=moduleLabel;
97  } else {
98  throw cms::Exception("PrescaleServiceConfigError")
99  << "Path '" << pathName << "' with (>1) HLTPrescalers: " << path2module[pathName] << "+" << moduleLabel << "!";
100  }
101  if (module2path[moduleLabel]=="") {
102  module2path[moduleLabel]=pathName;
103  } else {
104  throw cms::Exception("PrescaleServiceConfigError")
105  << " HLTPrescaler '" << moduleLabel << "' on (>1) Paths: " << module2path[moduleLabel] << "+" << pathName << "!";
106  }
107  }
108  }
109  }
110  // Check all HLTPrescaler instances are on a path
111  for (std::map<std::string,std::string>::const_iterator it = module2path.begin(); it!=module2path.end(); ++it) {
112  if (it->second=="") {
113  throw cms::Exception("PrescaleServiceConfigError")
114  << " HLTPrescaler '" << it->first << "' not found on any path!";
115  }
116  }
117 
118  // Check paths stored Prescale Table: each path is actually in the process config
119  for (std::map<std::string, std::vector<unsigned int> >::const_iterator it = prescaleTable_.begin(); it!=prescaleTable_.end(); ++it) {
120  if (path2module.find(it->first)==path2module.end()) {
121  throw cms::Exception("PrescaleServiceConfigError")
122  << " Path '"<< it->first << "' is unknown or does not contain any HLTPrescaler!";
123  }
124  }
125 
126  }
int i
Definition: DBlmapReader.cc:9
ParameterSet const & getProcessParameterSet()
Definition: Registry.cc:85

Member Data Documentation

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

Definition at line 55 of file PrescaleService.h.

Referenced by getPrescale().

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

Definition at line 57 of file PrescaleService.h.

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

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

Definition at line 56 of file PrescaleService.h.

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

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

Definition at line 59 of file PrescaleService.h.

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

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

Definition at line 58 of file PrescaleService.h.

Referenced by PrescaleService().