Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-26 03:56:09

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