CMS 3D CMS Logo

HLTPrescaleProvider.cc
Go to the documentation of this file.
1 
13 
14 #include <cassert>
15 #include <sstream>
16 
17 static const bool useL1EventSetup(true);
18 static const bool useL1GtTriggerMenuLite(false);
19 static const unsigned char countMax(2);
20 
22  const edm::EventSetup& iSetup,
23  const std::string& processName,
24  bool& changed) {
25  inited_ = true;
26 
27  count_[0] = 0;
28  count_[1] = 0;
29  count_[2] = 0;
30  count_[3] = 0;
31  count_[4] = 0;
32 
33  const bool result(hltConfigProvider_.init(iRun, iSetup, processName, changed));
34 
35  const unsigned int l1tType(hltConfigProvider_.l1tType());
36  if (l1tType == 1) {
39  l1GtUtils_->getL1GtRunCache(iRun, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
40  } else if (l1tType == 2) {
42  l1tGlobalUtil_->retrieveL1Setup(iSetup);
43  } else {
44  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - prescales will not be avaiable!";
45  }
46 
47  return result;
48 }
49 
52  return *l1GtUtils_;
53 }
54 
57  return *l1tGlobalUtil_;
58 }
59 
61  if (!inited_) {
62  throw cms::Exception("LogicError") << "HLTPrescaleProvider::prescaleSet,\n"
63  "HLTPrescaleProvider::init was not called at beginRun\n";
64  }
65  const unsigned int l1tType(hltConfigProvider_.l1tType());
66  if (l1tType == 1) {
68 
69  // return hltPrescaleTable_.set();
70  l1GtUtils_->getL1GtRunCache(iEvent, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
71  int errorTech(0);
72  const int psfsiTech(l1GtUtils_->prescaleFactorSetIndex(iEvent, L1GtUtils::TechnicalTrigger, errorTech));
73  int errorPhys(0);
74  const int psfsiPhys(l1GtUtils_->prescaleFactorSetIndex(iEvent, L1GtUtils::AlgorithmTrigger, errorPhys));
75  assert(psfsiTech == psfsiPhys);
76  if ((errorTech == 0) && (errorPhys == 0) && (psfsiTech >= 0) && (psfsiPhys >= 0) && (psfsiTech == psfsiPhys)) {
77  return psfsiPhys;
78  } else {
80  if (count_[0] < countMax) {
81  count_[0] += 1;
82  edm::LogError("HLTPrescaleProvider")
83  << " Using processName '" << hltConfigProvider_.processName() << "':"
84  << " Error in determining HLT prescale set index from L1 data using L1GtUtils:"
85  << " Tech/Phys error = " << errorTech << "/" << errorPhys << " Tech/Phys psfsi = " << psfsiTech << "/"
86  << psfsiPhys;
87  }
88  return -1;
89  }
90  } else if (l1tType == 2) {
92  l1tGlobalUtil_->retrieveL1Event(iEvent, iSetup);
93  return static_cast<int>(l1tGlobalUtil_->prescaleColumn());
94  } else {
95  if (count_[0] < countMax) {
96  count_[0] += 1;
97  edm::LogError("HLTPrescaleProvider")
98  << " Using processName '" << hltConfigProvider_.processName() << "':"
99  << " Unknown L1T Type " << l1tType << " - can not determine prescale set index!";
100  }
101  return -1;
102  }
103 }
104 
106  const edm::EventSetup& iSetup,
107  const std::string& trigger) {
108  const int set(prescaleSet(iEvent, iSetup));
109  if (set < 0) {
110  return 1;
111  } else {
112  return hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set), trigger);
113  }
114 }
115 
117  const edm::EventSetup& iSetup,
118  const std::string& trigger) {
119  // start with setting both L1T and HLT prescale values to 0
120  std::pair<int, int> result(std::pair<int, int>(0, 0));
121 
122  // get HLT prescale (possible if HLT prescale set index is correctly found)
123  const int set(prescaleSet(iEvent, iSetup));
124  if (set < 0) {
125  result.second = -1;
126  } else {
127  result.second = static_cast<int>(hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set), trigger));
128  }
129 
130  // get L1T prescale - works only for those hlt trigger paths with
131  // exactly one L1GT seed module which has exactly one L1T name as seed
132 
133  const unsigned int l1tType(hltConfigProvider_.l1tType());
134  if (l1tType == 1) {
135  checkL1GtUtils();
136  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
137  if (nL1GTSeedModules == 0) {
138  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
139  result.first = 1;
140  } else if (nL1GTSeedModules == 1) {
141  l1GtUtils_->getL1GtRunCache(iEvent, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
142  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
143  int l1error(0);
144  result.first = l1GtUtils_->prescaleFactor(iEvent, l1tname, l1error);
145  if (l1error != 0) {
146  if (count_[1] < countMax) {
147  count_[1] += 1;
148  edm::LogError("HLTPrescaleProvider")
149  << " Error in determining L1T prescale for HLT path: '" << trigger << "' with L1T seed: '" << l1tname
150  << "' using L1GtUtils: error code = " << l1error << "." << std::endl
151  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed "
152  "as seed!"
153  << std::endl
154  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."
155  << std::endl;
156  }
157  result.first = -1;
158  }
159  } else {
161  if (count_[2] < countMax) {
162  count_[2] += 1;
163  std::string dump("'" + hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second + "'");
164  for (unsigned int i = 1; i != nL1GTSeedModules; ++i) {
165  dump += " * '" + hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second + "'";
166  }
167  edm::LogError("HLTPrescaleProvider")
168  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1GTSeed modules, "
169  << nL1GTSeedModules << ", with L1 seeds: " << dump
170  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
171  }
172  result.first = -1;
173  }
174  } else if (l1tType == 2) {
176  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
177  if (nL1TSeedModules == 0) {
178  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
179  result.first = 1;
180  } else if (nL1TSeedModules == 1) {
181  // l1tGlobalUtil_->retrieveL1Event(iEvent,iSetup);
182  const std::string l1tname(hltConfigProvider_.hltL1TSeeds(trigger).at(0));
183  bool l1error(!l1tGlobalUtil_->getPrescaleByName(l1tname, result.first));
184  if (l1error) {
185  if (count_[1] < countMax) {
186  count_[1] += 1;
187  edm::LogError("HLTPrescaleProvider")
188  << " Error in determining L1T prescale for HLT path: '" << trigger << "' with L1T seed: '" << l1tname
189  << "' using L1TGlobalUtil: error cond = " << l1error << "." << std::endl
190  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed "
191  "as seed!"
192  << std::endl
193  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."
194  << std::endl;
195  }
196  result.first = -1;
197  }
198  } else {
200  if (count_[2] < countMax) {
201  count_[2] += 1;
203  for (unsigned int i = 1; i != nL1TSeedModules; ++i) {
204  dump += " * '" + hltConfigProvider_.hltL1TSeeds(trigger).at(i) + "'";
205  }
206  edm::LogError("HLTPrescaleProvider")
207  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1TSeed modules, "
208  << nL1TSeedModules << ", with L1T seeds: " << dump
209  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
210  }
211  result.first = -1;
212  }
213  } else {
214  if (count_[1] < countMax) {
215  count_[1] += 1;
216  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
217  }
218  result.first = -1;
219  }
220 
221  return result;
222 }
223 
224 std::pair<std::vector<std::pair<std::string, int> >, int> HLTPrescaleProvider::prescaleValuesInDetail(
225  const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) {
226  std::pair<std::vector<std::pair<std::string, int> >, int> result;
227  result.first.clear();
228 
229  // get HLT prescale (possible if HLT prescale set index is correctly found)
230  const int set(prescaleSet(iEvent, iSetup));
231  if (set < 0) {
232  result.second = -1;
233  } else {
234  result.second = static_cast<int>(hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set), trigger));
235  }
236 
237  // get L1T prescale - works only for those hlt trigger paths with
238  // exactly one L1GT seed module
239 
240  const unsigned int l1tType(hltConfigProvider_.l1tType());
241  if (l1tType == 1) {
242  checkL1GtUtils();
243 
244  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
245  if (nL1GTSeedModules == 0) {
246  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
247  result.first.clear();
248  } else if (nL1GTSeedModules == 1) {
249  l1GtUtils_->getL1GtRunCache(iEvent, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
250  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
252  l1Logical.logicalExpressionRunUpdate(iEvent.getRun(), iSetup, l1tname);
253  const std::vector<std::pair<std::string, int> >& errorCodes(l1Logical.errorCodes(iEvent));
254  result.first = l1Logical.prescaleFactors();
255  int l1error(l1Logical.isValid() ? 0 : 1);
256  for (auto const& errorCode : errorCodes) {
257  l1error += std::abs(errorCode.second);
258  }
259  if (l1error != 0) {
260  if (count_[3] < countMax) {
261  count_[3] += 1;
262  std::ostringstream message;
263  message << " Error in determining L1T prescales for HLT path: '" << trigger << "' with complex L1T seed: '"
264  << l1tname << "' using L1GtUtils: " << std::endl
265  << " isValid=" << l1Logical.isValid() << " l1tname/error/prescale " << errorCodes.size() << std::endl;
266  for (unsigned int i = 0; i < errorCodes.size(); ++i) {
267  message << " " << i << ":" << errorCodes[i].first << "/" << errorCodes[i].second << "/"
268  << result.first[i].second;
269  }
270  message << ".";
271  edm::LogError("HLTPrescaleProvider") << message.str();
272  }
273  result.first.clear();
274  }
275  } else {
277  if (count_[4] < countMax) {
278  count_[4] += 1;
279  std::string dump("'" + hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second + "'");
280  for (unsigned int i = 1; i != nL1GTSeedModules; ++i) {
281  dump += " * '" + hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second + "'";
282  }
283  edm::LogError("HLTPrescaleProvider")
284  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1GTSeed modules, "
285  << nL1GTSeedModules << ", with L1 seeds: " << dump
286  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
287  }
288  result.first.clear();
289  }
290  } else if (l1tType == 2) {
292  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
293  if (nL1TSeedModules == 0) {
294  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
295  result.first.clear();
296  } else if (nL1TSeedModules == 1) {
297  // l1tGlobalUtil_->retrieveL1Event(iEvent,iSetup);
299  GlobalLogicParser l1tGlobalLogicParser = GlobalLogicParser(l1tname);
300  const std::vector<GlobalLogicParser::OperandToken> l1tSeeds = l1tGlobalLogicParser.expressionSeedsOperandList();
301  int l1error(0);
302  int l1tPrescale(-1);
303  for (auto const& i : l1tSeeds) {
304  const string& l1tSeed = i.tokenName;
305  if (!l1tGlobalUtil_->getPrescaleByName(l1tSeed, l1tPrescale)) {
306  l1error += 1;
307  }
308  result.first.push_back(std::pair<std::string, int>(l1tSeed, l1tPrescale));
309  }
310  if (l1error != 0) {
311  if (count_[3] < countMax) {
312  count_[3] += 1;
313  string l1name = l1tname;
314  std::ostringstream message;
315  message << " Error in determining L1T prescales for HLT path: '" << trigger << "' with complex L1T seed: '"
316  << l1tname << "' using L1TGlobalUtil: " << std::endl
317  << " isValid=" << l1tGlobalLogicParser.checkLogicalExpression(l1name) << " l1tname/error/prescale "
318  << l1tSeeds.size() << std::endl;
319  for (unsigned int i = 0; i < l1tSeeds.size(); ++i) {
320  const string& l1tSeed = l1tSeeds[i].tokenName;
321  message << " " << i << ":" << l1tSeed << "/" << l1tGlobalUtil_->getPrescaleByName(l1tSeed, l1tPrescale)
322  << "/" << result.first[i].second;
323  }
324  message << ".";
325  edm::LogError("HLTPrescaleProvider") << message.str();
326  }
327  result.first.clear();
328  }
329  } else {
331  if (count_[4] < countMax) {
332  count_[4] += 1;
334  for (unsigned int i = 1; i != nL1TSeedModules; ++i) {
335  dump += " * '" + hltConfigProvider_.hltL1TSeeds(trigger).at(i) + "'";
336  }
337  edm::LogError("HLTPrescaleProvider")
338  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1TSeed modules, "
339  << nL1TSeedModules << ", with L1T seeds: " << dump
340  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
341  }
342  result.first.clear();
343  }
344  } else {
345  if (count_[3] < countMax) {
346  count_[3] += 1;
347  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
348  }
349  result.first.clear();
350  }
351 
352  return result;
353 }
354 
356  return hltConfigProvider_.moduleType(hltConfigProvider_.moduleLabel(i, triggerResults.index(i))) == "HLTPrescaler";
357 }
358 
360  if (!l1GtUtils_) {
361  throw cms::Exception("Configuration") << "HLTPrescaleProvider::checkL1GtUtils(),\n"
362  "Attempt to use L1GtUtils object when none was constructed.\n"
363  "Possibly the proper era is not configured or\n"
364  "the module configuration does not use the era properly\n"
365  "or input is from mixed eras";
366  }
367 }
368 
370  if (!l1tGlobalUtil_) {
371  throw cms::Exception("Configuration") << "HLTPrescaleProvider:::checkL1TGlobalUtil(),\n"
372  "Attempt to use L1TGlobalUtil object when none was constructed.\n"
373  "Possibly the proper era is not configured or\n"
374  "the module configuration does not use the era properly\n"
375  "or input is from mixed eras";
376  }
377 }
HLTPrescaleProvider::checkL1TGlobalUtil
void checkL1TGlobalUtil() const
Definition: HLTPrescaleProvider.cc:369
HLTPrescaleProvider::l1tGlobalUtil
l1t::L1TGlobalUtil const & l1tGlobalUtil() const
Definition: HLTPrescaleProvider.cc:55
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
HLTConfigProvider::moduleType
const std::string moduleType(const std::string &module) const
C++ class name of module.
Definition: HLTConfigProvider.h:103
edm::Run
Definition: Run.h:45
HLTPrescaleProvider::prescaleSet
int prescaleSet(const edm::Event &iEvent, const edm::EventSetup &iSetup)
Definition: HLTPrescaleProvider.cc:60
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
HLTPrescaleProvider::count_
unsigned char count_[5]
Definition: HLTPrescaleProvider.h:83
cms::cuda::assert
assert(be >=bs)
HLTPrescaleProvider::rejectedByHLTPrescaler
bool rejectedByHLTPrescaler(const edm::TriggerResults &triggerResults, unsigned int i) const
Definition: HLTPrescaleProvider.cc:355
HLTConfigProvider::moduleLabel
const std::string & moduleLabel(unsigned int trigger, unsigned int module) const
Definition: HLTConfigProvider.h:87
L1GtUtils::TechnicalTrigger
Definition: L1GtUtils.h:140
HLTConfigProvider::l1tType
unsigned int l1tType() const
L1T type (0=unknown, 1=legacy/stage-1 or 2=stage-2)
Definition: HLTConfigProvider.h:118
HLTPrescaleProvider::l1GtUtils
L1GtUtils const & l1GtUtils() const
Definition: HLTPrescaleProvider.cc:50
HLTConfigProvider::hltL1TSeeds
const std::vector< std::vector< std::string > > & hltL1TSeeds() const
Definition: HLTConfigProvider.h:136
HLTConfigProvider::hltL1GTSeeds
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
Definition: HLTConfigProvider.h:122
l1t::L1TGlobalUtil
Definition: L1TGlobalUtil.h:42
HLTPrescaleProvider::l1tGlobalUtil_
std::unique_ptr< l1t::L1TGlobalUtil > l1tGlobalUtil_
Definition: HLTPrescaleProvider.h:82
L1GtUtils
Definition: L1GtUtils.h:66
useL1EventSetup
static const bool useL1EventSetup(true)
GlobalLogicParser
Definition: GlobalLogicParser.h:17
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogError
Definition: MessageLogger.h:183
HLTConfigProvider::prescaleValue
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
Definition: HLTConfigProvider.h:186
HLTPrescaleProvider::prescaleValuesInDetail
std::pair< std::vector< std::pair< std::string, int > >, int > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Definition: HLTPrescaleProvider.cc:224
HLTPrescaleProvider::inited_
bool inited_
Definition: HLTPrescaleProvider.h:84
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
iEvent
int iEvent
Definition: GenABIO.cc:224
useL1GtTriggerMenuLite
static const bool useL1GtTriggerMenuLite(false)
HLTPrescaleProvider::l1GtUtils_
std::unique_ptr< L1GtUtils > l1GtUtils_
Definition: HLTPrescaleProvider.h:81
HLTConfigProvider::processName
const std::string & processName() const
process name
Definition: HLTConfigProvider.h:53
edm::EventSetup
Definition: EventSetup.h:57
HLTPrescaleProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
Definition: HLTPrescaleProvider.cc:21
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
L1GtUtils::AlgorithmTrigger
Definition: L1GtUtils.h:140
HLTConfigProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
Definition: HLTConfigProvider.cc:36
Exception
Definition: hltDiff.cc:246
countMax
static const unsigned char countMax(2)
HLTPrescaleProvider::prescaleValue
unsigned int prescaleValue(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
combining the two methods above
Definition: HLTPrescaleProvider.cc:105
HLTPrescaleProvider.h
Exception.h
trigger
Definition: HLTPrescaleTableCond.h:8
HLTPrescaleProvider::checkL1GtUtils
void checkL1GtUtils() const
Definition: HLTPrescaleProvider.cc:359
mps_fire.result
result
Definition: mps_fire.py:303
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HLTPrescaleProvider::prescaleValues
std::pair< int, int > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
Definition: HLTPrescaleProvider.cc:116
L1GtUtils::LogicalExpressionL1Results
Definition: L1GtUtils.h:157
edm::Event
Definition: Event.h:73
HLTPrescaleProvider::hltConfigProvider_
HLTConfigProvider hltConfigProvider_
Definition: HLTPrescaleProvider.h:80
edm::TriggerResults
Definition: TriggerResults.h:35