Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:53:58

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  EventProcessor.cc
0005  *
0006  *    Description:  EventProcessor Object
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  Process DDU output and fill MOs
0025  * @param  dduData DDU object to process
0026  */
0027   void EventProcessor::processDDU(const CSCDDUEventData& dduData, const CSCDCCExaminer& binChecker) {
0028     CSCDDUHeader dduHeader = dduData.header();
0029     CSCDDUTrailer dduTrailer = dduData.trailer();
0030     if (!dduTrailer.check()) {
0031       /**  LOG4CPLUS_WARN(logger_,eTag << "Skipped because of DDU Trailer check failed."); */
0032       return;
0033     }
0034 
0035     int dduID = dduHeader.source_id();
0036 
0037     if ((dduID >= FEDNumbering::MINCSCDDUFEDID) &&
0038         (dduID <= FEDNumbering::MAXCSCDDUFEDID))  /// New CSC readout without DCCs. CMS CSC DDU ID range 830-869
0039     {
0040       // dduID -= (FEDNumbering::MINCSCDDUFEDID - 1); /// TODO: Can require DDU-RUI remapping for actual system
0041       dduID = cscdqm::Utility::getRUIfromDDUId(dduHeader.source_id());
0042       if (dduID < 0) {
0043         LOG_WARN << "DDU source ID (" << dduHeader.source_id() << ") is out of valid range. Remapping to DDU ID 1.";
0044         dduID = 1;
0045       }
0046     } else {
0047       /**  Only 8bits are significant; format of DDU id is Dxx */
0048       dduID = dduID & 0xFF;
0049     }
0050 
0051     MonitorObject* mo = nullptr;
0052 
0053     if (getEMUHisto(h::EMU_ALL_DDUS_IN_READOUT, mo)) {
0054       mo->Fill(dduID);
0055     }
0056 
0057     std::string dduTag = DDUHistoDef::getPath(dduID);
0058 
0059     uint32_t dduEvtSize = dduData.sizeInWords() * 2;
0060 
0061     // if (dduEvtSize > 48)
0062     {
0063       /**  DDU word counter */
0064       int trl_word_count = 0;
0065       trl_word_count = dduTrailer.wordcount();
0066 
0067       if (getDDUHisto(h::DDU_BUFFER_SIZE, dduID, mo))
0068         mo->Fill(dduEvtSize);
0069 
0070       if (getDDUHisto(h::DDU_WORD_COUNT, dduID, mo))
0071         mo->Fill(trl_word_count);
0072 
0073       /** LOG4CPLUS_DEBUG(logger_,dduTag << " Trailer Word (64 bits) Count = " << std::dec << trl_word_count); */
0074 
0075       if (trl_word_count > 0) {
0076         if (getEMUHisto(h::EMU_ALL_DDUS_EVENT_SIZE, mo)) {
0077           mo->Fill(dduID, log10((double)trl_word_count));
0078         }
0079       }
0080 
0081       if (getEMUHisto(h::EMU_ALL_DDUS_AVERAGE_EVENT_SIZE, mo)) {
0082         mo->Fill(dduID, trl_word_count);
0083       }
0084     }
0085 
0086     fCloseL1As = dduTrailer.reserved() & 0x1;  // Get status if Close L1As bit
0087     /**  if (fCloseL1As) LOG4CPLUS_DEBUG(logger_,eTag << " Close L1As bit is set"); */
0088 
0089     /**  DDU Header bunch crossing number (BXN) */
0090     BXN = dduHeader.bxnum();
0091     /**  LOG4CPLUS_WARN(logger_,dduTag << " DDU Header BXN Number = " << std::dec << BXN); */
0092     if (getEMUHisto(h::EMU_DDU_BXN, mo))
0093       mo->Fill(BXN);
0094     if (getDDUHisto(h::DDU_BXN, dduID, mo))
0095       mo->Fill(BXN);
0096 
0097     /**  L1A number from DDU Header */
0098     int L1ANumber_previous_event = L1ANumbers[dduID];
0099     L1ANumbers[dduID] = (int)(dduHeader.lvl1num());
0100     L1ANumber = L1ANumbers[dduID];
0101     /** LOG4CPLUS_DEBUG(logger_,dduTag << " Header L1A Number = " << std::dec << L1ANumber); */
0102     int L1A_inc = L1ANumber - L1ANumber_previous_event;
0103 
0104     /** Handle 24-bit L1A roll-over maximum value case **/
0105     if (L1A_inc < 0)
0106       L1A_inc = 0xFFFFFF + L1A_inc;
0107 
0108     // if (!fFirstEvent) {
0109     if (fNotFirstEvent[dduID]) {
0110       if (getDDUHisto(h::DDU_L1A_INCREMENT, dduID, mo))
0111         mo->Fill(L1A_inc);
0112       if (getEMUHisto(h::EMU_ALL_DDUS_L1A_INCREMENT, mo)) {
0113         if (L1A_inc > 100000) {
0114           L1A_inc = 19;
0115         } else if (L1A_inc > 30000) {
0116           L1A_inc = 18;
0117         } else if (L1A_inc > 10000) {
0118           L1A_inc = 17;
0119         } else if (L1A_inc > 3000) {
0120           L1A_inc = 16;
0121         } else if (L1A_inc > 1000) {
0122           L1A_inc = 15;
0123         } else if (L1A_inc > 300) {
0124           L1A_inc = 14;
0125         } else if (L1A_inc > 100) {
0126           L1A_inc = 13;
0127         } else if (L1A_inc > 30) {
0128           L1A_inc = 12;
0129         } else if (L1A_inc > 10) {
0130           L1A_inc = 11;
0131         }
0132         mo->Fill(dduID, L1A_inc);
0133       }
0134     }
0135 
0136     /**  ==     Occupancy and number of DMB (CSC) with Data available (DAV) in header of particular DDU */
0137     int dmb_dav_header = 0;
0138     int dmb_dav_header_cnt = 0;
0139 
0140     int ddu_connected_inputs = 0;
0141     int ddu_connected_inputs_cnt = 0;
0142 
0143     int csc_error_state = 0;
0144     int csc_warning_state = 0;
0145 
0146     /**   ==    Number of active DMB (CSC) in header of particular DDU */
0147     int dmb_active_header = 0;
0148 
0149     dmb_dav_header = dduHeader.dmb_dav();
0150     dmb_active_header = (int)(dduHeader.ncsc() & 0xF);
0151     csc_error_state = dduTrailer.dmb_full() & 0x7FFF;    // Only 15 inputs for DDU
0152     csc_warning_state = dduTrailer.dmb_warn() & 0x7FFF;  // Only 15 inputs for DDU
0153     ddu_connected_inputs = dduHeader.live_cscs();
0154 
0155     /** LOG4CPLUS_DEBUG(logger_,dduTag << " Header DMB DAV = 0x" << std::hex << dmb_dav_header); */
0156     /** LOG4CPLUS_DEBUG(logger_,dduTag << " Header Number of Active DMB = " << std::dec << dmb_active_header); */
0157 
0158     double freq = 0;
0159     for (int i = 0; i < 15; ++i) {
0160       if ((dmb_dav_header >> i) & 0x1) {
0161         dmb_dav_header_cnt++;
0162         if (getDDUHisto(h::DDU_DMB_DAV_HEADER_OCCUPANCY_RATE, dduID, mo)) {
0163           mo->Fill(i + 1);
0164           freq = (100.0 * mo->GetBinContent(i + 1)) / config->getNEvents();
0165           if (getDDUHisto(h::DDU_DMB_DAV_HEADER_OCCUPANCY, dduID, mo))
0166             mo->SetBinContent(i + 1, freq);
0167         }
0168         if (getEMUHisto(h::EMU_ALL_DDUS_INPUTS_WITH_DATA, mo)) {
0169           mo->Fill(dduID, i);
0170         }
0171       }
0172 
0173       if ((ddu_connected_inputs >> i) & 0x1) {
0174         ddu_connected_inputs_cnt++;
0175         if (getDDUHisto(h::DDU_DMB_CONNECTED_INPUTS_RATE, dduID, mo)) {
0176           mo->Fill(i + 1);
0177           freq = (100.0 * mo->GetBinContent(i + 1)) / config->getNEvents();
0178           if (getDDUHisto(h::DDU_DMB_CONNECTED_INPUTS, dduID, mo))
0179             mo->SetBinContent(i + 1, freq);
0180         }
0181         if (getEMUHisto(h::EMU_ALL_DDUS_LIVE_INPUTS, mo)) {
0182           mo->Fill(dduID, i);
0183         }
0184       }
0185 
0186       if ((csc_error_state >> i) & 0x1) {
0187         if (getDDUHisto(h::DDU_CSC_ERRORS_RATE, dduID, mo)) {
0188           mo->Fill(i + 1);
0189           freq = (100.0 * mo->GetBinContent(i + 1)) / config->getNEvents();
0190           if (getDDUHisto(h::DDU_CSC_ERRORS, dduID, mo))
0191             mo->SetBinContent(i + 1, freq);
0192         }
0193         if (getEMUHisto(h::EMU_ALL_DDUS_INPUTS_ERRORS, mo)) {
0194           mo->Fill(dduID, i + 2);
0195         }
0196       }
0197 
0198       if ((csc_warning_state >> i) & 0x1) {
0199         if (getDDUHisto(h::DDU_CSC_WARNINGS_RATE, dduID, mo)) {
0200           mo->Fill(i + 1);
0201           freq = (100.0 * mo->GetBinContent(i + 1)) / config->getNEvents();
0202           if (getDDUHisto(h::DDU_CSC_WARNINGS, dduID, mo))
0203             mo->SetBinContent(i + 1, freq);
0204         }
0205         if (getEMUHisto(h::EMU_ALL_DDUS_INPUTS_WARNINGS, mo)) {
0206           mo->Fill(dduID, i + 2);
0207         }
0208       }
0209     }
0210 
0211     if (getEMUHisto(h::EMU_ALL_DDUS_AVERAGE_LIVE_INPUTS, mo)) {
0212       mo->Fill(dduID, ddu_connected_inputs_cnt);
0213     }
0214 
0215     // if (dduEvtSize > 48)
0216     {
0217       if (getEMUHisto(h::EMU_ALL_DDUS_AVERAGE_INPUTS_WITH_DATA, mo)) {
0218         mo->Fill(dduID, dmb_dav_header_cnt);
0219       }
0220     }
0221 
0222     if (getEMUHisto(h::EMU_ALL_DDUS_INPUTS_ERRORS, mo)) {
0223       if (csc_error_state > 0) {
0224         mo->Fill(dduID, 1);  // Any Input
0225       } else {
0226         mo->Fill(dduID, 0);  // No errors
0227       }
0228     }
0229 
0230     if (getEMUHisto(h::EMU_ALL_DDUS_INPUTS_WARNINGS, mo)) {
0231       if (csc_warning_state > 0) {
0232         mo->Fill(dduID, 1);  // Any Input
0233       } else {
0234         mo->Fill(dduID, 0);  // No errors
0235       }
0236     }
0237 
0238     if (getDDUHisto(h::DDU_DMB_DAV_HEADER_OCCUPANCY, dduID, mo))
0239       mo->SetEntries(config->getNEvents());
0240     if (getDDUHisto(h::DDU_DMB_CONNECTED_INPUTS, dduID, mo))
0241       mo->SetEntries(config->getNEvents());
0242     if (getDDUHisto(h::DDU_CSC_ERRORS, dduID, mo))
0243       mo->SetEntries(config->getNEvents());
0244     if (getDDUHisto(h::DDU_CSC_WARNINGS, dduID, mo))
0245       mo->SetEntries(config->getNEvents());
0246     if (getDDUHisto(h::DDU_DMB_ACTIVE_HEADER_COUNT, dduID, mo))
0247       mo->Fill(dmb_active_header);
0248     if (getDDUHisto(h::DDU_DMB_DAV_HEADER_COUNT_VS_DMB_ACTIVE_HEADER_COUNT, dduID, mo))
0249       mo->Fill(dmb_active_header, dmb_dav_header_cnt);
0250 
0251     /**  Check binary Error status at DDU Trailer */
0252     uint32_t trl_errorstat = dduTrailer.errorstat();
0253     if (dmb_dav_header_cnt == 0)
0254       trl_errorstat &= ~0x20000000;  // Ignore No Good DMB CRC bit of no DMB is present
0255     /**  LOG4CPLUS_DEBUG(logger_,dduTag << " Trailer Error Status = 0x" << std::hex << trl_errorstat); */
0256     for (int i = 0; i < 32; i++) {
0257       if ((trl_errorstat >> i) & 0x1) {
0258         if (getDDUHisto(h::DDU_TRAILER_ERRORSTAT_RATE, dduID, mo)) {
0259           mo->Fill(i);
0260           double freq = (100.0 * mo->GetBinContent(i + 1)) / config->getNEvents();
0261           if (getDDUHisto(h::DDU_TRAILER_ERRORSTAT_FREQUENCY, dduID, mo))
0262             mo->SetBinContent(i + 1, freq);
0263         }
0264         if (getDDUHisto(h::DDU_TRAILER_ERRORSTAT_TABLE, dduID, mo))
0265           mo->Fill(0., i);
0266       }
0267     }
0268     if (getEMUHisto(h::EMU_ALL_DDUS_TRAILER_ERRORS, mo)) {
0269       if (trl_errorstat) {
0270         mo->Fill(dduID, 1);  // Any Error
0271         for (int i = 0; i < 32; i++) {
0272           if ((trl_errorstat >> i) & 0x1) {
0273             mo->Fill(dduID, i + 2);
0274           }
0275         }
0276       } else {
0277         mo->Fill(dduID, 0);  // No Errors
0278       }
0279     }
0280 
0281     if (getDDUHisto(h::DDU_TRAILER_ERRORSTAT_TABLE, dduID, mo))
0282       mo->SetEntries(config->getNEvents());
0283     if (getDDUHisto(h::DDU_TRAILER_ERRORSTAT_FREQUENCY, dduID, mo))
0284       mo->SetEntries(config->getNEvents());
0285 
0286     ///** Check DDU Output Path status in DDU Header
0287     uint32_t ddu_output_path_status = dduHeader.output_path_status();
0288     if (getEMUHisto(h::EMU_ALL_DDUS_OUTPUT_PATH_STATUS, mo)) {
0289       if (ddu_output_path_status) {
0290         mo->Fill(dduID, 1);  // Any Error
0291         for (int i = 0; i < 16; i++) {
0292           if ((ddu_output_path_status >> i) & 0x1) {
0293             mo->Fill(dduID, i + 2);  // Fill Summary Histo
0294           }
0295         }
0296       } else {
0297         mo->Fill(dduID, 0);  // No Errors
0298       }
0299     }
0300 
0301     uint32_t nCSCs = 0;
0302 
0303     /**  Unpack all found CSC */
0304     if (config->getPROCESS_CSC()) {
0305       std::vector<CSCEventData> chamberDatas;
0306       chamberDatas.clear();
0307       chamberDatas = dduData.cscData();
0308 
0309       nCSCs = chamberDatas.size();
0310 
0311       for (uint32_t i = 0; i < nCSCs; i++) {
0312         processCSC(chamberDatas[i], dduID, binChecker);
0313       }
0314     }
0315 
0316     if (getDDUHisto(h::DDU_DMB_UNPACKED_VS_DAV, dduID, mo))
0317       mo->Fill(dmb_active_header, nCSCs);
0318 
0319     // fFirstEvent = false;
0320 
0321     /** First event per DDU **/
0322     fNotFirstEvent[dduID] = true;
0323   }
0324 
0325 }  // namespace cscdqm