Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:29

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  EventProcessor_processEvent.cc
0005  *
0006  *    Description:  EventProcessor Object Event entry methods
0007  *
0008  *        Version:  1.0
0009  *        Created:  10/03/2008 10:47:11 AM
0010  *       Revision:  none
0011  *       Compiler:  gcc
0012  *
0013  *         Author:  Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
0014  *        Company:  CERN, CH
0015  *
0016  * =====================================================================================
0017  */
0018 
0019 #include "CSCDQM_EventProcessor.h"
0020 
0021 namespace cscdqm {
0022 
0023   /**
0024  * @brief  Common Local and Global DQM function to be called before processing Event
0025  */
0026   void EventProcessor::preProcessEvent() {
0027     config->incNEvents();
0028     EmuEventDisplayWasReset = false;
0029   }
0030 
0031 #ifdef DQMLOCAL
0032 
0033   /**
0034  * @brief  Process event (Local DQM)
0035  * @param  data Event Data buffer
0036  * @param  dataSize Event Data buffer size
0037  * @param  errorStat Error status received by reading DAQ buffer
0038  * @param  nodeNumber DAQ node number
0039  * @return
0040  */
0041   void EventProcessor::processEvent(const char* data,
0042                                     const int32_t dataSize,
0043                                     const uint32_t errorStat,
0044                                     const int32_t nodeNumber) {
0045     preProcessEvent();
0046 
0047     config->incNEventsCSC();
0048 
0049     MonitorObject* me = 0;
0050     if (getEMUHisto(h::EMU_ALL_READOUT_ERRORS, me)) {
0051       if (errorStat != 0) {
0052         me->Fill(nodeNumber, 1);
0053         for (unsigned int i = 0; i < 16; i++) {
0054           if ((errorStat >> i) & 0x1) {
0055             me->Fill(nodeNumber, i + 2);
0056           }
0057         }
0058       } else {
0059         me->Fill(nodeNumber, 0);
0060       }
0061     }
0062 
0063     bool eventDenied = false;
0064     if (((uint32_t)errorStat & config->getDDU_CHECK_MASK()) > 0) {
0065       eventDenied = true;
0066     }
0067 
0068     const uint16_t* tmp = reinterpret_cast<const uint16_t*>(data);
0069     const uint16_t tmpSize = dataSize / sizeof(short);
0070 
0071     /** CSC DCC Examiner object */
0072     CSCDCCExaminer binChecker;
0073     binChecker.crcALCT(config->getBINCHECKER_CRC_ALCT());
0074     binChecker.crcTMB(config->getBINCHECKER_CRC_CLCT());
0075     binChecker.crcCFEB(config->getBINCHECKER_CRC_CFEB());
0076     binChecker.modeDDU(config->getBINCHECKER_MODE_DDU());
0077 
0078     if (config->getBINCHECKER_OUTPUT()) {
0079       // binChecker.output1().show();
0080       // binChecker.output2().show();
0081     } else {
0082       // binChecker.output1().hide();
0083       // binChecker.output2().hide();
0084     }
0085 
0086     binChecker.setMask(config->getBINCHECK_MASK());
0087 
0088     if (binChecker.check(tmp, tmpSize) < 0) {
0089       /** No ddu trailer found - force checker to summarize errors by adding artificial trailer */
0090       const uint16_t dduTrailer[4] = {0x8000, 0x8000, 0xFFFF, 0x8000};
0091       const uint16_t* tmp = dduTrailer;
0092       binChecker.check(tmp, uint32_t(4));
0093     }
0094 
0095     CSCDCCFormatStatusDigi formatStatusDigi(nodeNumber,
0096                                             config->getBINCHECK_MASK(),
0097                                             binChecker.getMask(),
0098                                             binChecker.errors(),
0099                                             binChecker.errorsDetailedDDU(),
0100                                             binChecker.errorsDetailed(),
0101                                             binChecker.payloadDetailed(),
0102                                             binChecker.statusDetailed());
0103 
0104     if (processExaminer(binChecker, formatStatusDigi)) {
0105       config->incNEventsGood();
0106 
0107       if (config->getPROCESS_DDU()) {
0108         CSCDDUEventData dduData((short unsigned int*)tmp, &binChecker);
0109         processDDU(dduData, binChecker);
0110       }
0111     }
0112   }
0113 
0114 #endif
0115 
0116 #ifdef DQMGLOBAL
0117 
0118   /**
0119  * @brief  Process event (Global DQM)
0120  * @param  e Event object
0121  * @param  inputTag Tag to search Event Data in
0122  * @param  standby HW standby status indicator
0123  * @return
0124  */
0125   void EventProcessor::processEvent(const edm::Event& e, const edm::InputTag& inputTag) {
0126     preProcessEvent();
0127 
0128     edm::Handle<FEDRawDataCollection> rawdata;
0129     if (!e.getByToken(frdtoken, rawdata)) {
0130       LOG_WARN << "No product: " << inputTag << " in stream";
0131       return;
0132     }
0133 
0134     bCSCEventCounted = false;
0135     size_t eventSize = 0;  /// Total Event Size in bytes
0136     cntDMBs = 0;
0137     cntCFEBs = 0;
0138     cntALCTs = 0;
0139     cntTMBs = 0;
0140     int nDDUs_out_of_sync = 0;
0141     int nDDUs_with_CSC_data_out_of_sync = 0;
0142     bool fGlobal_DCC_DDU_L1A_mismatch = false;
0143     bool fGlobal_DCC_DDU_L1A_mismatch_with_CSC_data = false;
0144     MonitorObject* mo = nullptr;
0145 
0146     // For new CSC readout layout, which wont include DCCs need to loop over DDU FED IDs. DCC IDs are included for backward compatibility with old data
0147     std::vector<unsigned int> cscFEDids;
0148 
0149     for (unsigned int id = FEDNumbering::MINCSCFEDID; id <= FEDNumbering::MAXCSCFEDID; ++id)  // loop over DCCs
0150     {
0151       cscFEDids.push_back(id);
0152     }
0153 
0154     for (unsigned int id = FEDNumbering::MINCSCDDUFEDID; id <= FEDNumbering::MAXCSCDDUFEDID; ++id)  // loop over DDUs
0155     {
0156       cscFEDids.push_back(id);
0157     }
0158 
0159     // run through the FED's
0160     for (unsigned int i = 0; i < cscFEDids.size(); i++)  // loop over all CSC FEDs (DCCs and DDUs)
0161     {
0162       unsigned int id = cscFEDids[i];
0163       bool isDDU_FED = ((id >= FEDNumbering::MINCSCDDUFEDID) && (id <= FEDNumbering::MAXCSCDDUFEDID)) ? true : false;
0164       // Take a reference to this FED's data and
0165       // construct the DCC data object
0166       const FEDRawData& fedData = rawdata->FEDData(id);
0167 
0168       //if fed has data then unpack it
0169       if (fedData.size() >= 32) {
0170         eventSize += fedData.size();
0171 
0172         // Count in CSC Event!
0173         if (!bCSCEventCounted) {
0174           config->incNEventsCSC();
0175           bCSCEventCounted = true;
0176         }
0177 
0178         if (!isDDU_FED) {
0179           // Filling in FED Entries histogram
0180           if (getEMUHisto(h::EMU_FED_ENTRIES, mo))
0181             mo->Fill(id);
0182 
0183           if (getEMUHisto(h::EMU_FED_BUFFER_SIZE, mo))
0184             mo->Fill(id, log10((double)fedData.size()));
0185 
0186           if (getFEDHisto(h::FED_BUFFER_SIZE, id, mo))
0187             mo->Fill(fedData.size());
0188         }
0189 
0190         const uint16_t* data = (uint16_t*)fedData.data();
0191         const size_t dataSize = fedData.size() / 2;
0192         const short unsigned int* udata = (short unsigned int*)fedData.data();
0193 
0194         /** CSC DCC Examiner object */
0195         CSCDCCExaminer binChecker;
0196         binChecker.crcALCT(config->getBINCHECKER_CRC_ALCT());
0197         binChecker.crcTMB(config->getBINCHECKER_CRC_CLCT());
0198         binChecker.crcCFEB(config->getBINCHECKER_CRC_CFEB());
0199         binChecker.modeDDU(config->getBINCHECKER_MODE_DDU());
0200 
0201         /// Check if we have DCC or DDU FED, by checking FED ID. Then set examiner to use DCC or DDU mode
0202         if (isDDU_FED) {
0203           binChecker.modeDDU(true);
0204         }
0205 
0206         if (config->getBINCHECKER_OUTPUT()) {
0207           // binChecker.output1().show();
0208           // binChecker.output2().show();
0209         } else {
0210           // binChecker.output1().hide();
0211           // binChecker.output2().hide();
0212         }
0213 
0214         binChecker.setMask(config->getBINCHECK_MASK());
0215 
0216         if (isDDU_FED) {
0217           if (binChecker.check(data, dataSize) >= 0) {
0218             CSCDCCFormatStatusDigi formatStatusDigi(id,
0219                                                     config->getBINCHECK_MASK(),
0220                                                     binChecker.getMask(),
0221                                                     binChecker.errors(),
0222                                                     binChecker.errorsDetailedDDU(),
0223                                                     binChecker.errorsDetailed(),
0224                                                     binChecker.payloadDetailed(),
0225                                                     binChecker.statusDetailed());
0226 
0227             if (processExaminer(binChecker, formatStatusDigi)) {
0228               config->incNEventsGood();
0229 
0230               if (config->getPROCESS_DDU()) {
0231                 CSCDDUEventData dduData(const_cast<short unsigned int*>(udata), &binChecker);
0232                 processDDU(dduData, binChecker);
0233               }
0234             }
0235           }
0236         }
0237 
0238         else {
0239           if (binChecker.check(data, dataSize) < 0) {
0240             if (getEMUHisto(h::EMU_FED_FATAL, mo))
0241               mo->Fill(id);
0242           } else {
0243             CSCDCCFormatStatusDigi formatStatusDigi(id,
0244                                                     config->getBINCHECK_MASK(),
0245                                                     binChecker.getMask(),
0246                                                     binChecker.errors(),
0247                                                     binChecker.errorsDetailedDDU(),
0248                                                     binChecker.errorsDetailed(),
0249                                                     binChecker.payloadDetailed(),
0250                                                     binChecker.statusDetailed());
0251 
0252             /// Fill summary FED/DCC Format Errors histos
0253             if (getEMUHisto(h::EMU_FED_FORMAT_ERRORS, mo)) {
0254               uint32_t errs = binChecker.errors();
0255 
0256               if (errs != 0) {
0257                 for (int i = 0; i < 29; i++) {
0258                   if ((errs >> i) & 0x1) {
0259                     mo->Fill(id, i + 1);
0260                   }
0261                 }
0262               } else {
0263                 mo->Fill(id, 0);
0264               }
0265             }
0266 
0267             if (processExaminer(binChecker, formatStatusDigi)) {
0268               config->incNEventsGood();
0269 
0270               if (binChecker.warnings() != 0) {
0271                 if (getEMUHisto(h::EMU_FED_NONFATAL, mo))
0272                   mo->Fill(id);
0273               }
0274 
0275               if (config->getPROCESS_DDU()) {
0276                 CSCDCCEventData dccData(const_cast<short unsigned int*>(udata), &binChecker);
0277                 const std::vector<CSCDDUEventData>& dduData = dccData.dduData();
0278 
0279                 /// Check for DCC and DDUs L1A counter mismatch and fill corresponding histogram
0280                 bool fDCC_DDU_L1A_mismatch = false;
0281                 bool fDCC_DDU_L1A_mismatch_with_CSC_data = false;
0282                 int DCC_L1A = dccData.dccHeader().getCDFEventNumber();
0283                 for (int ddu = 0; ddu < (int)dduData.size(); ddu++) {
0284                   if (DCC_L1A != dduData[ddu].header().lvl1num()) {
0285                     fDCC_DDU_L1A_mismatch = true;
0286                     fGlobal_DCC_DDU_L1A_mismatch = true;
0287                     nDDUs_out_of_sync++;
0288 
0289                     /// Check if DDU potentially has CSC data
0290                     if (dduData[ddu].sizeInWords() > 24) {
0291                       fDCC_DDU_L1A_mismatch_with_CSC_data = true;
0292                       fGlobal_DCC_DDU_L1A_mismatch_with_CSC_data = true;
0293                       nDDUs_with_CSC_data_out_of_sync++;
0294                       /*
0295                                                         std::cout <<  "FED" << id << " L1A:" << DCC_L1A <<  ", ";
0296                                                         std::cout << "DDU" << (dduData[ddu].header().source_id() & 0xFF )
0297                                                             << " L1A:" << dduData[ddu].header().lvl1num() << " size:" << (dduData[ddu].sizeInWords()*2);
0298                                                         std::cout << " - L1A mismatch";
0299                                                         std::cout << std::endl;
0300                                       */
0301                     }
0302                   }
0303                   processDDU(dduData[ddu], binChecker);
0304                 }
0305 
0306                 if (fDCC_DDU_L1A_mismatch && getEMUHisto(h::EMU_FED_DDU_L1A_MISMATCH, mo))
0307                   mo->Fill(id);
0308                 if (fDCC_DDU_L1A_mismatch_with_CSC_data && getEMUHisto(h::EMU_FED_DDU_L1A_MISMATCH_WITH_CSC_DATA, mo))
0309                   mo->Fill(id);
0310               }
0311 
0312             } else {
0313               if (getEMUHisto(h::EMU_FED_FORMAT_FATAL, mo))
0314                 mo->Fill(id);
0315             }
0316           }
0317         }
0318       }
0319     }
0320 
0321     if (fGlobal_DCC_DDU_L1A_mismatch && getEMUHisto(h::EMU_FED_DDU_L1A_MISMATCH_CNT, mo))
0322       mo->Fill(nDDUs_out_of_sync);
0323     if (fGlobal_DCC_DDU_L1A_mismatch && getEMUHisto(h::EMU_FED_DDU_L1A_MISMATCH_WITH_CSC_DATA_CNT, mo))
0324       mo->Fill(nDDUs_with_CSC_data_out_of_sync);
0325 
0326     if (getEMUHisto(h::EMU_FED_STATS, mo)) {
0327       mo->Fill(0);
0328       if (fGlobal_DCC_DDU_L1A_mismatch)
0329         mo->Fill(1);
0330       if (fGlobal_DCC_DDU_L1A_mismatch_with_CSC_data)
0331         mo->Fill(2);
0332     }
0333 
0334     if (getEMUHisto(h::EMU_FED_EVENT_SIZE, mo))
0335       mo->Fill(eventSize / 1024.);  /// CSC Event Size in KBytes
0336     if (getEMUHisto(h::EMU_FED_TOTAL_CSC_NUMBER, mo))
0337       mo->Fill(cntDMBs);  /// Total Number of CSC/DMBs in event (DDU Header DAV)
0338     if (getEMUHisto(h::EMU_FED_TOTAL_CFEB_NUMBER, mo))
0339       mo->Fill(cntCFEBs);  /// Total Number of CFEBs in event (DMB Header DAV)
0340     if (getEMUHisto(h::EMU_FED_TOTAL_ALCT_NUMBER, mo))
0341       mo->Fill(cntALCTs);  /// Total Number of ALCTs in event (DMB Header DAV)
0342     if (getEMUHisto(h::EMU_FED_TOTAL_TMB_NUMBER, mo))
0343       mo->Fill(cntTMBs);  /// Total Number of TMBs in event (DMB Header DAV)
0344   }
0345 
0346 #endif
0347 
0348 #undef ECHO_FUNCTION
0349 
0350 }  // namespace cscdqm