Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:18

0001 /**
0002  * \class L1GlobalTrigger
0003  *
0004  *
0005  * Description: see header file.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna
0011  *
0012  *
0013  */
0014 
0015 // this class header
0016 #include "L1GlobalTrigger.h"
0017 
0018 // system include files
0019 #include <algorithm>
0020 #include <iomanip>
0021 #include <iostream>
0022 #include <memory>
0023 
0024 // user include files
0025 //#include
0026 //"DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
0027 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
0028 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
0029 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0030 
0031 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
0032 
0033 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
0034 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
0035 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0036 
0037 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEmCand.h"
0038 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEtSums.h"
0039 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctHFBitCounts.h"
0040 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctHFRingEtSums.h"
0041 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCand.h"
0042 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCounts.h"
0043 
0044 #include "FWCore/Framework/interface/ESHandle.h"
0045 #include "FWCore/Framework/interface/Event.h"
0046 #include "FWCore/Framework/interface/EventSetup.h"
0047 #include "FWCore/Framework/interface/MakerMacros.h"
0048 
0049 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerFDL.h"
0050 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerGTL.h"
0051 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerPSB.h"
0052 
0053 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeExtWord.h"
0054 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h"
0055 #include "DataFormats/L1GlobalTrigger/interface/L1TcsWord.h"
0056 
0057 #include "DataFormats/Common/interface/RefProd.h"
0058 #include "FWCore/Utilities/interface/InputTag.h"
0059 
0060 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0061 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0062 #include <cstdint>
0063 
0064 // constructors
0065 
0066 L1GlobalTrigger::L1GlobalTrigger(const edm::ParameterSet &parSet)
0067     : m_muGmtInputTag(parSet.getParameter<edm::InputTag>("GmtInputTag")),
0068       m_caloGctInputTag(parSet.getParameter<edm::InputTag>("GctInputTag")),
0069       m_castorInputTag(parSet.getParameter<edm::InputTag>("CastorInputTag")),
0070       m_technicalTriggersInputTags(parSet.getParameter<std::vector<edm::InputTag>>("TechnicalTriggersInputTags")),
0071       m_produceL1GtDaqRecord(parSet.getParameter<bool>("ProduceL1GtDaqRecord")),
0072       m_produceL1GtEvmRecord(parSet.getParameter<bool>("ProduceL1GtEvmRecord")),
0073       m_produceL1GtObjectMapRecord(parSet.getParameter<bool>("ProduceL1GtObjectMapRecord")),
0074       m_writePsbL1GtDaqRecord(parSet.getParameter<bool>("WritePsbL1GtDaqRecord")),
0075       m_readTechnicalTriggerRecords(parSet.getParameter<bool>("ReadTechnicalTriggerRecords")),
0076       m_emulateBxInEvent(parSet.getParameter<int>("EmulateBxInEvent")),
0077       m_recordLength(parSet.getParameter<std::vector<int>>("RecordLength")),
0078       m_alternativeNrBxBoardDaq(parSet.getParameter<unsigned int>("AlternativeNrBxBoardDaq")),
0079       m_alternativeNrBxBoardEvm(parSet.getParameter<unsigned int>("AlternativeNrBxBoardEvm")),
0080       m_psBstLengthBytes(parSet.getParameter<int>("BstLengthBytes")),
0081       m_algorithmTriggersUnprescaled(parSet.getParameter<bool>("AlgorithmTriggersUnprescaled")),
0082       m_algorithmTriggersUnmasked(parSet.getParameter<bool>("AlgorithmTriggersUnmasked")),
0083       m_technicalTriggersUnprescaled(parSet.getParameter<bool>("TechnicalTriggersUnprescaled")),
0084       m_technicalTriggersUnmasked(parSet.getParameter<bool>("TechnicalTriggersUnmasked")),
0085       m_technicalTriggersVetoUnmasked(parSet.getParameter<bool>("TechnicalTriggersVetoUnmasked")),
0086       m_verbosity(parSet.getUntrackedParameter<int>("Verbosity", 0)),
0087       m_isDebugEnabled(edm::isDebugEnabled()),
0088       m_l1GtStableParToken(esConsumes<L1GtStableParameters, L1GtStableParametersRcd>()),
0089       m_l1GtParToken(esConsumes<L1GtParameters, L1GtParametersRcd>()),
0090       m_l1GtBMToken(esConsumes<L1GtBoardMaps, L1GtBoardMapsRcd>()),
0091       m_l1GtPfAlgoToken(esConsumes<L1GtPrescaleFactors, L1GtPrescaleFactorsAlgoTrigRcd>()),
0092       m_l1GtPfTechToken(esConsumes<L1GtPrescaleFactors, L1GtPrescaleFactorsTechTrigRcd>()),
0093       m_l1GtTmAlgoToken(esConsumes<L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd>()),
0094       m_l1GtTmTechToken(esConsumes<L1GtTriggerMask, L1GtTriggerMaskTechTrigRcd>()),
0095       m_l1GtTmVetoAlgoToken(esConsumes<L1GtTriggerMask, L1GtTriggerMaskVetoAlgoTrigRcd>()),
0096       m_l1GtTmVetoTechToken(esConsumes<L1GtTriggerMask, L1GtTriggerMaskVetoTechTrigRcd>()) {
0097   if (m_verbosity) {
0098     LogDebug("L1GlobalTrigger") << std::endl;
0099 
0100     LogTrace("L1GlobalTrigger") << "\nInput tag for muon collection from GMT:         " << m_muGmtInputTag
0101                                 << "\nInput tag for calorimeter collections from GCT: " << m_caloGctInputTag
0102                                 << "\nInput tag for CASTOR record:                    " << m_castorInputTag
0103                                 << "\nInput tag for technical triggers:               " << std::endl;
0104 
0105     // loop over all producers of technical trigger records
0106     for (std::vector<edm::InputTag>::const_iterator it = m_technicalTriggersInputTags.begin();
0107          it != m_technicalTriggersInputTags.end();
0108          it++) {
0109       LogTrace("L1GlobalTrigger") << "\n  " << (*it) << std::endl;
0110     }
0111 
0112     LogTrace("L1GlobalTrigger")
0113         << "\nProduce the L1 GT DAQ readout record:           " << m_produceL1GtDaqRecord
0114         << "\nProduce the L1 GT EVM readout record:           " << m_produceL1GtEvmRecord
0115         << "\nProduce the L1 GT Object Map record:            " << m_produceL1GtObjectMapRecord << " \n"
0116         << "\nWrite Psb content to L1 GT DAQ Record:          " << m_writePsbL1GtDaqRecord << " \n"
0117         << "\nRead technical trigger records:                 " << m_readTechnicalTriggerRecords << " \n"
0118         << "\nNumber of BxInEvent to be emulated:             " << m_emulateBxInEvent
0119         << "\nNumber of BXs corresponding to alternative 0:   " << m_recordLength.at(0)
0120         << "\nNumber of BXs corresponding to alternative 1:   " << m_recordLength.at(1) << " \n"
0121         << "\nAlternative for number of BX in GT DAQ record:   0x" << std::hex << m_alternativeNrBxBoardDaq
0122         << "\nAlternative for number of BX in GT EVM record:   0x" << std::hex << m_alternativeNrBxBoardEvm << std::dec
0123         << " \n"
0124         << "\nLength of BST message [bytes]:                  " << m_psBstLengthBytes << "\n"
0125         << "\nRun algorithm triggers unprescaled:             " << m_algorithmTriggersUnprescaled
0126         << "\nRun algorithm triggers unmasked (all enabled):  " << m_algorithmTriggersUnmasked << "\n"
0127         << "\nRun technical triggers unprescaled:             " << m_technicalTriggersUnprescaled
0128         << "\nRun technical triggers unmasked (all enabled):  " << m_technicalTriggersUnmasked
0129         << "\nRun technical triggers veto unmasked (no veto): " << m_technicalTriggersUnmasked << "\n"
0130         << std::endl;
0131   }
0132 
0133   if ((m_emulateBxInEvent > 0) && ((m_emulateBxInEvent % 2) == 0)) {
0134     m_emulateBxInEvent = m_emulateBxInEvent - 1;
0135 
0136     if (m_verbosity) {
0137       edm::LogWarning("L1GlobalTrigger") << "\nWARNING: Number of bunch crossing to be emulated rounded to: "
0138                                          << m_emulateBxInEvent << "\n         The number must be an odd number!\n"
0139                                          << std::endl;
0140     }
0141   }
0142 
0143   int requiredRecordLength = std::max(m_recordLength.at(0), m_recordLength.at(1));
0144   if ((m_emulateBxInEvent >= 0) && (m_emulateBxInEvent < requiredRecordLength)) {
0145     m_emulateBxInEvent = requiredRecordLength;
0146 
0147     if (m_verbosity) {
0148       edm::LogWarning("L1GlobalTrigger") << "\nWARNING: Number of bunch crossing required to be emulated ( "
0149                                          << m_emulateBxInEvent << " BX) smaller as required in RecordLength:"
0150                                          << "\n  Number of BXs corresponding to alternative 0:   "
0151                                          << m_recordLength.at(0)
0152                                          << "\n  Number of BXs corresponding to alternative 1:   "
0153                                          << m_recordLength.at(1) << "\nEmulating " << requiredRecordLength << " BX!"
0154                                          << "\n"
0155                                          << std::endl;
0156     }
0157   }
0158 
0159   // register products
0160   if (m_produceL1GtDaqRecord) {
0161     produces<L1GlobalTriggerReadoutRecord>();
0162   }
0163 
0164   if (m_produceL1GtEvmRecord) {
0165     produces<L1GlobalTriggerEvmReadoutRecord>();
0166   }
0167 
0168   if (m_produceL1GtObjectMapRecord) {
0169     produces<L1GlobalTriggerObjectMapRecord>();
0170   }
0171 
0172   // create new PSBs
0173   m_gtPSB = new L1GlobalTriggerPSB(m_caloGctInputTag, m_technicalTriggersInputTags, consumesCollector());
0174   m_gtPSB->setVerbosity(m_verbosity);
0175 
0176   // create new GTL
0177   m_gtGTL = new L1GlobalTriggerGTL(m_muGmtInputTag, consumesCollector());
0178   m_gtGTL->setVerbosity(m_verbosity);
0179 
0180   // create new FDL
0181   m_gtFDL = new L1GlobalTriggerFDL();
0182   m_gtFDL->setVerbosity(m_verbosity);
0183 
0184   // initialize cached IDs
0185 
0186   //
0187   m_l1GtStableParCacheID = 0ULL;
0188 
0189   m_numberPhysTriggers = 0;
0190   m_numberTechnicalTriggers = 0;
0191   m_numberDaqPartitions = 0;
0192 
0193   m_nrL1Mu = 0;
0194 
0195   m_nrL1NoIsoEG = 0;
0196   m_nrL1IsoEG = 0;
0197 
0198   m_nrL1CenJet = 0;
0199   m_nrL1ForJet = 0;
0200   m_nrL1TauJet = 0;
0201 
0202   m_nrL1JetCounts = 0;
0203 
0204   m_ifMuEtaNumberBits = 0;
0205   m_ifCaloEtaNumberBits = 0;
0206 
0207   //
0208   m_l1GtParCacheID = 0ULL;
0209 
0210   m_totalBxInEvent = 0;
0211 
0212   m_activeBoardsGtDaq = 0;
0213   m_activeBoardsGtEvm = 0;
0214   m_bstLengthBytes = 0;
0215 
0216   //
0217   m_l1GtBMCacheID = 0ULL;
0218 
0219   //
0220   m_l1GtPfAlgoCacheID = 0ULL;
0221   m_l1GtPfTechCacheID = 0ULL;
0222 
0223   m_l1GtTmAlgoCacheID = 0ULL;
0224   m_l1GtTmTechCacheID = 0ULL;
0225 
0226   m_l1GtTmVetoAlgoCacheID = 0ULL;
0227   m_l1GtTmVetoTechCacheID = 0ULL;
0228 
0229   consumes<L1MuGMTReadoutCollection>(m_muGmtInputTag);
0230 }
0231 
0232 // destructor
0233 L1GlobalTrigger::~L1GlobalTrigger() {
0234   delete m_gtPSB;
0235   delete m_gtGTL;
0236   delete m_gtFDL;
0237 }
0238 
0239 // member functions
0240 
0241 // method called to produce the data
0242 void L1GlobalTrigger::produce(edm::Event &iEvent, const edm::EventSetup &evSetup) {
0243   // process event iEvent
0244 
0245   // get / update the stable parameters from the EventSetup
0246   // local cache & check on cacheIdentifier
0247 
0248   unsigned long long l1GtStableParCacheID = evSetup.get<L1GtStableParametersRcd>().cacheIdentifier();
0249 
0250   if (m_l1GtStableParCacheID != l1GtStableParCacheID) {
0251     edm::ESHandle<L1GtStableParameters> l1GtStablePar = evSetup.getHandle(m_l1GtStableParToken);
0252     m_l1GtStablePar = l1GtStablePar.product();
0253 
0254     // number of physics triggers
0255     m_numberPhysTriggers = m_l1GtStablePar->gtNumberPhysTriggers();
0256 
0257     // number of technical triggers
0258     m_numberTechnicalTriggers = m_l1GtStablePar->gtNumberTechnicalTriggers();
0259 
0260     // number of DAQ partitions
0261     m_numberDaqPartitions = 8;  // FIXME add it to stable parameters
0262 
0263     // number of objects of each type
0264     m_nrL1Mu = static_cast<int>(m_l1GtStablePar->gtNumberL1Mu());
0265 
0266     m_nrL1NoIsoEG = static_cast<int>(m_l1GtStablePar->gtNumberL1NoIsoEG());
0267     m_nrL1IsoEG = static_cast<int>(m_l1GtStablePar->gtNumberL1IsoEG());
0268 
0269     m_nrL1CenJet = static_cast<int>(m_l1GtStablePar->gtNumberL1CenJet());
0270     m_nrL1ForJet = static_cast<int>(m_l1GtStablePar->gtNumberL1ForJet());
0271     m_nrL1TauJet = static_cast<int>(m_l1GtStablePar->gtNumberL1TauJet());
0272 
0273     m_nrL1JetCounts = static_cast<int>(m_l1GtStablePar->gtNumberL1JetCounts());
0274 
0275     // ... the rest of the objects are global
0276 
0277     m_ifMuEtaNumberBits = static_cast<int>(m_l1GtStablePar->gtIfMuEtaNumberBits());
0278     m_ifCaloEtaNumberBits = static_cast<int>(m_l1GtStablePar->gtIfCaloEtaNumberBits());
0279 
0280     // (re)initialize L1GlobalTriggerGTL
0281     m_gtGTL->init(m_nrL1Mu, m_numberPhysTriggers);
0282 
0283     // (re)initialize L1GlobalTriggerPSB
0284     m_gtPSB->init(m_nrL1NoIsoEG, m_nrL1IsoEG, m_nrL1CenJet, m_nrL1ForJet, m_nrL1TauJet, m_numberTechnicalTriggers);
0285 
0286     //
0287     m_l1GtStableParCacheID = l1GtStableParCacheID;
0288   }
0289 
0290   // get / update the parameters from the EventSetup
0291   // local cache & check on cacheIdentifier
0292 
0293   unsigned long long l1GtParCacheID = evSetup.get<L1GtParametersRcd>().cacheIdentifier();
0294 
0295   if (m_l1GtParCacheID != l1GtParCacheID) {
0296     edm::ESHandle<L1GtParameters> l1GtPar = evSetup.getHandle(m_l1GtParToken);
0297     m_l1GtPar = l1GtPar.product();
0298 
0299     //    total number of Bx's in the event coming from EventSetup
0300     m_totalBxInEvent = m_l1GtPar->gtTotalBxInEvent();
0301 
0302     //    active boards in L1 GT DAQ record and in L1 GT EVM record
0303     m_activeBoardsGtDaq = m_l1GtPar->gtDaqActiveBoards();
0304     m_activeBoardsGtEvm = m_l1GtPar->gtEvmActiveBoards();
0305 
0306     ///   length of BST message (in bytes) for L1 GT EVM record
0307     m_bstLengthBytes = m_l1GtPar->gtBstLengthBytes();
0308 
0309     m_l1GtParCacheID = l1GtParCacheID;
0310   }
0311 
0312   // negative value: emulate TotalBxInEvent as given in EventSetup
0313   if (m_emulateBxInEvent < 0) {
0314     m_emulateBxInEvent = m_totalBxInEvent;
0315   }
0316 
0317   int minBxInEvent = (m_emulateBxInEvent + 1) / 2 - m_emulateBxInEvent;
0318   int maxBxInEvent = (m_emulateBxInEvent + 1) / 2 - 1;
0319 
0320   int recordLength0 = m_recordLength.at(0);
0321   int recordLength1 = m_recordLength.at(1);
0322 
0323   if ((recordLength0 < 0) || (recordLength1 < 0)) {
0324     // take them from event setup
0325     // FIXME implement later - temporary solution
0326 
0327     recordLength0 = m_emulateBxInEvent;
0328     recordLength1 = m_emulateBxInEvent;
0329   }
0330 
0331   if (m_verbosity) {
0332     LogDebug("L1GlobalTrigger") << "\nTotal number of BX to emulate in the GT readout record: " << m_emulateBxInEvent
0333                                 << " = "
0334                                 << "[" << minBxInEvent << ", " << maxBxInEvent << "] BX\n"
0335                                 << "\nNumber of BX for alternative 0:  " << recordLength0
0336                                 << "\nNumber of BX for alternative 1:  " << recordLength1
0337                                 << "\nActive boards in L1 GT DAQ record (hex format) = " << std::hex
0338                                 << std::setw(sizeof(m_activeBoardsGtDaq) * 2) << std::setfill('0')
0339                                 << m_activeBoardsGtDaq << std::dec << std::setfill(' ')
0340                                 << "\nActive boards in L1 GT EVM record (hex format) = " << std::hex
0341                                 << std::setw(sizeof(m_activeBoardsGtEvm) * 2) << std::setfill('0')
0342                                 << m_activeBoardsGtEvm << std::dec << std::setfill(' ') << "\n"
0343                                 << std::endl;
0344   }
0345 
0346   // get / update the board maps from the EventSetup
0347   // local cache & check on cacheIdentifier
0348 
0349   typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
0350 
0351   unsigned long long l1GtBMCacheID = evSetup.get<L1GtBoardMapsRcd>().cacheIdentifier();
0352 
0353   if (m_l1GtBMCacheID != l1GtBMCacheID) {
0354     edm::ESHandle<L1GtBoardMaps> l1GtBM = evSetup.getHandle(m_l1GtBMToken);
0355     m_l1GtBM = l1GtBM.product();
0356 
0357     m_l1GtBMCacheID = l1GtBMCacheID;
0358   }
0359 
0360   // TODO need changes in CondFormats to cache the maps
0361   const std::vector<L1GtBoard> &boardMaps = m_l1GtBM->gtBoardMaps();
0362 
0363   // get / update the prescale factors from the EventSetup
0364   // local cache & check on cacheIdentifier
0365 
0366   unsigned long long l1GtPfAlgoCacheID = evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().cacheIdentifier();
0367 
0368   if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
0369     edm::ESHandle<L1GtPrescaleFactors> l1GtPfAlgo = evSetup.getHandle(m_l1GtPfAlgoToken);
0370     m_l1GtPfAlgo = l1GtPfAlgo.product();
0371 
0372     m_prescaleFactorsAlgoTrig = &(m_l1GtPfAlgo->gtPrescaleFactors());
0373 
0374     m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
0375   }
0376 
0377   unsigned long long l1GtPfTechCacheID = evSetup.get<L1GtPrescaleFactorsTechTrigRcd>().cacheIdentifier();
0378 
0379   if (m_l1GtPfTechCacheID != l1GtPfTechCacheID) {
0380     edm::ESHandle<L1GtPrescaleFactors> l1GtPfTech = evSetup.getHandle(m_l1GtPfTechToken);
0381     m_l1GtPfTech = l1GtPfTech.product();
0382 
0383     m_prescaleFactorsTechTrig = &(m_l1GtPfTech->gtPrescaleFactors());
0384 
0385     m_l1GtPfTechCacheID = l1GtPfTechCacheID;
0386   }
0387 
0388   // get / update the trigger mask from the EventSetup
0389   // local cache & check on cacheIdentifier
0390 
0391   unsigned long long l1GtTmAlgoCacheID = evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();
0392 
0393   if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
0394     edm::ESHandle<L1GtTriggerMask> l1GtTmAlgo = evSetup.getHandle(m_l1GtTmAlgoToken);
0395     m_l1GtTmAlgo = l1GtTmAlgo.product();
0396 
0397     m_triggerMaskAlgoTrig = m_l1GtTmAlgo->gtTriggerMask();
0398 
0399     m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
0400   }
0401 
0402   unsigned long long l1GtTmTechCacheID = evSetup.get<L1GtTriggerMaskTechTrigRcd>().cacheIdentifier();
0403 
0404   if (m_l1GtTmTechCacheID != l1GtTmTechCacheID) {
0405     edm::ESHandle<L1GtTriggerMask> l1GtTmTech = evSetup.getHandle(m_l1GtTmTechToken);
0406     m_l1GtTmTech = l1GtTmTech.product();
0407 
0408     m_triggerMaskTechTrig = m_l1GtTmTech->gtTriggerMask();
0409 
0410     m_l1GtTmTechCacheID = l1GtTmTechCacheID;
0411   }
0412 
0413   unsigned long long l1GtTmVetoAlgoCacheID = evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>().cacheIdentifier();
0414 
0415   if (m_l1GtTmVetoAlgoCacheID != l1GtTmVetoAlgoCacheID) {
0416     edm::ESHandle<L1GtTriggerMask> l1GtTmVetoAlgo = evSetup.getHandle(m_l1GtTmVetoAlgoToken);
0417     m_l1GtTmVetoAlgo = l1GtTmVetoAlgo.product();
0418 
0419     m_triggerMaskVetoAlgoTrig = m_l1GtTmVetoAlgo->gtTriggerMask();
0420 
0421     m_l1GtTmVetoAlgoCacheID = l1GtTmVetoAlgoCacheID;
0422   }
0423 
0424   unsigned long long l1GtTmVetoTechCacheID = evSetup.get<L1GtTriggerMaskVetoTechTrigRcd>().cacheIdentifier();
0425 
0426   if (m_l1GtTmVetoTechCacheID != l1GtTmVetoTechCacheID) {
0427     edm::ESHandle<L1GtTriggerMask> l1GtTmVetoTech = evSetup.getHandle(m_l1GtTmVetoTechToken);
0428     m_l1GtTmVetoTech = l1GtTmVetoTech.product();
0429 
0430     m_triggerMaskVetoTechTrig = m_l1GtTmVetoTech->gtTriggerMask();
0431 
0432     m_l1GtTmVetoTechCacheID = l1GtTmVetoTechCacheID;
0433   }
0434 
0435   // loop over blocks in the GT DAQ record receiving data, count them if they
0436   // are active all board type are defined in CondFormats/L1TObjects/L1GtFwd
0437   // enum L1GtBoardType { GTFE, FDL, PSB, GMT, TCS, TIM };
0438   // &
0439   // set the active flag for each object type received from GMT and GCT
0440   // all objects in the GT system are defined in enum L1GtObject from
0441   // DataFormats/L1Trigger/L1GlobalTriggerReadoutSetupFwd
0442 
0443   int daqNrGtfeBoards = 0;
0444 
0445   int daqNrFdlBoards = 0;
0446   int daqNrPsbBoards = 0;
0447   int daqNrGmtBoards = 0;
0448   int daqNrTcsBoards = 0;
0449   int daqNrTimBoards = 0;
0450 
0451   //
0452   bool receiveMu = false;
0453   bool receiveNoIsoEG = false;
0454   bool receiveIsoEG = false;
0455   bool receiveCenJet = false;
0456   bool receiveForJet = false;
0457   bool receiveTauJet = false;
0458   bool receiveETM = false;
0459   bool receiveETT = false;
0460   bool receiveHTT = false;
0461   bool receiveHTM = false;
0462   bool receiveJetCounts = false;
0463   bool receiveHfBitCounts = false;
0464   bool receiveHfRingEtSums = false;
0465 
0466   bool receiveExternal = false;
0467 
0468   bool receiveTechTr = false;
0469 
0470   for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
0471     int iPosition = itBoard->gtPositionDaqRecord();
0472     if (iPosition > 0) {
0473       int iActiveBit = itBoard->gtBitDaqActiveBoards();
0474       bool activeBoard = false;
0475 
0476       if (iActiveBit >= 0) {
0477         activeBoard = m_activeBoardsGtDaq & (1 << iActiveBit);
0478       }
0479 
0480       // use board if: in the record, but not in ActiveBoardsMap (iActiveBit <
0481       // 0)
0482       //               in the record and ActiveBoardsMap, and active
0483       if ((iActiveBit < 0) || activeBoard) {
0484         switch (itBoard->gtBoardType()) {
0485           case GTFE: {
0486             daqNrGtfeBoards++;
0487           }
0488 
0489           break;
0490           case FDL: {
0491             daqNrFdlBoards++;
0492           }
0493 
0494           break;
0495           case PSB: {
0496             daqNrPsbBoards++;
0497 
0498             // get the objects coming to this PSB
0499             std::vector<L1GtPsbQuad> quadInPsb = itBoard->gtQuadInPsb();
0500             for (std::vector<L1GtPsbQuad>::const_iterator itQuad = quadInPsb.begin(); itQuad != quadInPsb.end();
0501                  ++itQuad) {
0502               switch (*itQuad) {
0503                 case TechTr: {
0504                   receiveTechTr = true;
0505                 }
0506 
0507                 break;
0508                 case NoIsoEGQ: {
0509                   receiveNoIsoEG = true;
0510                 }
0511 
0512                 break;
0513                 case IsoEGQ: {
0514                   receiveIsoEG = true;
0515                 }
0516 
0517                 break;
0518                 case CenJetQ: {
0519                   receiveCenJet = true;
0520                 }
0521 
0522                 break;
0523                 case ForJetQ: {
0524                   receiveForJet = true;
0525                 }
0526 
0527                 break;
0528                 case TauJetQ: {
0529                   receiveTauJet = true;
0530                 }
0531 
0532                 break;
0533                 case ESumsQ: {
0534                   receiveETM = true;
0535                   receiveETT = true;
0536                   receiveHTT = true;
0537                   receiveHTM = true;
0538                 }
0539 
0540                 break;
0541                 case JetCountsQ: {
0542                   receiveJetCounts = true;
0543                 }
0544 
0545                 break;
0546                 case CastorQ: {
0547                   // obsolete
0548                 }
0549 
0550                 break;
0551                 case BptxQ: {
0552                   // obsolete
0553                 }
0554 
0555                 break;
0556                 case GtExternalQ: {
0557                   receiveExternal = true;
0558                 }
0559 
0560                 break;
0561                 case HfQ: {
0562                   receiveHfBitCounts = true;
0563                   receiveHfRingEtSums = true;
0564                 }
0565 
0566                 break;
0567                   // FIXME add MIP/Iso bits
0568                 default: {
0569                   // do nothing
0570                 }
0571 
0572                 break;
0573               }
0574             }
0575 
0576           }
0577 
0578           break;
0579           case GMT: {
0580             daqNrGmtBoards++;
0581             receiveMu = true;
0582           }
0583 
0584           break;
0585           case TCS: {
0586             daqNrTcsBoards++;
0587           }
0588 
0589           break;
0590           case TIM: {
0591             daqNrTimBoards++;
0592           }
0593 
0594           break;
0595           default: {
0596             // do nothing, all blocks are given in GtBoardType enum
0597           }
0598 
0599           break;
0600         }
0601       }
0602     }
0603   }
0604 
0605   // produce the L1GlobalTriggerReadoutRecord now, after we found how many
0606   // BxInEvent the record has and how many boards are active
0607   std::unique_ptr<L1GlobalTriggerReadoutRecord> gtDaqReadoutRecord(
0608       new L1GlobalTriggerReadoutRecord(m_emulateBxInEvent, daqNrFdlBoards, daqNrPsbBoards));
0609 
0610   // * produce the L1GlobalTriggerEvmReadoutRecord
0611   std::unique_ptr<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord(
0612       new L1GlobalTriggerEvmReadoutRecord(m_emulateBxInEvent, daqNrFdlBoards));
0613   // daqNrFdlBoards OK, just reserve memory at this point
0614 
0615   // * produce the L1GlobalTriggerObjectMapRecord
0616   std::unique_ptr<L1GlobalTriggerObjectMapRecord> gtObjectMapRecord(new L1GlobalTriggerObjectMapRecord());
0617 
0618   // fill the boards not depending on the BxInEvent in the L1 GT DAQ record
0619   // GMT, PSB and FDL depend on BxInEvent
0620 
0621   // fill in emulator the same bunch crossing (12 bits - hardwired number of
0622   // bits...) and the same local bunch crossing for all boards
0623   int bxCross = iEvent.bunchCrossing();
0624   uint16_t bxCrossHw = 0;
0625   if ((bxCross & 0xFFF) == bxCross) {
0626     bxCrossHw = static_cast<uint16_t>(bxCross);
0627   } else {
0628     bxCrossHw = 0;  // Bx number too large, set to 0!
0629     if (m_verbosity) {
0630       LogDebug("L1GlobalTrigger") << "\nBunch cross number [hex] = " << std::hex << bxCross
0631                                   << "\n  larger than 12 bits. Set to 0! \n"
0632                                   << std::dec << std::endl;
0633     }
0634   }
0635 
0636   if (m_produceL1GtDaqRecord) {
0637     for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
0638       int iPosition = itBoard->gtPositionDaqRecord();
0639       if (iPosition > 0) {
0640         int iActiveBit = itBoard->gtBitDaqActiveBoards();
0641         bool activeBoard = false;
0642 
0643         if (iActiveBit >= 0) {
0644           activeBoard = m_activeBoardsGtDaq & (1 << iActiveBit);
0645         }
0646 
0647         // use board if: in the record, but not in ActiveBoardsMap (iActiveBit <
0648         // 0)
0649         //               in the record and ActiveBoardsMap, and active
0650         if ((iActiveBit < 0) || activeBoard) {
0651           switch (itBoard->gtBoardType()) {
0652             case GTFE: {
0653               L1GtfeWord gtfeWordValue;
0654 
0655               gtfeWordValue.setBoardId(itBoard->gtBoardId());
0656 
0657               // cast int to uint16_t
0658               // there are normally 3 or 5 BxInEvent
0659               gtfeWordValue.setRecordLength(static_cast<uint16_t>(recordLength0));
0660 
0661               gtfeWordValue.setRecordLength1(static_cast<uint16_t>(recordLength1));
0662 
0663               // bunch crossing
0664               gtfeWordValue.setBxNr(bxCrossHw);
0665 
0666               // set the list of active boards
0667               gtfeWordValue.setActiveBoards(m_activeBoardsGtDaq);
0668 
0669               // set alternative for number of BX per board
0670               gtfeWordValue.setAltNrBxBoard(static_cast<uint16_t>(m_alternativeNrBxBoardDaq));
0671 
0672               // set the TOTAL_TRIGNR as read from iEvent
0673               // TODO check again - PTC stuff
0674 
0675               gtfeWordValue.setTotalTriggerNr(static_cast<uint32_t>(iEvent.id().event()));
0676 
0677               // ** fill L1GtfeWord in GT DAQ record
0678 
0679               gtDaqReadoutRecord->setGtfeWord(gtfeWordValue);
0680             }
0681 
0682             break;
0683             case TCS: {
0684               // nothing
0685             }
0686 
0687             break;
0688             case TIM: {
0689               // nothing
0690             }
0691 
0692             break;
0693             default: {
0694               // do nothing, all blocks are given in GtBoardType enum
0695             }
0696 
0697             break;
0698           }
0699         }
0700       }
0701     }
0702   }
0703 
0704   // fill the boards not depending on the BxInEvent in the L1 GT EVM record
0705 
0706   int evmNrFdlBoards = 0;
0707 
0708   if (m_produceL1GtEvmRecord) {
0709     // get the length of the BST message from parameter set or from event setup
0710 
0711     int bstLengthBytes = 0;
0712 
0713     if (m_psBstLengthBytes < 0) {
0714       // length from event setup
0715       bstLengthBytes = static_cast<int>(m_bstLengthBytes);
0716 
0717     } else {
0718       // length from parameter set
0719       bstLengthBytes = m_psBstLengthBytes;
0720     }
0721 
0722     if (m_verbosity) {
0723       LogTrace("L1GlobalTrigger") << "\n Length of BST message (in bytes): " << bstLengthBytes << "\n" << std::endl;
0724     }
0725 
0726     for (CItBoardMaps itBoard = boardMaps.begin(); itBoard != boardMaps.end(); ++itBoard) {
0727       int iPosition = itBoard->gtPositionEvmRecord();
0728       if (iPosition > 0) {
0729         int iActiveBit = itBoard->gtBitEvmActiveBoards();
0730         bool activeBoard = false;
0731 
0732         if (iActiveBit >= 0) {
0733           activeBoard = m_activeBoardsGtEvm & (1 << iActiveBit);
0734         }
0735 
0736         // use board if: in the record, but not in ActiveBoardsMap (iActiveBit <
0737         // 0)
0738         //               in the record and ActiveBoardsMap, and active
0739         if ((iActiveBit < 0) || activeBoard) {
0740           switch (itBoard->gtBoardType()) {
0741             case GTFE: {
0742               L1GtfeExtWord gtfeWordValue(bstLengthBytes);
0743 
0744               gtfeWordValue.setBoardId(itBoard->gtBoardId());
0745 
0746               // cast int to uint16_t
0747               // there are normally 3 or 5 BxInEvent
0748               gtfeWordValue.setRecordLength(static_cast<uint16_t>(recordLength0));
0749 
0750               gtfeWordValue.setRecordLength1(static_cast<uint16_t>(recordLength1));
0751 
0752               // bunch crossing
0753               gtfeWordValue.setBxNr(bxCrossHw);
0754 
0755               // set the list of active boards
0756               gtfeWordValue.setActiveBoards(m_activeBoardsGtEvm);
0757 
0758               // set alternative for number of BX per board
0759               gtfeWordValue.setAltNrBxBoard(static_cast<uint16_t>(m_alternativeNrBxBoardEvm));
0760 
0761               // set the TOTAL_TRIGNR as read from iEvent
0762               // TODO check again - PTC stuff
0763 
0764               gtfeWordValue.setTotalTriggerNr(static_cast<uint32_t>(iEvent.id().event()));
0765 
0766               // set the GPS time to the value read from Timestamp
0767               edm::TimeValue_t evTime = iEvent.time().value();
0768 
0769               gtfeWordValue.setGpsTime(evTime);
0770 
0771               // LogDebug("L1GlobalTrigger")
0772               //<< "\nEvent timestamp value [hex] = " << std::hex << evTime
0773               //<< "\nBST retrieved value [hex]   = " << gtfeWordValue.gpsTime()
0774               //<< std::dec << std::endl;
0775 
0776               // source of BST message: DDDD simulated data
0777               uint16_t bstSourceVal = 0xDDDD;
0778               gtfeWordValue.setBstSource(bstSourceVal);
0779 
0780               // ** fill L1GtfeWord in GT EVM record
0781 
0782               gtEvmReadoutRecord->setGtfeWord(gtfeWordValue);
0783             }
0784 
0785             break;
0786             case FDL: {
0787               evmNrFdlBoards++;
0788             }
0789 
0790             break;
0791             case TCS: {
0792               L1TcsWord tcsWordValue;
0793 
0794               tcsWordValue.setBoardId(itBoard->gtBoardId());
0795 
0796               // bunch crossing
0797               tcsWordValue.setBxNr(bxCrossHw);
0798 
0799               uint16_t trigType = 0x5;  // 0101 simulated event
0800               tcsWordValue.setTriggerType(trigType);
0801 
0802               // luminosity segment number
0803               tcsWordValue.setLuminositySegmentNr(static_cast<uint16_t>(iEvent.luminosityBlock()));
0804 
0805               // set the Event_Nr as read from iEvent
0806               tcsWordValue.setEventNr(static_cast<uint32_t>(iEvent.id().event()));
0807 
0808               // orbit number
0809               tcsWordValue.setOrbitNr(static_cast<uint64_t>(iEvent.orbitNumber()));
0810 
0811               // ** fill L1TcsWord in the EVM record
0812 
0813               gtEvmReadoutRecord->setTcsWord(tcsWordValue);
0814 
0815             }
0816 
0817             break;
0818             case TIM: {
0819               // nothing
0820             }
0821 
0822             break;
0823             default: {
0824               // do nothing, all blocks are given in GtBoardType enum
0825             }
0826 
0827             break;
0828           }
0829         }
0830       }
0831     }
0832   }
0833 
0834   // get the prescale factor set used in the actual luminosity segment
0835   int pfAlgoSetIndex = 0;  // FIXME
0836   const std::vector<int> &prescaleFactorsAlgoTrig = (*m_prescaleFactorsAlgoTrig).at(pfAlgoSetIndex);
0837 
0838   int pfTechSetIndex = 0;  // FIXME
0839   const std::vector<int> &prescaleFactorsTechTrig = (*m_prescaleFactorsTechTrig).at(pfTechSetIndex);
0840 
0841   //
0842 
0843   // loop over BxInEvent
0844   for (int iBxInEvent = minBxInEvent; iBxInEvent <= maxBxInEvent; ++iBxInEvent) {
0845     // * receive GCT object data via PSBs
0846     // LogDebug("L1GlobalTrigger")
0847     //<< "\nL1GlobalTrigger : receiving PSB data for bx = " << iBxInEvent <<
0848     //"\n"
0849     //<< std::endl;
0850 
0851     m_gtPSB->receiveGctObjectData(iEvent,
0852                                   m_caloGctInputTag,
0853                                   iBxInEvent,
0854                                   receiveNoIsoEG,
0855                                   m_nrL1NoIsoEG,
0856                                   receiveIsoEG,
0857                                   m_nrL1IsoEG,
0858                                   receiveCenJet,
0859                                   m_nrL1CenJet,
0860                                   receiveForJet,
0861                                   m_nrL1ForJet,
0862                                   receiveTauJet,
0863                                   m_nrL1TauJet,
0864                                   receiveETM,
0865                                   receiveETT,
0866                                   receiveHTT,
0867                                   receiveHTM,
0868                                   receiveJetCounts,
0869                                   receiveHfBitCounts,
0870                                   receiveHfRingEtSums);
0871 
0872     /// receive technical trigger
0873     if (m_readTechnicalTriggerRecords) {
0874       m_gtPSB->receiveTechnicalTriggers(
0875           iEvent, m_technicalTriggersInputTags, iBxInEvent, receiveTechTr, m_numberTechnicalTriggers);
0876     }
0877 
0878     if (receiveExternal) {
0879       // FIXME read the external conditions
0880     }
0881 
0882     if (m_produceL1GtDaqRecord && m_writePsbL1GtDaqRecord) {
0883       m_gtPSB->fillPsbBlock(iEvent,
0884                             m_activeBoardsGtDaq,
0885                             recordLength0,
0886                             recordLength1,
0887                             m_alternativeNrBxBoardDaq,
0888                             boardMaps,
0889                             iBxInEvent,
0890                             gtDaqReadoutRecord.get());
0891     }
0892 
0893     // * receive GMT object data via GTL
0894     // LogDebug("L1GlobalTrigger")
0895     //<< "\nL1GlobalTrigger : receiving GMT data for bx = " << iBxInEvent <<
0896     //"\n"
0897     //<< std::endl;
0898 
0899     m_gtGTL->receiveGmtObjectData(iEvent, m_muGmtInputTag, iBxInEvent, receiveMu, m_nrL1Mu);
0900 
0901     // * run GTL
0902     // LogDebug("L1GlobalTrigger")
0903     //<< "\nL1GlobalTrigger : running GTL for bx = " << iBxInEvent << "\n"
0904     //<< std::endl;
0905 
0906     m_gtGTL->run(iEvent,
0907                  evSetup,
0908                  m_gtPSB,
0909                  m_produceL1GtObjectMapRecord,
0910                  iBxInEvent,
0911                  gtObjectMapRecord.get(),
0912                  m_numberPhysTriggers,
0913                  m_nrL1Mu,
0914                  m_nrL1NoIsoEG,
0915                  m_nrL1IsoEG,
0916                  m_nrL1CenJet,
0917                  m_nrL1ForJet,
0918                  m_nrL1TauJet,
0919                  m_nrL1JetCounts,
0920                  m_ifMuEtaNumberBits,
0921                  m_ifCaloEtaNumberBits);
0922 
0923     // LogDebug("L1GlobalTrigger")
0924     //<< "\n AlgorithmOR\n" << m_gtGTL->getAlgorithmOR() << "\n"
0925     //<< std::endl;
0926 
0927     // * run FDL
0928     // LogDebug("L1GlobalTrigger")
0929     //<< "\nL1GlobalTrigger : running FDL for bx = " << iBxInEvent << "\n"
0930     //<< std::endl;
0931 
0932     m_gtFDL->run(iEvent,
0933                  prescaleFactorsAlgoTrig,
0934                  prescaleFactorsTechTrig,
0935                  m_triggerMaskAlgoTrig,
0936                  m_triggerMaskTechTrig,
0937                  m_triggerMaskVetoAlgoTrig,
0938                  m_triggerMaskVetoTechTrig,
0939                  boardMaps,
0940                  m_emulateBxInEvent,
0941                  iBxInEvent,
0942                  m_numberPhysTriggers,
0943                  m_numberTechnicalTriggers,
0944                  m_numberDaqPartitions,
0945                  m_gtGTL,
0946                  m_gtPSB,
0947                  pfAlgoSetIndex,
0948                  pfTechSetIndex,
0949                  m_algorithmTriggersUnprescaled,
0950                  m_algorithmTriggersUnmasked,
0951                  m_technicalTriggersUnprescaled,
0952                  m_technicalTriggersUnmasked,
0953                  m_technicalTriggersVetoUnmasked);
0954 
0955     if (m_produceL1GtDaqRecord && (daqNrFdlBoards > 0)) {
0956       m_gtFDL->fillDaqFdlBlock(iBxInEvent,
0957                                m_activeBoardsGtDaq,
0958                                recordLength0,
0959                                recordLength1,
0960                                m_alternativeNrBxBoardDaq,
0961                                boardMaps,
0962                                gtDaqReadoutRecord.get());
0963     }
0964 
0965     if (m_produceL1GtEvmRecord && (evmNrFdlBoards > 0)) {
0966       m_gtFDL->fillEvmFdlBlock(iBxInEvent,
0967                                m_activeBoardsGtEvm,
0968                                recordLength0,
0969                                recordLength1,
0970                                m_alternativeNrBxBoardEvm,
0971                                boardMaps,
0972                                gtEvmReadoutRecord.get());
0973     }
0974 
0975     // reset
0976     m_gtPSB->reset();
0977     m_gtGTL->reset();
0978     m_gtFDL->reset();
0979 
0980     // LogDebug("L1GlobalTrigger") << "\n Reset PSB, GTL, FDL\n" << std::endl;
0981   }
0982 
0983   if (receiveMu) {
0984     // LogDebug("L1GlobalTrigger")
0985     //<< "\n**** "
0986     //<< "\n  Persistent reference for L1MuGMTReadoutCollection with input tag:
0987     //"
0988     //<< m_muGmtInputTag
0989     //<< "\n**** \n"
0990     //<< std::endl;
0991 
0992     // get L1MuGMTReadoutCollection reference and set it in GT record
0993 
0994     edm::Handle<L1MuGMTReadoutCollection> gmtRcHandle;
0995     iEvent.getByLabel(m_muGmtInputTag, gmtRcHandle);
0996 
0997     if (!gmtRcHandle.isValid()) {
0998       if (m_verbosity) {
0999         edm::LogWarning("L1GlobalTrigger") << "\nWarning: L1MuGMTReadoutCollection with input tag " << m_muGmtInputTag
1000                                            << "\nrequested in configuration, but not found in the event.\n"
1001                                            << std::endl;
1002       }
1003     } else {
1004       gtDaqReadoutRecord->setMuCollectionRefProd(gmtRcHandle);
1005     }
1006   }
1007 
1008   if (m_verbosity && m_isDebugEnabled) {
1009     std::ostringstream myCoutStream;
1010     gtDaqReadoutRecord->print(myCoutStream);
1011     LogTrace("L1GlobalTrigger") << "\n The following L1 GT DAQ readout record was produced:\n"
1012                                 << myCoutStream.str() << "\n"
1013                                 << std::endl;
1014 
1015     myCoutStream.str("");
1016     myCoutStream.clear();
1017 
1018     gtEvmReadoutRecord->print(myCoutStream);
1019     LogTrace("L1GlobalTrigger") << "\n The following L1 GT EVM readout record was produced:\n"
1020                                 << myCoutStream.str() << "\n"
1021                                 << std::endl;
1022 
1023     myCoutStream.str("");
1024     myCoutStream.clear();
1025 
1026     const std::vector<L1GlobalTriggerObjectMap> objMapVec = gtObjectMapRecord->gtObjectMap();
1027 
1028     for (std::vector<L1GlobalTriggerObjectMap>::const_iterator it = objMapVec.begin(); it != objMapVec.end(); ++it) {
1029       (*it).print(myCoutStream);
1030     }
1031 
1032     LogDebug("L1GlobalTrigger") << "Test gtObjectMapRecord in L1GlobalTrigger \n\n"
1033                                 << myCoutStream.str() << "\n\n"
1034                                 << std::endl;
1035 
1036     myCoutStream.str("");
1037     myCoutStream.clear();
1038   }
1039 
1040   // **
1041   // register products
1042   if (m_produceL1GtDaqRecord) {
1043     iEvent.put(std::move(gtDaqReadoutRecord));
1044   }
1045 
1046   if (m_produceL1GtEvmRecord) {
1047     iEvent.put(std::move(gtEvmReadoutRecord));
1048   }
1049 
1050   if (m_produceL1GtObjectMapRecord) {
1051     iEvent.put(std::move(gtObjectMapRecord));
1052   }
1053 }
1054 
1055 // static data members
1056 
1057 DEFINE_FWK_MODULE(L1GlobalTrigger);