Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002  * \class L1GtPackUnpackAnalyzer
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 "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPackUnpackAnalyzer.h"
0017 
0018 // system include files
0019 #include <memory>
0020 
0021 // user include files
0022 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
0023 
0024 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0025 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0026 
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 
0029 // constructor(s)
0030 L1GtPackUnpackAnalyzer::L1GtPackUnpackAnalyzer(const edm::ParameterSet& parSet) {
0031   // input tag for the initial GT DAQ record:
0032   m_initialDaqGtInputTag = parSet.getParameter<edm::InputTag>("InitialDaqGtInputTag");
0033 
0034   // input tag for the initial GMT readout collection:
0035   m_initialMuGmtInputTag = parSet.getParameter<edm::InputTag>("InitialMuGmtInputTag");
0036 
0037   // input tag for the final GT DAQ and GMT records:
0038   m_finalGtGmtInputTag = parSet.getParameter<edm::InputTag>("FinalGtGmtInputTag");
0039 
0040   edm::LogInfo("L1GtPackUnpackAnalyzer") << "\nInput tag for the initial GT DAQ record:          "
0041                                          << m_initialDaqGtInputTag << " \n"
0042                                          << "\nInput tag for the initial GMT readout collection: "
0043                                          << m_initialMuGmtInputTag << " \n"
0044                                          << "\nInput tag for the final GT DAQ and GMT records:   "
0045                                          << m_finalGtGmtInputTag << " \n"
0046                                          << std::endl;
0047 }
0048 
0049 // destructor
0050 L1GtPackUnpackAnalyzer::~L1GtPackUnpackAnalyzer() {
0051   // empty
0052 }
0053 
0054 // member functions
0055 
0056 // method called once each job just before starting event loop
0057 void L1GtPackUnpackAnalyzer::beginJob() {
0058   // empty
0059 }
0060 
0061 // GT comparison
0062 void L1GtPackUnpackAnalyzer::analyzeGT(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0063   // define an output stream to print into
0064   // it can then be directed to whatever log level is desired
0065   std::ostringstream myCoutStream;
0066 
0067   // get the initial L1GlobalTriggerReadoutRecord
0068   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordInitial;
0069   iEvent.getByLabel(m_initialDaqGtInputTag, gtReadoutRecordInitial);
0070 
0071   if (!gtReadoutRecordInitial.isValid()) {
0072     edm::LogError("L1GtTrigReport") << "Initial L1GlobalTriggerReadoutRecord with input tag \n  "
0073                                     << m_initialDaqGtInputTag << " not found.\n\n"
0074                                     << std::endl;
0075     return;
0076   }
0077 
0078   // get the final L1GlobalTriggerReadoutRecord
0079   edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordFinal;
0080   iEvent.getByLabel(m_finalGtGmtInputTag, gtReadoutRecordFinal);
0081 
0082   if (!gtReadoutRecordFinal.isValid()) {
0083     edm::LogError("L1GtTrigReport") << "Final L1GlobalTriggerReadoutRecord with input tag \n  " << m_finalGtGmtInputTag
0084                                     << " not found.\n\n"
0085                                     << std::endl;
0086     return;
0087   }
0088 
0089   // compare GTFE
0090   const L1GtfeWord& gtfeWordInitial = gtReadoutRecordInitial->gtfeWord();
0091   const L1GtfeWord& gtfeWordFinal = gtReadoutRecordFinal->gtfeWord();
0092 
0093   if (gtfeWordInitial == gtfeWordFinal) {
0094     myCoutStream << "\nInitial and final GTFE blocks: identical.\n";
0095     gtfeWordInitial.print(myCoutStream);
0096   } else {
0097     myCoutStream << "\nInitial and final GTFE blocks: different.\n";
0098 
0099     myCoutStream << "\nInitial GTFE block\n";
0100     gtfeWordInitial.print(myCoutStream);
0101 
0102     myCoutStream << "\nFinal GTFE block\n";
0103     gtfeWordFinal.print(myCoutStream);
0104   }
0105 
0106   edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
0107 
0108   myCoutStream.str("");
0109   myCoutStream.clear();
0110 
0111   // FDL comparison
0112   const std::vector<L1GtFdlWord>& gtFdlVectorInitial = gtReadoutRecordInitial->gtFdlVector();
0113   const std::vector<L1GtFdlWord>& gtFdlVectorFinal = gtReadoutRecordFinal->gtFdlVector();
0114 
0115   int gtFdlVectorInitialSize = gtFdlVectorInitial.size();
0116   int gtFdlVectorFinalSize = gtFdlVectorFinal.size();
0117 
0118   if (gtFdlVectorInitialSize == gtFdlVectorFinalSize) {
0119     myCoutStream << "\nInitial and final FDL vector size: identical.\n";
0120     myCoutStream << "  Size: " << gtFdlVectorInitialSize << std::endl;
0121 
0122     for (int iFdl = 0; iFdl < gtFdlVectorInitialSize; ++iFdl) {
0123       const L1GtFdlWord& fdlWordInitial = gtFdlVectorInitial[iFdl];
0124       const L1GtFdlWord& fdlWordFinal = gtFdlVectorFinal[iFdl];
0125 
0126       if (fdlWordInitial == fdlWordFinal) {
0127         myCoutStream << "\nInitial and final FDL blocks: identical.\n";
0128         fdlWordInitial.print(myCoutStream);
0129 
0130       } else {
0131         myCoutStream << "\nInitial and final FDL blocks: different.\n";
0132 
0133         myCoutStream << "\nInitial FDL block\n";
0134         fdlWordInitial.print(myCoutStream);
0135 
0136         myCoutStream << "\nFinal FDL block\n";
0137         fdlWordFinal.print(myCoutStream);
0138       }
0139     }
0140   } else {
0141     myCoutStream << "\nInitial and final FDL vector size: different.\n";
0142     myCoutStream << "  Initial size: " << gtFdlVectorInitialSize << std::endl;
0143     myCoutStream << "  Final size: " << gtFdlVectorFinalSize << std::endl;
0144   }
0145 
0146   edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
0147 
0148   myCoutStream.str("");
0149   myCoutStream.clear();
0150 
0151   // PSB comparison
0152   const std::vector<L1GtPsbWord>& gtPsbVectorInitial = gtReadoutRecordInitial->gtPsbVector();
0153   const std::vector<L1GtPsbWord>& gtPsbVectorFinal = gtReadoutRecordFinal->gtPsbVector();
0154 
0155   int gtPsbVectorInitialSize = gtPsbVectorInitial.size();
0156   int gtPsbVectorFinalSize = gtPsbVectorFinal.size();
0157 
0158   if (gtPsbVectorInitialSize == gtPsbVectorFinalSize) {
0159     myCoutStream << "\nInitial and final PSB vector size: identical.\n";
0160     myCoutStream << "  Size: " << gtPsbVectorInitialSize << std::endl;
0161 
0162     // the order of PSB block in the gtPsbVector is different in emulator and unpacker
0163     // TODO can be fixed?
0164     for (int iPsb = 0; iPsb < gtPsbVectorInitialSize; ++iPsb) {
0165       const L1GtPsbWord& psbWordInitial = gtPsbVectorInitial[iPsb];
0166       const uint16_t boardIdInitial = psbWordInitial.boardId();
0167       const int bxInEventInitial = psbWordInitial.bxInEvent();
0168 
0169       // search the corresponding PSB in the final record using the
0170       // BoardId and the BxInEvent
0171 
0172       bool foundPSB = false;
0173 
0174       for (int iPsbF = 0; iPsbF < gtPsbVectorFinalSize; ++iPsbF) {
0175         const L1GtPsbWord& psbWordFinal = gtPsbVectorFinal[iPsbF];
0176         const uint16_t boardIdFinal = psbWordFinal.boardId();
0177         const int bxInEventFinal = psbWordFinal.bxInEvent();
0178 
0179         if ((boardIdFinal == boardIdInitial) && (bxInEventInitial == bxInEventFinal)) {
0180           foundPSB = true;
0181 
0182           // compare the boards
0183           if (psbWordInitial == psbWordFinal) {
0184             myCoutStream << "\nInitial and final PSB blocks: identical.\n";
0185             psbWordInitial.print(myCoutStream);
0186 
0187           } else {
0188             myCoutStream << "\nInitial and final PSB blocks: different.\n";
0189 
0190             myCoutStream << "\nInitial PSB block\n";
0191             psbWordInitial.print(myCoutStream);
0192 
0193             myCoutStream << "\nFinal PSB block\n";
0194             psbWordFinal.print(myCoutStream);
0195           }
0196         }
0197       }
0198 
0199       if (!foundPSB) {
0200         myCoutStream << "\nNo final PSB with boardID = " << boardIdInitial << " and BxINEvent = " << bxInEventInitial
0201                      << " was found"
0202                      << "\nInitial and final PSB vectors: different";
0203       }
0204     }
0205   } else {
0206     myCoutStream << "\nInitial and final PSB vector size: different.\n";
0207     myCoutStream << "  Initial size: " << gtPsbVectorInitialSize << std::endl;
0208     myCoutStream << "  Final size: " << gtPsbVectorFinalSize << std::endl;
0209   }
0210 
0211   edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
0212 
0213   myCoutStream.str("");
0214   myCoutStream.clear();
0215 
0216   // get reference to muon collection
0217   const edm::RefProd<L1MuGMTReadoutCollection> muCollRefProdInitial = gtReadoutRecordInitial->muCollectionRefProd();
0218 
0219   const edm::RefProd<L1MuGMTReadoutCollection> muCollRefProdFinal = gtReadoutRecordFinal->muCollectionRefProd();
0220 
0221   if (muCollRefProdInitial == muCollRefProdFinal) {
0222     myCoutStream << "\nInitial and final RefProd<L1MuGMTReadoutCollection>: identical.\n";
0223   } else {
0224     myCoutStream << "\nInitial and final RefProd<L1MuGMTReadoutCollection>: different.\n";
0225   }
0226 
0227   edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
0228 
0229   myCoutStream.str("");
0230   myCoutStream.clear();
0231 }
0232 
0233 // GMT comparison
0234 void L1GtPackUnpackAnalyzer::analyzeGMT(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0235   // define an output stream to print into
0236   // it can then be directed to whatever log level is desired
0237   std::ostringstream myCoutStream;
0238 
0239   // get initial L1MuGMTReadoutCollection
0240   edm::Handle<L1MuGMTReadoutCollection> gmtRcInitial;
0241   iEvent.getByLabel(m_initialMuGmtInputTag, gmtRcInitial);
0242 
0243   if (!gmtRcInitial.isValid()) {
0244     edm::LogError("L1GtPackUnpackAnalyzer")
0245         << "Initial L1MuGMTReadoutCollection with input tag \n  " << m_initialMuGmtInputTag << " not found.\n\n"
0246         << std::endl;
0247     return;
0248   }
0249 
0250   std::vector<L1MuGMTReadoutRecord> muRecordsInitial = gmtRcInitial->getRecords();
0251 
0252   // get final L1MuGMTReadoutCollection
0253   edm::Handle<L1MuGMTReadoutCollection> gmtRcFinal;
0254   iEvent.getByLabel(m_finalGtGmtInputTag, gmtRcFinal);
0255 
0256   if (!gmtRcFinal.isValid()) {
0257     edm::LogError("L1GtPackUnpackAnalyzer")
0258         << "Final L1MuGMTReadoutCollection with input tag \n  " << m_finalGtGmtInputTag << " not found.\n\n"
0259         << std::endl;
0260     return;
0261   }
0262 
0263   std::vector<L1MuGMTReadoutRecord> muRecordsFinal = gmtRcFinal->getRecords();
0264 
0265   int muRecordsInitialSize = muRecordsInitial.size();
0266   int muRecordsFinalSize = muRecordsFinal.size();
0267 
0268   if (muRecordsInitialSize == muRecordsFinalSize) {
0269     myCoutStream << "\nInitial and final L1MuGMTReadoutCollection record size: identical.\n";
0270     myCoutStream << "  Size: " << muRecordsInitialSize << std::endl;
0271   } else {
0272     myCoutStream << "\nInitial and final  L1MuGMTReadoutCollection record size: different.\n";
0273     myCoutStream << "  Initial size: " << muRecordsInitialSize << std::endl;
0274     myCoutStream << "  Final size: " << muRecordsFinalSize << std::endl;
0275   }
0276 
0277   edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
0278 
0279   myCoutStream.str("");
0280   myCoutStream.clear();
0281 }
0282 
0283 // analyze each event: event loop
0284 void L1GtPackUnpackAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0285   // GT DAQ comparison
0286   analyzeGT(iEvent, evSetup);
0287 
0288   // GMT comparison
0289   analyzeGMT(iEvent, evSetup);
0290 }
0291 
0292 // method called once each job just after ending the event loop
0293 void L1GtPackUnpackAnalyzer::endJob() {
0294   // empty
0295 }