Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:05

0001 // L1TGlobalProducer.cc
0002 //author:   Brian Winer - Ohio State
0003 //          Vladimir Rekovic - extend for overlap removal
0004 //          Elisa Fontanesi - extended for three-body correlation conditions
0005 
0006 #include "L1Trigger/L1TGlobal/plugins/L1TGlobalProducer.h"
0007 
0008 // system include files
0009 #include <memory>
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <algorithm>
0013 
0014 #include "FWCore/Utilities/interface/typedefs.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 #include "DataFormats/Common/interface/RefProd.h"
0024 
0025 #include "L1Trigger/L1TGlobal/interface/GlobalParamsHelper.h"
0026 
0027 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0028 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0029 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
0030 
0031 #include "L1Trigger/L1TGlobal/interface/TriggerMenu.h"
0032 
0033 #include "TriggerMenuParser.h"
0034 
0035 using namespace l1t;
0036 
0037 void L1TGlobalProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0038   edm::ParameterSetDescription desc;
0039   // These parameters are part of the L1T/HLT interface, avoid changing if possible::
0040   desc.add<edm::InputTag>("MuonInputTag", edm::InputTag(""))
0041       ->setComment("InputTag for Global Muon Trigger (required parameter:  default value is invalid)");
0042   desc.add<edm::InputTag>("MuonShowerInputTag", edm::InputTag(""))
0043       ->setComment("InputTag for Global Muon Shower Trigger (required parameter:  default value is invalid)");
0044   desc.add<edm::InputTag>("EGammaInputTag", edm::InputTag(""))
0045       ->setComment("InputTag for Calo Trigger EGamma (required parameter:  default value is invalid)");
0046   desc.add<edm::InputTag>("TauInputTag", edm::InputTag(""))
0047       ->setComment("InputTag for Calo Trigger Tau (required parameter:  default value is invalid)");
0048   desc.add<edm::InputTag>("JetInputTag", edm::InputTag(""))
0049       ->setComment("InputTag for Calo Trigger Jet (required parameter:  default value is invalid)");
0050   desc.add<edm::InputTag>("EtSumInputTag", edm::InputTag(""))
0051       ->setComment("InputTag for Calo Trigger EtSum (required parameter:  default value is invalid)");
0052   desc.add<edm::InputTag>("EtSumZdcInputTag", edm::InputTag(""))
0053       ->setComment("InputTag for ZDC EtSums Plus and Minus (required parameter:  default value is invalid)");
0054   desc.add<edm::InputTag>("ExtInputTag", edm::InputTag(""))
0055       ->setComment("InputTag for external conditions (not required, but recommend to specify explicitly in config)");
0056   desc.add<edm::InputTag>("AlgoBlkInputTag", edm::InputTag("hltGtStage2Digis"))
0057       ->setComment(
0058           "InputTag for unpacked Algblk (required only if GetPrescaleColumnFromData orRequireMenuToMatchAlgoBlkInput "
0059           "set to true)");
0060   desc.add<bool>("GetPrescaleColumnFromData", false)
0061       ->setComment("Get prescale column from unpacked GlobalAlgBck. Otherwise use value specified in PrescaleSet");
0062   desc.add<bool>("AlgorithmTriggersUnprescaled", false)
0063       ->setComment("not required, but recommend to specify explicitly in config");
0064   desc.add<bool>("RequireMenuToMatchAlgoBlkInput", true)
0065       ->setComment(
0066           "This requires that the L1 menu record to match the menu used to produce the inputed L1 results, should be "
0067           "true when used by the HLT to produce the object map");
0068   desc.add<bool>("AlgorithmTriggersUnmasked", false)
0069       ->setComment("not required, but recommend to specify explicitly in config");
0070 
0071   //AXOl1TL model version:
0072   desc.add<std::string>("AXOL1TLModelVersion", "");
0073 
0074   // switch for muon showers in Run-3
0075   desc.add<bool>("useMuonShowers", false);
0076 
0077   // disables resetting the prescale counters each lumisection (needed for offline)
0078   //  originally, the L1T firmware applied the reset of prescale counters at the end of every LS;
0079   //  this reset was disabled in the L1T firmware starting from run-362658 (November 25th, 2022), see
0080   //  https://github.com/cms-sw/cmssw/pull/37395#issuecomment-1323437044
0081   desc.add<bool>("resetPSCountersEachLumiSec", false);
0082 
0083   // initialise prescale counters with a semi-random value in the range [0, prescale*10^precision - 1];
0084   // if false, the prescale counters are initialised to zero
0085   desc.add<bool>("semiRandomInitialPSCounters", false);
0086 
0087   // These parameters have well defined  default values and are not currently
0088   // part of the L1T/HLT interface.  They can be cleaned up or updated at will:
0089   desc.add<bool>("ProduceL1GtDaqRecord", true);
0090   desc.add<bool>("ProduceL1GtObjectMapRecord", true);
0091   desc.add<int>("EmulateBxInEvent", 1);
0092   desc.add<int>("L1DataBxInEvent", 5);
0093   desc.add<unsigned int>("AlternativeNrBxBoardDaq", 0);
0094   desc.add<int>("BstLengthBytes", -1);
0095   desc.add<unsigned int>("PrescaleSet", 1);
0096   desc.addUntracked<int>("Verbosity", 0);
0097   desc.addUntracked<bool>("PrintL1Menu", false);
0098   desc.add<std::string>("TriggerMenuLuminosity", "startup");
0099   descriptions.add("L1TGlobalProducer", desc);
0100 }
0101 
0102 // constructors
0103 
0104 L1TGlobalProducer::L1TGlobalProducer(const edm::ParameterSet& parSet)
0105     : m_muInputTag(parSet.getParameter<edm::InputTag>("MuonInputTag")),
0106       m_muShowerInputTag(parSet.getParameter<edm::InputTag>("MuonShowerInputTag")),
0107       m_egInputTag(parSet.getParameter<edm::InputTag>("EGammaInputTag")),
0108       m_tauInputTag(parSet.getParameter<edm::InputTag>("TauInputTag")),
0109       m_jetInputTag(parSet.getParameter<edm::InputTag>("JetInputTag")),
0110       m_sumInputTag(parSet.getParameter<edm::InputTag>("EtSumInputTag")),
0111       m_sumZdcInputTag(parSet.getParameter<edm::InputTag>("EtSumZdcInputTag")),
0112       m_extInputTag(parSet.getParameter<edm::InputTag>("ExtInputTag")),
0113 
0114       m_produceL1GtDaqRecord(parSet.getParameter<bool>("ProduceL1GtDaqRecord")),
0115       m_produceL1GtObjectMapRecord(parSet.getParameter<bool>("ProduceL1GtObjectMapRecord")),
0116 
0117       m_emulateBxInEvent(parSet.getParameter<int>("EmulateBxInEvent")),
0118       m_L1DataBxInEvent(parSet.getParameter<int>("L1DataBxInEvent")),
0119 
0120       m_alternativeNrBxBoardDaq(parSet.getParameter<unsigned int>("AlternativeNrBxBoardDaq")),
0121       m_psBstLengthBytes(parSet.getParameter<int>("BstLengthBytes")),
0122 
0123       m_prescaleSet(parSet.getParameter<unsigned int>("PrescaleSet")),
0124 
0125       m_algorithmTriggersUnprescaled(parSet.getParameter<bool>("AlgorithmTriggersUnprescaled")),
0126       m_algorithmTriggersUnmasked(parSet.getParameter<bool>("AlgorithmTriggersUnmasked")),
0127 
0128       m_verbosity(parSet.getUntrackedParameter<int>("Verbosity")),
0129       m_printL1Menu(parSet.getUntrackedParameter<bool>("PrintL1Menu")),
0130       m_isDebugEnabled(edm::isDebugEnabled()),
0131       m_getPrescaleColumnFromData(parSet.getParameter<bool>("GetPrescaleColumnFromData")),
0132       m_requireMenuToMatchAlgoBlkInput(parSet.getParameter<bool>("RequireMenuToMatchAlgoBlkInput")),
0133       m_algoblkInputTag(parSet.getParameter<edm::InputTag>("AlgoBlkInputTag")),
0134       m_resetPSCountersEachLumiSec(parSet.getParameter<bool>("resetPSCountersEachLumiSec")),
0135       m_semiRandomInitialPSCounters(parSet.getParameter<bool>("semiRandomInitialPSCounters")),
0136       m_AXOL1TLModelVersion(parSet.getParameter<std::string>("AXOL1TLModelVersion")),
0137       m_useMuonShowers(parSet.getParameter<bool>("useMuonShowers")) {
0138   m_egInputToken = consumes<BXVector<EGamma>>(m_egInputTag);
0139   m_tauInputToken = consumes<BXVector<Tau>>(m_tauInputTag);
0140   m_jetInputToken = consumes<BXVector<Jet>>(m_jetInputTag);
0141   m_sumInputToken = consumes<BXVector<EtSum>>(m_sumInputTag);
0142   m_sumZdcInputToken = consumes<BXVector<EtSum>>(m_sumZdcInputTag);
0143   m_muInputToken = consumes<BXVector<Muon>>(m_muInputTag);
0144   if (m_useMuonShowers)
0145     m_muShowerInputToken = consumes<BXVector<MuonShower>>(m_muShowerInputTag);
0146   m_extInputToken = consumes<BXVector<GlobalExtBlk>>(m_extInputTag);
0147   m_l1GtStableParToken = esConsumes<L1TGlobalParameters, L1TGlobalParametersRcd>();
0148   m_l1GtMenuToken = esConsumes<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>();
0149   if (!(m_algorithmTriggersUnprescaled && m_algorithmTriggersUnmasked)) {
0150     m_l1GtPrescaleVetosToken = esConsumes<L1TGlobalPrescalesVetosFract, L1TGlobalPrescalesVetosFractRcd>();
0151   }
0152   if (m_getPrescaleColumnFromData || m_requireMenuToMatchAlgoBlkInput) {
0153     m_algoblkInputToken = consumes<BXVector<GlobalAlgBlk>>(m_algoblkInputTag);
0154   }
0155 
0156   if (m_verbosity) {
0157     LogTrace("L1TGlobalProducer") << "\nInput tag for muon collection from uGMT:         " << m_muInputTag
0158                                   << "\nInput tag for calorimeter jet collections from Cal: " << m_jetInputTag
0159                                   << "\nInput tag for external conditions     :         " << m_extInputTag << std::endl;
0160 
0161     LogTrace("L1TGlobalProducer") << "\nProduce the L1 uGT DAQ readout record:          " << m_produceL1GtDaqRecord
0162                                   << "\nProduce the L1 uGT Object Map record:           "
0163                                   << m_produceL1GtObjectMapRecord << " \n"
0164                                   << "\nNumber of BxInEvent to be emulated:             " << m_emulateBxInEvent << " \n"
0165                                   << "\nAlternative for number of BX in GT DAQ record:   0x" << std::hex
0166                                   << m_alternativeNrBxBoardDaq << " \n"
0167                                   << "\nRun algorithm triggers unprescaled:             "
0168                                   << m_algorithmTriggersUnprescaled
0169                                   << "\nRun algorithm triggers unmasked (all enabled):  " << m_algorithmTriggersUnmasked
0170                                   << "\n"
0171                                   << std::endl;
0172   }
0173 
0174   if ((m_emulateBxInEvent > 0) && ((m_emulateBxInEvent % 2) == 0)) {
0175     m_emulateBxInEvent = m_emulateBxInEvent - 1;
0176 
0177     if (m_verbosity) {
0178       edm::LogWarning("L1TGlobalProducer")
0179           << "\nWARNING: Number of bunch crossing to be emulated rounded to: " << m_emulateBxInEvent
0180           << "\n         The number must be an odd number!\n"
0181           << std::endl;
0182     }
0183   }
0184 
0185   if ((m_L1DataBxInEvent > 0) && ((m_L1DataBxInEvent % 2) == 0)) {
0186     m_L1DataBxInEvent = m_L1DataBxInEvent - 1;
0187 
0188     if (m_verbosity) {
0189       edm::LogWarning("L1TGlobalProducer")
0190           << "\nWARNING: Number of bunch crossing for incoming L1 Data rounded to: " << m_L1DataBxInEvent
0191           << "\n         The number must be an odd number!\n"
0192           << std::endl;
0193     }
0194   } else if (m_L1DataBxInEvent < 0) {
0195     m_L1DataBxInEvent = 1;
0196 
0197     if (m_verbosity) {
0198       edm::LogWarning("L1TGlobalProducer")
0199           << "\nWARNING: Number of bunch crossing for incoming L1 Data was changed to: " << m_L1DataBxInEvent
0200           << "\n         The number must be an odd positive number!\n"
0201           << std::endl;
0202     }
0203   }
0204 
0205   // register products
0206   if (m_produceL1GtDaqRecord) {
0207     produces<GlobalAlgBlkBxCollection>();
0208     //blwEXT produces<GlobalExtBlkBxCollection>();
0209   }
0210 
0211   if (m_produceL1GtObjectMapRecord) {
0212     produces<GlobalObjectMapRecord>();
0213   }
0214 
0215   // create new uGt Board
0216   m_uGtBrd = std::make_unique<GlobalBoard>();
0217   m_uGtBrd->setVerbosity(m_verbosity);
0218   m_uGtBrd->setResetPSCountersEachLumiSec(m_resetPSCountersEachLumiSec);
0219   m_uGtBrd->setSemiRandomInitialPSCounters(m_semiRandomInitialPSCounters);
0220 
0221   // initialize cached IDs
0222 
0223   //
0224   m_l1GtParCacheID = 0ULL;
0225   m_l1GtMenuCacheID = 0ULL;
0226 
0227   m_numberPhysTriggers = 0;
0228   m_numberDaqPartitions = 0;
0229 
0230   m_nrL1Mu = 0;
0231   m_nrL1MuShower = 0;
0232   m_nrL1EG = 0;
0233   m_nrL1Tau = 0;
0234 
0235   m_nrL1Jet = 0;
0236 
0237   m_ifMuEtaNumberBits = 0;
0238   m_ifCaloEtaNumberBits = 0;
0239 
0240   //
0241   m_l1GtParCacheID = 0ULL;
0242 
0243   m_totalBxInEvent = 0;
0244 
0245   m_activeBoardsGtDaq = 0;
0246   m_bstLengthBytes = 0;
0247 
0248   //
0249   m_l1GtBMCacheID = 0ULL;
0250 
0251   //
0252   m_l1GtPfAlgoCacheID = 0ULL;
0253 
0254   m_l1GtTmAlgoCacheID = 0ULL;
0255 
0256   m_l1GtTmVetoAlgoCacheID = 0ULL;
0257 
0258   m_currentLumi = 0;
0259 
0260   // Set default, initial, dummy prescale factor table
0261   std::vector<std::vector<double>> temp_prescaleTable;
0262 
0263   temp_prescaleTable.push_back(std::vector<double>());
0264   m_initialPrescaleFactorsAlgoTrig = temp_prescaleTable;
0265 }
0266 
0267 // destructor
0268 L1TGlobalProducer::~L1TGlobalProducer() {}
0269 
0270 // member functions
0271 
0272 // method called to produce the data
0273 void L1TGlobalProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {
0274   // process event iEvent
0275   // get / update the stable parameters from the EventSetup
0276   // local cache & check on cacheIdentifier
0277 
0278   unsigned long long l1GtParCacheID = evSetup.get<L1TGlobalParametersRcd>().cacheIdentifier();
0279 
0280   if (m_l1GtParCacheID != l1GtParCacheID) {
0281     edm::ESHandle<L1TGlobalParameters> l1GtStablePar = evSetup.getHandle(m_l1GtStableParToken);
0282     m_l1GtStablePar = l1GtStablePar.product();
0283     const GlobalParamsHelper* data = GlobalParamsHelper::readFromEventSetup(m_l1GtStablePar);
0284 
0285     // number of bx
0286     m_totalBxInEvent = data->totalBxInEvent();
0287 
0288     // number of physics triggers
0289     m_numberPhysTriggers = data->numberPhysTriggers();
0290 
0291     // number of objects of each type
0292     m_nrL1Mu = data->numberL1Mu();
0293 
0294     // There should be at most 1 muon shower object per BX
0295     // This object contains information for the in-time
0296     // showers and out-of-time showers
0297     if (m_useMuonShowers)
0298       m_nrL1MuShower = 1;
0299 
0300     // EG
0301     m_nrL1EG = data->numberL1EG();
0302 
0303     // jets
0304     m_nrL1Jet = data->numberL1Jet();
0305 
0306     // taus
0307     m_nrL1Tau = data->numberL1Tau();
0308 
0309     if (m_L1DataBxInEvent < 1)
0310       m_L1DataBxInEvent = 1;
0311     int minL1DataBxInEvent = (m_L1DataBxInEvent + 1) / 2 - m_L1DataBxInEvent;
0312     int maxL1DataBxInEvent = (m_L1DataBxInEvent + 1) / 2 - 1;
0313 
0314     // Initialize Board
0315     m_uGtBrd->init(m_numberPhysTriggers,
0316                    m_nrL1Mu,
0317                    m_nrL1MuShower,
0318                    m_nrL1EG,
0319                    m_nrL1Tau,
0320                    m_nrL1Jet,
0321                    minL1DataBxInEvent,
0322                    maxL1DataBxInEvent);
0323 
0324     //
0325     m_l1GtParCacheID = l1GtParCacheID;
0326   }
0327 
0328   if (m_emulateBxInEvent < 0) {
0329     m_emulateBxInEvent = m_totalBxInEvent;
0330   }
0331 
0332   if (m_emulateBxInEvent < 1)
0333     m_emulateBxInEvent = 1;
0334   int minEmulBxInEvent = (m_emulateBxInEvent + 1) / 2 - m_emulateBxInEvent;
0335   int maxEmulBxInEvent = (m_emulateBxInEvent + 1) / 2 - 1;
0336 
0337   // get / update the trigger menu from the EventSetup
0338   // local cache & check on cacheIdentifier
0339   unsigned long long l1GtMenuCacheID = evSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
0340 
0341   if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
0342     const GlobalParamsHelper* data = GlobalParamsHelper::readFromEventSetup(m_l1GtStablePar);
0343 
0344     edm::ESHandle<L1TUtmTriggerMenu> l1GtMenu = evSetup.getHandle(m_l1GtMenuToken);
0345     const L1TUtmTriggerMenu* utml1GtMenu = l1GtMenu.product();
0346 
0347     if (m_requireMenuToMatchAlgoBlkInput) {
0348       edm::Handle<BXVector<GlobalAlgBlk>> m_uGtAlgBlk;
0349       iEvent.getByToken(m_algoblkInputToken, m_uGtAlgBlk);
0350       if (m_uGtAlgBlk->size() >= 1) {
0351         if ((*m_uGtAlgBlk)[0].getL1FirmwareUUID() != static_cast<int>(utml1GtMenu->getFirmwareUuidHashed())) {
0352           throw cms::Exception("ConditionsError")
0353               << " Error L1 menu loaded in via conditions does not match the L1 actually run "
0354               << (*m_uGtAlgBlk)[0].getL1FirmwareUUID() << " vs " << utml1GtMenu->getFirmwareUuidHashed()
0355               << ". This means that the mapping of the names to the bits may be incorrect. Please check the "
0356                  "L1TUtmTriggerMenuRcd record supplied. Unless you know what you are doing, do not simply disable this "
0357                  "check via the config as this a major error and the indication of something very wrong";
0358         }
0359       }
0360     }
0361 
0362     // Instantiate Parser
0363     TriggerMenuParser gtParser = TriggerMenuParser();
0364 
0365     gtParser.setGtNumberConditionChips(data->numberChips());
0366     gtParser.setGtPinsOnConditionChip(data->pinsOnChip());
0367     gtParser.setGtOrderConditionChip(data->orderOfChip());
0368     gtParser.setGtNumberPhysTriggers(data->numberPhysTriggers());
0369 
0370     //Parse menu into emulator classes
0371     gtParser.parseCondFormats(utml1GtMenu);
0372 
0373     // transfer the condition map and algorithm map from parser to L1uGtTriggerMenu
0374     m_l1GtMenu = std::make_unique<TriggerMenu>(gtParser.gtTriggerMenuName(),
0375                                                data->numberChips(),
0376                                                gtParser.vecMuonTemplate(),
0377                                                gtParser.vecMuonShowerTemplate(),
0378                                                gtParser.vecCaloTemplate(),
0379                                                gtParser.vecEnergySumTemplate(),
0380                                                gtParser.vecEnergySumZdcTemplate(),
0381                                                gtParser.vecAXOL1TLTemplate(),
0382                                                gtParser.vecExternalTemplate(),
0383                                                gtParser.vecCorrelationTemplate(),
0384                                                gtParser.vecCorrelationThreeBodyTemplate(),
0385                                                gtParser.vecCorrelationWithOverlapRemovalTemplate(),
0386                                                gtParser.corMuonTemplate(),
0387                                                gtParser.corCaloTemplate(),
0388                                                gtParser.corEnergySumTemplate());
0389 
0390     m_l1GtMenu->setGtTriggerMenuInterface(gtParser.gtTriggerMenuInterface());
0391     m_l1GtMenu->setGtTriggerMenuImplementation(gtParser.gtTriggerMenuImplementation());
0392     m_l1GtMenu->setGtScaleDbKey(gtParser.gtScaleDbKey());
0393     m_l1GtMenu->setGtScales(gtParser.gtScales());
0394     m_l1GtMenu->setGtTriggerMenuUUID(gtParser.gtTriggerMenuUUID());
0395 
0396     m_l1GtMenu->setGtAlgorithmMap(gtParser.gtAlgorithmMap());
0397     m_l1GtMenu->setGtAlgorithmAliasMap(gtParser.gtAlgorithmAliasMap());
0398 
0399     m_l1GtMenu->buildGtConditionMap();
0400 
0401     int printV = 2;
0402     if (m_printL1Menu)
0403       m_l1GtMenu->print(std::cout, printV);
0404 
0405     m_l1GtMenuCacheID = l1GtMenuCacheID;
0406   }
0407 
0408   // get / update the board maps from the EventSetup
0409   // local cache & check on cacheIdentifier
0410 
0411   /*   *** Drop L1GtBoard Maps for now
0412     typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
0413 
0414     unsigned long long l1GtBMCacheID = evSetup.get<L1GtBoardMapsRcd>().cacheIdentifier();
0415 */
0416 
0417   /*  ** Drop board mapping for now
0418     if (m_l1GtBMCacheID != l1GtBMCacheID) {
0419 
0420         edm::ESHandle< L1GtBoardMaps > l1GtBM;
0421         evSetup.get< L1GtBoardMapsRcd >().get( l1GtBM );
0422         m_l1GtBM = l1GtBM.product();
0423 
0424         m_l1GtBMCacheID = l1GtBMCacheID;
0425 
0426     }
0427    
0428 
0429     // TODO need changes in CondFormats to cache the maps
0430     const std::vector<L1GtBoard>& boardMaps = m_l1GtBM->gtBoardMaps();
0431 */
0432   // get / update the prescale factors from the EventSetup
0433   // local cache & check on cacheIdentifier
0434 
0435   // Only get event record if not unprescaled and not unmasked
0436   if (!(m_algorithmTriggersUnprescaled && m_algorithmTriggersUnmasked)) {
0437     unsigned long long l1GtPfAlgoCacheID = evSetup.get<L1TGlobalPrescalesVetosFractRcd>().cacheIdentifier();
0438 
0439     if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
0440       edm::ESHandle<L1TGlobalPrescalesVetosFract> l1GtPrescalesFractVetoes =
0441           evSetup.getHandle(m_l1GtPrescaleVetosToken);
0442       const L1TGlobalPrescalesVetosFract* es = l1GtPrescalesFractVetoes.product();
0443       m_l1GtPrescalesVetosFract = PrescalesVetosFractHelper::readFromEventSetup(es);
0444 
0445       m_prescaleFactorsAlgoTrig = &(m_l1GtPrescalesVetosFract->prescaleTable());
0446       m_triggerMaskVetoAlgoTrig = &(m_l1GtPrescalesVetosFract->triggerMaskVeto());
0447 
0448       m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
0449     }
0450     if (m_getPrescaleColumnFromData &&
0451         (m_currentLumi != iEvent.luminosityBlock())) {  // get prescale column from unpacked data
0452 
0453       m_currentLumi = iEvent.luminosityBlock();
0454 
0455       edm::Handle<BXVector<GlobalAlgBlk>> m_uGtAlgBlk;
0456       iEvent.getByToken(m_algoblkInputToken, m_uGtAlgBlk);
0457 
0458       if (m_uGtAlgBlk.isValid() && !m_uGtAlgBlk->isEmpty(0)) {
0459         std::vector<GlobalAlgBlk>::const_iterator algBlk = m_uGtAlgBlk->begin(0);
0460         m_prescaleSet = static_cast<unsigned int>(algBlk->getPreScColumn());
0461       } else {
0462         m_prescaleSet = 1;
0463         edm::LogError("L1TGlobalProduce")
0464             << "Could not find valid algo block. Setting prescale column to 1" << std::endl;
0465       }
0466     }
0467   } else {
0468     // Set Prescale factors to initial dummy values
0469     m_prescaleSet = 0;
0470     m_prescaleFactorsAlgoTrig = &m_initialPrescaleFactorsAlgoTrig;
0471     m_triggerMaskAlgoTrig = &m_initialTriggerMaskAlgoTrig;
0472     m_triggerMaskVetoAlgoTrig = &m_initialTriggerMaskVetoAlgoTrig;
0473   }
0474 
0475   // get / update the trigger mask from the EventSetup
0476   // local cache & check on cacheIdentifier
0477 
0478   /*  **** For now Leave out Masks  *****
0479     unsigned long long l1GtTmAlgoCacheID =
0480         evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();
0481 
0482     if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
0483 
0484         edm::ESHandle< L1GtTriggerMask > l1GtTmAlgo;
0485         evSetup.get< L1GtTriggerMaskAlgoTrigRcd >().get( l1GtTmAlgo );
0486         m_l1GtTmAlgo = l1GtTmAlgo.product();
0487 
0488         m_triggerMaskAlgoTrig = m_l1GtTmAlgo->gtTriggerMask();
0489 
0490         m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
0491 
0492     }
0493 */
0494 
0495   /*  **** For now Leave out Veto Masks  *****
0496     unsigned long long l1GtTmVetoAlgoCacheID =
0497         evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>().cacheIdentifier();
0498 
0499     if (m_l1GtTmVetoAlgoCacheID != l1GtTmVetoAlgoCacheID) {
0500 
0501         edm::ESHandle< L1GtTriggerMask > l1GtTmVetoAlgo;
0502         evSetup.get< L1GtTriggerMaskVetoAlgoTrigRcd >().get( l1GtTmVetoAlgo );
0503         m_l1GtTmVetoAlgo = l1GtTmVetoAlgo.product();
0504 
0505         m_triggerMaskVetoAlgoTrig = m_l1GtTmVetoAlgo->gtTriggerMask();
0506 
0507         m_l1GtTmVetoAlgoCacheID = l1GtTmVetoAlgoCacheID;
0508 
0509     }
0510 */
0511 
0512   // ******  Board Maps Need to be redone....hard code for now ******
0513   // loop over blocks in the GT DAQ record receiving data, count them if they are active
0514   // all board type are defined in CondFormats/L1TObjects/L1GtFwd
0515   // &
0516   // set the active flag for each object type received from GMT and GCT
0517   // all objects in the GT system
0518 
0519   //
0520   bool receiveMu = true;
0521   bool receiveMuShower = true;
0522   bool receiveEG = true;
0523   bool receiveTau = true;
0524   bool receiveJet = true;
0525   bool receiveEtSums = true;
0526   bool receiveEtSumsZdc = true;
0527   bool receiveExt = true;
0528 
0529   /*  *** Boards need redefining *****
0530     for (CItBoardMaps
0531             itBoard = boardMaps.begin();
0532             itBoard != boardMaps.end(); ++itBoard) {
0533 
0534         int iPosition = itBoard->gtPositionDaqRecord();
0535         if (iPosition > 0) {
0536 
0537             int iActiveBit = itBoard->gtBitDaqActiveBoards();
0538             bool activeBoard = false;
0539 
0540             if (iActiveBit >= 0) {
0541                 activeBoard = m_activeBoardsGtDaq & (1 << iActiveBit);
0542             }
0543 
0544             // use board if: in the record, but not in ActiveBoardsMap (iActiveBit < 0)
0545             //               in the record and ActiveBoardsMap, and active
0546             if ((iActiveBit < 0) || activeBoard) {
0547 
0548 // ******  Decide what board manipulation (if any we want here)
0549 
0550             }
0551         }
0552 
0553     }
0554 */
0555 
0556   // Produce the Output Records for the GT
0557   std::unique_ptr<GlobalAlgBlkBxCollection> uGtAlgRecord(
0558       new GlobalAlgBlkBxCollection(0, minEmulBxInEvent, maxEmulBxInEvent));
0559 
0560   // * produce the GlobalObjectMapRecord
0561   std::unique_ptr<GlobalObjectMapRecord> gtObjectMapRecord(new GlobalObjectMapRecord());
0562 
0563   // fill the boards not depending on the BxInEvent in the L1 GT DAQ record
0564   // GMT, PSB and FDL depend on BxInEvent
0565 
0566   // fill in emulator the same bunch crossing (12 bits - hardwired number of bits...)
0567   // and the same local bunch crossing for all boards
0568   int bxCross = iEvent.bunchCrossing();
0569   uint16_t bxCrossHw = 0;
0570   if ((bxCross & 0xFFF) == bxCross) {
0571     bxCrossHw = static_cast<uint16_t>(bxCross);
0572   } else {
0573     bxCrossHw = 0;  // Bx number too large, set to 0!
0574     if (m_verbosity) {
0575       LogDebug("L1TGlobalProducer") << "\nBunch cross number [hex] = " << std::hex << bxCross
0576                                     << "\n  larger than 12 bits. Set to 0! \n"
0577                                     << std::dec << std::endl;
0578     }
0579   }
0580   LogDebug("L1TGlobalProducer") << "HW BxCross " << bxCrossHw << std::endl;
0581 
0582   // get the prescale factor from the configuration for now
0583   // prescale set index counts from zero
0584   unsigned int pfAlgoSetIndex = m_prescaleSet;
0585 
0586   auto max = (*m_prescaleFactorsAlgoTrig).size() - 1;
0587   if (pfAlgoSetIndex > max) {
0588     edm::LogWarning("L1TGlobalProducer") << "\nAttempting to access prescale algo set: " << m_prescaleSet
0589                                          << "\nNumber of prescale algo sets available: 0.." << max
0590                                          << "Setting former to latter." << std::endl;
0591     pfAlgoSetIndex = max;
0592   }
0593 
0594   const std::vector<double>& prescaleFactorsAlgoTrig = (*m_prescaleFactorsAlgoTrig).at(pfAlgoSetIndex);
0595 
0596   // For now, set masks according to prescale value of 0
0597   m_initialTriggerMaskAlgoTrig.clear();
0598   for (unsigned int iAlgo = 0; iAlgo < prescaleFactorsAlgoTrig.size(); iAlgo++) {
0599     unsigned int value = prescaleFactorsAlgoTrig[iAlgo];
0600     value = (value == 0) ? 0 : 1;
0601     m_initialTriggerMaskAlgoTrig.push_back(value);
0602   }
0603   m_triggerMaskAlgoTrig = &m_initialTriggerMaskAlgoTrig;
0604 
0605   const std::vector<unsigned int>& triggerMaskAlgoTrig = *m_triggerMaskAlgoTrig;
0606   const std::vector<int>& triggerMaskVetoAlgoTrig = *m_triggerMaskVetoAlgoTrig;
0607 
0608   LogDebug("L1TGlobalProducer") << "Size of prescale vector" << prescaleFactorsAlgoTrig.size() << std::endl;
0609 
0610   // Load the calorimeter input onto the uGt Board
0611   m_uGtBrd->receiveCaloObjectData(iEvent,
0612                                   m_egInputToken,
0613                                   m_tauInputToken,
0614                                   m_jetInputToken,
0615                                   m_sumInputToken,
0616                                   m_sumZdcInputToken,
0617                                   receiveEG,
0618                                   m_nrL1EG,
0619                                   receiveTau,
0620                                   m_nrL1Tau,
0621                                   receiveJet,
0622                                   m_nrL1Jet,
0623                                   receiveEtSums,
0624                                   receiveEtSumsZdc);
0625 
0626   m_uGtBrd->receiveMuonObjectData(iEvent, m_muInputToken, receiveMu, m_nrL1Mu);
0627 
0628   //for getting model version to the condition class, later will come from the menu
0629   //used in runGTL
0630   m_uGtBrd->setAXOL1TLModelVersion(m_AXOL1TLModelVersion);
0631 
0632   if (m_useMuonShowers)
0633     m_uGtBrd->receiveMuonShowerObjectData(iEvent, m_muShowerInputToken, receiveMuShower, m_nrL1MuShower);
0634 
0635   m_uGtBrd->receiveExternalData(iEvent, m_extInputToken, receiveExt);
0636 
0637   // loop over BxInEvent
0638   for (int iBxInEvent = minEmulBxInEvent; iBxInEvent <= maxEmulBxInEvent; ++iBxInEvent) {
0639     //  run GTL
0640     LogDebug("L1TGlobalProducer") << "\nL1TGlobalProducer : running GTL  for bx = " << iBxInEvent << "\n" << std::endl;
0641 
0642     //  Run the GTL for this BX
0643     m_uGtBrd->runGTL(iEvent,
0644                      evSetup,
0645                      m_l1GtMenu.get(),
0646                      m_produceL1GtObjectMapRecord,
0647                      iBxInEvent,
0648                      gtObjectMapRecord,
0649                      m_numberPhysTriggers,
0650                      m_nrL1Mu,
0651                      m_nrL1MuShower,
0652                      m_nrL1EG,
0653                      m_nrL1Tau,
0654                      m_nrL1Jet);
0655 
0656     //  run FDL
0657     LogDebug("L1TGlobalProducer") << "\nL1TGlobalProducer : running FDL for bx = " << iBxInEvent << "\n" << std::endl;
0658 
0659     //  Run the Final Decision Logic for this BX
0660     m_uGtBrd->runFDL(iEvent,
0661                      iBxInEvent,
0662                      m_totalBxInEvent,
0663                      m_numberPhysTriggers,
0664                      prescaleFactorsAlgoTrig,
0665                      triggerMaskAlgoTrig,
0666                      triggerMaskVetoAlgoTrig,
0667                      m_algorithmTriggersUnprescaled,
0668                      m_algorithmTriggersUnmasked);
0669 
0670     // Fill in the DAQ Records
0671     if (m_produceL1GtDaqRecord) {
0672       m_uGtBrd->fillAlgRecord(iBxInEvent,
0673                               uGtAlgRecord,
0674                               m_prescaleSet,
0675                               m_l1GtMenu->gtTriggerMenuUUID(),
0676                               m_l1GtMenu->gtTriggerMenuImplementation());
0677     }
0678 
0679   }  //End Loop over Bx
0680 
0681   // Add explicit reset of Board
0682   m_uGtBrd->reset();
0683 
0684   if (m_verbosity && m_isDebugEnabled) {
0685     std::ostringstream myCoutStream;
0686 
0687     for (int bx = minEmulBxInEvent; bx < maxEmulBxInEvent; bx++) {
0688       /// Needs error checking that something exists at this bx.
0689       (uGtAlgRecord->at(bx, 0)).print(myCoutStream);
0690     }
0691 
0692     LogTrace("L1TGlobalProducer") << "\n The following L1 GT DAQ readout record was produced:\n"
0693                                   << myCoutStream.str() << "\n"
0694                                   << std::endl;
0695 
0696     myCoutStream.str("");
0697     myCoutStream.clear();
0698 
0699     const std::vector<GlobalObjectMap> objMapVec = gtObjectMapRecord->gtObjectMap();
0700 
0701     for (std::vector<GlobalObjectMap>::const_iterator it = objMapVec.begin(); it != objMapVec.end(); ++it) {
0702       (*it).print(myCoutStream);
0703     }
0704 
0705     LogDebug("L1TGlobalProducer") << "Test gtObjectMapRecord in L1TGlobalProducer \n\n"
0706                                   << myCoutStream.str() << "\n\n"
0707                                   << std::endl;
0708 
0709     myCoutStream.str("");
0710     myCoutStream.clear();
0711   }
0712 
0713   // register products
0714   if (m_produceL1GtDaqRecord) {
0715     iEvent.put(std::move(uGtAlgRecord));
0716   }
0717 
0718   if (m_produceL1GtObjectMapRecord) {
0719     iEvent.put(std::move(gtObjectMapRecord));
0720   }
0721 }
0722 
0723 //define this as a plug-in
0724 #include "FWCore/PluginManager/interface/ModuleDef.h"
0725 #include "FWCore/Framework/interface/MakerMacros.h"
0726 #include <cstdint>
0727 DEFINE_FWK_MODULE(L1TGlobalProducer);