Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
/*
 * =====================================================================================
 *
 *       Filename:  EventProcessor.cc
 *
 *    Description:  Process Examiner output
 *
 *        Version:  1.0
 *        Created:  10/03/2008 10:47:11 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
 *        Company:  CERN, CH
 *
 * =====================================================================================
 */

#include "CSCDQM_EventProcessor.h"

namespace cscdqm {

  /**
 * @brief  Fill monitor elements with CSCDCCFormatStatusDigi information.
 * @return true if this buffer (event) was accepted by Examiner else otherwise
 */
  bool EventProcessor::processExaminer(const CSCDCCExaminer& binChecker, const CSCDCCFormatStatusDigi& digi) {
    bool eventAccepted = true;
    MonitorObject* mo = nullptr;

    uint32_t binErrorStatus = digi.getDDUSummaryErrors();

    if (getEMUHisto(h::EMU_ALL_DDUS_FORMAT_ERRORS, mo)) {
      const std::set<DDUIdType> DDUs = digi.getListOfDDUs();
      for (std::set<DDUIdType>::const_iterator ddu_itr = DDUs.begin(); ddu_itr != DDUs.end(); ++ddu_itr) {
        ExaminerStatusType errs = digi.getDDUErrors(*ddu_itr);
        int dduID = (*ddu_itr) & 0xFF;
        if (((*ddu_itr) >= FEDNumbering::MINCSCDDUFEDID) &&
            ((*ddu_itr) <=
             FEDNumbering::MAXCSCDDUFEDID))  /// New CSC readout without DCCs. CMS CSC DDU ID range 830-869
        {
          // dduID = (*ddu_itr) - FEDNumbering::MINCSCDDUFEDID + 1; /// TODO: Can require DDU-RUI remapping for actual system
          dduID = cscdqm::Utility::getRUIfromDDUId((*ddu_itr));
          if (dduID < 0) {
            LOG_WARN << "DDU source ID (" << (*ddu_itr) << ") is out of valid range. Remapping to DDU ID 1.";
            dduID = 1;
          }
        }
        if (errs != 0) {
          for (int i = 0; i < 29; i++) {
            if ((errs >> i) & 0x1) {
              mo->Fill(dduID, i + 1);
            }
          }
        } else {
          mo->Fill(dduID, 0);
        }
      }
    }

    // =VB= We want to use DCC level check mask as in CSCDCCUnpacker and not DDU mask
    // 	    Otherwise whole DCC event could be skipped because of a single chamber error
    unsigned long dccBinCheckMask = 0x06080016;
    //    if ((binErrorStatus & config->getDDU_BINCHECK_MASK()) > 0) {
    if ((binErrorStatus & dccBinCheckMask) > 0) {
      eventAccepted = false;
    }

    if (binErrorStatus != 0) {
      config->incNEventsBad();
    }

    /** Check and fill CSC Payload information */

    {
      uint32_t i = 0;
      CSCIdType chamberID = 0;
      while (digi.nextCSCWithPayload(i, chamberID)) {
        int crateID = (chamberID >> 4) & 0xFF;
        int dmbSlot = chamberID & 0xF;

        if (crateID == 255) {
          continue;
        }
        if ((crateID > 60) || (dmbSlot > 10) || (crateID <= 0) || (dmbSlot <= 0)) {
          continue;
        }

        // Check if in standby!
        {
          CSCDetId cid;
          if (!config->fnGetCSCDetId(crateID, dmbSlot, cid)) {
            continue;
          }
        }

        /** Update counters */
        config->incChamberCounter(DMB_EVENTS, crateID, dmbSlot);
        long DMBEvents = config->getChamberCounterValue(DMB_EVENTS, crateID, dmbSlot);
        config->copyChamberCounterValue(DMB_EVENTS, DMB_TRIGGERS, crateID, dmbSlot);
        cntDMBs++;

        if (getEMUHisto(h::EMU_DMB_REPORTING, mo)) {
          mo->Fill(crateID, dmbSlot);
        }

        unsigned int cscType = 0;
        unsigned int cscPosition = 0;
        if (!getCSCFromMap(crateID, dmbSlot, cscType, cscPosition))
          continue;

        if (cscPosition && getEMUHisto(h::EMU_CSC_REPORTING, mo)) {
          mo->Fill(cscPosition, cscType);
        }

        /** Get FEBs Data Available Info */
        long payload = digi.getCSCPayload(chamberID);
        int cfeb_dav = (payload >> 7) & 0x7F;
        int cfeb_active = payload & 0x1F;
        cfeb_active |= ((payload >> 14) & 0x03) << 5;
        int alct_dav = (payload >> 5) & 0x1;
        int tmb_dav = (payload >> 6) & 0x1;
        int cfeb_dav_num = 0;

        if (alct_dav == 0) {
          if (cscPosition && getEMUHisto(h::EMU_CSC_WO_ALCT, mo)) {
            mo->Fill(cscPosition, cscType);
          }
          if (getEMUHisto(h::EMU_DMB_WO_ALCT, mo)) {
            mo->Fill(crateID, dmbSlot);
          }
        }

        if (tmb_dav == 0) {
          if (cscPosition && getEMUHisto(h::EMU_CSC_WO_CLCT, mo)) {
            mo->Fill(cscPosition, cscType);
          }
          if (getEMUHisto(h::EMU_DMB_WO_CLCT, mo)) {
            mo->Fill(crateID, dmbSlot);
          }
        }

        if (cfeb_dav == 0) {
          if (cscPosition && getEMUHisto(h::EMU_CSC_WO_CFEB, mo)) {
            mo->Fill(cscPosition, cscType);
          }
          if (getEMUHisto(h::EMU_DMB_WO_CFEB, mo)) {
            mo->Fill(crateID, dmbSlot);
          }
        }

        /** Increment total number of CFEBs, ALCTs, TMBs **/
        for (int i = 0; i < 7; i++) {
          if ((cfeb_dav >> i) & 0x1)
            cntCFEBs++;
        }

        if (alct_dav > 0) {
          cntALCTs++;
        }

        if (tmb_dav > 0) {
          cntTMBs++;
        }

        MonitorObject *mof = nullptr, *mo1 = nullptr, *mo2 = nullptr;
        if (getCSCHisto(h::CSC_ACTUAL_DMB_CFEB_DAV_RATE, crateID, dmbSlot, mo) &&
            getCSCHisto(h::CSC_ACTUAL_DMB_CFEB_DAV_FREQUENCY, crateID, dmbSlot, mof)) {
          if (getCSCHisto(h::CSC_DMB_CFEB_DAV_UNPACKING_INEFFICIENCY, crateID, dmbSlot, mo1) &&
              getCSCHisto(h::CSC_DMB_CFEB_DAV, crateID, dmbSlot, mo2)) {
            for (int i = 1; i <= 7; i++) {
              double actual_dav_num = mo->GetBinContent(i);
              double unpacked_dav_num = mo2->GetBinContent(i);
              if (actual_dav_num) {
                mo1->SetBinContent(i, 1, 100. * (1 - unpacked_dav_num / actual_dav_num));
              }
              mo1->SetEntries((int)DMBEvents);
            }
          }
          for (int i = 0; i < 7; i++) {
            int cfeb_present = (cfeb_dav >> i) & 0x1;
            cfeb_dav_num += cfeb_present;
            if (cfeb_present) {
              mo->Fill(i);
            }
            float cfeb_entries = mo->GetBinContent(i + 1);
            mof->SetBinContent(i + 1, ((float)cfeb_entries / (float)(DMBEvents) * 100.0));
          }
          mof->SetEntries((int)DMBEvents);
        }

        if (getCSCHisto(h::CSC_ACTUAL_DMB_CFEB_DAV_MULTIPLICITY_RATE, crateID, dmbSlot, mo) &&
            getCSCHisto(h::CSC_ACTUAL_DMB_CFEB_DAV_MULTIPLICITY_FREQUENCY, crateID, dmbSlot, mof)) {
          for (unsigned short i = 1; i < 7; i++) {
            float cfeb_entries = mo->GetBinContent(i);
            mof->SetBinContent(i, ((float)cfeb_entries / (float)(DMBEvents) * 100.0));
          }
          mof->SetEntries((int)DMBEvents);

          if (getCSCHisto(h::CSC_DMB_CFEB_DAV_MULTIPLICITY_UNPACKING_INEFFICIENCY, crateID, dmbSlot, mo1) &&
              getCSCHisto(h::CSC_DMB_CFEB_DAV_MULTIPLICITY, crateID, dmbSlot, mo2)) {
            for (unsigned short i = 1; i < 9; i++) {
              float actual_dav_num = mo->GetBinContent(i);
              float unpacked_dav_num = mo2->GetBinContent(i);
              if (actual_dav_num) {
                mo1->SetBinContent(i, 1, 100. * (1 - unpacked_dav_num / actual_dav_num));
              }
              mo1->SetEntries((int)DMBEvents);
            }
          }
          mo->Fill(cfeb_dav_num);
        }

        if (getCSCHisto(h::CSC_DMB_CFEB_ACTIVE_VS_DAV, crateID, dmbSlot, mo))
          mo->Fill(cfeb_dav, cfeb_active);

        /** Fill Histogram for FEB DAV Efficiency */
        if (getCSCHisto(h::CSC_ACTUAL_DMB_FEB_DAV_RATE, crateID, dmbSlot, mo)) {
          if (getCSCHisto(h::CSC_ACTUAL_DMB_FEB_DAV_FREQUENCY, crateID, dmbSlot, mo1)) {
            for (int i = 1; i < 4; i++) {
              float dav_num = mo->GetBinContent(i);
              mo1->SetBinContent(i, ((float)dav_num / (float)(DMBEvents) * 100.0));
            }
            mo1->SetEntries((int)DMBEvents);

            if (getCSCHisto(h::CSC_DMB_FEB_DAV_UNPACKING_INEFFICIENCY, crateID, dmbSlot, mof) &&
                getCSCHisto(h::CSC_DMB_FEB_DAV_RATE, crateID, dmbSlot, mo2)) {
              for (int i = 1; i < 4; i++) {
                float actual_dav_num = mo->GetBinContent(i);
                float unpacked_dav_num = mo2->GetBinContent(i);
                if (actual_dav_num) {
                  mof->SetBinContent(i, 1, 100. * (1 - unpacked_dav_num / actual_dav_num));
                }
                mof->SetEntries((int)DMBEvents);
                mof->SetMaximum(100.0);
              }
            }
          }

          if (alct_dav > 0) {
            mo->Fill(0.0);
          }
          if (tmb_dav > 0) {
            mo->Fill(1.0);
          }
          if (cfeb_dav > 0) {
            mo->Fill(2.0);
          }
        }

        float feb_combination_dav = -1.0;
        /** Fill Histogram for Different Combinations of FEB DAV Efficiency */
        if (getCSCHisto(h::CSC_ACTUAL_DMB_FEB_COMBINATIONS_DAV_RATE, crateID, dmbSlot, mo)) {
          if (alct_dav == 0 && tmb_dav == 0 && cfeb_dav == 0)
            feb_combination_dav = 0.0;  // Nothing
          if (alct_dav > 0 && tmb_dav == 0 && cfeb_dav == 0)
            feb_combination_dav = 1.0;  // ALCT Only
          if (alct_dav == 0 && tmb_dav > 0 && cfeb_dav == 0)
            feb_combination_dav = 2.0;  // TMB Only
          if (alct_dav == 0 && tmb_dav == 0 && cfeb_dav > 0)
            feb_combination_dav = 3.0;  // CFEB Only
          if (alct_dav == 0 && tmb_dav > 0 && cfeb_dav > 0)
            feb_combination_dav = 4.0;  // TMB+CFEB
          if (alct_dav > 0 && tmb_dav > 0 && cfeb_dav == 0)
            feb_combination_dav = 5.0;  // ALCT+TMB
          if (alct_dav > 0 && tmb_dav == 0 && cfeb_dav > 0)
            feb_combination_dav = 6.0;  // ALCT+CFEB
          if (alct_dav > 0 && tmb_dav > 0 && cfeb_dav > 0)
            feb_combination_dav = 7.0;  // ALCT+TMB+CFEB
          // mo->Fill(feb_combination_dav);

          if (getCSCHisto(h::CSC_ACTUAL_DMB_FEB_COMBINATIONS_DAV_FREQUENCY, crateID, dmbSlot, mo1)) {
            for (int i = 1; i < 9; i++) {
              float feb_combination_dav_number = mo->GetBinContent(i);
              mo1->SetBinContent(i, ((float)feb_combination_dav_number / (float)(DMBEvents) * 100.0));
            }
            mo1->SetEntries(DMBEvents);

            if (getCSCHisto(h::CSC_DMB_FEB_COMBINATIONS_DAV_UNPACKING_INEFFICIENCY, crateID, dmbSlot, mof) &&
                getCSCHisto(h::CSC_DMB_FEB_COMBINATIONS_DAV_RATE, crateID, dmbSlot, mo2)) {
              for (int i = 1; i < 9; i++) {
                float actual_dav_num = mo->GetBinContent(i);
                float unpacked_dav_num = mo2->GetBinContent(i);
                if (actual_dav_num) {
                  mof->SetBinContent(i, 1, 100. * (1 - unpacked_dav_num / actual_dav_num));
                }
                mof->SetEntries((int)DMBEvents);
                mof->SetMaximum(100.0);
              }
            }
          }
          mo->Fill(feb_combination_dav);
        }
      }
    }

    /** Check and fill CSC Data Flow Problems */

    {
      uint32_t i = 0;
      CSCIdType chamberID = 0;
      while (digi.nextCSCWithStatus(i, chamberID)) {
        unsigned int crateID = (chamberID >> 4) & 0xFF;
        unsigned int dmbSlot = chamberID & 0xF;
        ExaminerStatusType chStatus = digi.getCSCStatus(chamberID);

        if (crateID == 255) {
          continue;
        }
        if ((crateID > 60) || (dmbSlot > 10) || (crateID <= 0) || (dmbSlot <= 0)) {
          continue;
        }

        // Check if in standby!
        {
          CSCDetId cid;
          if (!config->fnGetCSCDetId(crateID, dmbSlot, cid)) {
            continue;
          }
        }

        unsigned int cscType = 0;
        unsigned int cscPosition = 0;
        if (!getCSCFromMap(crateID, dmbSlot, cscType, cscPosition))
          continue;

        if (getCSCHisto(h::CSC_BINCHECK_DATAFLOW_PROBLEMS_TABLE, crateID, dmbSlot, mo)) {
          for (int bit = 0; bit < binChecker.nSTATUSES; bit++) {
            if (chStatus & (1 << bit)) {
              mo->Fill(0., bit);
            }
          }
          mo->SetEntries(config->getChamberCounterValue(DMB_EVENTS, crateID, dmbSlot));
        }

        int anyInputFull = chStatus & 0x3F;
        if (anyInputFull) {
          if (cscPosition && getEMUHisto(h::EMU_CSC_DMB_INPUT_FIFO_FULL, mo)) {
            mo->Fill(cscPosition, cscType);
          }
          if (getEMUHisto(h::EMU_DMB_INPUT_FIFO_FULL, mo)) {
            mo->Fill(crateID, dmbSlot);
          }
        }

        int anyInputTO = (chStatus >> 7) & 0x3FFF;
        if (anyInputTO) {
          if (cscPosition && getEMUHisto(h::EMU_CSC_DMB_INPUT_TIMEOUT, mo)) {
            mo->Fill(cscPosition, cscType);
          }
          if (getEMUHisto(h::EMU_DMB_INPUT_TIMEOUT, mo)) {
            mo->Fill(crateID, dmbSlot);
          }
        }

        if (digi.getCSCStatus(chamberID) & (1 << 22)) {
          if (getEMUHisto(h::EMU_DMB_FORMAT_WARNINGS, mo)) {
            mo->Fill(crateID, dmbSlot);
          }

          if (cscPosition && getEMUHisto(h::EMU_CSC_FORMAT_WARNINGS, mo)) {
            mo->Fill(cscPosition, cscType);
          }
        }
      }
    }

    /**  Check and fill CSC Format Errors  */

    {
      uint32_t i = 0;
      CSCIdType chamberID = 0;
      while (digi.nextCSCWithError(i, chamberID)) {
        const unsigned int crateID = (chamberID >> 4) & 0xFF;
        const unsigned int dmbSlot = chamberID & 0xF;
        const ExaminerStatusType chErr = digi.getCSCErrors(chamberID);

        if ((crateID == 255) || (chErr & 0x80)) {
          continue;  // = Skip chamber detection if DMB header is missing (Error code 6)
        }
        if ((crateID > 60) || (dmbSlot > 10) || (crateID <= 0) || (dmbSlot <= 0)) {
          continue;
        }

        // Check if in standby!
        {
          CSCDetId cid;
          if (!config->fnGetCSCDetId(crateID, dmbSlot, cid)) {
            continue;
          }
        }

        if ((chErr & config->getBINCHECK_MASK()) != 0) {
          config->incChamberCounter(BAD_EVENTS, crateID, dmbSlot);
        }

        bool isCSCError = false;
        bool fillBC = getCSCHisto(h::CSC_BINCHECK_ERRORSTAT_TABLE, crateID, dmbSlot, mo);

        for (int bit = 5; bit < 24; bit++) {
          if (chErr & (1 << bit)) {
            isCSCError = true;
            if (fillBC) {
              mo->Fill(0., bit - 5);
            } else {
              break;
            }
          }

          if (fillBC) {
            mo->SetEntries(config->getChamberCounterValue(DMB_EVENTS, crateID, dmbSlot));
          }
        }

        if (isCSCError) {
          if (getEMUHisto(h::EMU_DMB_FORMAT_ERRORS, mo)) {
            mo->Fill(crateID, dmbSlot);
          }

          if (eventAccepted && getEMUHisto(h::EMU_DMB_UNPACKED_WITH_ERRORS, mo)) {
            mo->Fill(crateID, dmbSlot);
          }

          unsigned int cscType = 0;
          unsigned int cscPosition = 0;
          if (!getCSCFromMap(crateID, dmbSlot, cscType, cscPosition))
            continue;

          if (cscPosition && getEMUHisto(h::EMU_CSC_FORMAT_ERRORS, mo)) {
            mo->Fill(cscPosition, cscType);
          }

          if (eventAccepted && cscPosition && getEMUHisto(h::EMU_CSC_UNPACKED_WITH_ERRORS, mo)) {
            mo->Fill(cscPosition, cscType);
          }
        }
      }
    }

    return eventAccepted;
  }

}  // namespace cscdqm