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