CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/L1Trigger/GlobalTrigger/src/L1GlobalTrigger.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTrigger.h"
00019 
00020 // system include files
00021 #include <memory>
00022 #include <iostream>
00023 #include <iomanip>
00024 #include <algorithm>
00025 
00026 #include <boost/cstdint.hpp>
00027 
00028 // user include files
00029 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00030 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00031 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00032 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
00033 
00034 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
00035 
00036 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00037 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTCand.h"
00038 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTExtendedCand.h"
00039 
00040 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEmCand.h"
00041 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCand.h"
00042 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEtSums.h"
00043 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCounts.h"
00044 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctHFBitCounts.h"
00045 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctHFRingEtSums.h"
00046 
00047 #include "FWCore/Framework/interface/Event.h"
00048 #include "FWCore/Framework/interface/EventSetup.h"
00049 #include "FWCore/Framework/interface/ESHandle.h"
00050 
00051 #include "CondFormats/L1TObjects/interface/L1GtStableParameters.h"
00052 #include "CondFormats/DataRecord/interface/L1GtStableParametersRcd.h"
00053 
00054 #include "CondFormats/L1TObjects/interface/L1GtParameters.h"
00055 #include "CondFormats/DataRecord/interface/L1GtParametersRcd.h"
00056 
00057 #include "CondFormats/L1TObjects/interface/L1GtFwd.h"
00058 #include "CondFormats/L1TObjects/interface/L1GtBoard.h"
00059 #include "CondFormats/L1TObjects/interface/L1GtBoardMaps.h"
00060 #include "CondFormats/DataRecord/interface/L1GtBoardMapsRcd.h"
00061 
00062 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00063 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00064 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsTechTrigRcd.h"
00065 
00066 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00067 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00068 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00069 
00070 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoAlgoTrigRcd.h"
00071 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoTechTrigRcd.h"
00072 
00073 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerPSB.h"
00074 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerGTL.h"
00075 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerFDL.h"
00076 
00077 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeWord.h"
00078 #include "DataFormats/L1GlobalTrigger/interface/L1GtfeExtWord.h"
00079 #include "DataFormats/L1GlobalTrigger/interface/L1TcsWord.h"
00080 
00081 #include "DataFormats/Common/interface/RefProd.h"
00082 #include "FWCore/Utilities/interface/InputTag.h"
00083 
00084 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00085 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00086 
00087 
00088 
00089 // constructors
00090 
00091 L1GlobalTrigger::L1GlobalTrigger(const edm::ParameterSet& parSet) :
00092             m_muGmtInputTag(parSet.getParameter<edm::InputTag> ("GmtInputTag")),
00093             m_caloGctInputTag(parSet.getParameter<edm::InputTag> ("GctInputTag")),
00094             m_castorInputTag(parSet.getParameter<edm::InputTag> ("CastorInputTag")),
00095             m_technicalTriggersInputTags(parSet.getParameter<std::vector<edm::InputTag> > (
00096                     "TechnicalTriggersInputTags")),
00097             m_produceL1GtDaqRecord(parSet.getParameter<bool> ("ProduceL1GtDaqRecord")),
00098             m_produceL1GtEvmRecord(parSet.getParameter<bool> ("ProduceL1GtEvmRecord")),
00099             m_produceL1GtObjectMapRecord(parSet.getParameter<bool> ("ProduceL1GtObjectMapRecord")),
00100             m_writePsbL1GtDaqRecord(parSet.getParameter<bool> ("WritePsbL1GtDaqRecord")),
00101             m_readTechnicalTriggerRecords(parSet.getParameter<bool> ("ReadTechnicalTriggerRecords")),
00102             m_emulateBxInEvent(parSet.getParameter<int> ("EmulateBxInEvent")),
00103             m_recordLength(parSet.getParameter<std::vector<int> > ("RecordLength")),
00104             m_alternativeNrBxBoardDaq(parSet.getParameter<unsigned int> ("AlternativeNrBxBoardDaq")),
00105             m_alternativeNrBxBoardEvm(parSet.getParameter<unsigned int> ("AlternativeNrBxBoardEvm")),
00106             m_psBstLengthBytes(parSet.getParameter<int> ("BstLengthBytes")),
00107             m_verbosity(parSet.getUntrackedParameter<int>("Verbosity", 0)),
00108             m_isDebugEnabled(edm::isDebugEnabled())
00109 
00110 
00111 {
00112 
00113     if (m_verbosity && m_isDebugEnabled) {
00114 
00115         LogTrace("L1GlobalTrigger")
00116                 << "\nInput tag for muon collection from GMT:         " << m_muGmtInputTag
00117                 << "\nInput tag for calorimeter collections from GCT: " << m_caloGctInputTag
00118                 << "\nInput tag for CASTOR record:                    " << m_castorInputTag
00119                 << "\nInput tag for technical triggers:               "
00120                 << std::endl;
00121 
00122         // loop over all producers of technical trigger records
00123         for (std::vector<edm::InputTag>::const_iterator it = m_technicalTriggersInputTags.begin(); it
00124                 != m_technicalTriggersInputTags.end(); it++) {
00125             LogTrace("L1GlobalTrigger") << "\n  " << ( *it ) << std::endl;
00126         }
00127 
00128         LogTrace("L1GlobalTrigger")
00129                 << "\nProduce the L1 GT DAQ readout record:           " << m_produceL1GtDaqRecord
00130                 << "\nProduce the L1 GT EVM readout record:           " << m_produceL1GtEvmRecord
00131                 << "\nProduce the L1 GT Object Map record:            " << m_produceL1GtObjectMapRecord
00132                 << " \n"
00133                 << "\nWrite Psb content to L1 GT DAQ Record:          " << m_writePsbL1GtDaqRecord
00134                 << " \n"
00135                 << "\nRead technical trigger records:                 " << m_readTechnicalTriggerRecords
00136                 << " \n"
00137                 << "\nNumber of BxInEvent to be emulated:             " << m_emulateBxInEvent
00138                 << "\nNumber of BXs corresponding to alternative 0:   " << m_recordLength.at(0)
00139                 << "\nNumber of BXs corresponding to alternative 1:   " << m_recordLength.at(1)
00140                 << " \n"
00141                 << "\nAlternative for number of BX in GT DAQ record:   0x" << std::hex
00142                 << m_alternativeNrBxBoardDaq
00143                 << "\nAlternative for number of BX in GT EVM record:   0x" << std::hex
00144                 << m_alternativeNrBxBoardEvm << std::dec
00145                 << " \n"
00146                 << "\nLength of BST message [bytes]:                  " << m_psBstLengthBytes
00147                 << "\n"
00148                 << std::endl;
00149     }
00150 
00151 
00152     if ( ( m_emulateBxInEvent > 0 ) && ( ( m_emulateBxInEvent % 2 ) == 0 )) {
00153         m_emulateBxInEvent = m_emulateBxInEvent - 1;
00154 
00155         if (m_verbosity) {
00156             edm::LogWarning("L1GlobalTrigger")
00157                     << "\nWARNING: Number of bunch crossing to be emulated rounded to: "
00158                     << m_emulateBxInEvent << "\n         The number must be an odd number!\n"
00159                     << std::endl;
00160         }
00161     }
00162 
00163     int requiredRecordLength = std::max(m_recordLength.at(0), m_recordLength.at(1));
00164     if ((m_emulateBxInEvent >= 0) && (m_emulateBxInEvent < requiredRecordLength) ) {
00165 
00166         m_emulateBxInEvent = requiredRecordLength;
00167 
00168         if (m_verbosity) {
00169             edm::LogWarning("L1GlobalTrigger")
00170                     << "\nWARNING: Number of bunch crossing required to be emulated ( "
00171                     << m_emulateBxInEvent << " BX) smaller as required in RecordLength:"
00172                     << "\n  Number of BXs corresponding to alternative 0:   " << m_recordLength.at(0)
00173                     << "\n  Number of BXs corresponding to alternative 1:   " << m_recordLength.at(1)
00174                     << "\nEmulating " << requiredRecordLength << " BX!"
00175                     << "\n"
00176                     << std::endl;
00177         }
00178 
00179     }
00180 
00181     // register products
00182     if (m_produceL1GtDaqRecord) {
00183         produces<L1GlobalTriggerReadoutRecord>();
00184     }
00185 
00186     if (m_produceL1GtEvmRecord) {
00187         produces<L1GlobalTriggerEvmReadoutRecord>();
00188     }
00189 
00190     if (m_produceL1GtObjectMapRecord) {
00191         produces<L1GlobalTriggerObjectMapRecord>();
00192     }
00193 
00194     // create new PSBs
00195     m_gtPSB = new L1GlobalTriggerPSB();
00196     m_gtPSB->setVerbosity(m_verbosity);
00197 
00198     // create new GTL
00199     m_gtGTL = new L1GlobalTriggerGTL();
00200     m_gtGTL->setVerbosity(m_verbosity);
00201 
00202     // create new FDL
00203     m_gtFDL = new L1GlobalTriggerFDL();
00204     m_gtFDL->setVerbosity(m_verbosity);
00205 
00206     // initialize cached IDs
00207 
00208     //
00209     m_l1GtStableParCacheID = 0ULL;
00210 
00211     m_numberPhysTriggers = 0;
00212     m_numberTechnicalTriggers = 0;
00213     m_numberDaqPartitions = 0;
00214 
00215     m_nrL1Mu = 0;
00216 
00217     m_nrL1NoIsoEG = 0;
00218     m_nrL1IsoEG = 0;
00219 
00220     m_nrL1CenJet = 0;
00221     m_nrL1ForJet = 0;
00222     m_nrL1TauJet = 0;
00223 
00224     m_nrL1JetCounts = 0;
00225 
00226     m_ifMuEtaNumberBits = 0;
00227     m_ifCaloEtaNumberBits = 0;
00228 
00229     //
00230     m_l1GtParCacheID = 0ULL;
00231 
00232     m_totalBxInEvent = 0;
00233 
00234     m_activeBoardsGtDaq = 0;
00235     m_activeBoardsGtEvm = 0;
00236     m_bstLengthBytes = 0;
00237 
00238     //
00239     m_l1GtBMCacheID = 0ULL;
00240 
00241     //
00242     m_l1GtPfAlgoCacheID = 0ULL;
00243     m_l1GtPfTechCacheID = 0ULL;
00244 
00245     m_l1GtTmAlgoCacheID = 0ULL;
00246     m_l1GtTmTechCacheID = 0ULL;
00247 
00248     m_l1GtTmVetoAlgoCacheID = 0ULL;
00249     m_l1GtTmVetoTechCacheID = 0ULL;
00250 
00251 }
00252 
00253 // destructor
00254 L1GlobalTrigger::~L1GlobalTrigger()
00255 {
00256 
00257     delete m_gtPSB;
00258     delete m_gtGTL;
00259     delete m_gtFDL;
00260 }
00261 
00262 // member functions
00263 
00264 // method called to produce the data
00265 void L1GlobalTrigger::produce(edm::Event& iEvent, const edm::EventSetup& evSetup)
00266 {
00267 
00268     // process event iEvent
00269 
00270         // get / update the stable parameters from the EventSetup
00271     // local cache & check on cacheIdentifier
00272 
00273     unsigned long long l1GtStableParCacheID =
00274             evSetup.get<L1GtStableParametersRcd>().cacheIdentifier();
00275 
00276     if (m_l1GtStableParCacheID != l1GtStableParCacheID) {
00277 
00278         edm::ESHandle< L1GtStableParameters > l1GtStablePar;
00279         evSetup.get< L1GtStableParametersRcd >().get( l1GtStablePar );
00280         m_l1GtStablePar = l1GtStablePar.product();
00281 
00282         // number of physics triggers
00283         m_numberPhysTriggers = m_l1GtStablePar->gtNumberPhysTriggers();
00284 
00285         // number of technical triggers
00286         m_numberTechnicalTriggers = m_l1GtStablePar->gtNumberTechnicalTriggers();
00287 
00288         // number of DAQ partitions
00289         m_numberDaqPartitions = 8; // FIXME add it to stable parameters
00290 
00291         // number of objects of each type
00292         m_nrL1Mu = static_cast<int> (m_l1GtStablePar->gtNumberL1Mu());
00293 
00294         m_nrL1NoIsoEG = static_cast<int> (m_l1GtStablePar->gtNumberL1NoIsoEG());
00295         m_nrL1IsoEG = static_cast<int> (m_l1GtStablePar->gtNumberL1IsoEG());
00296 
00297         m_nrL1CenJet = static_cast<int> (m_l1GtStablePar->gtNumberL1CenJet());
00298         m_nrL1ForJet = static_cast<int> (m_l1GtStablePar->gtNumberL1ForJet());
00299         m_nrL1TauJet = static_cast<int> (m_l1GtStablePar->gtNumberL1TauJet());
00300 
00301         m_nrL1JetCounts = static_cast<int> (m_l1GtStablePar->gtNumberL1JetCounts());
00302 
00303         // ... the rest of the objects are global
00304 
00305         m_ifMuEtaNumberBits = static_cast<int> (m_l1GtStablePar->gtIfMuEtaNumberBits());
00306         m_ifCaloEtaNumberBits = static_cast<int> (m_l1GtStablePar->gtIfCaloEtaNumberBits());
00307 
00308         // (re)initialize L1GlobalTriggerGTL
00309         m_gtGTL->init(m_nrL1Mu, m_numberPhysTriggers);
00310 
00311         // (re)initialize L1GlobalTriggerPSB
00312         m_gtPSB->init(m_nrL1NoIsoEG, m_nrL1IsoEG,
00313                 m_nrL1CenJet, m_nrL1ForJet, m_nrL1TauJet,
00314                 m_numberTechnicalTriggers);
00315 
00316         //
00317         m_l1GtStableParCacheID = l1GtStableParCacheID;
00318 
00319     }
00320 
00321     // get / update the parameters from the EventSetup
00322     // local cache & check on cacheIdentifier
00323 
00324     unsigned long long l1GtParCacheID = evSetup.get<L1GtParametersRcd>().cacheIdentifier();
00325 
00326     if (m_l1GtParCacheID != l1GtParCacheID) {
00327 
00328         edm::ESHandle< L1GtParameters > l1GtPar;
00329         evSetup.get< L1GtParametersRcd >().get( l1GtPar );
00330         m_l1GtPar = l1GtPar.product();
00331 
00332         //    total number of Bx's in the event coming from EventSetup
00333         m_totalBxInEvent = m_l1GtPar->gtTotalBxInEvent();
00334 
00335         //    active boards in L1 GT DAQ record and in L1 GT EVM record
00336         m_activeBoardsGtDaq = m_l1GtPar->gtDaqActiveBoards();
00337         m_activeBoardsGtEvm = m_l1GtPar->gtEvmActiveBoards();
00338 
00340         m_bstLengthBytes = m_l1GtPar->gtBstLengthBytes();
00341 
00342 
00343         m_l1GtParCacheID = l1GtParCacheID;
00344 
00345     }
00346 
00347     // negative value: emulate TotalBxInEvent as given in EventSetup
00348     if (m_emulateBxInEvent < 0) {
00349         m_emulateBxInEvent = m_totalBxInEvent;
00350     }
00351 
00352     int minBxInEvent = (m_emulateBxInEvent + 1)/2 - m_emulateBxInEvent;
00353     int maxBxInEvent = (m_emulateBxInEvent + 1)/2 - 1;
00354 
00355     int recordLength0 = m_recordLength.at(0);
00356     int recordLength1 = m_recordLength.at(1);
00357 
00358     if ((recordLength0 < 0) || (recordLength1 < 0) ) {
00359 
00360         // take them from event setup
00361         // FIXME implement later - temporary solution
00362 
00363         recordLength0 = m_emulateBxInEvent;
00364         recordLength1 = m_emulateBxInEvent;
00365 
00366     }
00367 
00368 
00369 
00370     if (m_verbosity) {
00371 
00372         LogDebug("L1GlobalTrigger")
00373                 << "\nTotal number of BX to emulate in the GT readout record: "
00374                 << m_emulateBxInEvent << " = " << "[" << minBxInEvent << ", " << maxBxInEvent
00375                 << "] BX\n"
00376                 << "\nNumber of BX for alternative 0:  " << recordLength0
00377                 << "\nNumber of BX for alternative 1:  " << recordLength1
00378                 << "\nActive boards in L1 GT DAQ record (hex format) = " << std::hex
00379                 << std::setw(sizeof(m_activeBoardsGtDaq) * 2) << std::setfill('0')
00380                 << m_activeBoardsGtDaq << std::dec << std::setfill(' ')
00381                 << "\nActive boards in L1 GT EVM record (hex format) = " << std::hex
00382                 << std::setw(sizeof(m_activeBoardsGtEvm) * 2) << std::setfill('0')
00383                 << m_activeBoardsGtEvm << std::dec << std::setfill(' ') << "\n"
00384                 << std::endl;
00385     }
00386 
00387     // get / update the board maps from the EventSetup
00388     // local cache & check on cacheIdentifier
00389 
00390     typedef std::vector<L1GtBoard>::const_iterator CItBoardMaps;
00391 
00392     unsigned long long l1GtBMCacheID = evSetup.get<L1GtBoardMapsRcd>().cacheIdentifier();
00393 
00394     if (m_l1GtBMCacheID != l1GtBMCacheID) {
00395 
00396         edm::ESHandle< L1GtBoardMaps > l1GtBM;
00397         evSetup.get< L1GtBoardMapsRcd >().get( l1GtBM );
00398         m_l1GtBM = l1GtBM.product();
00399 
00400         m_l1GtBMCacheID = l1GtBMCacheID;
00401 
00402     }
00403 
00404     // TODO need changes in CondFormats to cache the maps
00405     const std::vector<L1GtBoard>& boardMaps = m_l1GtBM->gtBoardMaps();
00406 
00407     // get / update the prescale factors from the EventSetup
00408     // local cache & check on cacheIdentifier
00409 
00410     unsigned long long l1GtPfAlgoCacheID =
00411         evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().cacheIdentifier();
00412 
00413     if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
00414 
00415         edm::ESHandle< L1GtPrescaleFactors > l1GtPfAlgo;
00416         evSetup.get< L1GtPrescaleFactorsAlgoTrigRcd >().get( l1GtPfAlgo );
00417         m_l1GtPfAlgo = l1GtPfAlgo.product();
00418 
00419         m_prescaleFactorsAlgoTrig = &(m_l1GtPfAlgo->gtPrescaleFactors());
00420 
00421         m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
00422 
00423     }
00424 
00425     unsigned long long l1GtPfTechCacheID =
00426         evSetup.get<L1GtPrescaleFactorsTechTrigRcd>().cacheIdentifier();
00427 
00428     if (m_l1GtPfTechCacheID != l1GtPfTechCacheID) {
00429 
00430         edm::ESHandle< L1GtPrescaleFactors > l1GtPfTech;
00431         evSetup.get< L1GtPrescaleFactorsTechTrigRcd >().get( l1GtPfTech );
00432         m_l1GtPfTech = l1GtPfTech.product();
00433 
00434         m_prescaleFactorsTechTrig = &(m_l1GtPfTech->gtPrescaleFactors());
00435 
00436         m_l1GtPfTechCacheID = l1GtPfTechCacheID;
00437 
00438     }
00439 
00440 
00441     // get / update the trigger mask from the EventSetup
00442     // local cache & check on cacheIdentifier
00443 
00444     unsigned long long l1GtTmAlgoCacheID =
00445         evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();
00446 
00447     if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
00448 
00449         edm::ESHandle< L1GtTriggerMask > l1GtTmAlgo;
00450         evSetup.get< L1GtTriggerMaskAlgoTrigRcd >().get( l1GtTmAlgo );
00451         m_l1GtTmAlgo = l1GtTmAlgo.product();
00452 
00453         m_triggerMaskAlgoTrig = m_l1GtTmAlgo->gtTriggerMask();
00454 
00455         m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
00456 
00457     }
00458 
00459 
00460     unsigned long long l1GtTmTechCacheID =
00461         evSetup.get<L1GtTriggerMaskTechTrigRcd>().cacheIdentifier();
00462 
00463     if (m_l1GtTmTechCacheID != l1GtTmTechCacheID) {
00464 
00465         edm::ESHandle< L1GtTriggerMask > l1GtTmTech;
00466         evSetup.get< L1GtTriggerMaskTechTrigRcd >().get( l1GtTmTech );
00467         m_l1GtTmTech = l1GtTmTech.product();
00468 
00469         m_triggerMaskTechTrig = m_l1GtTmTech->gtTriggerMask();
00470 
00471         m_l1GtTmTechCacheID = l1GtTmTechCacheID;
00472 
00473     }
00474 
00475     unsigned long long l1GtTmVetoAlgoCacheID =
00476         evSetup.get<L1GtTriggerMaskVetoAlgoTrigRcd>().cacheIdentifier();
00477 
00478     if (m_l1GtTmVetoAlgoCacheID != l1GtTmVetoAlgoCacheID) {
00479 
00480         edm::ESHandle< L1GtTriggerMask > l1GtTmVetoAlgo;
00481         evSetup.get< L1GtTriggerMaskVetoAlgoTrigRcd >().get( l1GtTmVetoAlgo );
00482         m_l1GtTmVetoAlgo = l1GtTmVetoAlgo.product();
00483 
00484         m_triggerMaskVetoAlgoTrig = m_l1GtTmVetoAlgo->gtTriggerMask();
00485 
00486         m_l1GtTmVetoAlgoCacheID = l1GtTmVetoAlgoCacheID;
00487 
00488     }
00489 
00490 
00491     unsigned long long l1GtTmVetoTechCacheID =
00492         evSetup.get<L1GtTriggerMaskVetoTechTrigRcd>().cacheIdentifier();
00493 
00494     if (m_l1GtTmVetoTechCacheID != l1GtTmVetoTechCacheID) {
00495 
00496         edm::ESHandle< L1GtTriggerMask > l1GtTmVetoTech;
00497         evSetup.get< L1GtTriggerMaskVetoTechTrigRcd >().get( l1GtTmVetoTech );
00498         m_l1GtTmVetoTech = l1GtTmVetoTech.product();
00499 
00500         m_triggerMaskVetoTechTrig = m_l1GtTmVetoTech->gtTriggerMask();
00501 
00502         m_l1GtTmVetoTechCacheID = l1GtTmVetoTechCacheID;
00503 
00504     }
00505 
00506     // loop over blocks in the GT DAQ record receiving data, count them if they are active
00507     // all board type are defined in CondFormats/L1TObjects/L1GtFwd
00508     // enum L1GtBoardType { GTFE, FDL, PSB, GMT, TCS, TIM };
00509     // &
00510     // set the active flag for each object type received from GMT and GCT
00511     // all objects in the GT system are defined in enum L1GtObject from
00512     // DataFormats/L1Trigger/L1GlobalTriggerReadoutSetupFwd
00513 
00514     int daqNrGtfeBoards = 0;
00515 
00516     int daqNrFdlBoards = 0;
00517     int daqNrPsbBoards = 0;
00518     int daqNrGmtBoards = 0;
00519     int daqNrTcsBoards = 0;
00520     int daqNrTimBoards = 0;
00521 
00522     //
00523     bool receiveMu = false;
00524     bool receiveNoIsoEG = false;
00525     bool receiveIsoEG = false;
00526     bool receiveCenJet = false;
00527     bool receiveForJet = false;
00528     bool receiveTauJet = false;
00529     bool receiveETM = false;
00530     bool receiveETT = false;
00531     bool receiveHTT = false;
00532     bool receiveHTM = false;
00533     bool receiveJetCounts = false;
00534     bool receiveHfBitCounts = false;
00535     bool receiveHfRingEtSums = false;
00536 
00537     bool receiveCastor = false;
00538     bool receiveBptx = false;
00539     bool receiveExternal = false;
00540 
00541     bool receiveTechTr = false;
00542 
00543     for (CItBoardMaps
00544             itBoard = boardMaps.begin();
00545             itBoard != boardMaps.end(); ++itBoard) {
00546 
00547         int iPosition = itBoard->gtPositionDaqRecord();
00548         if (iPosition > 0) {
00549 
00550             int iActiveBit = itBoard->gtBitDaqActiveBoards();
00551             bool activeBoard = false;
00552 
00553             if (iActiveBit >= 0) {
00554                 activeBoard = m_activeBoardsGtDaq & (1 << iActiveBit);
00555             }
00556 
00557             // use board if: in the record, but not in ActiveBoardsMap (iActiveBit < 0)
00558             //               in the record and ActiveBoardsMap, and active
00559             if ((iActiveBit < 0) || activeBoard) {
00560 
00561                 switch (itBoard->gtBoardType()) {
00562 
00563                     case GTFE: {
00564                             daqNrGtfeBoards++;
00565                         }
00566 
00567                         break;
00568                     case FDL: {
00569                             daqNrFdlBoards++;
00570                         }
00571 
00572                         break;
00573                     case PSB: {
00574                             daqNrPsbBoards++;
00575 
00576                             // get the objects coming to this PSB
00577                             std::vector<L1GtPsbQuad> quadInPsb = itBoard->gtQuadInPsb();
00578                             for (std::vector<L1GtPsbQuad>::const_iterator
00579                                     itQuad = quadInPsb.begin();
00580                                     itQuad != quadInPsb.end(); ++itQuad) {
00581 
00582                                 switch (*itQuad) {
00583 
00584                                     case TechTr: {
00585                                             receiveTechTr = true;
00586                                         }
00587 
00588                                         break;
00589                                     case NoIsoEGQ: {
00590                                             receiveNoIsoEG = true;
00591                                         }
00592 
00593                                         break;
00594                                     case IsoEGQ: {
00595                                             receiveIsoEG = true;
00596                                         }
00597 
00598                                         break;
00599                                     case CenJetQ: {
00600                                             receiveCenJet = true;
00601                                         }
00602 
00603                                         break;
00604                                     case ForJetQ: {
00605                                             receiveForJet = true;
00606                                         }
00607 
00608                                         break;
00609                                     case TauJetQ: {
00610                                             receiveTauJet = true;
00611                                         }
00612 
00613                                         break;
00614                                     case ESumsQ: {
00615                                             receiveETM = true;
00616                                             receiveETT = true;
00617                                             receiveHTT = true;
00618                                             receiveHTM = true;
00619                                         }
00620 
00621                                         break;
00622                                     case JetCountsQ: {
00623                                             receiveJetCounts = true;
00624                                         }
00625 
00626                                         break;
00627                                     case CastorQ: {
00628                                             receiveCastor = true;
00629                                         }
00630 
00631                                         break;
00632                                     case BptxQ: {
00633                                             receiveBptx = true;
00634                                         }
00635 
00636                                         break;
00637                                     case GtExternalQ: {
00638                                             receiveExternal = true;
00639                                         }
00640 
00641                                         break;
00642                                     case HfQ: {
00643                                             receiveHfBitCounts = true;
00644                                             receiveHfRingEtSums = true;
00645                                         }
00646 
00647                                         break;
00648                                         // FIXME add MIP/Iso bits
00649                                     default: {
00650                                             // do nothing
00651                                         }
00652 
00653                                         break;
00654                                 }
00655 
00656                             }
00657 
00658                         }
00659 
00660                         break;
00661                     case GMT: {
00662                             daqNrGmtBoards++;
00663                             receiveMu = true;
00664                         }
00665 
00666                         break;
00667                     case TCS: {
00668                             daqNrTcsBoards++;
00669                         }
00670 
00671                         break;
00672                     case TIM: {
00673                             daqNrTimBoards++;
00674                         }
00675 
00676                         break;
00677                     default: {
00678                             // do nothing, all blocks are given in GtBoardType enum
00679                         }
00680 
00681                         break;
00682                 }
00683             }
00684         }
00685 
00686     }
00687 
00688     // produce the L1GlobalTriggerReadoutRecord now, after we found how many
00689     // BxInEvent the record has and how many boards are active
00690     std::auto_ptr<L1GlobalTriggerReadoutRecord> gtDaqReadoutRecord(
00691         new L1GlobalTriggerReadoutRecord(
00692             m_emulateBxInEvent, daqNrFdlBoards, daqNrPsbBoards) );
00693 
00694 
00695     // * produce the L1GlobalTriggerEvmReadoutRecord
00696     std::auto_ptr<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord(
00697         new L1GlobalTriggerEvmReadoutRecord(m_emulateBxInEvent, daqNrFdlBoards) );
00698     // daqNrFdlBoards OK, just reserve memory at this point
00699 
00700     // * produce the L1GlobalTriggerObjectMapRecord
00701     std::auto_ptr<L1GlobalTriggerObjectMapRecord> gtObjectMapRecord(
00702         new L1GlobalTriggerObjectMapRecord() );
00703 
00704 
00705     // fill the boards not depending on the BxInEvent in the L1 GT DAQ record
00706     // GMT, PSB and FDL depend on BxInEvent
00707 
00708     // fill in emulator the same bunch crossing (12 bits - hardwired number of bits...)
00709     // and the same local bunch crossing for all boards
00710     int bxCross = iEvent.bunchCrossing();
00711     boost::uint16_t bxCrossHw = 0;
00712     if ((bxCross & 0xFFF) == bxCross) {
00713         bxCrossHw = static_cast<boost::uint16_t> (bxCross);
00714     }
00715     else {
00716         bxCrossHw = 0; // Bx number too large, set to 0!
00717         if (m_verbosity) {
00718 
00719             LogDebug("L1GlobalTrigger")
00720                 << "\nBunch cross number [hex] = " << std::hex << bxCross
00721                 << "\n  larger than 12 bits. Set to 0! \n" << std::dec
00722                 << std::endl;
00723         }
00724     }
00725 
00726 
00727     if (m_produceL1GtDaqRecord) {
00728 
00729         for (CItBoardMaps
00730                 itBoard = boardMaps.begin();
00731                 itBoard != boardMaps.end(); ++itBoard) {
00732 
00733             int iPosition = itBoard->gtPositionDaqRecord();
00734             if (iPosition > 0) {
00735 
00736                 int iActiveBit = itBoard->gtBitDaqActiveBoards();
00737                 bool activeBoard = false;
00738 
00739                 if (iActiveBit >= 0) {
00740                     activeBoard = m_activeBoardsGtDaq & (1 << iActiveBit);
00741                 }
00742 
00743                 // use board if: in the record, but not in ActiveBoardsMap (iActiveBit < 0)
00744                 //               in the record and ActiveBoardsMap, and active
00745                 if ((iActiveBit < 0) || activeBoard) {
00746 
00747                     switch (itBoard->gtBoardType()) {
00748 
00749                         case GTFE: {
00750                                 L1GtfeWord gtfeWordValue;
00751 
00752                                 gtfeWordValue.setBoardId( itBoard->gtBoardId() );
00753 
00754                                 // cast int to boost::uint16_t
00755                                 // there are normally 3 or 5 BxInEvent
00756                                 gtfeWordValue.setRecordLength(
00757                                     static_cast<boost::uint16_t>(recordLength0));
00758 
00759                                 gtfeWordValue.setRecordLength1(
00760                                     static_cast<boost::uint16_t>(recordLength1));
00761 
00762                                 // bunch crossing
00763                                 gtfeWordValue.setBxNr(bxCrossHw);
00764 
00765                                 // set the list of active boards
00766                                 gtfeWordValue.setActiveBoards(m_activeBoardsGtDaq);
00767 
00768                                 // set alternative for number of BX per board
00769                                 gtfeWordValue.setAltNrBxBoard(
00770                                     static_cast<boost::uint16_t> (m_alternativeNrBxBoardDaq));
00771 
00772                                 // set the TOTAL_TRIGNR as read from iEvent
00773                                 // TODO check again - PTC stuff
00774 
00775                                 gtfeWordValue.setTotalTriggerNr(
00776                                     static_cast<boost::uint32_t>(iEvent.id().event()));
00777 
00778                                 // ** fill L1GtfeWord in GT DAQ record
00779 
00780                                 gtDaqReadoutRecord->setGtfeWord(gtfeWordValue);
00781                             }
00782 
00783                             break;
00784                         case TCS: {
00785                                 // nothing
00786                             }
00787 
00788                             break;
00789                         case TIM: {
00790                                 // nothing
00791                             }
00792 
00793                             break;
00794                         default: {
00795                                 // do nothing, all blocks are given in GtBoardType enum
00796                             }
00797 
00798                             break;
00799                     }
00800                 }
00801             }
00802 
00803         }
00804 
00805     }
00806 
00807     // fill the boards not depending on the BxInEvent in the L1 GT EVM record
00808 
00809     int evmNrFdlBoards = 0;
00810 
00811     if (m_produceL1GtEvmRecord) {
00812 
00813         // get the length of the BST message from parameter set or from event setup
00814 
00815         int bstLengthBytes = 0;
00816 
00817         if (m_psBstLengthBytes < 0) {
00818             // length from event setup
00819             bstLengthBytes = static_cast<int> (m_bstLengthBytes);
00820 
00821         } else {
00822             // length from parameter set
00823             bstLengthBytes = m_psBstLengthBytes;
00824         }
00825 
00826         if (m_verbosity) {
00827 
00828             LogTrace("L1GlobalTrigger")
00829                 << "\n Length of BST message (in bytes): "
00830                 << bstLengthBytes << "\n"
00831                 << std::endl;
00832         }
00833 
00834         for (CItBoardMaps
00835                 itBoard = boardMaps.begin();
00836                 itBoard != boardMaps.end(); ++itBoard) {
00837 
00838             int iPosition = itBoard->gtPositionEvmRecord();
00839             if (iPosition > 0) {
00840 
00841                 int iActiveBit = itBoard->gtBitEvmActiveBoards();
00842                 bool activeBoard = false;
00843 
00844                 if (iActiveBit >= 0) {
00845                     activeBoard = m_activeBoardsGtEvm & (1 << iActiveBit);
00846                 }
00847 
00848                 // use board if: in the record, but not in ActiveBoardsMap (iActiveBit < 0)
00849                 //               in the record and ActiveBoardsMap, and active
00850                 if ((iActiveBit < 0) || activeBoard) {
00851 
00852                     switch (itBoard->gtBoardType()) {
00853 
00854                         case GTFE: {
00855                                 L1GtfeExtWord gtfeWordValue(bstLengthBytes);
00856 
00857                                 gtfeWordValue.setBoardId(itBoard->gtBoardId() );
00858 
00859                                 // cast int to boost::uint16_t
00860                                 // there are normally 3 or 5 BxInEvent
00861                                 gtfeWordValue.setRecordLength(
00862                                     static_cast<boost::uint16_t>(recordLength0));
00863 
00864                                 gtfeWordValue.setRecordLength1(
00865                                     static_cast<boost::uint16_t>(recordLength1));
00866 
00867                                 // bunch crossing
00868                                 gtfeWordValue.setBxNr(bxCrossHw);
00869 
00870                                 // set the list of active boards
00871                                 gtfeWordValue.setActiveBoards(m_activeBoardsGtEvm);
00872 
00873                                 // set alternative for number of BX per board
00874                                 gtfeWordValue.setAltNrBxBoard(
00875                                     static_cast<boost::uint16_t> (m_alternativeNrBxBoardEvm));
00876 
00877                                 // set the TOTAL_TRIGNR as read from iEvent
00878                                 // TODO check again - PTC stuff
00879 
00880                                 gtfeWordValue.setTotalTriggerNr(
00881                                     static_cast<boost::uint32_t>(iEvent.id().event()));
00882 
00883                                 // set the GPS time to the value read from Timestamp
00884                                 edm::TimeValue_t evTime = iEvent.time().value();
00885 
00886                                 gtfeWordValue.setGpsTime(evTime);
00887 
00888                                 //LogDebug("L1GlobalTrigger")
00889                                 //<< "\nEvent timestamp value [hex] = " << std::hex << evTime
00890                                 //<< "\nBST retrieved value [hex]   = " << gtfeWordValue.gpsTime()
00891                                 //<< std::dec << std::endl;
00892 
00893                                 // source of BST message: DDDD simulated data
00894                                 boost::uint16_t bstSourceVal = 0xDDDD;
00895                                 gtfeWordValue.setBstSource(bstSourceVal);
00896 
00897                                 // ** fill L1GtfeWord in GT EVM record
00898 
00899                                 gtEvmReadoutRecord->setGtfeWord(gtfeWordValue);
00900                             }
00901 
00902                             break;
00903                         case FDL: {
00904                                 evmNrFdlBoards++;
00905                             }
00906 
00907                             break;
00908                         case TCS: {
00909 
00910                                 L1TcsWord tcsWordValue;
00911 
00912                                 tcsWordValue.setBoardId( itBoard->gtBoardId() );
00913 
00914                                 // bunch crossing
00915                                 tcsWordValue.setBxNr(bxCrossHw);
00916 
00917                                 boost::uint16_t trigType = 0x5; // 0101 simulated event
00918                                 tcsWordValue.setTriggerType(trigType);
00919 
00920                                 // luminosity segment number
00921                                 tcsWordValue.setLuminositySegmentNr(
00922                                         static_cast<boost::uint16_t>(iEvent.luminosityBlock()));
00923 
00924 
00925                                 // set the Event_Nr as read from iEvent
00926                                 tcsWordValue.setEventNr(
00927                                     static_cast<boost::uint32_t>(iEvent.id().event()));
00928 
00929                                 // orbit number
00930                                 tcsWordValue.setOrbitNr(
00931                                         static_cast<boost::uint64_t>(iEvent.orbitNumber()) );
00932 
00933                                 // ** fill L1TcsWord in the EVM record
00934 
00935                                 gtEvmReadoutRecord->setTcsWord(tcsWordValue);
00936 
00937                             }
00938 
00939                             break;
00940                         case TIM: {
00941                                 // nothing
00942                             }
00943 
00944                             break;
00945                         default: {
00946                                 // do nothing, all blocks are given in GtBoardType enum
00947                             }
00948 
00949                             break;
00950                     }
00951                 }
00952             }
00953 
00954         }
00955 
00956     }
00957 
00958     // get the prescale factor set used in the actual luminosity segment
00959     int pfAlgoSetIndex = 0; // FIXME
00960     const std::vector<int>& prescaleFactorsAlgoTrig =
00961         (*m_prescaleFactorsAlgoTrig).at(pfAlgoSetIndex);
00962 
00963     int pfTechSetIndex = 0; // FIXME
00964     const std::vector<int>& prescaleFactorsTechTrig =
00965         (*m_prescaleFactorsTechTrig).at(pfTechSetIndex);
00966 
00967     //
00968 
00969     // loop over BxInEvent
00970     for (int iBxInEvent = minBxInEvent; iBxInEvent <= maxBxInEvent;
00971             ++iBxInEvent) {
00972 
00973         // * receive GCT object data via PSBs
00974         //LogDebug("L1GlobalTrigger")
00975         //<< "\nL1GlobalTrigger : receiving PSB data for bx = " << iBxInEvent << "\n"
00976         //<< std::endl;
00977 
00978         m_gtPSB->receiveGctObjectData(
00979             iEvent,
00980             m_caloGctInputTag, iBxInEvent,
00981             receiveNoIsoEG, m_nrL1NoIsoEG,
00982             receiveIsoEG, m_nrL1IsoEG,
00983             receiveCenJet, m_nrL1CenJet,
00984             receiveForJet, m_nrL1ForJet,
00985             receiveTauJet, m_nrL1TauJet,
00986             receiveETM, receiveETT, receiveHTT, receiveHTM,
00987             receiveJetCounts,
00988             receiveHfBitCounts,
00989             receiveHfRingEtSums);
00990 
00992         if (m_readTechnicalTriggerRecords) {
00993             m_gtPSB->receiveTechnicalTriggers(iEvent,
00994                     m_technicalTriggersInputTags, iBxInEvent, receiveTechTr,
00995                     m_numberTechnicalTriggers);
00996         }
00997 
00998         if (m_produceL1GtDaqRecord && m_writePsbL1GtDaqRecord) {
00999             m_gtPSB->fillPsbBlock(
01000                     iEvent, m_activeBoardsGtDaq, recordLength0, recordLength1,
01001                     m_alternativeNrBxBoardDaq, boardMaps, iBxInEvent, gtDaqReadoutRecord);
01002         }
01003 
01004         // * receive GMT object data via GTL
01005         //LogDebug("L1GlobalTrigger")
01006         //<< "\nL1GlobalTrigger : receiving GMT data for bx = " << iBxInEvent << "\n"
01007         //<< std::endl;
01008 
01009         m_gtGTL->receiveGmtObjectData(iEvent, m_muGmtInputTag, iBxInEvent,
01010                 receiveMu, m_nrL1Mu);
01011 
01012         // * run GTL
01013         //LogDebug("L1GlobalTrigger")
01014         //<< "\nL1GlobalTrigger : running GTL for bx = " << iBxInEvent << "\n"
01015         //<< std::endl;
01016 
01017         m_gtGTL->run(iEvent, evSetup, m_gtPSB,
01018             m_produceL1GtObjectMapRecord, iBxInEvent, gtObjectMapRecord,
01019             m_numberPhysTriggers,
01020             m_nrL1Mu,
01021             m_nrL1NoIsoEG,
01022             m_nrL1IsoEG,
01023             m_nrL1CenJet,
01024             m_nrL1ForJet,
01025             m_nrL1TauJet,
01026             m_nrL1JetCounts,
01027             m_ifMuEtaNumberBits,
01028             m_ifCaloEtaNumberBits);
01029 
01030         //LogDebug("L1GlobalTrigger")
01031         //<< "\n AlgorithmOR\n" << m_gtGTL->getAlgorithmOR() << "\n"
01032         //<< std::endl;
01033 
01034         // * run FDL
01035         //LogDebug("L1GlobalTrigger")
01036         //<< "\nL1GlobalTrigger : running FDL for bx = " << iBxInEvent << "\n"
01037         //<< std::endl;
01038 
01039         m_gtFDL->run(iEvent,
01040                 prescaleFactorsAlgoTrig, prescaleFactorsTechTrig,
01041                 m_triggerMaskAlgoTrig, m_triggerMaskTechTrig,
01042                 m_triggerMaskVetoAlgoTrig, m_triggerMaskVetoTechTrig,
01043                 boardMaps, m_emulateBxInEvent, iBxInEvent,
01044                 m_numberPhysTriggers, m_numberTechnicalTriggers,
01045                 m_numberDaqPartitions,
01046                 m_gtGTL, m_gtPSB,
01047                 pfAlgoSetIndex,
01048                 pfTechSetIndex);
01049 
01050         if (m_produceL1GtDaqRecord && ( daqNrFdlBoards > 0 )) {
01051             m_gtFDL->fillDaqFdlBlock(iBxInEvent,
01052                     m_activeBoardsGtDaq, recordLength0, recordLength1, m_alternativeNrBxBoardDaq,
01053                     boardMaps, gtDaqReadoutRecord);
01054         }
01055 
01056 
01057         if (m_produceL1GtEvmRecord && ( evmNrFdlBoards > 0 )) {
01058             m_gtFDL->fillEvmFdlBlock(iBxInEvent,
01059                     m_activeBoardsGtEvm, recordLength0, recordLength1, m_alternativeNrBxBoardEvm,
01060                     boardMaps, gtEvmReadoutRecord);
01061         }
01062 
01063         // reset
01064         m_gtPSB->reset();
01065         m_gtGTL->reset();
01066         m_gtFDL->reset();
01067 
01068         //LogDebug("L1GlobalTrigger") << "\n Reset PSB, GTL, FDL\n" << std::endl;
01069 
01070     }
01071 
01072 
01073     if ( receiveMu ) {
01074 
01075 
01076         //LogDebug("L1GlobalTrigger")
01077         //<< "\n**** "
01078         //<< "\n  Persistent reference for L1MuGMTReadoutCollection with input tag: "
01079         //<< m_muGmtInputTag
01080         //<< "\n**** \n"
01081         //<< std::endl;
01082 
01083         // get L1MuGMTReadoutCollection reference and set it in GT record
01084 
01085         edm::Handle<L1MuGMTReadoutCollection> gmtRcHandle;
01086         iEvent.getByLabel(m_muGmtInputTag, gmtRcHandle);
01087 
01088 
01089 
01090         if (!gmtRcHandle.isValid()) {
01091             if (m_verbosity) {
01092                 edm::LogWarning("L1GlobalTrigger")
01093                         << "\nWarning: L1MuGMTReadoutCollection with input tag " << m_muGmtInputTag
01094                         << "\nrequested in configuration, but not found in the event.\n"
01095                         << std::endl;
01096             }
01097         } else {
01098 
01099             gtDaqReadoutRecord->setMuCollectionRefProd(gmtRcHandle);
01100 
01101         }
01102 
01103     }
01104 
01105     if ( m_verbosity && m_isDebugEnabled ) {
01106 
01107         std::ostringstream myCoutStream;
01108         gtDaqReadoutRecord->print(myCoutStream);
01109         LogTrace("L1GlobalTrigger")
01110         << "\n The following L1 GT DAQ readout record was produced:\n"
01111         << myCoutStream.str() << "\n"
01112         << std::endl;
01113 
01114         myCoutStream.str("");
01115         myCoutStream.clear();
01116 
01117         gtEvmReadoutRecord->print(myCoutStream);
01118         LogTrace("L1GlobalTrigger")
01119         << "\n The following L1 GT EVM readout record was produced:\n"
01120         << myCoutStream.str() << "\n"
01121         << std::endl;
01122 
01123         myCoutStream.str("");
01124         myCoutStream.clear();
01125 
01126         const std::vector<L1GlobalTriggerObjectMap> objMapVec =
01127             gtObjectMapRecord->gtObjectMap();
01128 
01129         for (std::vector<L1GlobalTriggerObjectMap>::const_iterator
01130                 it = objMapVec.begin(); it != objMapVec.end(); ++it) {
01131 
01132             (*it).print(myCoutStream);
01133 
01134         }
01135 
01136 
01137         LogDebug("L1GlobalTrigger")
01138         << "Test gtObjectMapRecord in L1GlobalTrigger \n\n" << myCoutStream.str() << "\n\n"
01139         << std::endl;
01140 
01141         myCoutStream.str("");
01142         myCoutStream.clear();
01143 
01144     }
01145 
01146     // **
01147     // register products
01148     if (m_produceL1GtDaqRecord) {
01149         iEvent.put( gtDaqReadoutRecord );
01150     }
01151 
01152     if (m_produceL1GtEvmRecord) {
01153         iEvent.put( gtEvmReadoutRecord );
01154     }
01155 
01156     if (m_produceL1GtObjectMapRecord) {
01157         iEvent.put( gtObjectMapRecord );
01158     }
01159 
01160 }
01161 
01162 // static data members
01163