Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-07 05:50:16

0001 #ifndef EventFilter_CSCRawToDigi_CSCDCCExaminer_h
0002 #define EventFilter_CSCRawToDigi_CSCDCCExaminer_h
0003 #include <set>
0004 #include <map>
0005 #include <vector>
0006 #include <string>
0007 #ifdef LOCAL_UNPACK
0008 #include <iostream>
0009 #else
0010 #include <ostream>
0011 #endif
0012 
0013 #include "DataFormats/CSCDigi/interface/CSCDCCFormatStatusDigi.h"
0014 
0015 class CSCDCCExaminer {
0016 public:
0017   const uint16_t nERRORS, nWARNINGS, nPAYLOADS, nSTATUSES;
0018 
0019 private:
0020   std::vector<const char*> sERROR, sWARNING, sERROR_, sWARNING_, sDMBExpectedPayload, sDMBEventStaus;
0021   ExaminerStatusType bERROR, bWARNING;
0022   ExaminerStatusType bSUM_ERROR, bSUM_WARNING;  // Summary flags for errors and warnings
0023   bool fERROR[29];                              //[nERRORS];
0024   bool fWARNING[5];                             //[nWARNINGS];
0025   bool fSUM_ERROR[29];                          //[nERRORS];
0026   bool fSUM_WARNING[5];                         //[nWARNINGS];
0027 
0028   std::set<CSCIdType> fCHAMB_ERR[29];                      // Set of chambers which contain particular error
0029   std::set<CSCIdType> fCHAMB_WRN[5];                       // Set of chambers which contain particular warning
0030   std::map<CSCIdType, ExaminerStatusType> bCHAMB_ERR;      // chamber <=> errors in bits
0031   std::map<CSCIdType, ExaminerStatusType> bCHAMB_WRN;      // chamber <=> errors in bits
0032   std::map<CSCIdType, ExaminerStatusType> bCHAMB_PAYLOAD;  //
0033   std::map<CSCIdType, ExaminerStatusType> bCHAMB_STATUS;   //
0034   std::map<DDUIdType, ExaminerStatusType> bDDU_ERR;        // ddu     <-> errors in bits
0035   std::map<DDUIdType, ExaminerStatusType> bDDU_WRN;        // ddu     <-> errors in bits
0036 
0037 #ifdef LOCAL_UNPACK
0038   class OStream : public std::ostream {
0039   private:
0040     class buffer : public std::streambuf {};
0041     buffer buff;
0042     std::streambuf* stream;
0043     std::streambuf* null;
0044     std::string name;
0045 
0046   public:
0047     void show(void) { rdbuf(stream); }
0048     void hide(void) { rdbuf(null); }
0049     void sign(std::string nm) { name = nm; }
0050     void sign(const char* nm) { name = nm; }
0051 
0052     void redirect(std::ostream& str) {
0053       stream = str.rdbuf();
0054       tie(&str);
0055       if (rdbuf() != null)
0056         rdbuf(stream);
0057     }
0058 
0059     template <class T>
0060     std::ostream& operator<<(const T& val) {
0061       return (*(std::ostream*)this) << name << val;
0062     }
0063 
0064     OStream(void) : std::ostream(std::cout.rdbuf()), buff(), stream(std::cout.rdbuf()), null(&buff), name("") {}
0065     OStream(std::ostream& str) : std::ostream(str.rdbuf()), buff(), stream(str.rdbuf()), null(&buff), name("") {}
0066   };
0067 
0068   OStream COUT, CERR;
0069 #endif
0070 
0071   CSCIdType currentChamber;  // ( (CrateNumber<<4) + DMBslot ) specifies chamber
0072 
0073   const uint16_t *buf_2, *buf_1, *buf0, *buf1, *buf2;
0074   uint16_t tmpbuf[16];
0075 
0076   bool fDCC_Header;
0077   bool fDCC_Trailer;
0078   bool fDDU_Header;
0079   bool fDDU_Trailer;
0080   bool fDMB_Header;
0081   bool fDMB_Trailer;
0082   bool fALCT_Header;
0083   bool fTMB_Header;
0084   bool fTMB_Format2007;
0085   bool fALCT_Format2007;
0086   bool fFormat2013;
0087 
0088   bool uniqueALCT, uniqueTMB;  // Do not merge two DMBs if Trailer of the first and Header of the second are lost
0089 
0090   bool DAV_ALCT;          // ...
0091   bool DAV_TMB;           // Check if DAV bits lie
0092   int DAV_CFEB;           // ...
0093   int DAV_DMB;            // ...
0094   int DMB_Active, nDMBs;  // ...
0095 
0096 public:
0097   uint32_t cntDDU_Headers;
0098   uint32_t cntDDU_Trailers;
0099   std::map<CSCIdType, uint32_t> cntCHAMB_Headers;
0100   std::map<CSCIdType, uint32_t> cntCHAMB_Trailers;
0101 
0102 private:
0103   void clear();
0104   void zeroCounts();
0105   void sync_stats();
0106   /// checks DAV_ALCT, DAV_TMB, and DAV_CFEB
0107   void checkDAVs();
0108   void checkTriggerHeadersAndTrailers();
0109 
0110   inline int scanbuf(const uint16_t*& buf, int32_t length, uint16_t sig, uint16_t mask = 0xFFFF);
0111 
0112   uint32_t DDU_WordsSinceLastHeader;
0113   uint32_t DDU_WordCount;
0114   uint32_t DDU_WordMismatch_Occurrences;
0115   uint32_t DDU_WordsSinceLastTrailer;
0116 
0117   uint32_t ALCT_WordsSinceLastHeader;
0118   uint32_t ALCT_WordsSinceLastHeaderZeroSuppressed;
0119   uint32_t ALCT_WordCount;
0120   uint32_t ALCT_WordsExpected;
0121   uint32_t ALCT_WordsBeforeRaw;  /// number of ALCT words before anode raw data
0122   uint32_t ALCT_ZSE;             /// check zero suppression mode
0123   uint32_t nWG_round_up;         /// to decode if zero suppression enabled
0124 
0125   uint32_t TMB_WordsSinceLastHeader;
0126   uint32_t TMB_WordCount;
0127   uint32_t TMB_WordsExpected;
0128   uint32_t TMB_Tbins;
0129   uint32_t TMB_WordsRPC;
0130   uint32_t TMB_WordsGEM;
0131   uint32_t TMB_Firmware_Revision;
0132   uint32_t DDU_Firmware_Revision;
0133 
0134   uint32_t CFEB_SampleWordCount;
0135   uint32_t CFEB_SampleCount;
0136   uint32_t CFEB_BSampleCount;
0137 
0138   bool checkCrcALCT;
0139   uint32_t ALCT_CRC;
0140   bool checkCrcTMB;
0141   uint32_t TMB_CRC;
0142   bool checkCrcCFEB;
0143   uint32_t CFEB_CRC;
0144 
0145   bool modeDDUonly;
0146   DDUIdType sourceID;
0147   ExaminerMaskType examinerMask;
0148 
0149   //int headerDAV_Active; // Obsolete since 16.09.05
0150 
0151   // data blocks:
0152   std::map<DDUIdType, const uint16_t*> dduBuffers;                        // < DDUsourceID, pointer >
0153   std::map<DDUIdType, std::map<CSCIdType, const uint16_t*> > dmbBuffers;  // < DDUsourceID, < DMBid, pointer > >
0154   std::map<DDUIdType, uint32_t> dduOffsets;                               // < DDUsourceID, pointer_offset >
0155   std::map<DDUIdType, std::map<CSCIdType, uint32_t> > dmbOffsets;         // < DDUsourceID, < DMBid, pointer_offset > >
0156   std::map<DDUIdType, uint32_t> dduSize;                                  // < DDUsourceID, block_size >
0157   std::map<DDUIdType, std::map<CSCIdType, uint32_t> > dmbSize;            // < DDUsourceID, < DMBid, block_size > >
0158   const uint16_t* buffer_start;
0159 
0160 public:
0161 #ifdef LOCAL_UNPACK
0162   OStream& output1(void) { return COUT; }
0163   OStream& output2(void) { return CERR; }
0164 #endif
0165 
0166   int32_t check(const uint16_t*& buffer, int32_t length);
0167 
0168   void setMask(ExaminerMaskType mask) { examinerMask = mask; }
0169   ExaminerMaskType getMask() const { return examinerMask; }
0170 
0171   ExaminerStatusType errors(void) const { return bSUM_ERROR; }
0172   ExaminerStatusType warnings(void) const { return bSUM_WARNING; }
0173 
0174   const char* errName(int num) const {
0175     if (num >= 0 && num < nERRORS)
0176       return sERROR[num];
0177     else
0178       return "";
0179   }
0180   const char* wrnName(int num) const {
0181     if (num >= 0 && num < nWARNINGS)
0182       return sWARNING[num];
0183     else
0184       return "";
0185   }
0186 
0187   const char* errorName(int num) const {
0188     if (num >= 0 && num < nERRORS)
0189       return sERROR_[num];
0190     else
0191       return "";
0192   }
0193   const char* warningName(int num) const {
0194     if (num >= 0 && num < nWARNINGS)
0195       return sWARNING_[num];
0196     else
0197       return "";
0198   }
0199 
0200   const char* payloadName(int num) const {
0201     if (num >= 0 && num < nPAYLOADS)
0202       return sDMBExpectedPayload[num];
0203     else
0204       return "";
0205   }
0206   const char* statusName(int num) const {
0207     if (num >= 0 && num < nSTATUSES)
0208       return sDMBEventStaus[num];
0209     else
0210       return "";
0211   }
0212 
0213   bool error(int num) const {
0214     if (num >= 0 && num < nERRORS)
0215       return fSUM_ERROR[num];
0216     else
0217       return false;
0218   }
0219   bool warning(int num) const {
0220     if (num >= 0 && num < nWARNINGS)
0221       return fSUM_WARNING[num];
0222     else
0223       return false;
0224   }
0225 
0226   std::set<CSCIdType> chambersWithError(int num) const {
0227     if (num >= 0 && num < nERRORS)
0228       return fCHAMB_ERR[num];
0229     else
0230       return std::set<int>();
0231   }
0232   std::set<CSCIdType> chambersWithWarning(int num) const {
0233     if (num >= 0 && num < nWARNINGS)
0234       return fCHAMB_WRN[num];
0235     else
0236       return std::set<int>();
0237   }
0238 
0239   ExaminerStatusType payloadForChamber(CSCIdType chamber) const {
0240     std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_PAYLOAD.find(chamber);
0241     if (item != bCHAMB_PAYLOAD.end())
0242       return item->second;
0243     else
0244       return 0;
0245   }
0246 
0247   ExaminerStatusType statusForChamber(CSCIdType chamber) const {
0248     std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_STATUS.find(chamber);
0249     if (item != bCHAMB_STATUS.end())
0250       return item->second;
0251     else
0252       return 0;
0253   }
0254 
0255   ExaminerStatusType errorsForChamber(CSCIdType chamber) const {
0256     std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_ERR.find(chamber);
0257     /// Print (for debugging, to be removed)
0258 
0259     // for(item =bCHAMB_ERR.begin() ; item !=bCHAMB_ERR.end() ; item++)
0260     //std::cout << " Ex-errors: " << std::hex << (*item).second << std::dec << std::endl;
0261 
0262     item = bCHAMB_ERR.find(chamber);
0263     if (item != bCHAMB_ERR.end())
0264       return item->second;
0265     else
0266       return 0;
0267   }
0268 
0269   ExaminerStatusType warningsForChamber(CSCIdType chamber) const {
0270     std::map<CSCIdType, ExaminerStatusType>::const_iterator item = bCHAMB_WRN.find(chamber);
0271     if (item != bCHAMB_WRN.end())
0272       return item->second;
0273     else
0274       return 0;
0275   }
0276 
0277   ExaminerStatusType errorsForDDU(DDUIdType dduSourceID) const {
0278     std::map<DDUIdType, ExaminerStatusType>::const_iterator item = bDDU_ERR.find(dduSourceID);
0279     if (item != bDDU_ERR.end())
0280       return item->second;
0281     else
0282       return 0;
0283   }
0284   ExaminerStatusType warningsForDDU(DDUIdType dduSourceID) const {
0285     std::map<DDUIdType, ExaminerStatusType>::const_iterator item = bDDU_WRN.find(dduSourceID);
0286     if (item != bDDU_WRN.end())
0287       return item->second;
0288     else
0289       return 0;
0290   }
0291   std::vector<DDUIdType> listOfDDUs(void) const {
0292     std::vector<DDUIdType> DDUs;
0293     std::map<DDUIdType, ExaminerStatusType>::const_iterator item = bDDU_ERR.begin();
0294     while (item != bDDU_ERR.end()) {
0295       DDUs.push_back(item->first);
0296       item++;
0297     }
0298     return DDUs;
0299   }
0300 
0301   std::map<DDUIdType, ExaminerStatusType> errorsDetailedDDU(void) const { return bDDU_ERR; }
0302 
0303   std::map<CSCIdType, ExaminerStatusType> errorsDetailed(void) const { return bCHAMB_ERR; }
0304   std::map<CSCIdType, ExaminerStatusType> warningsDetailed(void) const { return bCHAMB_WRN; }
0305   std::map<CSCIdType, ExaminerStatusType> payloadDetailed(void) const { return bCHAMB_PAYLOAD; }
0306   std::map<CSCIdType, ExaminerStatusType> statusDetailed(void) const { return bCHAMB_STATUS; }
0307 
0308   void crcALCT(bool enable);
0309   void crcTMB(bool enable);
0310   void crcCFEB(bool enable);
0311 
0312   void modeDDU(bool enable);
0313 
0314   bool isDDUmode() { return modeDDUonly; };
0315 
0316   DDUIdType dduSourceID(void) { return sourceID; }
0317 
0318   std::map<DDUIdType, const uint16_t*> DDU_block(void) const { return dduBuffers; }
0319   std::map<DDUIdType, std::map<CSCIdType, const uint16_t*> > DMB_block(void) const { return dmbBuffers; }
0320 
0321   std::map<DDUIdType, uint32_t> DDU_ptrOffsets(void) const { return dduOffsets; }
0322   std::map<DDUIdType, std::map<CSCIdType, uint32_t> > DMB_ptrOffsets(void) const { return dmbOffsets; }
0323 
0324   std::map<DDUIdType, uint32_t> DDU_size(void) const { return dduSize; }
0325   std::map<DDUIdType, std::map<CSCIdType, uint32_t> > DMB_size(void) const { return dmbSize; }
0326 
0327   CSCDCCExaminer(ExaminerMaskType mask = 0x1);
0328   ~CSCDCCExaminer(void) {}
0329 };
0330 
0331 #endif