File indexing completed on 2024-04-06 12:03:59
0001 #ifndef CSCDCCFormatStatusDigi_CSCDCCFormatStatusDigi_h
0002 #define CSCDCCFormatStatusDigi_CSCDCCFormatStatusDigi_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0024 #include <set>
0025 #include <map>
0026 #include <algorithm>
0027 #include <iosfwd>
0028
0029
0030 typedef int32_t DCCIdType;
0031
0032
0033 typedef int16_t DDUIdType;
0034
0035
0036 typedef int32_t CSCIdType;
0037
0038
0039 typedef uint32_t ExaminerMaskType;
0040 typedef uint32_t ExaminerStatusType;
0041
0042
0043 enum FormatErrorFlag {
0044 ANY_ERRORS = 0,
0045 DDU_TRAILER_MISSING = 1,
0046 DDU_HEADER_MISSING = 2,
0047 DDU_CRC_ERROR = 3,
0048 DDU_WORD_COUNT_ERROR = 4,
0049 DMB_TRAILER_MISSING = 5,
0050 DMB_HEADER_MISSING = 6,
0051 ALCT_TRAILER_MISSING = 7,
0052 ALCT_HEADER_MISSING = 8,
0053 ALCT_WORD_COUNT_ERROR = 9,
0054 ALCT_CRC_ERROR = 10,
0055 ALCT_TRAILER_BIT_ERROR = 11,
0056 TMB_TRAILER_MISSING = 12,
0057 TMB_HEADER_MISSING = 13,
0058 TMB_WORD_COUNT_ERROR = 14,
0059 TMB_CRC_ERROR = 15,
0060 CFEB_WORD_COUNT_PER_SAMPLE_ERROR = 16,
0061 CFEB_SAMPLE_COUNT_ERROR = 17,
0062 CFEB_CRC_ERROR = 18,
0063 DDU_EVENT_SIZE_LIMIT_ERROR = 19,
0064 C_WORDS = 20,
0065 ALCT_DAV_ERROR = 21,
0066 TMB_DAV_ERROR = 22,
0067 CFEB_DAV_ERROR = 23,
0068 DMB_ACTIVE_ERROR = 24,
0069 DCC_TRAILER_MISSING = 25,
0070 DCC_HEADER_MISSING = 26,
0071 DMB_DAV_VS_DMB_ACTIVE_MISMATCH_ERROR = 27,
0072 EXTRA_WORDS_BETWEEN_DDU_HEADER_AND_FIRST_DMB_HEADER = 28
0073 };
0074
0075
0076 enum CSCPayloadFlag {
0077 CFEB1_ACTIVE = 0,
0078 CFEB2_ACTIVE = 1,
0079 CFEB3_ACTIVE = 2,
0080 CFEB4_ACTIVE = 3,
0081 CFEB5_ACTIVE = 4,
0082 ALCT_DAV = 5,
0083 TMB_DAV = 6,
0084 CFEB1_DAV = 7,
0085 CFEB2_DAV = 8,
0086 CFEB3_DAV = 9,
0087 CFEB4_DAV = 10,
0088 CFEB5_DAV = 11
0089 };
0090
0091
0092 enum CSCStatusFlag {
0093 ALCT_FIFO_FULL = 0,
0094 TMB_FIFO_FULL = 1,
0095 CFEB1_FIFO_FULL = 2,
0096 CFEB2_FIFO_FULL = 3,
0097 CFEB3_FIFO_FULL = 4,
0098 CFEB4_FIFO_FULL = 5,
0099 CFEB5_FIFO_FULL = 6,
0100 ALCT_START_TIMEOUT = 7,
0101 TMB_START_TIMEOUT = 8,
0102 CFEB1_START_TIMEOUT = 9,
0103 CFEB2_START_TIMEOUT = 10,
0104 CFEB3_START_TIMEOUT = 11,
0105 CFEB4_START_TIMEOUT = 12,
0106 CFEB5_START_TIMEOUT = 13,
0107 ALCT_END_TIMEOUT = 14,
0108 TMB_END_TIMEOUT = 15,
0109 CFEB1_END_TIMEOUT = 16,
0110 CFEB2_END_TIMEOUT = 17,
0111 CFEB3_END_TIMEOUT = 18,
0112 CFEB4_END_TIMEOUT = 19,
0113 CFEB5_END_TIMEOUT = 20,
0114 CFEB_ACTIVE_DAV_MISMATCH = 21,
0115 B_WORDS_FOUND = 22
0116 };
0117
0118
0119
0120
0121
0122
0123
0124
0125 template <class TKey, class TVal>
0126 bool nextInMap(uint32_t& it, TKey& key, const std::map<TKey, TVal>& m) {
0127 uint32_t c = 0;
0128 typename std::map<TKey, TVal>::const_iterator itr = m.begin();
0129 while (itr != m.end()) {
0130 if (c == it) {
0131 it++;
0132 key = itr->first;
0133 return true;
0134 }
0135 itr++;
0136 c++;
0137 }
0138 return false;
0139 }
0140
0141
0142
0143
0144
0145
0146 template <class TKey, class TVal>
0147 std::set<TKey> getKeysList(const std::map<TKey, TVal>& m) {
0148 std::set<TKey> keys;
0149 typename std::map<TKey, TVal>::const_iterator itr;
0150 for (itr = m.begin(); itr != m.end(); ++itr) {
0151 keys.insert(itr->first);
0152 }
0153 return keys;
0154 }
0155
0156
0157
0158
0159
0160 class CSCDCCFormatStatusDigi {
0161 private:
0162
0163
0164
0165
0166
0167 ExaminerMaskType fDCC_MASK;
0168
0169
0170 ExaminerMaskType fCSC_MASK;
0171
0172
0173 DCCIdType DCCId;
0174
0175
0176 ExaminerStatusType fDDU_SUMMARY_ERRORS;
0177
0178 std::map<DDUIdType, ExaminerStatusType> mDDU_ERRORS;
0179 std::map<CSCIdType, ExaminerStatusType> mCSC_ERRORS;
0180 std::map<CSCIdType, ExaminerStatusType> mCSC_PAYLOADS;
0181 std::map<CSCIdType, ExaminerStatusType> mCSC_STATUS;
0182
0183 protected:
0184
0185 CSCIdType makeCSCId(const uint16_t crateId, const uint16_t dmbId) const {
0186 return ((CSCIdType(crateId & 0xFF) << 4) | (dmbId & 0xF));
0187 }
0188
0189
0190 void init() {
0191 fDDU_SUMMARY_ERRORS = 0;
0192 fCSC_MASK = 0;
0193 fDCC_MASK = 0;
0194 mDDU_ERRORS.clear();
0195 mCSC_ERRORS.clear();
0196 mCSC_PAYLOADS.clear();
0197 mCSC_STATUS.clear();
0198 }
0199
0200 public:
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211 CSCDCCFormatStatusDigi(const DCCIdType DCCId_,
0212 const ExaminerMaskType fDCC_MASK_,
0213 const ExaminerMaskType fCSC_MASK_,
0214 const ExaminerStatusType fDDU_SUMMARY_ERRORS_,
0215 const std::map<DDUIdType, ExaminerStatusType>& mDDU_ERRORS_,
0216 const std::map<CSCIdType, ExaminerStatusType>& mCSC_ERRORS_,
0217 const std::map<CSCIdType, ExaminerStatusType>& mCSC_PAYLOADS_,
0218 const std::map<CSCIdType, ExaminerStatusType>& mCSC_STATUS_)
0219 : DCCId(DCCId_) {
0220 init();
0221 setDCCExaminerInfo(
0222 fDCC_MASK_, fCSC_MASK_, fDDU_SUMMARY_ERRORS_, mDDU_ERRORS_, mCSC_ERRORS_, mCSC_PAYLOADS_, mCSC_STATUS_);
0223 }
0224
0225 CSCDCCFormatStatusDigi(const DCCIdType DCCId_) : DCCId(DCCId_) { init(); }
0226
0227
0228 CSCDCCFormatStatusDigi() : DCCId(0) { init(); }
0229
0230
0231 void setDCCExaminerInfo(const ExaminerMaskType fDCC_MASK_,
0232 const ExaminerMaskType fCSC_MASK_,
0233 const ExaminerStatusType fDDU_SUMMARY_ERRORS_,
0234 const std::map<DDUIdType, ExaminerStatusType>& mDDU_ERRORS_,
0235 const std::map<CSCIdType, ExaminerStatusType>& mCSC_ERRORS_,
0236 const std::map<CSCIdType, ExaminerStatusType>& mCSC_PAYLOADS_,
0237 const std::map<CSCIdType, ExaminerStatusType>& mCSC_STATUS_);
0238
0239 #ifdef DEBUG
0240
0241
0242
0243 void setDCCId(DCCIdType id) { DCCId = id; }
0244 void setDCCMask(ExaminerMaskType mask) { fDCC_MASK = mask; }
0245 void setCSCMask(ExaminerMaskType mask) { fCSC_MASK = mask; }
0246 void setDDUSummaryErrors(ExaminerStatusType status) { fDDU_SUMMARY_ERRORS = status; }
0247 void setDDUErrors(DDUIdType DDUId, ExaminerStatusType status) {
0248 std::map<DDUIdType, ExaminerStatusType>::const_iterator item = mDDU_ERRORS.find(DDUId);
0249 if (item != mDDU_ERRORS.end())
0250 mDDU_ERRORS[DDUId] = status;
0251 else
0252 mDDU_ERRORS.insert(std::make_pair(DDUId, status));
0253 }
0254 void setCSCErrors(CSCIdType CSCId, ExaminerStatusType status) {
0255 std::map<CSCIdType, ExaminerStatusType>::const_iterator item = mCSC_ERRORS.find(CSCId);
0256 if (item != mCSC_ERRORS.end())
0257 mCSC_ERRORS[CSCId] = status;
0258 else
0259 mCSC_ERRORS.insert(std::make_pair(CSCId, status));
0260 }
0261 void setCSCPayload(CSCIdType CSCId, ExaminerStatusType status) {
0262 std::map<CSCIdType, ExaminerStatusType>::const_iterator item = mCSC_PAYLOADS.find(CSCId);
0263 if (item != mCSC_PAYLOADS.end())
0264 mCSC_PAYLOADS[CSCId] = status;
0265 else
0266 mCSC_PAYLOADS.insert(std::make_pair(CSCId, status));
0267 }
0268 void setCSCStatus(CSCIdType CSCId, ExaminerStatusType status) {
0269 std::map<CSCIdType, ExaminerStatusType>::const_iterator item = mCSC_STATUS.find(CSCId);
0270 if (item != mCSC_STATUS.end())
0271 mCSC_STATUS[CSCId] = status;
0272 else
0273 mCSC_STATUS.insert(std::make_pair(CSCId, status));
0274 }
0275
0276 #endif
0277
0278
0279
0280
0281
0282
0283 std::set<DDUIdType> getListOfDDUs() const { return getKeysList(mDDU_ERRORS); }
0284
0285 std::set<CSCIdType> getListOfCSCs() const { return getKeysList(mCSC_PAYLOADS); }
0286
0287 std::set<CSCIdType> getListOfCSCsWithErrors() const { return getKeysList(mCSC_ERRORS); }
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302 bool nextCSCWithError(uint32_t& iterator, CSCIdType& CSCId) const { return nextInMap(iterator, CSCId, mCSC_ERRORS); }
0303
0304
0305
0306
0307
0308
0309
0310
0311 bool nextCSCWithStatus(uint32_t& iterator, CSCIdType& CSCId) const { return nextInMap(iterator, CSCId, mCSC_STATUS); }
0312
0313
0314
0315
0316
0317
0318
0319
0320 bool nextCSCWithPayload(uint32_t& iterator, CSCIdType& CSCId) const {
0321 return nextInMap(iterator, CSCId, mCSC_PAYLOADS);
0322 }
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333 ExaminerStatusType getDDUSummaryErrors() const { return fDDU_SUMMARY_ERRORS; }
0334
0335 ExaminerStatusType getDDUErrors(const DDUIdType DDUId) const {
0336 std::map<DDUIdType, ExaminerStatusType>::const_iterator item = mDDU_ERRORS.find(DDUId);
0337 if (item != mDDU_ERRORS.end())
0338 return item->second;
0339 else
0340 return 0;
0341 }
0342
0343 ExaminerStatusType getCSCErrors(const CSCIdType CSCId) const {
0344 std::map<CSCIdType, ExaminerStatusType>::const_iterator item = mCSC_ERRORS.find(CSCId);
0345 if (item != mCSC_ERRORS.end())
0346 return item->second;
0347 else
0348 return 0;
0349 }
0350
0351 ExaminerStatusType getCSCErrors(const uint16_t crateId, const uint16_t dmbId) const {
0352 return getCSCErrors(makeCSCId(crateId, dmbId));
0353 }
0354
0355 ExaminerStatusType getCSCPayload(const CSCIdType CSCId) const {
0356 std::map<CSCIdType, ExaminerStatusType>::const_iterator item = mCSC_PAYLOADS.find(CSCId);
0357 if (item != mCSC_PAYLOADS.end())
0358 return item->second;
0359 else
0360 return 0;
0361 }
0362
0363 ExaminerStatusType getCSCPayload(const uint16_t crateId, const uint16_t dmbId) const {
0364 return getCSCPayload(makeCSCId(crateId, dmbId));
0365 }
0366
0367 ExaminerStatusType getCSCStatus(const CSCIdType CSCId) const {
0368 std::map<CSCIdType, ExaminerStatusType>::const_iterator item = mCSC_STATUS.find(CSCId);
0369 if (item != mCSC_STATUS.end())
0370 return item->second;
0371 else
0372 return 0;
0373 }
0374
0375 ExaminerStatusType getCSCStatus(const uint16_t crateId, const uint16_t dmbId) const {
0376 return getCSCStatus(makeCSCId(crateId, dmbId));
0377 }
0378
0379
0380
0381
0382 DCCIdType getDCCId() const { return DCCId; }
0383
0384
0385
0386
0387 ExaminerMaskType getDCCMask() const { return fDCC_MASK; }
0388
0389
0390
0391
0392 ExaminerMaskType getCSCMask() const { return fCSC_MASK; }
0393
0394
0395
0396
0397
0398 bool getDDUSummaryFlag(const FormatErrorFlag flag) const {
0399 return ((fDDU_SUMMARY_ERRORS & ExaminerStatusType(0x1 << flag)) != 0);
0400 }
0401 bool getDDUErrorFlag(const DDUIdType DDUId, const FormatErrorFlag flag) const {
0402 return ((getDDUErrors(DDUId) & ExaminerStatusType(0x1 << flag)) != 0);
0403 }
0404
0405 bool getCSCErrorFlag(const CSCIdType CSCId, const FormatErrorFlag flag) const {
0406 return ((getCSCErrors(CSCId) & ExaminerStatusType(0x1 << flag)) != 0);
0407 }
0408
0409 bool getCSCErrorFlag(const uint16_t crateId, const uint16_t dmbId, const FormatErrorFlag flag) const {
0410 return ((getCSCErrors(crateId, dmbId) & ExaminerStatusType(0x1 << flag)) != 0);
0411 }
0412
0413 bool getCSCPayloadFlag(const CSCIdType CSCId, const CSCPayloadFlag flag) const {
0414 return ((getCSCPayload(CSCId) & ExaminerStatusType(0x1 << flag)) != 0);
0415 }
0416
0417 bool getCSCPayloadFlag(const uint16_t crateId, const uint16_t dmbId, const CSCPayloadFlag flag) const {
0418 return ((getCSCPayload(crateId, dmbId) & ExaminerStatusType(0x1 << flag)) != 0);
0419 }
0420
0421 bool getCSCStatusFlag(const CSCIdType CSCId, const CSCStatusFlag flag) const {
0422 return ((getCSCStatus(CSCId) & ExaminerStatusType(0x1 << flag)) != 0);
0423 }
0424
0425 bool getCSCStatusFlag(const uint16_t crateId, const uint16_t dmbId, const CSCStatusFlag flag) const {
0426 return ((getCSCStatus(crateId, dmbId) & ExaminerStatusType(0x1 << flag)) != 0);
0427 }
0428
0429 void print() const;
0430 };
0431
0432 std::ostream& operator<<(std::ostream& o, const CSCDCCFormatStatusDigi& digi);
0433
0434 #endif