CMS 3D CMS Logo

L1GtUtils.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iomanip>
20 #include <memory>
21 
22 // user include files
26 
28 
29 // constructor(s)
31  :
32 
33  m_l1GtStableParCacheID(0ULL),
34  m_numberAlgorithmTriggers(0),
35 
36  m_numberTechnicalTriggers(0),
37 
38  m_l1GtPfAlgoCacheID(0ULL),
39  m_l1GtPfTechCacheID(0ULL),
40 
41  m_l1GtTmAlgoCacheID(0ULL),
42  m_l1GtTmTechCacheID(0ULL),
43 
44  m_l1GtTmVetoAlgoCacheID(0ULL),
45  m_l1GtTmVetoTechCacheID(0ULL),
46 
47  m_l1GtMenuCacheID(0ULL),
48 
49  m_l1EventSetupValid(false),
50 
51  m_l1GtMenuLiteValid(false),
52 
53  m_beginRunCache(false),
54 
55  m_runIDCache(0),
56 
57  m_physicsDaqPartition(0),
58 
59  m_retrieveL1EventSetup(false),
60 
61  m_retrieveL1GtTriggerMenuLite(false)
62 
63 {
64  if (useEventSetupIn == UseEventSetupIn::Run || useEventSetupIn == UseEventSetupIn::RunAndEvent) {
80  }
81  if (useEventSetupIn == UseEventSetupIn::Event || useEventSetupIn == UseEventSetupIn::RunAndEvent) {
90  }
91 }
92 
96  UseEventSetupIn useEventSetupIn)
97  : L1GtUtils(pset, iC, useL1GtTriggerMenuLite, useEventSetupIn) {}
98 
102  UseEventSetupIn useEventSetupIn)
103  : L1GtUtils(iC, useEventSetupIn) {
104  m_l1GtUtilsHelper = std::make_unique<L1GtUtilsHelper>(pset, iC, useL1GtTriggerMenuLite);
105 }
106 
107 // destructor
109  // empty
110 }
111 
112 const std::string L1GtUtils::triggerCategory(const TriggerCategory& trigCategory) const {
113  switch (trigCategory) {
114  case AlgorithmTrigger: {
115  return "Algorithm Trigger";
116  } break;
117  case TechnicalTrigger: {
118  return "Technical Trigger";
119  }
120 
121  break;
122  default: {
123  return EmptyString;
124  } break;
125  }
126 }
127 
128 void L1GtUtils::retrieveL1EventSetup(const edm::EventSetup& evSetup, bool isRun) {
129  //
130  m_retrieveL1EventSetup = true;
131 
132  m_l1EventSetupValid = true;
133  // FIXME test for each record if valid; if not set m_l1EventSetupValid = false;
134 
135  // get / update the stable parameters from the EventSetup
136  // local cache & check on cacheIdentifier
137 
138  auto l1GtStableParametersRcd = evSetup.get<L1GtStableParametersRcd>();
139  unsigned long long l1GtStableParCacheID = l1GtStableParametersRcd.cacheIdentifier();
140 
141  if (m_l1GtStableParCacheID != l1GtStableParCacheID) {
142  if (isRun) {
143  m_l1GtStablePar = &l1GtStableParametersRcd.get(m_L1GtStableParametersRunToken);
144  } else {
145  m_l1GtStablePar = &l1GtStableParametersRcd.get(m_L1GtStableParametersEventToken);
146  }
147 
148  // number of algorithm triggers
150 
151  // number of technical triggers
153 
155 
156  m_triggerMaskSet.reserve(maxNumberTrigger);
157  m_prescaleFactorSet.reserve(maxNumberTrigger);
158 
159  //
160  m_l1GtStableParCacheID = l1GtStableParCacheID;
161  }
162 
163  // get / update the prescale factors from the EventSetup
164  // local cache & check on cacheIdentifier
165 
166  auto l1GtPrescaleFactorsAlgoTrigRcd = evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>();
167  unsigned long long l1GtPfAlgoCacheID = l1GtPrescaleFactorsAlgoTrigRcd.cacheIdentifier();
168 
169  if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
170  if (isRun) {
171  m_l1GtPfAlgo = &l1GtPrescaleFactorsAlgoTrigRcd.get(m_L1GtPrescaleFactorsAlgoTrigRunToken);
172  } else {
173  m_l1GtPfAlgo = &l1GtPrescaleFactorsAlgoTrigRcd.get(m_L1GtPrescaleFactorsAlgoTrigEventToken);
174  }
175 
177 
178  m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
179  }
180 
181  auto l1GtPrescaleFactorsTechTrigRcd = evSetup.get<L1GtPrescaleFactorsTechTrigRcd>();
182  unsigned long long l1GtPfTechCacheID = l1GtPrescaleFactorsTechTrigRcd.cacheIdentifier();
183 
184  if (m_l1GtPfTechCacheID != l1GtPfTechCacheID) {
185  if (isRun) {
186  m_l1GtPfTech = &l1GtPrescaleFactorsTechTrigRcd.get(m_L1GtPrescaleFactorsTechTrigRunToken);
187  } else {
188  m_l1GtPfTech = &l1GtPrescaleFactorsTechTrigRcd.get(m_L1GtPrescaleFactorsTechTrigEventToken);
189  }
190 
192 
193  m_l1GtPfTechCacheID = l1GtPfTechCacheID;
194  }
195 
196  // get / update the trigger mask from the EventSetup
197  // local cache & check on cacheIdentifier
198 
199  auto l1GtTriggerMaskAlgoTrigRcd = evSetup.get<L1GtTriggerMaskAlgoTrigRcd>();
200  unsigned long long l1GtTmAlgoCacheID = l1GtTriggerMaskAlgoTrigRcd.cacheIdentifier();
201 
202  if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
203  if (isRun) {
204  m_l1GtTmAlgo = &l1GtTriggerMaskAlgoTrigRcd.get(m_L1GtTriggerMaskAlgoTrigRunToken);
205  } else {
206  m_l1GtTmAlgo = &l1GtTriggerMaskAlgoTrigRcd.get(m_L1GtTriggerMaskAlgoTrigEventToken);
207  }
208 
210 
211  m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
212  }
213 
214  auto l1GtTriggerMaskTechTrigRcd = evSetup.get<L1GtTriggerMaskTechTrigRcd>();
215  unsigned long long l1GtTmTechCacheID = l1GtTriggerMaskTechTrigRcd.cacheIdentifier();
216 
217  if (m_l1GtTmTechCacheID != l1GtTmTechCacheID) {
218  if (isRun) {
219  m_l1GtTmTech = &l1GtTriggerMaskTechTrigRcd.get(m_L1GtTriggerMaskTechTrigRunToken);
220  } else {
221  m_l1GtTmTech = &l1GtTriggerMaskTechTrigRcd.get(m_L1GtTriggerMaskTechTrigEventToken);
222  }
223 
225 
226  m_l1GtTmTechCacheID = l1GtTmTechCacheID;
227  }
228 
229  auto l1GtTriggerMaskVetoAlgoTrigRcd = evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>();
230  unsigned long long l1GtTmVetoAlgoCacheID = l1GtTriggerMaskVetoAlgoTrigRcd.cacheIdentifier();
231 
232  if (m_l1GtTmVetoAlgoCacheID != l1GtTmVetoAlgoCacheID) {
233  if (isRun) {
234  m_l1GtTmVetoAlgo = &l1GtTriggerMaskVetoAlgoTrigRcd.get(m_L1GtTriggerMaskVetoAlgoTrigRunToken);
235  } else {
236  m_l1GtTmVetoAlgo = &l1GtTriggerMaskVetoAlgoTrigRcd.get(m_L1GtTriggerMaskVetoAlgoTrigEventToken);
237  }
238 
240 
241  m_l1GtTmVetoAlgoCacheID = l1GtTmVetoAlgoCacheID;
242  }
243 
244  auto l1GtTriggerMaskVetoTechTrigRcd = evSetup.get<L1GtTriggerMaskVetoTechTrigRcd>();
245  unsigned long long l1GtTmVetoTechCacheID = l1GtTriggerMaskVetoTechTrigRcd.cacheIdentifier();
246 
247  if (m_l1GtTmVetoTechCacheID != l1GtTmVetoTechCacheID) {
248  if (isRun) {
249  m_l1GtTmVetoTech = &l1GtTriggerMaskVetoTechTrigRcd.get(m_L1GtTriggerMaskVetoTechTrigRunToken);
250  } else {
251  m_l1GtTmVetoTech = &l1GtTriggerMaskVetoTechTrigRcd.get(m_L1GtTriggerMaskVetoTechTrigEventToken);
252  }
253 
255 
256  m_l1GtTmVetoTechCacheID = l1GtTmVetoTechCacheID;
257  }
258 
259  // get / update the trigger menu from the EventSetup
260  // local cache & check on cacheIdentifier
261 
262  auto l1GtTriggerMenuRcd = evSetup.get<L1GtTriggerMenuRcd>();
263  unsigned long long l1GtMenuCacheID = l1GtTriggerMenuRcd.cacheIdentifier();
264 
265  if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
266  if (isRun) {
267  m_l1GtMenu = &l1GtTriggerMenuRcd.get(m_L1GtTriggerMenuRunToken);
268  } else {
269  m_l1GtMenu = &l1GtTriggerMenuRcd.get(m_L1GtTriggerMenuEventToken);
270  }
271 
274 
276 
277  m_l1GtMenuCacheID = l1GtMenuCacheID;
278  }
279 }
280 
283 
284  // get L1GtTriggerMenuLite
286  if (!m_l1GtUtilsHelper->l1GtTriggerMenuLiteToken().isUninitialized()) {
287  iRun.getByToken(m_l1GtUtilsHelper->l1GtTriggerMenuLiteToken(), l1GtMenuLite);
288  }
289 
290  if (!l1GtMenuLite.isValid()) {
291  LogDebug("L1GtUtils") << "\nL1GtTriggerMenuLite with \n " << m_l1GtUtilsHelper->l1GtTriggerMenuLiteInputTag()
292  << "\nrequested, but not found in the run." << std::endl;
293 
294  m_l1GtMenuLiteValid = false;
295  } else {
296  m_l1GtMenuLite = l1GtMenuLite.product();
297  m_l1GtMenuLiteValid = true;
298 
299  LogDebug("L1GtUtils") << "\nL1GtTriggerMenuLite with \n " << m_l1GtUtilsHelper->l1GtTriggerMenuLiteInputTag()
300  << "\nretrieved for run " << iRun.runAuxiliary().run() << std::endl;
301 
305 
308 
311  }
312 }
313 
315  const edm::EventSetup& evSetup,
316  bool useL1EventSetup,
317  bool useL1GtTriggerMenuLite) {
318  // first call will turn this to true: the quantities which can be cached in
319  // beginRun will not be cached then in analyze
320  m_beginRunCache = true;
321 
322  // if requested, retrieve and cache L1 event setup
323  // keep the caching based on cacheIdentifier() for each record
324  if (useL1EventSetup) {
325  bool isRun = true;
326  retrieveL1EventSetup(evSetup, isRun);
327  }
328 
329  // cached per run
330 
331  // if requested, retrieve and cache the L1GtTriggerMenuLite
332  // L1GtTriggerMenuLite is defined per run and produced in prompt reco by L1Reco
333  // and put in the Run section
336  }
337 }
338 
340  const edm::EventSetup& evSetup,
341  const bool useL1EventSetup,
342  const bool useL1GtTriggerMenuLite) {
343  // if there was no retrieval and caching in beginRun, do it here
344  if (!m_beginRunCache) {
345  // if requested, retrieve and cache L1 event setup
346  // keep the caching based on cacheIdentifier() for each record
347  if (useL1EventSetup) {
348  bool isRun = false;
349  retrieveL1EventSetup(evSetup, isRun);
350  }
351  }
352 
353  // cached per run
354 
355  const edm::Run& iRun = iEvent.getRun();
356  edm::RunID runID = iRun.runAuxiliary().id();
357 
358  if (runID != m_runIDCache) {
359  if (!m_beginRunCache) {
360  // if requested, retrieve and cache the L1GtTriggerMenuLite
361  // L1GtTriggerMenuLite is defined per run and produced in prompt reco by L1Reco
362  // and put in the Run section
365  }
366  }
367  m_runIDCache = runID;
368  }
369 }
370 
371 const bool L1GtUtils::l1AlgoTechTrigBitNumber(const std::string& nameAlgoTechTrig,
372  TriggerCategory& trigCategory,
373  int& bitNumber) const {
374  trigCategory = AlgorithmTrigger;
375  bitNumber = -1;
376 
378  if (m_l1GtMenuLiteValid) {
379  // test if the name is an algorithm alias
381  itTrig != m_algorithmAliasMapLite->end();
382  itTrig++) {
383  if (itTrig->second == nameAlgoTechTrig) {
384  trigCategory = AlgorithmTrigger;
385  bitNumber = itTrig->first;
386 
387  return true;
388  }
389  }
390 
391  // test if the name is an algorithm name
392  for (L1GtTriggerMenuLite::CItL1Trig itTrig = m_algorithmMapLite->begin(); itTrig != m_algorithmMapLite->end();
393  itTrig++) {
394  if (itTrig->second == nameAlgoTechTrig) {
395  trigCategory = AlgorithmTrigger;
396  bitNumber = itTrig->first;
397 
398  return true;
399  }
400  }
401 
402  // test if the name is a technical trigger
404  itTrig != m_technicalTriggerMapLite->end();
405  itTrig++) {
406  if (itTrig->second == nameAlgoTechTrig) {
407  trigCategory = TechnicalTrigger;
408  bitNumber = itTrig->first;
409 
410  return true;
411  }
412  }
413 
414  } else if (m_retrieveL1EventSetup) {
415  // test if the name is an algorithm alias
416  CItAlgo itAlgo = m_algorithmAliasMap->find(nameAlgoTechTrig);
417  if (itAlgo != m_algorithmAliasMap->end()) {
418  trigCategory = AlgorithmTrigger;
419  bitNumber = (itAlgo->second).algoBitNumber();
420 
421  return true;
422  }
423 
424  // test if the name is an algorithm name
425  itAlgo = m_algorithmMap->find(nameAlgoTechTrig);
426  if (itAlgo != m_algorithmMap->end()) {
427  trigCategory = AlgorithmTrigger;
428  bitNumber = (itAlgo->second).algoBitNumber();
429 
430  return true;
431  }
432 
433  // test if the name is a technical trigger
434  itAlgo = m_technicalTriggerMap->find(nameAlgoTechTrig);
435  if (itAlgo != m_technicalTriggerMap->end()) {
436  trigCategory = TechnicalTrigger;
437  bitNumber = (itAlgo->second).algoBitNumber();
438 
439  return true;
440  }
441 
442  } else {
443  // only L1GtTriggerMenuLite requested, but it is not valid
444  return false;
445  }
446  } else if (m_retrieveL1EventSetup) {
447  // test if the name is an algorithm alias
448  CItAlgo itAlgo = m_algorithmAliasMap->find(nameAlgoTechTrig);
449  if (itAlgo != m_algorithmAliasMap->end()) {
450  trigCategory = AlgorithmTrigger;
451  bitNumber = (itAlgo->second).algoBitNumber();
452 
453  return true;
454  }
455 
456  // test if the name is an algorithm name
457  itAlgo = m_algorithmMap->find(nameAlgoTechTrig);
458  if (itAlgo != m_algorithmMap->end()) {
459  trigCategory = AlgorithmTrigger;
460  bitNumber = (itAlgo->second).algoBitNumber();
461 
462  return true;
463  }
464 
465  // test if the name is a technical trigger
466  itAlgo = m_technicalTriggerMap->find(nameAlgoTechTrig);
467  if (itAlgo != m_technicalTriggerMap->end()) {
468  trigCategory = TechnicalTrigger;
469  bitNumber = (itAlgo->second).algoBitNumber();
470 
471  return true;
472  }
473 
474  } else {
475  // L1 trigger configuration not retrieved
476  return false;
477  }
478 
479  // all possibilities already tested, so it should not arrive here
480  return false;
481 }
482 
484  const TriggerCategory& trigCategory,
485  std::string& aliasL1Trigger,
486  std::string& nameL1Trigger) const {
487  aliasL1Trigger.clear();
488  nameL1Trigger.clear();
489 
491  if (m_l1GtMenuLiteValid) {
492  // for an algorithm trigger
493  if (trigCategory == AlgorithmTrigger) {
494  bool trigAliasFound = false;
495  bool trigNameFound = false;
496 
498  itTrig != m_algorithmAliasMapLite->end();
499  itTrig++) {
500  if (static_cast<int>(itTrig->first) == bitNumber) {
501  aliasL1Trigger = itTrig->second;
502  trigAliasFound = true;
503  break;
504  }
505  }
506 
507  for (L1GtTriggerMenuLite::CItL1Trig itTrig = m_algorithmMapLite->begin(); itTrig != m_algorithmMapLite->end();
508  itTrig++) {
509  if (static_cast<int>(itTrig->first) == bitNumber) {
510  nameL1Trigger = itTrig->second;
511  trigNameFound = true;
512  break;
513  }
514  }
515 
516  if (!(trigAliasFound && trigNameFound)) {
517  return false;
518  }
519 
520  return true;
521 
522  } else if (trigCategory == TechnicalTrigger) {
523  // for a technical trigger
524 
525  bool trigNameFound = false;
526 
528  itTrig != m_technicalTriggerMapLite->end();
529  itTrig++) {
530  if (static_cast<int>(itTrig->first) == bitNumber) {
531  nameL1Trigger = itTrig->second;
532 
533  // technically, no alias is defined for technical triggers
534  // users use mainly aliases, so just return the name here
535  aliasL1Trigger = itTrig->second;
536 
537  trigNameFound = true;
538  break;
539  }
540  }
541 
542  if (!(trigNameFound)) {
543  return false;
544  }
545 
546  return true;
547 
548  } else {
549  // non-existing trigger category...
550  return false;
551  }
552 
553  } else if (m_retrieveL1EventSetup) {
554  // for an algorithm trigger
555  if (trigCategory == AlgorithmTrigger) {
556  bool trigAliasFound = false;
557 
558  for (CItAlgo itTrig = m_algorithmAliasMap->begin(); itTrig != m_algorithmAliasMap->end(); itTrig++) {
559  if ((itTrig->second).algoBitNumber() == bitNumber) {
560  aliasL1Trigger = itTrig->first;
561  // get the name here, avoiding a loop on m_algorithmMap
562  nameL1Trigger = (itTrig->second).algoName();
563 
564  trigAliasFound = true;
565  break;
566  }
567  }
568 
569  if (!(trigAliasFound)) {
570  return false;
571  }
572 
573  return true;
574 
575  } else if (trigCategory == TechnicalTrigger) {
576  // for a technical trigger
577 
578  bool trigNameFound = false;
579 
580  for (CItAlgo itTrig = m_technicalTriggerMap->begin(); itTrig != m_technicalTriggerMap->end(); itTrig++) {
581  if ((itTrig->second).algoBitNumber() == bitNumber) {
582  nameL1Trigger = (itTrig->second).algoName();
583  // technically, no alias is defined for technical triggers
584  // users use mainly aliases, so just return the name here
585  aliasL1Trigger = nameL1Trigger;
586 
587  trigNameFound = true;
588  break;
589  }
590  }
591 
592  if (!(trigNameFound)) {
593  return false;
594  }
595 
596  return true;
597 
598  } else {
599  // non-existing trigger category...
600  return false;
601  }
602 
603  } else {
604  // only L1GtTriggerMenuLite requested, but it is not valid
605  return false;
606  }
607  } else if (m_retrieveL1EventSetup) {
608  // for an algorithm trigger
609  if (trigCategory == AlgorithmTrigger) {
610  bool trigAliasFound = false;
611 
612  for (CItAlgo itTrig = m_algorithmAliasMap->begin(); itTrig != m_algorithmAliasMap->end(); itTrig++) {
613  if ((itTrig->second).algoBitNumber() == bitNumber) {
614  aliasL1Trigger = itTrig->first;
615  // get the name here, avoiding a loop on m_algorithmMap
616  nameL1Trigger = (itTrig->second).algoName();
617 
618  trigAliasFound = true;
619  break;
620  }
621  }
622 
623  if (!(trigAliasFound)) {
624  return false;
625  }
626 
627  return true;
628 
629  } else if (trigCategory == TechnicalTrigger) {
630  // for a technical trigger
631 
632  bool trigNameFound = false;
633 
634  for (CItAlgo itTrig = m_technicalTriggerMap->begin(); itTrig != m_technicalTriggerMap->end(); itTrig++) {
635  if ((itTrig->second).algoBitNumber() == bitNumber) {
636  nameL1Trigger = (itTrig->second).algoName();
637  // technically, no alias is defined for technical triggers
638  // users use mainly aliases, so just return the name here
639  aliasL1Trigger = itTrig->first;
640 
641  trigNameFound = true;
642  break;
643  }
644  }
645 
646  if (!(trigNameFound)) {
647  return false;
648  }
649 
650  return true;
651 
652  } else {
653  // non-existing trigger category...
654  return false;
655  }
656 
657  } else {
658  // L1 trigger configuration not retrieved
659  return false;
660  }
661 
662  // all possibilities already tested, so it should not arrive here
663  return false;
664 }
665 
667  const std::string& nameAlgoTechTrig,
668  bool& decisionBeforeMask,
669  bool& decisionAfterMask,
670  int& prescaleFactor,
671  int& triggerMask) const {
672  // initial values for returned results
673  decisionBeforeMask = false;
674  decisionAfterMask = false;
675  prescaleFactor = -1;
676  triggerMask = -1;
677 
678  // initialize error code and L1 configuration code
679  int iError = 0;
680  int l1ConfCode = 0;
681 
682  // check if L1 configuration is available
683 
684  if (!availableL1Configuration(iError, l1ConfCode)) {
685  return iError;
686  }
687 
688  // at this point, a valid L1 configuration is available, so the if/else if/else
689  // can be simplified
690 
691  // if the given name is not an algorithm trigger alias, an algorithm trigger name
692  // or a technical trigger in the current menu, return with error code 1
693 
694  TriggerCategory trigCategory = AlgorithmTrigger;
695  int bitNumber = -1;
696 
697  if (!l1AlgoTechTrigBitNumber(nameAlgoTechTrig, trigCategory, bitNumber)) {
698  iError = l1ConfCode + 1;
699 
701  if (m_l1GtMenuLiteValid) {
702  LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n " << nameAlgoTechTrig
703  << "\not found in the trigger menu \n " << m_l1GtMenuLite->gtTriggerMenuImplementation()
704  << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
705 
706  } else {
707  // fall through: L1 trigger configuration from event setup
708  LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n " << nameAlgoTechTrig
709  << "\not found in the trigger menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
710  << "\nretrieved from Event Setup" << std::endl;
711  }
712 
713  } else {
714  // L1 trigger configuration from event setup only
715  LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n " << nameAlgoTechTrig
716  << "\not found in the trigger menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
717  << "\nretrieved from Event Setup" << std::endl;
718  }
719 
720  return iError;
721  }
722 
723  // check here if a positive bit number was retrieved
724  // exit in case of negative bit number, before retrieving L1 GT products, saving time
725 
726  if (bitNumber < 0) {
727  iError = l1ConfCode + 2;
728 
730  if (m_l1GtMenuLiteValid) {
731  LogDebug("L1GtUtils") << "\nNegative bit number for " << triggerCategory(trigCategory) << "\n "
732  << nameAlgoTechTrig << "\nfrom menu \n " << m_l1GtMenuLite->gtTriggerMenuImplementation()
733  << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
734 
735  } else {
736  // fall through: L1 trigger configuration from event setup
737  LogDebug("L1GtUtils") << "\nNegative bit number for " << triggerCategory(trigCategory) << "\n "
738  << nameAlgoTechTrig << "\nfrom menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
739  << "\nretrieved from Event Setup" << std::endl;
740  }
741 
742  } else {
743  // L1 trigger configuration from event setup only
744  LogDebug("L1GtUtils") << "\nNegative bit number for " << triggerCategory(trigCategory) << "\n "
745  << nameAlgoTechTrig << "\nfrom menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
746  << "\nretrieved from Event Setup" << std::endl;
747  }
748 
749  return iError;
750  }
751 
752  // retrieve L1GlobalTriggerRecord and 1GlobalTriggerReadoutRecord product
753  // intermediate error code for the records
754  // the module returns an error code only if both the lite and the readout record are missing
755 
756  int iErrorRecord = 0;
757 
758  bool validRecord = false;
759  bool gtReadoutRecordValid = false;
760 
762  if (!m_l1GtUtilsHelper->l1GtRecordToken().isUninitialized()) {
763  iEvent.getByToken(m_l1GtUtilsHelper->l1GtRecordToken(), gtRecord);
764  }
765  if (gtRecord.isValid()) {
766  validRecord = true;
767 
768  } else {
769  iErrorRecord = 10;
770  LogDebug("L1GtUtils") << "\nL1GlobalTriggerRecord with \n " << m_l1GtUtilsHelper->l1GtRecordInputTag()
771  << "\nnot found in the event." << std::endl;
772  }
773 
775  if (!m_l1GtUtilsHelper->l1GtReadoutRecordToken().isUninitialized()) {
776  iEvent.getByToken(m_l1GtUtilsHelper->l1GtReadoutRecordToken(), gtReadoutRecord);
777  }
778  if (gtReadoutRecord.isValid()) {
779  gtReadoutRecordValid = true;
780  validRecord = true;
781 
782  } else {
783  iErrorRecord = iErrorRecord + 100;
784  LogDebug("L1GtUtils") << "\nL1GlobalTriggerReadoutRecord with \n "
785  << m_l1GtUtilsHelper->l1GtReadoutRecordInputTag() << "\nnot found in the event." << std::endl;
786  }
787 
788  // get the prescale factor index from
789  // L1GlobalTriggerReadoutRecord if valid
790  // if not, from L1GlobalTriggerRecord if valid
791  // else return an error
792 
793  int pfIndexTechTrig = -1;
794  int pfIndexAlgoTrig = -1;
795 
796  if (validRecord) {
797  if (gtReadoutRecordValid) {
798  pfIndexTechTrig = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexTech();
799  pfIndexAlgoTrig = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexAlgo();
800 
801  } else {
802  pfIndexTechTrig = static_cast<int>(gtRecord->gtPrescaleFactorIndexTech());
803  pfIndexAlgoTrig = static_cast<int>(gtRecord->gtPrescaleFactorIndexAlgo());
804  }
805 
806  } else {
807  LogDebug("L1GtUtils") << "\nError: "
808  << "\nNo valid L1GlobalTriggerRecord with \n " << m_l1GtUtilsHelper->l1GtRecordInputTag()
809  << "\nfound in the event."
810  << "\nNo valid L1GlobalTriggerReadoutRecord with \n "
811  << m_l1GtUtilsHelper->l1GtReadoutRecordInputTag() << "\nfound in the event." << std::endl;
812 
813  iError = l1ConfCode + iErrorRecord;
814  return iError;
815  }
816 
817  // depending on trigger category (algorithm trigger or technical trigger)
818  // get the correct quantities
819 
820  // number of sets of prescale factors
821  // index of prescale factor set retrieved from data
822  // pointer to the actual prescale factor set
823  // pointer to the set of trigger masks
824 
825  size_t pfSetsSize = 0;
826  int pfIndex = -1;
827  const std::vector<int>* prescaleFactorsSubset = nullptr;
828  const std::vector<unsigned int>* triggerMasksSet = nullptr;
829 
830  switch (trigCategory) {
831  case AlgorithmTrigger: {
833  if (m_l1GtMenuLiteValid) {
834  pfSetsSize = m_prescaleFactorsAlgoTrigLite->size();
835  triggerMasksSet = m_triggerMaskAlgoTrigLite;
836 
837  } else {
838  // fall through: L1 trigger configuration from event setup
839  pfSetsSize = m_prescaleFactorsAlgoTrig->size();
840  triggerMasksSet = m_triggerMaskAlgoTrig;
841  }
842 
843  } else {
844  // L1 trigger configuration from event setup only
845  pfSetsSize = m_prescaleFactorsAlgoTrig->size();
846  triggerMasksSet = m_triggerMaskAlgoTrig;
847  }
848 
849  pfIndex = pfIndexAlgoTrig;
850 
851  } break;
852  case TechnicalTrigger: {
854  if (m_l1GtMenuLiteValid) {
855  pfSetsSize = m_prescaleFactorsTechTrigLite->size();
856  triggerMasksSet = m_triggerMaskTechTrigLite;
857 
858  } else {
859  // fall through: L1 trigger configuration from event setup
860  pfSetsSize = m_prescaleFactorsTechTrig->size();
861  triggerMasksSet = m_triggerMaskTechTrig;
862  }
863 
864  } else {
865  // L1 trigger configuration from event setup only
866  pfSetsSize = m_prescaleFactorsTechTrig->size();
867  triggerMasksSet = m_triggerMaskTechTrig;
868  }
869 
870  pfIndex = pfIndexTechTrig;
871 
872  } break;
873  default: {
874  // should not be the case
875  iError = l1ConfCode + iErrorRecord + 3;
876  return iError;
877 
878  } break;
879  }
880 
881  // test prescale factor set index correctness, then retrieve the actual set of prescale factors
882 
883  if (pfIndex < 0) {
884  iError = l1ConfCode + iErrorRecord + 1000;
885  LogDebug("L1GtUtils") << "\nError: index of prescale factor set retrieved from the data \n"
886  << "less than zero."
887  << "\n Value of index retrieved from data = " << pfIndex << std::endl;
888 
889  return iError;
890 
891  } else if (pfIndex >= (static_cast<int>(pfSetsSize))) {
892  iError = l1ConfCode + iErrorRecord + 2000;
893  LogDebug("L1GtUtils") << "\nError: index of prescale factor set retrieved from the data \n"
894  << "greater than the size of the vector of prescale factor sets."
895  << "\n Value of index retrieved from data = " << pfIndex
896  << "\n Vector size = " << pfSetsSize << std::endl;
897 
898  return iError;
899 
900  } else {
901  switch (trigCategory) {
902  case AlgorithmTrigger: {
904  if (m_l1GtMenuLiteValid) {
905  prescaleFactorsSubset = &((*m_prescaleFactorsAlgoTrigLite).at(pfIndex));
906 
907  } else {
908  // fall through: L1 trigger configuration from event setup
909  prescaleFactorsSubset = &((*m_prescaleFactorsAlgoTrig).at(pfIndex));
910  }
911 
912  } else {
913  // L1 trigger configuration from event setup only
914  prescaleFactorsSubset = &((*m_prescaleFactorsAlgoTrig).at(pfIndex));
915  }
916 
917  } break;
918  case TechnicalTrigger: {
920  if (m_l1GtMenuLiteValid) {
921  prescaleFactorsSubset = &((*m_prescaleFactorsTechTrigLite).at(pfIndex));
922 
923  } else {
924  // fall through: L1 trigger configuration from event setup
925  prescaleFactorsSubset = &((*m_prescaleFactorsTechTrig).at(pfIndex));
926  }
927 
928  } else {
929  // L1 trigger configuration from event setup only
930  prescaleFactorsSubset = &((*m_prescaleFactorsTechTrig).at(pfIndex));
931  }
932 
933  } break;
934  default: {
935  // do nothing - it was tested before, with return
936 
937  } break;
938  }
939  }
940 
941  // algorithm result before applying the trigger masks
942  // the bit number is positive (tested previously)
943 
944  switch (trigCategory) {
945  case AlgorithmTrigger: {
946  if (gtReadoutRecordValid) {
947  const DecisionWord& decWord = gtReadoutRecord->decisionWord();
948  decisionBeforeMask = trigResult(decWord, bitNumber, nameAlgoTechTrig, trigCategory, iError);
949  if (iError) {
950  return (iError + l1ConfCode + iErrorRecord);
951  }
952 
953  } else {
954  const DecisionWord& decWord = gtRecord->decisionWordBeforeMask();
955  decisionBeforeMask = trigResult(decWord, bitNumber, nameAlgoTechTrig, trigCategory, iError);
956  if (iError) {
957  return (iError + l1ConfCode + iErrorRecord);
958  }
959  }
960 
961  } break;
962  case TechnicalTrigger: {
963  if (gtReadoutRecordValid) {
964  const DecisionWord& decWord = gtReadoutRecord->technicalTriggerWord();
965  decisionBeforeMask = trigResult(decWord, bitNumber, nameAlgoTechTrig, trigCategory, iError);
966  if (iError) {
967  return (iError + l1ConfCode + iErrorRecord);
968  }
969 
970  } else {
971  const DecisionWord& decWord = gtRecord->technicalTriggerWordBeforeMask();
972  decisionBeforeMask = trigResult(decWord, bitNumber, nameAlgoTechTrig, trigCategory, iError);
973  if (iError) {
974  return (iError + l1ConfCode + iErrorRecord);
975  }
976  }
977 
978  } break;
979  default: {
980  // do nothing - it was tested before, with return
981 
982  } break;
983  }
984 
985  // prescale factor
986  // the bit number is positive (tested previously)
987 
988  if (bitNumber < (static_cast<int>(prescaleFactorsSubset->size()))) {
989  prescaleFactor = (*prescaleFactorsSubset)[bitNumber];
990  } else {
991  iError = l1ConfCode + iErrorRecord + 4000;
992  LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber << " retrieved for " << triggerCategory(trigCategory)
993  << "\n " << nameAlgoTechTrig << "\ngreater than size of actual L1 GT prescale factor set: "
994  << prescaleFactorsSubset->size() << "\nError: Inconsistent L1 trigger configuration!"
995  << std::endl;
996 
997  return iError;
998  }
999 
1000  // trigger mask and trigger result after applying the trigger masks
1001 
1002  if (bitNumber < (static_cast<int>((*triggerMasksSet).size()))) {
1004  if (m_l1GtMenuLiteValid) {
1005  triggerMask = (*triggerMasksSet)[bitNumber];
1006 
1007  } else {
1008  // fall through: L1 trigger configuration from event setup
1009  // masks in event setup are for all partitions
1010  triggerMask = ((*triggerMasksSet)[bitNumber]) & (1 << m_physicsDaqPartition);
1011  }
1012 
1013  } else {
1014  // L1 trigger configuration from event setup only
1015  // masks in event setup are for all partitions
1016  triggerMask = ((*triggerMasksSet)[bitNumber]) & (1 << m_physicsDaqPartition);
1017  }
1018 
1019  } else {
1020  iError = l1ConfCode + iErrorRecord + 5000;
1021  LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber << " retrieved for " << triggerCategory(trigCategory)
1022  << "\n " << nameAlgoTechTrig
1023  << "\ngreater than size of L1 GT trigger mask set: " << (*triggerMasksSet).size()
1024  << "\nError: Inconsistent L1 trigger configuration!" << std::endl;
1025 
1026  return iError;
1027  }
1028 
1030 
1031  if (triggerMask) {
1032  decisionAfterMask = false;
1033  }
1034 
1035  return iError;
1036 }
1037 
1039  const std::string& nameAlgoTechTrig,
1040  int& errorCode) const {
1041  // initial values
1042  bool decisionBeforeMask = false;
1043  bool decisionAfterMask = false;
1044  int prescaleFactor = -1;
1045  int triggerMask = -1;
1046 
1048 
1049  return decisionBeforeMask;
1050 }
1051 
1053  const std::string& nameAlgoTechTrig,
1054  int& errorCode) const {
1055  // initial values
1056  bool decisionBeforeMask = false;
1057  bool decisionAfterMask = false;
1058  int prescaleFactor = -1;
1059  int triggerMask = -1;
1060 
1062 
1063  return decisionAfterMask;
1064 }
1065 
1066 const bool L1GtUtils::decision(const edm::Event& iEvent, const std::string& nameAlgoTechTrig, int& errorCode) const {
1067  // initial values
1068  bool decisionBeforeMask = false;
1069  bool decisionAfterMask = false;
1070  int prescaleFactor = -1;
1071  int triggerMask = -1;
1072 
1074 
1075  return decisionAfterMask;
1076 }
1077 
1079  const std::string& nameAlgoTechTrig,
1080  int& errorCode) const {
1081  // initial values
1082  bool decisionBeforeMask = false;
1083  bool decisionAfterMask = false;
1084  int prescaleFactor = -1;
1085  int triggerMask = -1;
1086 
1088 
1089  return prescaleFactor;
1090 }
1091 
1092 const int L1GtUtils::triggerMask(const edm::Event& iEvent, const std::string& nameAlgoTechTrig, int& errorCode) const {
1093  // initial values
1094  bool decisionBeforeMask = false;
1095  bool decisionAfterMask = false;
1096  int prescaleFactor = -1;
1097  int triggerMask = -1;
1098 
1100 
1101  return triggerMask;
1102 }
1103 
1104 const int L1GtUtils::triggerMask(const std::string& nameAlgoTechTrig, int& errorCode) const {
1105  // initial values for returned results
1106  int triggerMaskValue = -1;
1107 
1108  // initialize error code and L1 configuration code
1109  int iError = 0;
1110  int l1ConfCode = 0;
1111 
1112  // check if L1 configuration is available
1113 
1114  if (!availableL1Configuration(iError, l1ConfCode)) {
1115  errorCode = iError;
1116  return triggerMaskValue;
1117  }
1118 
1119  // at this point, a valid L1 configuration is available, so the if/else if/else
1120  // can be simplified
1121 
1122  // if the given name is not an algorithm trigger alias, an algorithm trigger name
1123  // or a technical trigger in the current menu, return with error code 1
1124 
1125  TriggerCategory trigCategory = AlgorithmTrigger;
1126  int bitNumber = -1;
1127 
1128  if (!l1AlgoTechTrigBitNumber(nameAlgoTechTrig, trigCategory, bitNumber)) {
1129  iError = l1ConfCode + 1;
1130 
1132  if (m_l1GtMenuLiteValid) {
1133  LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n " << nameAlgoTechTrig
1134  << "\not found in the trigger menu \n " << m_l1GtMenuLite->gtTriggerMenuImplementation()
1135  << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
1136 
1137  } else {
1138  // fall through: L1 trigger configuration from event setup
1139  LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n " << nameAlgoTechTrig
1140  << "\not found in the trigger menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
1141  << "\nretrieved from Event Setup" << std::endl;
1142  }
1143 
1144  } else {
1145  // L1 trigger configuration from event setup only
1146  LogDebug("L1GtUtils") << "\nAlgorithm/technical trigger \n " << nameAlgoTechTrig
1147  << "\not found in the trigger menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
1148  << "\nretrieved from Event Setup" << std::endl;
1149  }
1150 
1151  errorCode = iError;
1152  return triggerMaskValue;
1153  }
1154 
1155  // check here if a positive bit number was retrieved
1156  // exit in case of negative bit number, before retrieving L1 GT products, saving time
1157 
1158  if (bitNumber < 0) {
1159  iError = l1ConfCode + 2;
1160 
1162  if (m_l1GtMenuLiteValid) {
1163  LogDebug("L1GtUtils") << "\nNegative bit number for " << triggerCategory(trigCategory) << "\n "
1164  << nameAlgoTechTrig << "\nfrom menu \n " << m_l1GtMenuLite->gtTriggerMenuImplementation()
1165  << "\nretrieved from L1GtTriggerMenuLite" << std::endl;
1166 
1167  } else {
1168  // fall through: L1 trigger configuration from event setup
1169  LogDebug("L1GtUtils") << "\nNegative bit number for " << triggerCategory(trigCategory) << "\n "
1170  << nameAlgoTechTrig << "\nfrom menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
1171  << "\nretrieved from Event Setup" << std::endl;
1172  }
1173 
1174  } else {
1175  // L1 trigger configuration from event setup only
1176  LogDebug("L1GtUtils") << "\nNegative bit number for " << triggerCategory(trigCategory) << "\n "
1177  << nameAlgoTechTrig << "\nfrom menu \n " << m_l1GtMenu->gtTriggerMenuImplementation()
1178  << "\nretrieved from Event Setup" << std::endl;
1179  }
1180 
1181  errorCode = iError;
1182  return triggerMaskValue;
1183  }
1184 
1185  // depending on trigger category (algorithm trigger or technical trigger)
1186  // get the correct quantities
1187 
1188  // pointer to the set of trigger masks
1189 
1190  const std::vector<unsigned int>* triggerMasksSet = nullptr;
1191 
1192  switch (trigCategory) {
1193  case AlgorithmTrigger: {
1195  if (m_l1GtMenuLiteValid) {
1196  triggerMasksSet = m_triggerMaskAlgoTrigLite;
1197 
1198  } else {
1199  // fall through: L1 trigger configuration from event setup
1200  triggerMasksSet = m_triggerMaskAlgoTrig;
1201  }
1202 
1203  } else {
1204  // L1 trigger configuration from event setup only
1205  triggerMasksSet = m_triggerMaskAlgoTrig;
1206  }
1207 
1208  } break;
1209  case TechnicalTrigger: {
1211  if (m_l1GtMenuLiteValid) {
1212  triggerMasksSet = m_triggerMaskTechTrigLite;
1213 
1214  } else {
1215  // fall through: L1 trigger configuration from event setup
1216  triggerMasksSet = m_triggerMaskTechTrig;
1217  }
1218 
1219  } else {
1220  // L1 trigger configuration from event setup only
1221  triggerMasksSet = m_triggerMaskTechTrig;
1222  }
1223 
1224  } break;
1225  default: {
1226  // should not be the case
1227  iError = l1ConfCode + 3;
1228 
1229  errorCode = iError;
1230  return triggerMaskValue;
1231 
1232  } break;
1233  }
1234 
1235  // trigger mask
1236 
1237  if (bitNumber < (static_cast<int>((*triggerMasksSet).size()))) {
1239  if (m_l1GtMenuLiteValid) {
1240  triggerMaskValue = (*triggerMasksSet)[bitNumber];
1241 
1242  } else {
1243  // fall through: L1 trigger configuration from event setup
1244  // masks in event setup are for all partitions
1245  triggerMaskValue = ((*triggerMasksSet)[bitNumber]) & (1 << m_physicsDaqPartition);
1246  }
1247 
1248  } else {
1249  // L1 trigger configuration from event setup only
1250  // masks in event setup are for all partitions
1251  triggerMaskValue = ((*triggerMasksSet)[bitNumber]) & (1 << m_physicsDaqPartition);
1252  }
1253 
1254  } else {
1255  iError = l1ConfCode + 5000;
1256  LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber << " retrieved for " << triggerCategory(trigCategory)
1257  << "\n " << nameAlgoTechTrig
1258  << "\ngreater than size of L1 GT trigger mask set: " << (*triggerMasksSet).size()
1259  << "\nError: Inconsistent L1 trigger configuration!" << std::endl;
1260 
1261  errorCode = iError;
1262  return triggerMaskValue;
1263  }
1264 
1265  errorCode = iError;
1266  return triggerMaskValue;
1267 }
1268 
1270  const TriggerCategory& trigCategory,
1271  int& errorCode) const {
1272  // initialize the index to a negative value
1273  int pfIndex = -1;
1274 
1275  // initialize error code and L1 configuration code
1276  int iError = 0;
1277  int l1ConfCode = 0;
1278 
1279  // check if L1 configuration is available
1280 
1281  if (!availableL1Configuration(iError, l1ConfCode)) {
1282  errorCode = iError;
1283  return pfIndex;
1284  }
1285 
1286  // at this point, a valid L1 configuration is available, so the if/else if/else
1287  // can be simplified
1288 
1289  // retrieve L1GlobalTriggerRecord and 1GlobalTriggerReadoutRecord product
1290  // intermediate error code for the records
1291  // the module returns an error code only if both the lite and the readout record are missing
1292 
1293  int iErrorRecord = 0;
1294 
1295  bool validRecord = false;
1296  bool gtReadoutRecordValid = false;
1297 
1299  if (!m_l1GtUtilsHelper->l1GtRecordToken().isUninitialized()) {
1300  iEvent.getByToken(m_l1GtUtilsHelper->l1GtRecordToken(), gtRecord);
1301  }
1302  if (gtRecord.isValid()) {
1303  validRecord = true;
1304 
1305  } else {
1306  iErrorRecord = 10;
1307  LogDebug("L1GtUtils") << "\nL1GlobalTriggerRecord with \n " << m_l1GtUtilsHelper->l1GtRecordInputTag()
1308  << "\nnot found in the event." << std::endl;
1309  }
1310 
1312  if (!m_l1GtUtilsHelper->l1GtReadoutRecordToken().isUninitialized()) {
1313  iEvent.getByToken(m_l1GtUtilsHelper->l1GtReadoutRecordToken(), gtReadoutRecord);
1314  }
1315  if (gtReadoutRecord.isValid()) {
1316  gtReadoutRecordValid = true;
1317  validRecord = true;
1318 
1319  } else {
1320  iErrorRecord = iErrorRecord + 100;
1321  LogDebug("L1GtUtils") << "\nL1GlobalTriggerReadoutRecord with \n "
1322  << m_l1GtUtilsHelper->l1GtReadoutRecordInputTag() << "\nnot found in the event." << std::endl;
1323  }
1324 
1325  // get the prescale factor index from
1326  // L1GlobalTriggerReadoutRecord if valid
1327  // if not, from L1GlobalTriggerRecord if valid
1328  // else return an error
1329 
1330  int pfIndexTechTrig = -1;
1331  int pfIndexAlgoTrig = -1;
1332 
1333  if (validRecord) {
1334  if (gtReadoutRecordValid) {
1335  pfIndexTechTrig = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexTech();
1336  pfIndexAlgoTrig = (gtReadoutRecord->gtFdlWord()).gtPrescaleFactorIndexAlgo();
1337 
1338  } else {
1339  pfIndexTechTrig = static_cast<int>(gtRecord->gtPrescaleFactorIndexTech());
1340  pfIndexAlgoTrig = static_cast<int>(gtRecord->gtPrescaleFactorIndexAlgo());
1341  }
1342 
1343  } else {
1344  LogDebug("L1GtUtils") << "\nError: "
1345  << "\nNo valid L1GlobalTriggerRecord with \n " << m_l1GtUtilsHelper->l1GtRecordInputTag()
1346  << "\nfound in the event."
1347  << "\nNo valid L1GlobalTriggerReadoutRecord with \n "
1348  << m_l1GtUtilsHelper->l1GtReadoutRecordInputTag() << "\nfound in the event." << std::endl;
1349 
1350  iError = l1ConfCode + iErrorRecord;
1351 
1352  errorCode = iError;
1353  return pfIndex;
1354  }
1355 
1356  // depending on trigger category (algorithm trigger or technical trigger)
1357  // get the correct quantities
1358 
1359  // number of sets of prescale factors
1360  // index of prescale factor set retrieved from data
1361  // pointer to the actual prescale factor set
1362  // pointer to the set of trigger masks
1363 
1364  size_t pfSetsSize = 0;
1365 
1366  switch (trigCategory) {
1367  case AlgorithmTrigger: {
1369  if (m_l1GtMenuLiteValid) {
1370  pfSetsSize = m_prescaleFactorsAlgoTrigLite->size();
1371 
1372  } else {
1373  // fall through: L1 trigger configuration from event setup
1374  pfSetsSize = m_prescaleFactorsAlgoTrig->size();
1375  }
1376 
1377  } else {
1378  // L1 trigger configuration from event setup only
1379  pfSetsSize = m_prescaleFactorsAlgoTrig->size();
1380  }
1381 
1382  pfIndex = pfIndexAlgoTrig;
1383 
1384  } break;
1385  case TechnicalTrigger: {
1387  if (m_l1GtMenuLiteValid) {
1388  pfSetsSize = m_prescaleFactorsTechTrigLite->size();
1389 
1390  } else {
1391  // fall through: L1 trigger configuration from event setup
1392  pfSetsSize = m_prescaleFactorsTechTrig->size();
1393  }
1394 
1395  } else {
1396  // L1 trigger configuration from event setup only
1397  pfSetsSize = m_prescaleFactorsTechTrig->size();
1398  }
1399 
1400  pfIndex = pfIndexTechTrig;
1401 
1402  } break;
1403  default: {
1404  // should not be the case
1405  iError = l1ConfCode + iErrorRecord + 3;
1406  return iError;
1407 
1408  } break;
1409  }
1410 
1411  // test prescale factor set index correctness, then retrieve the actual set of prescale factors
1412 
1413  if (pfIndex < 0) {
1414  iError = l1ConfCode + iErrorRecord + 1000;
1415  LogDebug("L1GtUtils") << "\nError: index of prescale factor set retrieved from the data \n"
1416  << "less than zero."
1417  << "\n Value of index retrieved from data = " << pfIndex << std::endl;
1418 
1419  errorCode = iError;
1420  return pfIndex;
1421 
1422  } else if (pfIndex >= (static_cast<int>(pfSetsSize))) {
1423  iError = l1ConfCode + iErrorRecord + 2000;
1424  LogDebug("L1GtUtils") << "\nError: index of prescale factor set retrieved from the data \n"
1425  << "greater than the size of the vector of prescale factor sets."
1426  << "\n Value of index retrieved from data = " << pfIndex
1427  << "\n Vector size = " << pfSetsSize << std::endl;
1428 
1429  errorCode = iError;
1430  return pfIndex;
1431 
1432  } else {
1433  errorCode = iError;
1434  return pfIndex;
1435  }
1436 
1437  errorCode = iError;
1438  return pfIndex;
1439 }
1440 
1441 const std::vector<int>& L1GtUtils::prescaleFactorSet(const edm::Event& iEvent,
1442  const TriggerCategory& trigCategory,
1443  int& errorCode) {
1444  // clear the vector before filling it
1445  m_prescaleFactorSet.clear();
1446 
1447  // initialize error code
1448  int iError = 0;
1449 
1450  const int pfIndex = prescaleFactorSetIndex(iEvent, trigCategory, iError);
1451 
1452  if (iError == 0) {
1453  switch (trigCategory) {
1454  case AlgorithmTrigger: {
1456  if (m_l1GtMenuLiteValid) {
1457  m_prescaleFactorSet = (*m_prescaleFactorsAlgoTrigLite).at(pfIndex);
1458 
1459  } else {
1460  // fall through: L1 trigger configuration from event setup
1461  m_prescaleFactorSet = (*m_prescaleFactorsAlgoTrig).at(pfIndex);
1462  }
1463 
1464  } else {
1465  // L1 trigger configuration from event setup only
1466  m_prescaleFactorSet = (*m_prescaleFactorsAlgoTrig).at(pfIndex);
1467  }
1468 
1469  } break;
1470  case TechnicalTrigger: {
1472  if (m_l1GtMenuLiteValid) {
1473  m_prescaleFactorSet = (*m_prescaleFactorsTechTrigLite).at(pfIndex);
1474 
1475  } else {
1476  // fall through: L1 trigger configuration from event setup
1477  m_prescaleFactorSet = (*m_prescaleFactorsTechTrig).at(pfIndex);
1478  }
1479 
1480  } else {
1481  // L1 trigger configuration from event setup only
1482  m_prescaleFactorSet = (*m_prescaleFactorsTechTrig).at(pfIndex);
1483  }
1484 
1485  } break;
1486  default: {
1487  // do nothing - it was tested before, with return
1488 
1489  } break;
1490  }
1491  }
1492 
1493  errorCode = iError;
1494  return m_prescaleFactorSet;
1495 }
1496 
1497 const std::vector<unsigned int>& L1GtUtils::triggerMaskSet(const TriggerCategory& trigCategory, int& errorCode) {
1498  // clear the vector before filling it
1499  m_triggerMaskSet.clear();
1500 
1501  // initialize error code and L1 configuration code
1502  int iError = 0;
1503  int l1ConfCode = 0;
1504 
1505  // check if L1 configuration is available
1506 
1507  if (!availableL1Configuration(iError, l1ConfCode)) {
1508  errorCode = iError;
1509  return m_triggerMaskSet;
1510  }
1511 
1512  // at this point, a valid L1 configuration is available, so the if/else if/else
1513  // can be simplified
1514 
1515  // depending on trigger category (algorithm trigger or technical trigger)
1516  // get the correct quantities
1517 
1518  // pointer to the set of trigger masks
1519 
1520  switch (trigCategory) {
1521  case AlgorithmTrigger: {
1523  // L1GtTriggerMenuLite has masks for physics partition only
1524  // avoid copy to m_triggerMaskSet, return directly m_triggerMaskAlgoTrigLite
1525  if (m_l1GtMenuLiteValid) {
1526  errorCode = iError;
1527  return (*m_triggerMaskAlgoTrigLite);
1528 
1529  } else {
1530  // fall through: L1 trigger configuration from event setup
1531  for (unsigned i = 0; i < m_triggerMaskAlgoTrig->size(); i++) {
1533  }
1534  }
1535 
1536  } else {
1537  // L1 trigger configuration from event setup only
1538  for (unsigned i = 0; i < m_triggerMaskAlgoTrig->size(); i++) {
1540  }
1541  }
1542  } break;
1543  case TechnicalTrigger: {
1545  if (m_l1GtMenuLiteValid) {
1546  errorCode = iError;
1547  return (*m_triggerMaskTechTrigLite);
1548 
1549  } else {
1550  // fall through: L1 trigger configuration from event setup
1551  for (unsigned i = 0; i < m_triggerMaskTechTrig->size(); i++) {
1553  }
1554  }
1555 
1556  } else {
1557  // L1 trigger configuration from event setup only
1558  for (unsigned i = 0; i < m_triggerMaskTechTrig->size(); i++) {
1560  }
1561  }
1562  } break;
1563  default: {
1564  // should not be the case
1565  iError = l1ConfCode + 3;
1566 
1567  errorCode = iError;
1568  return m_triggerMaskSet;
1569 
1570  } break;
1571  }
1572 
1573  errorCode = iError;
1574  return m_triggerMaskSet;
1575 }
1576 
1579  if (m_l1GtMenuLiteValid) {
1581 
1582  } else if (m_retrieveL1EventSetup) {
1583  return m_l1GtMenu->gtTriggerMenuName();
1584 
1585  } else {
1586  // only L1GtTriggerMenuLite requested, but it is not valid
1587  return EmptyString;
1588  }
1589  } else if (m_retrieveL1EventSetup) {
1590  return m_l1GtMenu->gtTriggerMenuName();
1591 
1592  } else {
1593  // L1 trigger configuration not retrieved
1594  return EmptyString;
1595  }
1596 }
1597 
1600  if (m_l1GtMenuLiteValid) {
1602 
1603  } else if (m_retrieveL1EventSetup) {
1605 
1606  } else {
1607  // only L1GtTriggerMenuLite requested, but it is not valid
1608  return EmptyString;
1609  }
1610  } else if (m_retrieveL1EventSetup) {
1612 
1613  } else {
1614  // L1 trigger configuration not retrieved
1615  return EmptyString;
1616  }
1617 }
1618 
1620  // initialize error code and return value
1621  int iError = 0;
1622  int l1ConfCode = 0;
1623 
1624  // check if L1 configuration is available
1625 
1626  if (!availableL1Configuration(iError, l1ConfCode)) {
1627  errorCode = iError;
1628  return nullptr;
1629  }
1630 
1631  if (m_retrieveL1EventSetup) {
1632  errorCode = iError;
1633  return m_l1GtMenu;
1634  } else {
1635  iError = l1ConfCode;
1636 
1637  errorCode = iError;
1638  return nullptr;
1639  }
1640 
1641  errorCode = iError;
1642  return m_l1GtMenu;
1643 }
1644 
1646  // initialize error code and return value
1647  int iError = 0;
1648  int l1ConfCode = 0;
1649 
1650  // check if L1 configuration is available
1651 
1652  if (!availableL1Configuration(iError, l1ConfCode)) {
1653  errorCode = iError;
1654  return nullptr;
1655  }
1656 
1658  if (m_l1GtMenuLiteValid) {
1659  errorCode = iError;
1660  return m_l1GtMenuLite;
1661 
1662  } else {
1663  iError = l1ConfCode;
1664 
1665  errorCode = iError;
1666  return nullptr;
1667  }
1668  } else {
1669  iError = l1ConfCode;
1670 
1671  errorCode = iError;
1672  return nullptr;
1673  }
1674 
1675  errorCode = iError;
1676  return m_l1GtMenuLite;
1677 }
1678 
1679 const bool L1GtUtils::availableL1Configuration(int& errorCode, int& l1ConfCode) const {
1681  if (!m_retrieveL1EventSetup) {
1682  LogDebug("L1GtUtils") << "\nRetrieve L1 trigger configuration from L1GtTriggerMenuLite only.\n" << std::endl;
1683  l1ConfCode = 0;
1684  } else {
1685  LogDebug("L1GtUtils") << "\nFall through: retrieve L1 trigger configuration from L1GtTriggerMenuLite."
1686  << "\nIf L1GtTriggerMenuLite not valid, try to retrieve from event setup.\n"
1687  << std::endl;
1688  l1ConfCode = 100000;
1689  }
1690 
1691  if (m_l1GtMenuLiteValid) {
1692  LogDebug("L1GtUtils") << "\nRetrieve L1 trigger configuration from L1GtTriggerMenuLite, valid product.\n"
1693  << std::endl;
1694  l1ConfCode = l1ConfCode + 10000;
1695  errorCode = 0;
1696 
1697  return true;
1698 
1699  } else if (m_retrieveL1EventSetup) {
1700  if (m_l1EventSetupValid) {
1701  LogDebug("L1GtUtils") << "\nFall through: retrieve L1 trigger configuration from event setup."
1702  << "\nFirst option was L1GtTriggerMenuLite - but product is not valid.\n"
1703  << std::endl;
1704  l1ConfCode = l1ConfCode + 20000;
1705  errorCode = 0;
1706 
1707  return true;
1708 
1709  } else {
1710  LogDebug("L1GtUtils") << "\nFall through: L1GtTriggerMenuLite not valid, event setup not valid.\n" << std::endl;
1711  l1ConfCode = l1ConfCode + L1GtNotValidError;
1712  errorCode = l1ConfCode;
1713 
1714  return false;
1715  }
1716 
1717  } else {
1718  LogDebug("L1GtUtils") << "\nError: L1 trigger configuration requested from L1GtTriggerMenuLite only"
1719  << "\nbut L1GtTriggerMenuLite is not valid.\n"
1720  << std::endl;
1721  l1ConfCode = l1ConfCode + L1GtNotValidError;
1722  errorCode = l1ConfCode;
1723 
1724  return false;
1725  }
1726  } else if (m_retrieveL1EventSetup) {
1727  LogDebug("L1GtUtils") << "\nRetrieve L1 trigger configuration from event setup."
1728  << "\nL1GtTriggerMenuLite product was not requested.\n"
1729  << std::endl;
1730  l1ConfCode = 200000;
1731 
1732  if (m_l1EventSetupValid) {
1733  LogDebug("L1GtUtils") << "\nRetrieve L1 trigger configuration from event setup only."
1734  << "\nValid L1 trigger event setup.\n"
1735  << std::endl;
1736  l1ConfCode = l1ConfCode + 10000;
1737  errorCode = 0;
1738 
1739  return true;
1740 
1741  } else {
1742  LogDebug("L1GtUtils") << "\nRetrieve L1 trigger configuration from event setup only."
1743  << "\nNo valid L1 trigger event setup.\n"
1744  << std::endl;
1745  l1ConfCode = l1ConfCode + L1GtNotValidError;
1746  errorCode = l1ConfCode;
1747 
1748  return false;
1749  }
1750 
1751  } else {
1752  LogDebug("L1GtUtils") << "\nError: no L1 trigger configuration requested to be retrieved."
1753  << "\nMust call before getL1GtRunCache in beginRun and analyze.\n"
1754  << std::endl;
1755  l1ConfCode = 300000;
1756  errorCode = l1ConfCode;
1757 
1758  return false;
1759  }
1760 }
1761 
1762 // private methods
1763 
1764 const bool L1GtUtils::trigResult(const DecisionWord& decWord,
1765  const int bitNumber,
1766  const std::string& nameAlgoTechTrig,
1767  const TriggerCategory& trigCategory,
1768  int& errorCode) const {
1769  bool trigRes = false;
1770  errorCode = 0;
1771 
1772  if (bitNumber < (static_cast<int>(decWord.size()))) {
1773  trigRes = decWord[bitNumber];
1774  } else {
1775  errorCode = 3000;
1776  LogDebug("L1GtUtils") << "\nError: bit number " << bitNumber << " retrieved for " << triggerCategory(trigCategory)
1777  << "\n " << nameAlgoTechTrig
1778  << "\ngreater than size of L1 GT decision word: " << decWord.size()
1779  << "\nError: Inconsistent L1 trigger configuration!" << std::endl;
1780  }
1781 
1782  return trigRes;
1783 }
1784 
1786  :
1787 
1788  m_logicalExpression(expression),
1789 
1790  m_l1GtUtils(l1GtUtils),
1791 
1792  m_l1ConfCode(-1),
1793 
1794  m_validL1Configuration(false),
1795 
1796  m_validLogicalExpression(false),
1797 
1798  m_l1ResultsAlreadyCalled(false),
1799 
1800  m_expL1TriggersSize(0),
1801 
1802  m_expBitsTechTrigger(false) {
1803  initialize();
1804 }
1805 
1806 // destructor
1808  // empty
1809 }
1810 
1812  // get the vector of triggers corresponding to the logical expression
1813  // check also the logical expression - add/remove spaces if needed
1814 
1815  try {
1816  L1GtLogicParser m_l1AlgoLogicParser = L1GtLogicParser(m_logicalExpression);
1817 
1818  // list of L1 triggers from the logical expression
1819  m_expL1Triggers = m_l1AlgoLogicParser.operandTokenVector();
1820  m_expL1TriggersSize = m_expL1Triggers.size();
1821 
1822  m_validLogicalExpression = true;
1823 
1824  } catch (cms::Exception& ex) {
1825  m_validLogicalExpression = false;
1826 
1827  edm::LogWarning("L1GtUtils") << ex;
1828  edm::LogWarning("L1GtUtils") << ex.what();
1829  edm::LogWarning("L1GtUtils") << ex.explainSelf();
1830  }
1831 
1832  // try to convert the string representing each L1 trigger to bit number,
1833  // to check if the logical expression is constructed from bit numbers
1834  // trade-off: cache it here, irrespective of the expression
1835  // when the conversion fails (normally for the first seed,
1836  // if not expression of technical trigger bits), stop and
1837  // set m_expBitsTechTrigger to false
1838 
1839  m_expBitsTechTrigger = true;
1840 
1841  for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
1842  const std::string& bitString = (m_expL1Triggers[iTrig]).tokenName;
1843  std::istringstream bitStream(bitString);
1844  int bitInt;
1845 
1846  if ((bitStream >> bitInt).fail()) {
1847  m_expBitsTechTrigger = false;
1848 
1849  break;
1850  }
1851 
1852  (m_expL1Triggers[iTrig]).tokenNumber = bitInt;
1853  }
1854 
1855  // resize and fill
1856  m_decisionsBeforeMask.resize(m_expL1TriggersSize);
1857  m_decisionsAfterMask.resize(m_expL1TriggersSize);
1858  m_prescaleFactors.resize(m_expL1TriggersSize);
1859  m_triggerMasks.resize(m_expL1TriggersSize);
1860  m_errorCodes.resize(m_expL1TriggersSize);
1861  m_expTriggerCategory.resize(m_expL1TriggersSize);
1862  m_expTriggerInMenu.resize(m_expL1TriggersSize);
1863 
1864  LogDebug("L1GtUtils") << std::endl;
1865  LogTrace("L1GtUtils") << "\nLogical expression\n " << m_logicalExpression << "\n has " << m_expL1TriggersSize
1866  << " L1 triggers" << std::endl;
1867  for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
1868  const std::string& trigNameOrAlias = (m_expL1Triggers[iTrig]).tokenName;
1869  LogTrace("L1GtUtils") << " " << trigNameOrAlias << std::endl;
1870 
1871  (m_decisionsBeforeMask[iTrig]).first = trigNameOrAlias;
1872  (m_decisionsBeforeMask[iTrig]).second = false;
1873 
1874  (m_decisionsAfterMask[iTrig]).first = trigNameOrAlias;
1875  (m_decisionsAfterMask[iTrig]).second = false;
1876 
1877  (m_prescaleFactors[iTrig]).first = trigNameOrAlias;
1878  (m_prescaleFactors[iTrig]).second = -1;
1879 
1880  (m_triggerMasks[iTrig]).first = trigNameOrAlias;
1881  (m_triggerMasks[iTrig]).second = -1;
1882 
1883  (m_errorCodes[iTrig]).first = trigNameOrAlias;
1884  (m_errorCodes[iTrig]).second = -1;
1885 
1886  m_expTriggerCategory[iTrig] = L1GtUtils::AlgorithmTrigger;
1887 
1888  m_expTriggerInMenu[iTrig] = false;
1889  }
1890  LogTrace("L1GtUtils") << std::endl;
1891 
1892  return true;
1893 }
1894 
1896  const edm::EventSetup& evSetup,
1897  const std::string& logicExpression) {
1898  // initialize error code
1899  int errorCode = 0;
1900 
1901  // logical expression has changed - one must re-initialize all quantities related to the logical expression
1902  // and clear the vectors
1903 
1904  m_logicalExpression = logicExpression;
1905  m_validLogicalExpression = false;
1906 
1907  m_l1ResultsAlreadyCalled = false;
1908 
1909  m_expL1TriggersSize = 0;
1910  m_expBitsTechTrigger = false;
1911 
1912  //
1913  m_decisionsBeforeMask.clear();
1914  m_decisionsAfterMask.clear();
1915  m_prescaleFactors.clear();
1916  m_triggerMasks.clear();
1917  m_errorCodes.clear();
1918  m_expTriggerCategory.clear();
1919  m_expTriggerInMenu.clear();
1920 
1921  initialize();
1922 
1923  //
1924  errorCode = logicalExpressionRunUpdate(iRun, evSetup);
1925 
1926  return errorCode;
1927 }
1928 
1930  const edm::EventSetup& evSetup) {
1931  // check first that a valid L1 configuration was retrieved,
1932  // to prevent also calls before the L1 configuration retrieval
1933 
1934  // initialize error code and L1 configuration code
1935  int errorCode = 0;
1936  int l1ConfCode = 0;
1937 
1938  if (!(m_l1GtUtils.availableL1Configuration(errorCode, l1ConfCode))) {
1939  m_validL1Configuration = false;
1940  return errorCode;
1941  } else {
1942  m_validL1Configuration = true;
1943  m_l1ConfCode = l1ConfCode;
1944  }
1945 
1946  // check if the trigger (name of alias) from the logical expression are in the menu,
1947  // if names are used, set tokenNumber to the corresponding bit number
1948  // if technical trigger bits, set tokenName to the corresponding technical trigger name, if
1949  // a technical trigger exists on that bit
1950  // for each trigger, set also the trigger category
1951 
1952  // initialization
1954  int bitNumber = -1;
1955 
1956  for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
1957  trigCategory = L1GtUtils::AlgorithmTrigger;
1958  bitNumber = -1;
1959  const std::string& trigNameOrAlias = (m_expL1Triggers[iTrig]).tokenName;
1960 
1961  if (!m_expBitsTechTrigger) {
1962  const bool triggerInMenu = m_l1GtUtils.l1AlgoTechTrigBitNumber(trigNameOrAlias, trigCategory, bitNumber);
1963 
1964  (m_expL1Triggers[iTrig]).tokenNumber = bitNumber;
1965  m_expTriggerCategory[iTrig] = trigCategory;
1966  m_expTriggerInMenu[iTrig] = triggerInMenu;
1967 
1968  } else {
1969  std::string aliasL1Trigger;
1970  std::string nameL1Trigger;
1971 
1972  trigCategory = L1GtUtils::TechnicalTrigger;
1973  bitNumber = (m_expL1Triggers[iTrig]).tokenNumber;
1974 
1975  const bool triggerInMenu =
1976  m_l1GtUtils.l1TriggerNameFromBit(bitNumber, trigCategory, aliasL1Trigger, nameL1Trigger);
1977 
1978  if (!triggerInMenu) {
1979  aliasL1Trigger = "Technical_trigger_bit_" + (m_expL1Triggers[iTrig]).tokenName + "_empty";
1980  }
1981 
1982  (m_expL1Triggers[iTrig]).tokenName = aliasL1Trigger;
1983  m_expTriggerCategory[iTrig] = trigCategory;
1984  m_expTriggerInMenu[iTrig] = triggerInMenu;
1985 
1986  // put the names of the technical triggers in the returned quantities
1987 
1988  (m_decisionsBeforeMask[iTrig]).first = aliasL1Trigger;
1989  (m_decisionsAfterMask[iTrig]).first = aliasL1Trigger;
1990  (m_prescaleFactors[iTrig]).first = aliasL1Trigger;
1991  (m_triggerMasks[iTrig]).first = aliasL1Trigger;
1992  (m_errorCodes[iTrig]).first = aliasL1Trigger;
1993  }
1994  }
1995 
1996  return errorCode;
1997 }
1998 
1999 const std::vector<std::pair<std::string, bool> >& L1GtUtils::LogicalExpressionL1Results::decisionsBeforeMask() {
2000  // throw an exception if the result is not computed once per event - user usage error
2001  if (!m_l1ResultsAlreadyCalled) {
2002  throw cms::Exception("FailModule")
2003  << "\nUsage error: "
2004  << "\n Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
2005  << std::endl;
2006  }
2007 
2008  return m_decisionsBeforeMask;
2009 }
2010 
2011 const std::vector<std::pair<std::string, bool> >& L1GtUtils::LogicalExpressionL1Results::decisionsAfterMask() {
2012  // throw an exception if the result is not computed once per event - user usage error
2013  if (!m_l1ResultsAlreadyCalled) {
2014  throw cms::Exception("FailModule")
2015  << "\nUsage error: "
2016  << "\n Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
2017  << std::endl;
2018  }
2019 
2020  return m_decisionsAfterMask;
2021 }
2022 
2023 const std::vector<std::pair<std::string, int> >& L1GtUtils::LogicalExpressionL1Results::prescaleFactors() {
2024  // throw an exception if the result is not computed once per event - user usage error
2025  if (!m_l1ResultsAlreadyCalled) {
2026  throw cms::Exception("FailModule")
2027  << "\nUsage error: "
2028  << "\n Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
2029  << std::endl;
2030  }
2031 
2032  return m_prescaleFactors;
2033 }
2034 
2035 const std::vector<std::pair<std::string, int> >& L1GtUtils::LogicalExpressionL1Results::triggerMasks() {
2036  // throw an exception if the result is not computed once per event - user usage error
2037  if (!m_l1ResultsAlreadyCalled) {
2038  throw cms::Exception("FailModule")
2039  << "\nUsage error: "
2040  << "\n Method 'errorCodes' must be called in the event loop before attempting to use this method.\n"
2041  << std::endl;
2042  }
2043 
2044  return m_triggerMasks;
2045 }
2046 
2047 const std::vector<std::pair<std::string, int> >& L1GtUtils::LogicalExpressionL1Results::errorCodes(
2048  const edm::Event& iEvent) {
2049  m_l1ResultsAlreadyCalled = false;
2050 
2051  // if not a valid L1 configuration, reset all quantities and return
2052  if (!m_validL1Configuration) {
2053  reset(m_decisionsBeforeMask);
2054  reset(m_decisionsAfterMask);
2055  reset(m_prescaleFactors);
2056  reset(m_triggerMasks);
2057  reset(m_errorCodes);
2058 
2059  m_l1ResultsAlreadyCalled = true;
2060  return m_errorCodes;
2061  }
2062 
2063  l1Results(iEvent);
2064 
2065  m_l1ResultsAlreadyCalled = true;
2066 
2067  return m_errorCodes;
2068 }
2069 
2070 void L1GtUtils::LogicalExpressionL1Results::reset(const std::vector<std::pair<std::string, bool> >& _pairVector) const {
2071  std::vector<std::pair<std::string, bool> > pairVector = _pairVector;
2072  for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
2073  (pairVector[iTrig]).second = false;
2074  }
2075 }
2076 
2077 void L1GtUtils::LogicalExpressionL1Results::reset(const std::vector<std::pair<std::string, int> >& _pairVector) const {
2078  std::vector<std::pair<std::string, int> > pairVector = _pairVector;
2079  for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
2080  (pairVector[iTrig]).second = -1;
2081  }
2082 }
2083 
2085  // reset the vectors before filling them
2086  reset(m_decisionsBeforeMask);
2087  reset(m_decisionsAfterMask);
2088  reset(m_prescaleFactors);
2089  reset(m_triggerMasks);
2090  reset(m_errorCodes);
2091 
2092  // initialization of actual values for each trigger
2093  bool decisionBeforeMaskValue = false;
2094  bool decisionAfterMaskValue = false;
2095  int prescaleFactorValue = -1;
2096  int triggerMaskValue = -1;
2097  int errorCode = -1;
2098 
2099  LogDebug("L1GtUtils") << std::endl;
2100  LogTrace("L1GtUtils") << "\nLogical expression\n " << m_logicalExpression << std::endl;
2101 
2102  // for each trigger, if it is in the L1 menu, get the prescale factor and trigger mask
2103 
2104  for (size_t iTrig = 0; iTrig < m_expL1TriggersSize; ++iTrig) {
2105  const std::string& trigNameOrAlias = (m_expL1Triggers[iTrig]).tokenName;
2106 
2107  if (m_expTriggerInMenu[iTrig]) {
2108  errorCode = m_l1GtUtils.l1Results(iEvent,
2109  trigNameOrAlias,
2110  decisionBeforeMaskValue,
2111  decisionAfterMaskValue,
2112  prescaleFactorValue,
2113  triggerMaskValue);
2114 
2115  if (errorCode != 0) {
2116  // error while retrieving the results
2117  // for this trigger: set prescale factor to -1, trigger mask to -1
2118 
2119  decisionBeforeMaskValue = false;
2120  decisionAfterMaskValue = false;
2121  prescaleFactorValue = -1;
2122  triggerMaskValue = -1;
2123  }
2124 
2125  } else {
2126  // no trigger name or trigger alias in the menu, no bits:
2127  // for this trigger: set prescale factor to -1, set the error code
2128 
2129  decisionBeforeMaskValue = false;
2130  decisionAfterMaskValue = false;
2131  prescaleFactorValue = -1;
2132  triggerMaskValue = -1;
2133  errorCode = m_l1ConfCode + 1;
2134  }
2135 
2136  LogTrace("L1GtUtils") << "\n" << trigNameOrAlias << ":" << std::endl;
2137 
2138  (m_decisionsBeforeMask[iTrig]).second = decisionBeforeMaskValue;
2139  LogTrace("L1GtUtils") << " decision before mask = " << decisionBeforeMaskValue << std::endl;
2140 
2141  (m_decisionsAfterMask[iTrig]).second = decisionAfterMaskValue;
2142  LogTrace("L1GtUtils") << " decision after mask = " << decisionAfterMaskValue << std::endl;
2143 
2144  (m_prescaleFactors[iTrig]).second = prescaleFactorValue;
2145  LogTrace("L1GtUtils") << " prescale factor = " << prescaleFactorValue << std::endl;
2146 
2147  (m_triggerMasks[iTrig]).second = triggerMaskValue;
2148  LogTrace("L1GtUtils") << " trigger mask = " << triggerMaskValue << std::endl;
2149 
2150  (m_errorCodes[iTrig]).second = errorCode;
2151  LogTrace("L1GtUtils") << " error code = " << errorCode << std::endl;
2152  }
2153 
2154  LogDebug("L1GtUtils") << std::endl;
2155 }
2156 
2158 const int L1GtUtils::L1GtNotValidError = 99999;
const int prescaleFactorSetIndex(const edm::Event &iEvent, const TriggerCategory &trigCategory, int &errorCode) const
Definition: L1GtUtils.cc:1269
const AlgorithmMap & gtTechnicalTriggerMap() const
get / set the technical trigger map
bool m_retrieveL1GtTriggerMenuLite
Definition: L1GtUtils.h:471
edm::RunID m_runIDCache
run cache ID
Definition: L1GtUtils.h:460
const std::vector< unsigned int > & gtTriggerMaskTechTrig() const
get the trigger mask for technical triggers
const std::vector< unsigned int > & gtTriggerMask() const
get the trigger mask
static AlgebraicMatrix initialize()
const L1TriggerMap & gtAlgorithmMap() const
get / set the algorithm map (by name)
void l1Results(const edm::Event &iEvent)
Definition: L1GtUtils.cc:2084
void retrieveL1EventSetup(const edm::EventSetup &, bool isRun=true)
retrieve all the relevant L1 trigger event setup records and cache them to improve the speed ...
Definition: L1GtUtils.cc:128
LogicalExpressionL1Results(const std::string &, L1GtUtils &)
constructor(s)
Definition: L1GtUtils.cc:1785
std::vector< unsigned int > m_triggerMaskSet
Definition: L1GtUtils.h:466
unsigned long long m_l1GtMenuCacheID
Definition: L1GtUtils.h:431
const std::vector< unsigned int > * m_triggerMaskAlgoTrig
Definition: L1GtUtils.h:423
const int logicalExpressionRunUpdate(const edm::Run &, const edm::EventSetup &, const std::string &)
Definition: L1GtUtils.cc:1895
virtual std::string explainSelf() const
Definition: Exception.cc:108
const std::vector< std::vector< int > > & gtPrescaleFactorsAlgoTrig() const
get the prescale factors by reference / set the prescale factors
const L1GtTriggerMenuLite * ptrL1GtTriggerMenuLite(int &errorCode)
return a pointer to the L1GtTriggerMenuLite product
Definition: L1GtUtils.cc:1645
const std::vector< unsigned int > * m_triggerMaskTechTrig
Definition: L1GtUtils.h:424
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
const L1GtTriggerMask * m_l1GtTmVetoTech
Definition: L1GtUtils.h:420
const int prescaleFactor(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return prescale factor for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1078
T const * product() const
Definition: Handle.h:70
const bool l1AlgoTechTrigBitNumber(const std::string &nameAlgoTechTrig, TriggerCategory &trigCategory, int &bitNumber) const
Definition: L1GtUtils.cc:371
const std::vector< std::vector< int > > * m_prescaleFactorsAlgoTrigLite
Definition: L1GtUtils.h:451
edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd > m_L1GtTriggerMenuRunToken
Definition: L1GtUtils.h:483
virtual ~L1GtUtils()
destructor
Definition: L1GtUtils.cc:108
const L1GtTriggerMask * m_l1GtTmAlgo
trigger masks & veto masks
Definition: L1GtUtils.h:411
const AlgorithmMap * m_algorithmMap
Definition: L1GtUtils.h:433
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd > m_L1GtTriggerMaskAlgoTrigRunToken
Definition: L1GtUtils.h:479
const std::vector< std::pair< std::string, int > > & prescaleFactors()
Definition: L1GtUtils.cc:2023
const DecisionWord & decisionWord(int bxInEventValue) const
const std::vector< unsigned int > & gtTriggerMaskAlgoTrig() const
get the trigger mask for physics algorithms
const std::vector< std::vector< int > > * m_prescaleFactorsTechTrig
Definition: L1GtUtils.h:408
const L1TriggerMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
const L1GtStableParameters * m_l1GtStablePar
event setup cached stuff
Definition: L1GtUtils.h:391
unsigned long long m_l1GtPfAlgoCacheID
Definition: L1GtUtils.h:402
const std::vector< unsigned int > & triggerMaskSet(const TriggerCategory &trigCategory, int &errorCode)
Definition: L1GtUtils.cc:1497
UseEventSetupIn
Definition: L1GtUtils.h:76
const std::vector< std::pair< std::string, int > > & triggerMasks()
Definition: L1GtUtils.cc:2035
const std::vector< std::vector< int > > * m_prescaleFactorsAlgoTrig
Definition: L1GtUtils.h:407
const std::vector< std::vector< int > > & gtPrescaleFactors() const
get the prescale factors by reference
const L1GtFdlWord gtFdlWord(int bxInEventValue) const
get / set FDL word (record) in the GT readout record
const L1GtTriggerMenuLite::L1TriggerMap * m_algorithmAliasMapLite
Definition: L1GtUtils.h:445
unsigned long long cacheIdentifier() const
#define LogTrace(id)
RunNumber_t run() const
Definition: RunAuxiliary.h:31
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
const std::string & l1TriggerMenuImplementation() const
return the L1 trigger menu implementation
Definition: L1GtUtils.cc:1598
const std::string & gtTriggerMenuName() const
edm::ESGetToken< L1GtTriggerMenu, L1GtTriggerMenuRcd > m_L1GtTriggerMenuEventToken
Definition: L1GtUtils.h:493
U second(std::pair< T, U > const &p)
const L1GtTriggerMenuLite::L1TriggerMap * m_algorithmMapLite
Definition: L1GtUtils.h:444
unsigned long long m_l1GtTmVetoTechCacheID
Definition: L1GtUtils.h:421
RunAuxiliary const & runAuxiliary() const override
Definition: Run.h:62
const int l1Results(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, bool &decisionBeforeMask, bool &decisionAfterMask, int &prescaleFactor, int &triggerMask) const
Definition: L1GtUtils.cc:666
const std::vector< std::pair< std::string, bool > > & decisionsAfterMask()
Definition: L1GtUtils.cc:2011
const bool trigResult(const DecisionWord &decWord, const int bitNumber, const std::string &nameAlgoTechTrig, const TriggerCategory &trigCategory, int &errorCode) const
Definition: L1GtUtils.cc:1764
edm::ESGetToken< L1GtPrescaleFactors, L1GtPrescaleFactorsTechTrigRcd > m_L1GtPrescaleFactorsTechTrigRunToken
Definition: L1GtUtils.h:478
const std::vector< std::pair< std::string, bool > > & decisionsBeforeMask()
Definition: L1GtUtils.cc:1999
edm::ESGetToken< L1GtPrescaleFactors, L1GtPrescaleFactorsAlgoTrigRcd > m_L1GtPrescaleFactorsAlgoTrigRunToken
Definition: L1GtUtils.h:477
const bool l1TriggerNameFromBit(const int &bitNumber, const TriggerCategory &trigCategory, std::string &aliasL1Trigger, std::string &nameL1Trigger) const
Definition: L1GtUtils.cc:483
int iEvent
Definition: GenABIO.cc:224
const AlgorithmMap * m_algorithmAliasMap
Definition: L1GtUtils.h:434
std::vector< OperandToken > & operandTokenVector()
return the vector of operand tokens
unsigned long long m_l1GtTmTechCacheID
Definition: L1GtUtils.h:415
const std::vector< std::vector< int > > * m_prescaleFactorsTechTrigLite
Definition: L1GtUtils.h:452
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskTechTrigRcd > m_L1GtTriggerMaskTechTrigRunToken
Definition: L1GtUtils.h:480
const bool availableL1Configuration(int &errorCode, int &l1ConfCode) const
Definition: L1GtUtils.cc:1679
const L1GtTriggerMask * m_l1GtTmVetoAlgo
Definition: L1GtUtils.h:417
std::vector< bool > DecisionWord
typedefs
const unsigned int gtPrescaleFactorIndexTech() const
get/set index of the set of prescale factors
static const std::string EmptyString
Definition: L1GtUtils.h:373
edm::ESGetToken< L1GtStableParameters, L1GtStableParametersRcd > m_L1GtStableParametersEventToken
Definition: L1GtUtils.h:486
const L1GtPrescaleFactors * m_l1GtPfAlgo
prescale factors
Definition: L1GtUtils.h:401
unsigned long long m_l1GtTmAlgoCacheID
Definition: L1GtUtils.h:412
const std::string & l1TriggerMenu() const
return the L1 trigger menu name
Definition: L1GtUtils.cc:1577
void reset(const std::vector< std::pair< std::string, bool > > &) const
reset for each L1 trigger the value from pair.second
Definition: L1GtUtils.cc:2070
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd > m_L1GtTriggerMaskAlgoTrigEventToken
Definition: L1GtUtils.h:489
T get() const
Definition: EventSetup.h:82
unsigned int m_numberTechnicalTriggers
number of technical triggers
Definition: L1GtUtils.h:398
const TechnicalTriggerWord & technicalTriggerWord(int bxInEventValue) const
bool m_retrieveL1EventSetup
flags to check which method was used to retrieve L1 trigger configuration
Definition: L1GtUtils.h:470
edm::ESGetToken< L1GtPrescaleFactors, L1GtPrescaleFactorsTechTrigRcd > m_L1GtPrescaleFactorsTechTrigEventToken
Definition: L1GtUtils.h:488
const std::string & gtTriggerMenuImplementation() const
RunID const & id() const
Definition: RunAuxiliary.h:27
unsigned int m_physicsDaqPartition
index of physics DAQ partition
Definition: L1GtUtils.h:464
unsigned int m_numberAlgorithmTriggers
number of algorithm triggers
Definition: L1GtUtils.h:395
L1TriggerMap::const_iterator CItL1Trig
iterators through map containing the physics algorithms or the technical triggers ...
const std::vector< int > & prescaleFactorSet(const edm::Event &iEvent, const TriggerCategory &trigCategory, int &errorCode)
Definition: L1GtUtils.cc:1441
const L1GtTriggerMask * m_l1GtTmTech
Definition: L1GtUtils.h:414
const L1GtTriggerMenuLite * m_l1GtMenuLite
L1GtTriggerMenuLite cached stuff.
Definition: L1GtUtils.h:442
const std::vector< std::vector< int > > & gtPrescaleFactorsTechTrig() const
const std::string & gtTriggerMenuImplementation() const
const L1GtPrescaleFactors * m_l1GtPfTech
Definition: L1GtUtils.h:404
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskVetoTechTrigRcd > m_L1GtTriggerMaskVetoTechTrigEventToken
Definition: L1GtUtils.h:492
const AlgorithmMap * m_technicalTriggerMap
Definition: L1GtUtils.h:435
const std::string triggerCategory(const TriggerCategory &) const
public methods
Definition: L1GtUtils.cc:112
const std::vector< unsigned int > * m_triggerMaskVetoAlgoTrig
Definition: L1GtUtils.h:426
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:318
std::unique_ptr< L1GtUtilsHelper > m_l1GtUtilsHelper
Definition: L1GtUtils.h:473
const std::vector< unsigned int > * m_triggerMaskTechTrigLite
Definition: L1GtUtils.h:449
static const bool useL1GtTriggerMenuLite(true)
const int triggerMask(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return trigger mask for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1092
bool m_l1GtMenuLiteValid
Definition: L1GtUtils.h:454
bool isValid() const
Definition: HandleBase.h:70
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskTechTrigRcd > m_L1GtTriggerMaskTechTrigEventToken
Definition: L1GtUtils.h:490
L1GtUtils(edm::ParameterSet const &pset, edm::ConsumesCollector &&iC, bool useL1GtTriggerMenuLite, UseEventSetupIn use=UseEventSetupIn::Run)
Definition: L1GtUtils.cc:93
const std::vector< unsigned int > * m_triggerMaskAlgoTrigLite
Definition: L1GtUtils.h:448
bool m_beginRunCache
flag for call of getL1GtRunCache in beginRun
Definition: L1GtUtils.h:457
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1066
void getL1GtRunCache(const edm::Run &, const edm::EventSetup &, const bool, const bool)
get all the run-constant quantities for L1 trigger and cache them
Definition: L1GtUtils.cc:314
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskVetoAlgoTrigRcd > m_L1GtTriggerMaskVetoAlgoTrigEventToken
Definition: L1GtUtils.h:491
const L1GtTriggerMenu * m_l1GtMenu
Definition: L1GtUtils.h:430
const DecisionWord decisionWordBeforeMask() const
unsigned long long m_l1GtPfTechCacheID
Definition: L1GtUtils.h:405
const std::string & gtTriggerMenuName() const
const bool decisionAfterMask(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return decision after trigger mask for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1052
static const int L1GtNotValidError
Definition: L1GtUtils.h:374
const L1TriggerMap & gtTechnicalTriggerMap() const
get / set the technical trigger map
unsigned int gtNumberTechnicalTriggers() const
get / set the number of technical triggers
bool m_l1EventSetupValid
Definition: L1GtUtils.h:437
const unsigned int gtPrescaleFactorIndexAlgo() const
unsigned long long m_l1GtTmVetoAlgoCacheID
Definition: L1GtUtils.h:418
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskVetoAlgoTrigRcd > m_L1GtTriggerMaskVetoAlgoTrigRunToken
Definition: L1GtUtils.h:481
std::vector< int > m_prescaleFactorSet
Definition: L1GtUtils.h:467
Log< level::Warning, false > LogWarning
char const * what() const noexcept override
Definition: Exception.cc:103
const AlgorithmMap & gtAlgorithmMap() const
get / set the algorithm map (by name)
const TechnicalTriggerWord technicalTriggerWordBeforeMask() const
const L1GtTriggerMenu * ptrL1TriggerMenuEventSetup(int &errorCode)
return a pointer to the L1 trigger menu from event setup
Definition: L1GtUtils.cc:1619
edm::ESGetToken< L1GtStableParameters, L1GtStableParametersRcd > m_L1GtStableParametersRunToken
Definition: L1GtUtils.h:476
void reset(double vett[256])
Definition: TPedValues.cc:11
unsigned long long m_l1GtStableParCacheID
Definition: L1GtUtils.h:392
const bool decisionBeforeMask(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return decision before trigger mask for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1038
const L1GtTriggerMenuLite::L1TriggerMap * m_technicalTriggerMapLite
Definition: L1GtUtils.h:446
edm::ESGetToken< L1GtTriggerMask, L1GtTriggerMaskVetoTechTrigRcd > m_L1GtTriggerMaskVetoTechTrigRunToken
Definition: L1GtUtils.h:482
edm::ESGetToken< L1GtPrescaleFactors, L1GtPrescaleFactorsAlgoTrigRcd > m_L1GtPrescaleFactorsAlgoTrigEventToken
Definition: L1GtUtils.h:487
static const bool useL1EventSetup(true)
Definition: Run.h:45
const std::vector< unsigned int > * m_triggerMaskVetoTechTrig
Definition: L1GtUtils.h:427
unsigned int gtNumberPhysTriggers() const
get / set the number of physics trigger algorithms
#define LogDebug(id)
void retrieveL1GtTriggerMenuLite(const edm::Run &)
retrieve L1GtTriggerMenuLite (per run product) and cache it to improve the speed
Definition: L1GtUtils.cc:281
const std::vector< std::pair< std::string, int > > & errorCodes(const edm::Event &)
Definition: L1GtUtils.cc:2047