CSCDCCExaminer

Macros

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
#ifndef EventFilter_CSCRawToDigi_CSCDCCExaminer_h
#define EventFilter_CSCRawToDigi_CSCDCCExaminer_h
#include <set>
#include <map>
#include <vector>
#include <string>
#ifdef LOCAL_UNPACK
#include <iostream>
#else
#include <ostream>
#endif

#include "DataFormats/CSCDigi/interface/CSCDCCFormatStatusDigi.h"

class CSCDCCExaminer {
public:
  const uint16_t nERRORS, nWARNINGS, nPAYLOADS, nSTATUSES;

private:
  std::vector<const char*> sERROR, sWARNING, sERROR_, sWARNING_, sDMBExpectedPayload, sDMBEventStaus;
  ExaminerStatusType bERROR, bWARNING;
  ExaminerStatusType bSUM_ERROR, bSUM_WARNING;  // Summary flags for errors and warnings
  bool fERROR[29];                              //[nERRORS];
  bool fWARNING[5];                             //[nWARNINGS];
  bool fSUM_ERROR[29];                          //[nERRORS];
  bool fSUM_WARNING[5];                         //[nWARNINGS];

  std::set<CSCIdType> fCHAMB_ERR[29];                      // Set of chambers which contain particular error
  std::set<CSCIdType> fCHAMB_WRN[5];                       // Set of chambers which contain particular warning
  std::map<CSCIdType, ExaminerStatusType> bCHAMB_ERR;      // chamber <=> errors in bits
  std::map<CSCIdType, ExaminerStatusType> bCHAMB_WRN;      // chamber <=> errors in bits
  std::map<CSCIdType, ExaminerStatusType> bCHAMB_PAYLOAD;  //
  std::map<CSCIdType, ExaminerStatusType> bCHAMB_STATUS;   //
  std::map<DDUIdType, ExaminerStatusType> bDDU_ERR;        // ddu     <-> errors in bits
  std::map<DDUIdType, ExaminerStatusType> bDDU_WRN;        // ddu     <-> errors in bits

#ifdef LOCAL_UNPACK
  class OStream : public std::ostream {
  private:
    class buffer : public std::streambuf {};
    buffer buff;
    std::streambuf* stream;
    std::streambuf* null;
    std::string name;

  public:
    void show(void) { rdbuf(stream); }
    void hide(void) { rdbuf(null); }
    void sign(std::string nm) { name = nm; }
    void sign(const char* nm) { name = nm; }

    void redirect(std::ostream& str) {
      stream = str.rdbuf();
      tie(&str);
      if (rdbuf() != null)
        rdbuf(stream);
    }

    template <class T>
    std::ostream& operator<<(const T& val) {
      return (*(std::ostream*)this) << name << val;
    }

    OStream(void) : std::ostream(std::cout.rdbuf()), buff(), stream(std::cout.rdbuf()), null(&buff), name("") {}
    OStream(std::ostream& str) : std::ostream(str.rdbuf()), buff(), stream(str.rdbuf()), null(&buff), name("") {}
  };

  OStream COUT, CERR;
#endif

  CSCIdType currentChamber;  // ( (CrateNumber<<4) + DMBslot ) specifies chamber

  const uint16_t *buf_2, *buf_1, *buf0, *buf1, *buf2;
  uint16_t tmpbuf[16];

  bool fDCC_Header;
  bool fDCC_Trailer;
  bool fDDU_Header;
  bool fDDU_Trailer;
  bool fDMB_Header;
  bool fDMB_Trailer;
  bool fALCT_Header;
  bool fTMB_Header;
  bool fTMB_Format2007;
  bool fALCT_Format2007;
  bool fFormat2013;

  bool uniqueALCT, uniqueTMB;  // Do not merge two DMBs if Trailer of the first and Header of the second are lost

  bool DAV_ALCT;          // ...
  bool DAV_TMB;           // Check if DAV bits lie
  int DAV_CFEB;           // ...
  int DAV_DMB;            // ...
  int DMB_Active, nDMBs;  // ...

public:
  uint32_t cntDDU_Headers;
  uint32_t cntDDU_Trailers;
  std::map<CSCIdType, uint32_t> cntCHAMB_Headers;
  std::map<CSCIdType, uint32_t> cntCHAMB_Trailers;

private:
  void clear();
  void zeroCounts();
  void sync_stats();
  /// checks DAV_ALCT, DAV_TMB, and DAV_CFEB
  void checkDAVs();
  void checkTriggerHeadersAndTrailers();

  inline int scanbuf(const uint16_t*& buf, int32_t length, uint16_t sig, uint16_t mask = 0xFFFF);

  uint32_t DDU_WordsSinceLastHeader;
  uint32_t DDU_WordCount;
  uint32_t DDU_WordMismatch_Occurrences;
  uint32_t DDU_WordsSinceLastTrailer;

  uint32_t ALCT_WordsSinceLastHeader;
  uint32_t ALCT_WordsSinceLastHeaderZeroSuppressed;
  uint32_t ALCT_WordCount;
  uint32_t ALCT_WordsExpected;
  uint32_t ALCT_WordsBeforeRaw;  /// number of ALCT words before anode raw data
  uint32_t ALCT_ZSE;             /// check zero suppression mode
  uint32_t nWG_round_up;         /// to decode if zero suppression enabled

  uint32_t TMB_WordsSinceLastHeader;
  uint32_t TMB_WordCount;
  uint32_t TMB_WordsExpected;
  uint32_t TMB_Tbins;
  uint32_t TMB_WordsRPC;
  uint32_t TMB_WordsGEM;
  uint32_t TMB_Firmware_Revision;
  uint32_t DDU_Firmware_Revision;

  uint32_t CFEB_SampleWordCount;
  uint32_t CFEB_SampleCount;
  uint32_t CFEB_BSampleCount;

  bool checkCrcALCT;
  uint32_t ALCT_CRC;
  bool checkCrcTMB;
  uint32_t TMB_CRC;
  bool checkCrcCFEB;
  uint32_t CFEB_CRC;

  bool modeDDUonly;
  DDUIdType sourceID;
  ExaminerMaskType examinerMask;

  //int headerDAV_Active; // Obsolete since 16.09.05

  // data blocks:
  std::map<DDUIdType, const uint16_t*> dduBuffers;                        // < DDUsourceID, pointer >
  std::map<DDUIdType, std::map<CSCIdType, const uint16_t*> > dmbBuffers;  // < DDUsourceID, < DMBid, pointer > >
  std::map<DDUIdType, uint32_t> dduOffsets;                               // < DDUsourceID, pointer_offset >
  std::map<DDUIdType, std::map<CSCIdType, uint32_t> > dmbOffsets;         // < DDUsourceID, < DMBid, pointer_offset > >
  std::map<DDUIdType, uint32_t> dduSize;                                  // < DDUsourceID, block_size >
  std::map<DDUIdType, std::map<CSCIdType, uint32_t> > dmbSize;            // < DDUsourceID, < DMBid, block_size > >
  const uint16_t* buffer_start;

public:
#ifdef LOCAL_UNPACK
  OStream& output1(void) { return COUT; }
  OStream& output2(void) { return CERR; }
#endif

  int32_t check(const uint16_t*& buffer, int32_t length);

  void setMask(ExaminerMaskType mask) { examinerMask = mask; }
  ExaminerMaskType getMask() const { return examinerMask; }

  ExaminerStatusType errors(void) const { return bSUM_ERROR; }
  ExaminerStatusType warnings(void) const { return bSUM_WARNING; }

  const char* errName(int num) const {
    if (num >= 0 && num < nERRORS)
      return sERROR[num];
    else
      return "";
  }
  const char* wrnName(int num) const {
    if (num >= 0 && num < nWARNINGS)
      return sWARNING[num];
    else
      return "";
  }

  const char* errorName(int num) const {
    if (num >= 0 && num < nERRORS)
      return sERROR_[num];
    else
      return "";
  }
  const char* warningName(int num) const {
    if (num >= 0 && num < nWARNINGS)
      return sWARNING_[num];
    else
      return "";
  }

  const char* payloadName(int num) const {
    if (num >= 0 && num < nPAYLOADS)
      return sDMBExpectedPayload[num];
    else
      return "";
  }
  const char* statusName(int num) const {
    if (num >= 0 && num < nSTATUSES)
      return sDMBEventStaus[num];
    else
      return "";
  }

  bool error(int num) const {
    if (num >= 0 && num < nERRORS)
      return fSUM_ERROR[num];
    else
      return false;
  }
  bool warning(int num) const {
    if (num >= 0 && num < nWARNINGS)
      return fSUM_WARNING[num];
    else
      return false;
  }

  std::set<CSCIdType> chambersWithError(int num) const {
    if (num >= 0 && num < nERRORS)
      return fCHAMB_ERR[num];
    else
      return std::set<int>();
  }
  std::set<CSCIdType> chambersWithWarning(int num) const {
    if (num >= 0 && num < nWARNINGS)
      return fCHAMB_WRN[num];
    else
      return std::set<int>();
  }

  ExaminerStatusType payloadForChamber(CSCIdType chamber) const {
    std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_PAYLOAD.find(chamber);
    if (item != bCHAMB_PAYLOAD.end())
      return item->second;
    else
      return 0;
  }

  ExaminerStatusType statusForChamber(CSCIdType chamber) const {
    std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_STATUS.find(chamber);
    if (item != bCHAMB_STATUS.end())
      return item->second;
    else
      return 0;
  }

  ExaminerStatusType errorsForChamber(CSCIdType chamber) const {
    std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_ERR.find(chamber);
    /// Print (for debugging, to be removed)

    // for(item =bCHAMB_ERR.begin() ; item !=bCHAMB_ERR.end() ; item++)
    //std::cout << " Ex-errors: " << std::hex << (*item).second << std::dec << std::endl;

    item = bCHAMB_ERR.find(chamber);
    if (item != bCHAMB_ERR.end())
      return item->second;
    else
      return 0;
  }

  ExaminerStatusType warningsForChamber(CSCIdType chamber) const {
    std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_WRN.find(chamber);
    if (item != bCHAMB_WRN.end())
      return item->second;
    else
      return 0;
  }

  ExaminerStatusType errorsForDDU(DDUIdType dduSourceID) const {
    std::map<DDUIdType, ExaminerStatusType>::const_iterator item = bDDU_ERR.find(dduSourceID);
    if (item != bDDU_ERR.end())
      return item->second;
    else
      return 0;
  }
  ExaminerStatusType warningsForDDU(DDUIdType dduSourceID) const {
    std::map<DDUIdType, ExaminerStatusType>::const_iterator item = bDDU_WRN.find(dduSourceID);
    if (item != bDDU_WRN.end())
      return item->second;
    else
      return 0;
  }
  std::vector<DDUIdType> listOfDDUs(void) const {
    std::vector<DDUIdType> DDUs;
    std::map<DDUIdType, ExaminerStatusType>::const_iterator item = bDDU_ERR.begin();
    while (item != bDDU_ERR.end()) {
      DDUs.push_back(item->first);
      item++;
    }
    return DDUs;
  }

  std::map<DDUIdType, ExaminerStatusType> errorsDetailedDDU(void) const { return bDDU_ERR; }

  std::map<CSCIdType, ExaminerStatusType> errorsDetailed(void) const { return bCHAMB_ERR; }
  std::map<CSCIdType, ExaminerStatusType> warningsDetailed(void) const { return bCHAMB_WRN; }
  std::map<CSCIdType, ExaminerStatusType> payloadDetailed(void) const { return bCHAMB_PAYLOAD; }
  std::map<CSCIdType, ExaminerStatusType> statusDetailed(void) const { return bCHAMB_STATUS; }

  void crcALCT(bool enable);
  void crcTMB(bool enable);
  void crcCFEB(bool enable);

  void modeDDU(bool enable);

  bool isDDUmode() { return modeDDUonly; };

  DDUIdType dduSourceID(void) { return sourceID; }

  std::map<DDUIdType, const uint16_t*> DDU_block(void) const { return dduBuffers; }
  std::map<DDUIdType, std::map<CSCIdType, const uint16_t*> > DMB_block(void) const { return dmbBuffers; }

  std::map<DDUIdType, uint32_t> DDU_ptrOffsets(void) const { return dduOffsets; }
  std::map<DDUIdType, std::map<CSCIdType, uint32_t> > DMB_ptrOffsets(void) const { return dmbOffsets; }

  std::map<DDUIdType, uint32_t> DDU_size(void) const { return dduSize; }
  std::map<DDUIdType, std::map<CSCIdType, uint32_t> > DMB_size(void) const { return dmbSize; }

  CSCDCCExaminer(ExaminerMaskType mask = 0x1);
  ~CSCDCCExaminer(void) {}
};

#endif