Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-16 02:43:00

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