CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/L1Trigger/GlobalTriggerAnalyzer/src/L1GtPackUnpackAnalyzer.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtPackUnpackAnalyzer.h"
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00025 
00026 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00027 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00028 
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 
00031 
00032 
00033 // constructor(s)
00034 L1GtPackUnpackAnalyzer::L1GtPackUnpackAnalyzer(const edm::ParameterSet& parSet)
00035 {
00036 
00037     // input tag for the initial GT DAQ record: 
00038     m_initialDaqGtInputTag = parSet.getParameter<edm::InputTag>("InitialDaqGtInputTag");
00039 
00040     // input tag for the initial GMT readout collection: 
00041     m_initialMuGmtInputTag = parSet.getParameter<edm::InputTag>("InitialMuGmtInputTag");
00042 
00043     // input tag for the final GT DAQ and GMT records: 
00044     m_finalGtGmtInputTag = parSet.getParameter<edm::InputTag>("FinalGtGmtInputTag");
00045     
00046 
00047     edm::LogInfo("L1GtPackUnpackAnalyzer")
00048     << "\nInput tag for the initial GT DAQ record:          "
00049     << m_initialDaqGtInputTag << " \n"
00050     << "\nInput tag for the initial GMT readout collection: "
00051     << m_initialMuGmtInputTag << " \n"
00052     << "\nInput tag for the final GT DAQ and GMT records:   "
00053     << m_finalGtGmtInputTag << " \n"
00054     << std::endl;
00055 
00056 }
00057 
00058 // destructor
00059 L1GtPackUnpackAnalyzer::~L1GtPackUnpackAnalyzer()
00060 {   
00061     // empty   
00062 }
00063 
00064 // member functions
00065 
00066 // method called once each job just before starting event loop
00067 void L1GtPackUnpackAnalyzer::beginJob()
00068 {
00069     // empty
00070 }
00071 
00072 
00073 // GT comparison
00074 void L1GtPackUnpackAnalyzer::analyzeGT(const edm::Event& iEvent, const edm::EventSetup& evSetup)
00075 {
00076 
00077     // define an output stream to print into
00078     // it can then be directed to whatever log level is desired
00079     std::ostringstream myCoutStream;
00080 
00081     // get the initial L1GlobalTriggerReadoutRecord
00082     edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordInitial;
00083     iEvent.getByLabel(m_initialDaqGtInputTag, gtReadoutRecordInitial);
00084 
00085     if (!gtReadoutRecordInitial.isValid()) {
00086         edm::LogError("L1GtTrigReport")
00087                 << "Initial L1GlobalTriggerReadoutRecord with input tag \n  "
00088                 << m_initialDaqGtInputTag << " not found.\n\n"
00089                 << std::endl;
00090         return;
00091                
00092     }
00093     
00094     // get the final L1GlobalTriggerReadoutRecord
00095     edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordFinal;
00096     iEvent.getByLabel(m_finalGtGmtInputTag, gtReadoutRecordFinal);
00097 
00098     if (!gtReadoutRecordFinal.isValid()) {
00099         edm::LogError("L1GtTrigReport")
00100                 << "Final L1GlobalTriggerReadoutRecord with input tag \n  "
00101                 << m_finalGtGmtInputTag << " not found.\n\n"
00102                 << std::endl;
00103         return;
00104                
00105     }
00106     
00107     // compare GTFE
00108     const L1GtfeWord& gtfeWordInitial = gtReadoutRecordInitial->gtfeWord();
00109     const L1GtfeWord& gtfeWordFinal = gtReadoutRecordFinal->gtfeWord();
00110    
00111     if (gtfeWordInitial == gtfeWordFinal) {
00112         myCoutStream << "\nInitial and final GTFE blocks: identical.\n";
00113         gtfeWordInitial.print(myCoutStream);       
00114     } else {
00115         myCoutStream << "\nInitial and final GTFE blocks: different.\n";
00116 
00117         myCoutStream << "\nInitial GTFE block\n";
00118         gtfeWordInitial.print(myCoutStream);       
00119 
00120         myCoutStream << "\nFinal GTFE block\n";
00121         gtfeWordFinal.print(myCoutStream);       
00122         
00123     }
00124     
00125     edm::LogInfo("L1GtPackUnpackAnalyzer")
00126     << myCoutStream.str()
00127     << std::endl;
00128 
00129 
00130     myCoutStream.str("");
00131     myCoutStream.clear();
00132 
00133     // FDL comparison
00134     const std::vector<L1GtFdlWord>& gtFdlVectorInitial = gtReadoutRecordInitial->gtFdlVector();
00135     const std::vector<L1GtFdlWord>& gtFdlVectorFinal = gtReadoutRecordFinal->gtFdlVector();
00136        
00137     int gtFdlVectorInitialSize = gtFdlVectorInitial.size();
00138     int gtFdlVectorFinalSize = gtFdlVectorFinal.size();
00139     
00140     if (gtFdlVectorInitialSize == gtFdlVectorFinalSize) {
00141         myCoutStream << "\nInitial and final FDL vector size: identical.\n";
00142         myCoutStream << "  Size: " << gtFdlVectorInitialSize << std::endl;
00143         
00144         for (int iFdl = 0; iFdl < gtFdlVectorInitialSize; ++iFdl) {
00145             
00146             const L1GtFdlWord& fdlWordInitial = gtFdlVectorInitial[iFdl];
00147             const L1GtFdlWord& fdlWordFinal = gtFdlVectorFinal[iFdl];
00148             
00149             if (fdlWordInitial == fdlWordFinal) {
00150                 myCoutStream << "\nInitial and final FDL blocks: identical.\n";
00151                 fdlWordInitial.print(myCoutStream); 
00152                 
00153             } else {
00154                 myCoutStream << "\nInitial and final FDL blocks: different.\n";
00155 
00156                 myCoutStream << "\nInitial FDL block\n";
00157                 fdlWordInitial.print(myCoutStream);       
00158 
00159                 myCoutStream << "\nFinal FDL block\n";
00160                 fdlWordFinal.print(myCoutStream);       
00161                                
00162             }
00163             
00164         }
00165     }
00166     else {
00167         myCoutStream << "\nInitial and final FDL vector size: different.\n";
00168         myCoutStream << "  Initial size: " << gtFdlVectorInitialSize << std::endl;
00169         myCoutStream << "  Final size: " << gtFdlVectorFinalSize << std::endl;
00170 
00171     }
00172 
00173     edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
00174 
00175     myCoutStream.str("");
00176     myCoutStream.clear();
00177    
00178     
00179     // PSB comparison
00180     const std::vector<L1GtPsbWord>& gtPsbVectorInitial = gtReadoutRecordInitial->gtPsbVector();
00181     const std::vector<L1GtPsbWord>& gtPsbVectorFinal = gtReadoutRecordFinal->gtPsbVector();
00182        
00183     int gtPsbVectorInitialSize = gtPsbVectorInitial.size();
00184     int gtPsbVectorFinalSize = gtPsbVectorFinal.size();
00185     
00186     if (gtPsbVectorInitialSize == gtPsbVectorFinalSize) {
00187         myCoutStream << "\nInitial and final PSB vector size: identical.\n";
00188         myCoutStream << "  Size: " << gtPsbVectorInitialSize << std::endl;
00189 
00190         // the order of PSB block in the gtPsbVector is different in emulator and unpacker
00191         // TODO can be fixed?
00192         for (int iPsb = 0; iPsb < gtPsbVectorInitialSize; ++iPsb) {
00193             
00194             const L1GtPsbWord& psbWordInitial = gtPsbVectorInitial[iPsb];
00195             const boost::uint16_t boardIdInitial = psbWordInitial.boardId();
00196             const int bxInEventInitial = psbWordInitial.bxInEvent();
00197             
00198             // search the corresponding PSB in the final record using the 
00199             // BoardId and the BxInEvent  
00200             
00201             bool foundPSB = false;
00202             
00203             for (int iPsbF = 0; iPsbF < gtPsbVectorFinalSize; ++iPsbF) {
00204 
00205                 const L1GtPsbWord& psbWordFinal = gtPsbVectorFinal[iPsbF];
00206                 const boost::uint16_t boardIdFinal = psbWordFinal.boardId();
00207                 const int bxInEventFinal = psbWordFinal.bxInEvent();
00208                 
00209                 if ((boardIdFinal == boardIdInitial) && (bxInEventInitial
00210                         == bxInEventFinal)) {
00211                     
00212                     foundPSB = true;
00213                     
00214                     // compare the boards
00215                     if (psbWordInitial == psbWordFinal) {
00216                         myCoutStream
00217                                 << "\nInitial and final PSB blocks: identical.\n";
00218                         psbWordInitial.print(myCoutStream);
00219 
00220                     }
00221                     else {
00222                         myCoutStream
00223                                 << "\nInitial and final PSB blocks: different.\n";
00224 
00225                         myCoutStream << "\nInitial PSB block\n";
00226                         psbWordInitial.print(myCoutStream);
00227 
00228                         myCoutStream << "\nFinal PSB block\n";
00229                         psbWordFinal.print(myCoutStream);
00230 
00231                     }
00232                 }
00233 
00234             }
00235             
00236             if (!foundPSB) {
00237                 myCoutStream
00238                         << "\nNo final PSB with boardID = " << boardIdInitial
00239                         << " and BxINEvent = " << bxInEventInitial << " was found"
00240                         << "\nInitial and final PSB vectors: different";
00241                 
00242             }
00243 
00244         }
00245     }
00246     else {
00247         myCoutStream << "\nInitial and final PSB vector size: different.\n";
00248         myCoutStream << "  Initial size: " << gtPsbVectorInitialSize << std::endl;
00249         myCoutStream << "  Final size: " << gtPsbVectorFinalSize << std::endl;
00250 
00251     }
00252 
00253     edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
00254 
00255     myCoutStream.str("");
00256     myCoutStream.clear();
00257    
00258     
00259 
00260     
00261     
00262     // get reference to muon collection
00263     const edm::RefProd<L1MuGMTReadoutCollection> muCollRefProdInitial =
00264             gtReadoutRecordInitial->muCollectionRefProd();
00265 
00266     const edm::RefProd<L1MuGMTReadoutCollection> muCollRefProdFinal =
00267             gtReadoutRecordFinal->muCollectionRefProd();
00268 
00269     if (muCollRefProdInitial == muCollRefProdFinal) {
00270         myCoutStream 
00271             << "\nInitial and final RefProd<L1MuGMTReadoutCollection>: identical.\n";
00272     }
00273     else {
00274         myCoutStream 
00275             << "\nInitial and final RefProd<L1MuGMTReadoutCollection>: different.\n";
00276 
00277     }
00278 
00279     edm::LogInfo("L1GtPackUnpackAnalyzer")
00280     << myCoutStream.str()
00281     << std::endl;
00282 
00283     myCoutStream.str("");
00284     myCoutStream.clear();
00285 
00286 
00287 }
00288 
00289 // GMT comparison
00290 void L1GtPackUnpackAnalyzer::analyzeGMT(const edm::Event& iEvent,
00291         const edm::EventSetup& evSetup) {
00292 
00293     // define an output stream to print into
00294     // it can then be directed to whatever log level is desired
00295     std::ostringstream myCoutStream;
00296 
00297     // get initial L1MuGMTReadoutCollection
00298     edm::Handle<L1MuGMTReadoutCollection> gmtRcInitial;
00299     iEvent.getByLabel(m_initialMuGmtInputTag, gmtRcInitial);
00300 
00301     if (!gmtRcInitial.isValid()) {
00302         edm::LogError("L1GtPackUnpackAnalyzer")
00303                 << "Initial L1MuGMTReadoutCollection with input tag \n  "
00304                 << m_initialMuGmtInputTag << " not found.\n\n"
00305                 << std::endl;
00306         return;
00307                
00308     }
00309 
00310     std::vector<L1MuGMTReadoutRecord> muRecordsInitial = gmtRcInitial->getRecords();
00311 
00312     // get final L1MuGMTReadoutCollection
00313     edm::Handle<L1MuGMTReadoutCollection> gmtRcFinal;
00314     iEvent.getByLabel(m_finalGtGmtInputTag, gmtRcFinal);
00315 
00316     if (!gmtRcFinal.isValid()) {
00317         edm::LogError("L1GtPackUnpackAnalyzer")
00318                 << "Final L1MuGMTReadoutCollection with input tag \n  "
00319                 << m_finalGtGmtInputTag << " not found.\n\n"
00320                 << std::endl;
00321         return;
00322                
00323     }
00324 
00325     std::vector<L1MuGMTReadoutRecord> muRecordsFinal = gmtRcFinal->getRecords();
00326 
00327     int muRecordsInitialSize = muRecordsInitial.size();
00328     int muRecordsFinalSize = muRecordsFinal.size();
00329     
00330     if (muRecordsInitialSize == muRecordsFinalSize) {
00331         myCoutStream 
00332             << "\nInitial and final L1MuGMTReadoutCollection record size: identical.\n";
00333         myCoutStream << "  Size: " << muRecordsInitialSize << std::endl;
00334     }
00335     else {
00336         myCoutStream 
00337             << "\nInitial and final  L1MuGMTReadoutCollection record size: different.\n";
00338         myCoutStream << "  Initial size: " << muRecordsInitialSize << std::endl;
00339         myCoutStream << "  Final size: " << muRecordsFinalSize << std::endl;
00340 
00341     }
00342 
00343     edm::LogInfo("L1GtPackUnpackAnalyzer") << myCoutStream.str() << std::endl;
00344 
00345     myCoutStream.str("");
00346     myCoutStream.clear();
00347 
00348 }
00349 
00350 // analyze each event: event loop
00351 void L1GtPackUnpackAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup)
00352 {
00353     
00354     // GT DAQ comparison
00355     analyzeGT(iEvent, evSetup);
00356 
00357     // GMT comparison
00358     analyzeGMT(iEvent, evSetup);
00359 
00360 }
00361 
00362 
00363 // method called once each job just after ending the event loop
00364 void L1GtPackUnpackAnalyzer::endJob()
00365 {
00366 
00367     // empty
00368 
00369 }
00370