Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:32

0001 /*
0002 /P.Katsoulis
0003 /G.Karathanasis     
0004 */
0005 
0006 #include "L1TBMTFAlgoSelector.h"
0007 
0008 //The Constructor defines what to be consumed and produced
0009 dqmBmtfAlgoSelector::L1TBMTFAlgoSelector::L1TBMTFAlgoSelector(const edm::ParameterSet &ps) {
0010   bmtfKalmanToken = consumes<l1t::RegionalMuonCandBxCollection>(ps.getParameter<edm::InputTag>("bmtfKalman"));
0011   bmtfLegacyToken = consumes<l1t::RegionalMuonCandBxCollection>(ps.getParameter<edm::InputTag>("bmtfLegacy"));
0012   fedToken = consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("feds"));
0013 
0014   produces<l1t::RegionalMuonCandBxCollection>("BMTF");
0015   produces<l1t::RegionalMuonCandBxCollection>("BMTF2");
0016 }
0017 
0018 dqmBmtfAlgoSelector::L1TBMTFAlgoSelector::~L1TBMTFAlgoSelector() {}
0019 
0020 void dqmBmtfAlgoSelector::L1TBMTFAlgoSelector::produce(edm::Event &eve, const edm::EventSetup &eveSetup) {
0021   //Declare the Handlers
0022   edm::Handle<FEDRawDataCollection> feds;
0023   eve.getByToken(fedToken, feds);
0024   edm::Handle<l1t::RegionalMuonCandBxCollection> bmtfKalman;
0025   eve.getByToken(bmtfKalmanToken, bmtfKalman);
0026   edm::Handle<l1t::RegionalMuonCandBxCollection> bmtfLegacy;
0027   eve.getByToken(bmtfLegacyToken, bmtfLegacy);
0028 
0029   //----> Make RegMuonCand Copies
0030   auto *bmtfKalman_copy = new l1t::RegionalMuonCandBxCollection(*bmtfKalman);
0031   auto *bmtfLegacy_copy = new l1t::RegionalMuonCandBxCollection(*bmtfLegacy);
0032   edm::LogInfo("L1TDQM") << "copy RegionalMuonCandBxCollections created";
0033   edm::LogInfo("L1TDQM") << "bmtfKalman_copy address: " << bmtfKalman_copy;
0034   edm::LogInfo("L1TDQM") << "bmtfLegacy_copy address: " << bmtfLegacy_copy;
0035 
0036   //-----> Get the fw-ver
0037   int nonEmptyFed = 0;
0038   if (feds->FEDData(1376).size() > 0)
0039     nonEmptyFed = 1376;
0040   else if (feds->FEDData(1377).size() > 0)
0041     nonEmptyFed = 1377;
0042   else {
0043     edm::LogError("L1TDQM") << "[L1TBMTFAlgoSelector] Both BMTF feds (1376, 1377) seem empty."
0044                             << "Using Default Configuration."
0045                             << "Will be wrong if this is Kalman triggering and ZS is enabled";
0046     //Define the default configuration
0047     std::unique_ptr<l1t::RegionalMuonCandBxCollection> bmtfTriggering, bmtfSecondary;
0048     bmtfTriggering.reset(bmtfLegacy_copy);
0049     bmtfSecondary.reset(bmtfKalman_copy);
0050     //Print in log the addresses
0051     edm::LogInfo("L1TDQM") << "Triggering and Secondary pointers filled:";
0052     edm::LogInfo("L1TDQM") << "bmtfTriggering address: " << bmtfTriggering.get();
0053     edm::LogInfo("L1TDQM") << "bmtfSecondary address: " << bmtfSecondary.get();
0054     //Produce the products
0055     eve.put(std::move(bmtfTriggering), "BMTF");
0056     eve.put(std::move(bmtfSecondary), "BMTF2");
0057     return;
0058   }
0059 
0060   const FEDRawData &l1tRcd = feds->FEDData(nonEmptyFed);
0061   ;
0062   edm::LogInfo("L1TDQM") << "L1T Rcd taken from the FEDData.";
0063   edm::LogInfo("L1TDQM") << "l1tRcd.size=" << l1tRcd.size() << "   for fed:" << nonEmptyFed;
0064 
0065   const unsigned char *data = l1tRcd.data();
0066   FEDHeader header(data);
0067   edm::LogInfo("L1TDQM") << "header and data extracted from the Rcd.";
0068 
0069   amc13::Packet packet;
0070   if (!packet.parse((const uint64_t *)data,
0071                     (const uint64_t *)(data + 8),
0072                     (l1tRcd.size()) / 8,
0073                     header.lvl1ID(),
0074                     header.bxID(),
0075                     false,
0076                     false)) {
0077     edm::LogError("L1TDQM") << "Could not extract AMC13 Packet.";
0078     return;
0079   }
0080 
0081   edm::LogInfo("L1TDQM") << "AMC13-packet-payload size = " << packet.payload().size();
0082   unsigned algo_ver;
0083   if (!packet.payload().empty()) {
0084     auto payload64 = (packet.payload().at(0)).data();
0085     const uint32_t *start = (const uint32_t *)payload64.get();
0086     const uint32_t *end = start + (packet.payload().at(0).size() * 2);
0087 
0088     l1t::MP7Payload payload(start, end, false);
0089     algo_ver = payload.getAlgorithmFWVersion();
0090 
0091     edm::LogInfo("L1TDQM") << "algo-ver = " << algo_ver << std::endl;
0092   } else {
0093     edm::LogError("L1TDQM") << "amc13 payload is empty, cannot extract AMC13 Packet...";
0094     return;
0095   }
0096 
0097   //----->Make the Decision which Algo Triggers
0098   std::unique_ptr<l1t::RegionalMuonCandBxCollection> bmtfTriggering, bmtfSecondary;
0099   if (algo_ver >= 2499805536) {  //95000160(hex)
0100     // kalman triggers
0101     bmtfTriggering.reset(bmtfKalman_copy);
0102     bmtfSecondary.reset(bmtfLegacy_copy);
0103   } else {
0104     // legacy triggers
0105     bmtfTriggering.reset(bmtfLegacy_copy);
0106     bmtfSecondary.reset(bmtfKalman_copy);
0107   }
0108 
0109   edm::LogInfo("L1TDQM") << "Triggering and Secondary pointers filled:";
0110   edm::LogInfo("L1TDQM") << "bmtfTriggering address: " << bmtfTriggering.get();
0111   edm::LogInfo("L1TDQM") << "bmtfSecondary address: " << bmtfSecondary.get();
0112 
0113   eve.put(std::move(bmtfTriggering), "BMTF");
0114   eve.put(std::move(bmtfSecondary), "BMTF2");
0115 
0116   return;
0117 }
0118 
0119 using namespace dqmBmtfAlgoSelector;
0120 DEFINE_FWK_MODULE(L1TBMTFAlgoSelector);