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