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 
105 template <>
106 FractionalPrescale HLTPrescaleProvider::convertL1PS<FractionalPrescale>(double val) const {
107  int numer = static_cast<int>(val * kL1PrescaleDenominator_ + 0.5);
108  static constexpr double kL1RoundingEpsilon = 0.001;
109  if (std::abs(numer - val * kL1PrescaleDenominator_) > kL1RoundingEpsilon) {
110  edm::LogWarning("ValueError") << " Error, L1 prescale val " << val
111  << "does not appear to precisely expressable as int / " << kL1PrescaleDenominator_
112  << ", using a FractionalPrescale is a loss of precision";
113  }
114 
115  return {numer, kL1PrescaleDenominator_};
116 }
117 
119  const edm::EventSetup& iSetup,
120  const std::string& trigger) {
121  // get L1T prescale - works only for those hlt trigger paths with
122  // exactly one L1GT seed module which has exactly one L1T name as seed
123 
124  double result = -1;
125 
126  const unsigned int l1tType(hltConfigProvider_.l1tType());
127  if (l1tType == 1) {
128  checkL1GtUtils();
129  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
130  if (nL1GTSeedModules == 0) {
131  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
132  result = 1;
133  } else if (nL1GTSeedModules == 1) {
134  l1GtUtils_->getL1GtRunCache(iEvent, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
135  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
136  int l1error(0);
137  result = l1GtUtils_->prescaleFactor(iEvent, l1tname, l1error);
138  if (l1error != 0) {
139  if (count_[1] < countMax) {
140  count_[1] += 1;
141  edm::LogError("HLTPrescaleProvider")
142  << " Error in determining L1T prescale for HLT path: '" << trigger << "' with L1T seed: '" << l1tname
143  << "' using L1GtUtils: error code = " << l1error << "." << std::endl
144  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed "
145  "as seed!"
146  << std::endl
147  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."
148  << std::endl;
149  }
150  result = -1;
151  }
152  } else {
154  if (count_[2] < countMax) {
155  count_[2] += 1;
156  std::string dump("'" + hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second + "'");
157  for (unsigned int i = 1; i != nL1GTSeedModules; ++i) {
158  dump += " * '" + hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second + "'";
159  }
160  edm::LogError("HLTPrescaleProvider")
161  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1GTSeed modules, "
162  << nL1GTSeedModules << ", with L1 seeds: " << dump
163  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
164  }
165  result = -1;
166  }
167  } else if (l1tType == 2) {
169  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
170  if (nL1TSeedModules == 0) {
171  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
172  result = 1;
173  } else if (nL1TSeedModules == 1) {
174  // l1tGlobalUtil_->retrieveL1Event(iEvent,iSetup);
175  const std::string l1tname(hltConfigProvider_.hltL1TSeeds(trigger).at(0));
176  bool l1error(!l1tGlobalUtil_->getPrescaleByName(l1tname, result));
177  if (l1error) {
178  if (count_[1] < countMax) {
179  count_[1] += 1;
180  edm::LogError("HLTPrescaleProvider")
181  << " Error in determining L1T prescale for HLT path: '" << trigger << "' with L1T seed: '" << l1tname
182  << "' using L1TGlobalUtil: error cond = " << l1error << "." << std::endl
183  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed "
184  "as seed!"
185  << std::endl
186  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."
187  << std::endl;
188  }
189  result = -1;
190  }
191  } else {
193  if (count_[2] < countMax) {
194  count_[2] += 1;
196  for (unsigned int i = 1; i != nL1TSeedModules; ++i) {
197  dump += " * '" + hltConfigProvider_.hltL1TSeeds(trigger).at(i) + "'";
198  }
199  edm::LogError("HLTPrescaleProvider")
200  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1TSeed modules, "
201  << nL1TSeedModules << ", with L1T seeds: " << dump
202  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
203  }
204  result = -1;
205  }
206  } else {
207  if (count_[1] < countMax) {
208  count_[1] += 1;
209  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
210  }
211  result = -1;
212  }
213 
214  return result;
215 }
216 
217 std::vector<std::pair<std::string, double> > HLTPrescaleProvider::getL1PrescaleValueInDetail(
218  const edm::Event& iEvent, const edm::EventSetup& iSetup, const std::string& trigger) {
219  std::vector<std::pair<std::string, double> > result;
220 
221  const unsigned int l1tType(hltConfigProvider_.l1tType());
222  if (l1tType == 1) {
223  checkL1GtUtils();
224 
225  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
226  if (nL1GTSeedModules == 0) {
227  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
228  result.clear();
229  } else if (nL1GTSeedModules == 1) {
230  l1GtUtils_->getL1GtRunCache(iEvent, iSetup, useL1EventSetup, useL1GtTriggerMenuLite);
231  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
233  l1Logical.logicalExpressionRunUpdate(iEvent.getRun(), iSetup, l1tname);
234  const std::vector<std::pair<std::string, int> >& errorCodes(l1Logical.errorCodes(iEvent));
235  auto resultInt = l1Logical.prescaleFactors();
236  result.clear();
237  for (const auto& entry : resultInt) {
238  result.push_back(entry);
239  }
240 
241  int l1error(l1Logical.isValid() ? 0 : 1);
242  for (auto const& errorCode : errorCodes) {
243  l1error += std::abs(errorCode.second);
244  }
245  if (l1error != 0) {
246  if (count_[3] < countMax) {
247  count_[3] += 1;
248  std::ostringstream message;
249  message << " Error in determining L1T prescales for HLT path: '" << trigger << "' with complex L1T seed: '"
250  << l1tname << "' using L1GtUtils: " << std::endl
251  << " isValid=" << l1Logical.isValid() << " l1tname/error/prescale " << errorCodes.size() << std::endl;
252  for (unsigned int i = 0; i < errorCodes.size(); ++i) {
253  message << " " << i << ":" << errorCodes[i].first << "/" << errorCodes[i].second << "/" << result[i].second;
254  }
255  message << ".";
256  edm::LogError("HLTPrescaleProvider") << message.str();
257  }
258  result.clear();
259  }
260  } else {
262  if (count_[4] < countMax) {
263  count_[4] += 1;
264  std::string dump("'" + hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second + "'");
265  for (unsigned int i = 1; i != nL1GTSeedModules; ++i) {
266  dump += " * '" + hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second + "'";
267  }
268  edm::LogError("HLTPrescaleProvider")
269  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1GTSeed modules, "
270  << nL1GTSeedModules << ", with L1 seeds: " << dump
271  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
272  }
273  result.clear();
274  }
275  } else if (l1tType == 2) {
277  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
278  if (nL1TSeedModules == 0) {
279  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
280  result.clear();
281  } else if (nL1TSeedModules == 1) {
282  // l1tGlobalUtil_->retrieveL1Event(iEvent,iSetup);
284  GlobalLogicParser l1tGlobalLogicParser = GlobalLogicParser(l1tname);
285  const std::vector<GlobalLogicParser::OperandToken> l1tSeeds = l1tGlobalLogicParser.expressionSeedsOperandList();
286  int l1error(0);
287  double l1tPrescale(-1);
288  for (auto const& i : l1tSeeds) {
289  const string& l1tSeed = i.tokenName;
290  if (!l1tGlobalUtil_->getPrescaleByName(l1tSeed, l1tPrescale)) {
291  l1error += 1;
292  }
293  result.push_back(std::pair<std::string, double>(l1tSeed, l1tPrescale));
294  }
295  if (l1error != 0) {
296  if (count_[3] < countMax) {
297  count_[3] += 1;
298  string l1name = l1tname;
299  std::ostringstream message;
300  message << " Error in determining L1T prescales for HLT path: '" << trigger << "' with complex L1T seed: '"
301  << l1tname << "' using L1TGlobalUtil: " << std::endl
302  << " isValid=" << l1tGlobalLogicParser.checkLogicalExpression(l1name) << " l1tname/error/prescale "
303  << l1tSeeds.size() << std::endl;
304  for (unsigned int i = 0; i < l1tSeeds.size(); ++i) {
305  const string& l1tSeed = l1tSeeds[i].tokenName;
306  message << " " << i << ":" << l1tSeed << "/" << l1tGlobalUtil_->getPrescaleByName(l1tSeed, l1tPrescale)
307  << "/" << result[i].second;
308  }
309  message << ".";
310  edm::LogError("HLTPrescaleProvider") << message.str();
311  }
312  result.clear();
313  }
314  } else {
316  if (count_[4] < countMax) {
317  count_[4] += 1;
319  for (unsigned int i = 1; i != nL1TSeedModules; ++i) {
320  dump += " * '" + hltConfigProvider_.hltL1TSeeds(trigger).at(i) + "'";
321  }
322  edm::LogError("HLTPrescaleProvider")
323  << " Error in determining L1T prescale for HLT path: '" << trigger << "' has multiple L1TSeed modules, "
324  << nL1TSeedModules << ", with L1T seeds: " << dump
325  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
326  }
327  result.clear();
328  }
329  } else {
330  if (count_[3] < countMax) {
331  count_[3] += 1;
332  edm::LogError("HLTPrescaleProvider") << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
333  }
334  result.clear();
335  }
336 
337  return result;
338 }
339 
341  return hltConfigProvider_.moduleType(hltConfigProvider_.moduleLabel(i, triggerResults.index(i))) == "HLTPrescaler";
342 }
343 
345  if (!l1GtUtils_) {
346  throw cms::Exception("Configuration") << "HLTPrescaleProvider::checkL1GtUtils(),\n"
347  "Attempt to use L1GtUtils object when none was constructed.\n"
348  "Possibly the proper era is not configured or\n"
349  "the module configuration does not use the era properly\n"
350  "or input is from mixed eras";
351  }
352 }
353 
355  if (!l1tGlobalUtil_) {
356  throw cms::Exception("Configuration") << "HLTPrescaleProvider:::checkL1TGlobalUtil(),\n"
357  "Attempt to use L1TGlobalUtil object when none was constructed.\n"
358  "Possibly the proper era is not configured or\n"
359  "the module configuration does not use the era properly\n"
360  "or input is from mixed eras";
361  }
362 }
363 
364 template <>
365 unsigned int HLTPrescaleProvider::prescaleValue<unsigned int>(const edm::Event& iEvent,
366  const edm::EventSetup& iSetup,
367  const std::string& trigger) {
368  const int set(prescaleSet(iEvent, iSetup));
369  return set < 0 ? 1 : hltConfigProvider_.prescaleValue<unsigned int>(static_cast<unsigned int>(set), trigger);
370 }
HLTPrescaleProvider::checkL1TGlobalUtil
void checkL1TGlobalUtil() const
Definition: HLTPrescaleProvider.cc:354
HLTPrescaleProvider::l1tGlobalUtil
l1t::L1TGlobalUtil const & l1tGlobalUtil() const
Definition: HLTPrescaleProvider.cc:55
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
HLTConfigProvider::moduleType
const std::string moduleType(const std::string &module) const
C++ class name of module.
Definition: HLTConfigProvider.h:104
edm::Run
Definition: Run.h:45
mps_splice.entry
entry
Definition: mps_splice.py:68
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:112
cms::cuda::assert
assert(be >=bs)
HLTPrescaleProvider::rejectedByHLTPrescaler
bool rejectedByHLTPrescaler(const edm::TriggerResults &triggerResults, unsigned int i) const
Definition: HLTPrescaleProvider.cc:340
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HLTConfigProvider::moduleLabel
const std::string & moduleLabel(unsigned int trigger, unsigned int module) const
Definition: HLTConfigProvider.h:88
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:119
HLTPrescaleProvider::l1GtUtils
L1GtUtils const & l1GtUtils() const
Definition: HLTPrescaleProvider.cc:50
HLTConfigProvider::hltL1TSeeds
const std::vector< std::vector< std::string > > & hltL1TSeeds() const
Definition: HLTConfigProvider.h:137
HLTConfigProvider::hltL1GTSeeds
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
Definition: HLTConfigProvider.h:123
l1t::L1TGlobalUtil
Definition: L1TGlobalUtil.h:44
HLTPrescaleProvider::l1tGlobalUtil_
std::unique_ptr< l1t::L1TGlobalUtil > l1tGlobalUtil_
Definition: HLTPrescaleProvider.h:111
L1GtUtils
Definition: L1GtUtils.h:66
useL1EventSetup
static const bool useL1EventSetup(true)
GlobalLogicParser
Definition: GlobalLogicParser.h:17
HLTPrescaleProvider::kL1PrescaleDenominator_
static constexpr int kL1PrescaleDenominator_
Definition: HLTPrescaleProvider.h:108
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLTConfigProvider::prescaleValue
T prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
Definition: HLTConfigProvider.h:188
HLTPrescaleProvider::inited_
bool inited_
Definition: HLTPrescaleProvider.h:113
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:110
HLTConfigProvider::processName
const std::string & processName() const
process name
Definition: HLTConfigProvider.h:54
edm::EventSetup
Definition: EventSetup.h:57
FractionalPrescale
boost::rational< int > FractionalPrescale
Definition: FractionalPrescale.h:5
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HLTPrescaleProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
Definition: HLTPrescaleProvider.cc:21
HLTPrescaleProvider::getL1PrescaleValueInDetail
std::vector< std::pair< std::string, double > > getL1PrescaleValueInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Definition: HLTPrescaleProvider.cc:217
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
L1GtUtils::AlgorithmTrigger
Definition: L1GtUtils.h:140
heppy_batch.val
val
Definition: heppy_batch.py:351
HLTConfigProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
Definition: HLTConfigProvider.cc:36
HLTPrescaleProvider::getL1PrescaleValue
double getL1PrescaleValue(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Definition: HLTPrescaleProvider.cc:118
Exception
Definition: hltDiff.cc:246
countMax
static const unsigned char countMax(2)
HLTPrescaleProvider.h
Exception.h
trigger
Definition: HLTPrescaleTableCond.h:8
HLTPrescaleProvider::checkL1GtUtils
void checkL1GtUtils() const
Definition: HLTPrescaleProvider.cc:344
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1GtUtils::LogicalExpressionL1Results
Definition: L1GtUtils.h:157
edm::Event
Definition: Event.h:73
HLTPrescaleProvider::hltConfigProvider_
HLTConfigProvider hltConfigProvider_
Definition: HLTPrescaleProvider.h:109
edm::TriggerResults
Definition: TriggerResults.h:35