CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DataFormats/CSCDigi/interface/CSCDCCFormatStatusDigi.h

Go to the documentation of this file.
00001 #ifndef CSCDCCFormatStatusDigi_CSCDCCFormatStatusDigi_h
00002 #define CSCDCCFormatStatusDigi_CSCDCCFormatStatusDigi_h
00003 
00004 
00005 /*
00006  * =====================================================================================
00007  *
00008  *       Filename:  CSCDCCFormatStatusDigi.h
00009  *
00010  *    Description:  CSC DCC Format error, status and payload flags for a single DCC
00011  *
00012  *        Version:  1.0
00013  *        Created:  02/12/2009 03:22:34 PM
00014  *       Revision:  none
00015  *       Compiler:  gcc
00016  *
00017  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch,
00018  *                  Victor Barashko (VB), victor.barashko@cern.ch
00019  *        Company:  CERN, CH
00020  *
00021  * =====================================================================================
00022  */
00023 
00024 
00025 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00026 #include <set>
00027 #include <map>
00028 #include <algorithm>
00029 #include <iosfwd>
00030 
00031 
00033 typedef int32_t DCCIdType;
00034 
00036 typedef int16_t DDUIdType;
00037 
00039 typedef int32_t CSCIdType;
00040 
00042 typedef uint32_t ExaminerMaskType;
00043 typedef uint32_t ExaminerStatusType;
00044 
00046 enum FormatErrorFlag {
00047   ANY_ERRORS                                          = 0,
00048   DDU_TRAILER_MISSING                                 = 1,
00049   DDU_HEADER_MISSING                                  = 2,
00050   DDU_CRC_ERROR                                       = 3,
00051   DDU_WORD_COUNT_ERROR                                = 4,
00052   DMB_TRAILER_MISSING                                 = 5,
00053   DMB_HEADER_MISSING                                  = 6,
00054   ALCT_TRAILER_MISSING                                = 7,
00055   ALCT_HEADER_MISSING                                 = 8,
00056   ALCT_WORD_COUNT_ERROR                               = 9,
00057   ALCT_CRC_ERROR                                      = 10,
00058   ALCT_TRAILER_BIT_ERROR                              = 11,
00059   TMB_TRAILER_MISSING                                 = 12,
00060   TMB_HEADER_MISSING                                  = 13,
00061   TMB_WORD_COUNT_ERROR                                = 14,
00062   TMB_CRC_ERROR                                       = 15,
00063   CFEB_WORD_COUNT_PER_SAMPLE_ERROR                    = 16,
00064   CFEB_SAMPLE_COUNT_ERROR                             = 17,
00065   CFEB_CRC_ERROR                                      = 18,
00066   DDU_EVENT_SIZE_LIMIT_ERROR                          = 19,
00067   C_WORDS                                             = 20,
00068   ALCT_DAV_ERROR                                      = 21,
00069   TMB_DAV_ERROR                                       = 22,
00070   CFEB_DAV_ERROR                                      = 23,
00071   DMB_ACTIVE_ERROR                                    = 24,
00072   DCC_TRAILER_MISSING                                 = 25,
00073   DCC_HEADER_MISSING                                  = 26,
00074   DMB_DAV_VS_DMB_ACTIVE_MISMATCH_ERROR                = 27,
00075   EXTRA_WORDS_BETWEEN_DDU_HEADER_AND_FIRST_DMB_HEADER = 28
00076 };
00077 
00079 enum CSCPayloadFlag {
00080   CFEB1_ACTIVE = 0,
00081   CFEB2_ACTIVE = 1,
00082   CFEB3_ACTIVE = 2,
00083   CFEB4_ACTIVE = 3,
00084   CFEB5_ACTIVE = 4,
00085   ALCT_DAV     = 5,
00086   TMB_DAV      = 6,
00087   CFEB1_DAV    = 7,
00088   CFEB2_DAV    = 8,
00089   CFEB3_DAV    = 9,
00090   CFEB4_DAV    = 10,
00091   CFEB5_DAV    = 11
00092 };
00093 
00095 enum CSCStatusFlag {
00096   ALCT_FIFO_FULL           = 0,
00097   TMB_FIFO_FULL            = 1,
00098   CFEB1_FIFO_FULL          = 2,
00099   CFEB2_FIFO_FULL          = 3,
00100   CFEB3_FIFO_FULL          = 4,
00101   CFEB4_FIFO_FULL          = 5,
00102   CFEB5_FIFO_FULL          = 6,
00103   ALCT_START_TIMEOUT       = 7,
00104   TMB_START_TIMEOUT        = 8,
00105   CFEB1_START_TIMEOUT      = 9,
00106   CFEB2_START_TIMEOUT      = 10,
00107   CFEB3_START_TIMEOUT      = 11,
00108   CFEB4_START_TIMEOUT      = 12,
00109   CFEB5_START_TIMEOUT      = 13,
00110   ALCT_END_TIMEOUT         = 14,
00111   TMB_END_TIMEOUT          = 15,
00112   CFEB1_END_TIMEOUT        = 16,
00113   CFEB2_END_TIMEOUT        = 17,
00114   CFEB3_END_TIMEOUT        = 18,
00115   CFEB4_END_TIMEOUT        = 19,
00116   CFEB5_END_TIMEOUT        = 20,
00117   CFEB_ACTIVE_DAV_MISMATCH = 21,
00118   B_WORDS_FOUND            = 22
00119 };
00120     
00128 template <class TKey, class TVal>
00129 bool nextInMap(uint32_t& it, TKey& key, const std::map<TKey, TVal>& m) { 
00130   uint32_t c = 0;
00131   typename std::map<TKey, TVal>::const_iterator itr = m.begin();
00132   while (itr != m.end()) {
00133     if (c == it) {
00134       it++;
00135       key = itr->first;
00136       return true;
00137     }
00138     itr++;
00139     c++;
00140   }
00141   return false;
00142 }
00143 
00149 template <class TKey, class TVal>
00150 std::set<TKey> getKeysList(const std::map<TKey, TVal>& m)
00151 {
00152   std::set<TKey> keys;
00153   typename std::map<TKey, TVal>::const_iterator itr;
00154   for (itr  = m.begin(); itr != m.end(); ++itr) {
00155      keys.insert(itr->first);
00156   }
00157   return keys;
00158 }
00159 
00164 class CSCDCCFormatStatusDigi {
00165 
00166  private:
00167 
00174   ExaminerMaskType fDCC_MASK;
00175 
00177   ExaminerMaskType fCSC_MASK;
00178 
00180   DCCIdType DCCId;
00181 
00183   ExaminerStatusType fDDU_SUMMARY_ERRORS;
00184 
00185   std::map<DDUIdType, ExaminerStatusType> mDDU_ERRORS;
00186   std::map<CSCIdType, ExaminerStatusType> mCSC_ERRORS;
00187   std::map<CSCIdType, ExaminerStatusType> mCSC_PAYLOADS;
00188   std::map<CSCIdType, ExaminerStatusType> mCSC_STATUS;
00189 
00190  protected:
00191 
00193   CSCIdType makeCSCId(const uint16_t crateId, const uint16_t dmbId) const
00194     { return ( (CSCIdType(crateId&0xFF)<<4) | (dmbId&0xF) ); }
00195 
00197   void init() {
00198     fDDU_SUMMARY_ERRORS = 0;
00199     fCSC_MASK = 0;
00200     fDCC_MASK = 0;
00201     mDDU_ERRORS.clear();
00202     mCSC_ERRORS.clear();
00203     mCSC_PAYLOADS.clear();
00204     mCSC_STATUS.clear();
00205   }
00206 
00207  public:
00208 
00219   CSCDCCFormatStatusDigi(const DCCIdType DCCId_, 
00220                          const ExaminerMaskType fDCC_MASK_,
00221                          const ExaminerMaskType fCSC_MASK_,
00222                          const ExaminerStatusType fDDU_SUMMARY_ERRORS_,
00223                          const std::map<DDUIdType, ExaminerStatusType> mDDU_ERRORS_,
00224                          const std::map<CSCIdType, ExaminerStatusType> mCSC_ERRORS_,
00225                          const std::map<CSCIdType, ExaminerStatusType> mCSC_PAYLOADS_,
00226                          const std::map<CSCIdType, ExaminerStatusType> mCSC_STATUS_): DCCId(DCCId_) 
00227     {
00228       init();
00229       setDCCExaminerInfo(fDCC_MASK_, fCSC_MASK_, fDDU_SUMMARY_ERRORS_, mDDU_ERRORS_, mCSC_ERRORS_, mCSC_PAYLOADS_, mCSC_STATUS_);
00230     }
00231 
00232 
00233   CSCDCCFormatStatusDigi(const DCCIdType DCCId_): DCCId(DCCId_) {init();}
00234 
00235 
00237   CSCDCCFormatStatusDigi (): DCCId(0) {init();}
00238 
00239 
00241   void setDCCExaminerInfo(const ExaminerMaskType fDCC_MASK_,
00242                          const ExaminerMaskType fCSC_MASK_,
00243                          const ExaminerStatusType fDDU_SUMMARY_ERRORS_,
00244                          const std::map<DDUIdType, ExaminerStatusType> mDDU_ERRORS_,
00245                          const std::map<CSCIdType, ExaminerStatusType> mCSC_ERRORS_,
00246                          const std::map<CSCIdType, ExaminerStatusType> mCSC_PAYLOADS_, 
00247                          const std::map<CSCIdType, ExaminerStatusType> mCSC_STATUS_);
00248 
00249 #ifdef DEBUG
00250 
00253   void setDCCId(DCCIdType id) { DCCId = id; }
00254   void setDCCMask(ExaminerMaskType mask) { fDCC_MASK = mask; }
00255   void setCSCMask(ExaminerMaskType mask) { fCSC_MASK = mask; }
00256   void setDDUSummaryErrors(ExaminerStatusType status) { fDDU_SUMMARY_ERRORS = status; }
00257   void setDDUErrors(DDUIdType DDUId, ExaminerStatusType status )  {
00258     std::map<DDUIdType,ExaminerStatusType>::const_iterator item = mDDU_ERRORS.find(DDUId);
00259     if( item != mDDU_ERRORS.end() ) mDDU_ERRORS[DDUId] = status; else mDDU_ERRORS.insert(std::make_pair(DDUId, status));
00260   }
00261   void setCSCErrors(CSCIdType CSCId, ExaminerStatusType status )  {
00262     std::map<CSCIdType,ExaminerStatusType>::const_iterator item = mCSC_ERRORS.find(CSCId);
00263     if( item != mCSC_ERRORS.end() ) mCSC_ERRORS[CSCId] = status; else mCSC_ERRORS.insert(std::make_pair(CSCId, status));
00264   }
00265   void setCSCPayload(CSCIdType CSCId, ExaminerStatusType status )  {
00266     std::map<CSCIdType,ExaminerStatusType>::const_iterator item = mCSC_PAYLOADS.find(CSCId);
00267     if( item != mCSC_PAYLOADS.end() ) mCSC_PAYLOADS[CSCId] = status; else mCSC_PAYLOADS.insert(std::make_pair(CSCId, status));
00268   }
00269   void setCSCStatus(CSCIdType CSCId, ExaminerStatusType status )  {
00270     std::map<CSCIdType,ExaminerStatusType>::const_iterator item = mCSC_STATUS.find(CSCId);
00271     if( item != mCSC_STATUS.end() ) mCSC_STATUS[CSCId] = status; else mCSC_STATUS.insert(std::make_pair(CSCId, status));
00272   }
00273 
00274 #endif
00275 
00281   std::set<DDUIdType> getListOfDDUs() const {
00282     return getKeysList(mDDU_ERRORS);
00283   }
00284 
00285   std::set<CSCIdType> getListOfCSCs() const {
00286     return getKeysList(mCSC_PAYLOADS);
00287   }
00288     
00289   std::set<CSCIdType> getListOfCSCsWithErrors() const {
00290     return getKeysList(mCSC_ERRORS);
00291   }
00292 
00306   bool nextCSCWithError(uint32_t& iterator, CSCIdType& CSCId) const {
00307     return nextInMap(iterator, CSCId, mCSC_ERRORS);
00308   }
00309 
00317   bool nextCSCWithStatus(uint32_t& iterator, CSCIdType& CSCId) const {
00318     return nextInMap(iterator, CSCId, mCSC_STATUS);
00319   }
00320 
00328   bool nextCSCWithPayload(uint32_t& iterator, CSCIdType& CSCId) const {
00329     return nextInMap(iterator, CSCId, mCSC_PAYLOADS);
00330   }
00331 
00342   ExaminerStatusType getDDUSummaryErrors() const { return fDDU_SUMMARY_ERRORS; }
00343 
00344   ExaminerStatusType getDDUErrors(const DDUIdType DDUId) const {
00345     std::map<DDUIdType,ExaminerStatusType>::const_iterator item = mDDU_ERRORS.find(DDUId);
00346     if( item != mDDU_ERRORS.end() ) return item->second; else return 0;
00347   }
00348 
00349 
00350   ExaminerStatusType getCSCErrors(const CSCIdType CSCId) const {
00351     std::map<CSCIdType,ExaminerStatusType>::const_iterator item = mCSC_ERRORS.find(CSCId);
00352     if( item != mCSC_ERRORS.end() ) return item->second; else return 0;
00353   } 
00354 
00355   ExaminerStatusType getCSCErrors(const uint16_t crateId, const uint16_t dmbId) const
00356     { return getCSCErrors( makeCSCId(crateId, dmbId) ); }
00357 
00358 
00359   ExaminerStatusType getCSCPayload(const CSCIdType CSCId) const {
00360     std::map<CSCIdType,ExaminerStatusType>::const_iterator item = mCSC_PAYLOADS.find(CSCId);
00361     if( item != mCSC_PAYLOADS.end() ) return item->second; else return 0;
00362   }
00363 
00364   ExaminerStatusType getCSCPayload(const uint16_t crateId, const uint16_t dmbId) const
00365     { return getCSCPayload( makeCSCId(crateId, dmbId) ); }
00366 
00367 
00368   ExaminerStatusType getCSCStatus(const CSCIdType CSCId) const {
00369     std::map<CSCIdType,ExaminerStatusType>::const_iterator item = mCSC_STATUS.find(CSCId);
00370     if( item != mCSC_STATUS.end() ) return item->second; else return 0;
00371   }
00372 
00373   ExaminerStatusType getCSCStatus(const uint16_t crateId, const uint16_t dmbId) const
00374     { return getCSCStatus( makeCSCId(crateId, dmbId) ); }
00375 
00376 
00377   /* 
00378    * Return FED/DCC Id
00379    */
00380   DCCIdType getDCCId() const { return DCCId; }
00381 
00385   ExaminerMaskType getDCCMask() const { return fDCC_MASK; }
00386 
00390   ExaminerMaskType getCSCMask() const { return fCSC_MASK; }
00391     
00396   bool getDDUSummaryFlag(const FormatErrorFlag flag) const 
00397     { return ( (fDDU_SUMMARY_ERRORS & ExaminerStatusType(0x1<<flag) ) != 0); }
00398   bool getDDUErrorFlag(const DDUIdType DDUId, const FormatErrorFlag flag) const
00399     { return ( (getDDUErrors(DDUId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00400 
00401   bool getCSCErrorFlag(const CSCIdType CSCId, const FormatErrorFlag flag) const
00402     { return ( (getCSCErrors(CSCId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00403 
00404   bool getCSCErrorFlag(const uint16_t crateId, const uint16_t dmbId, const FormatErrorFlag flag) const
00405     { return ( (getCSCErrors(crateId, dmbId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00406 
00407   bool getCSCPayloadFlag(const CSCIdType CSCId, const CSCPayloadFlag flag) const
00408     { return ( (getCSCPayload(CSCId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00409 
00410   bool getCSCPayloadFlag(const uint16_t crateId, const uint16_t dmbId, const CSCPayloadFlag flag) const
00411     { return ( (getCSCPayload(crateId,dmbId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00412 
00413   bool getCSCStatusFlag(const CSCIdType CSCId, const CSCStatusFlag flag) const
00414     { return ( (getCSCStatus(CSCId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00415 
00416   bool getCSCStatusFlag(const uint16_t crateId, const uint16_t dmbId, const CSCStatusFlag flag) const
00417     { return ( (getCSCStatus(crateId, dmbId) & ExaminerStatusType(0x1<<flag) ) != 0); }
00418 
00419   void print() const;
00420  
00421 
00422 };
00423 
00424 
00425 std::ostream & operator<<(std::ostream & o, const CSCDCCFormatStatusDigi& digi);
00426 
00427 #endif