00001 #ifndef CSCDCCExaminer_h
00002 #define CSCDCCExaminer_h
00003 #include <set>
00004 #include <map>
00005 #include <vector>
00006 #include <string>
00007 #include <iostream>
00008
00009 #include "DataFormats/CSCDigi/interface/CSCDCCFormatStatusDigi.h"
00010
00011 class CSCDCCExaminer {
00012 public:
00013 const uint16_t nERRORS, nWARNINGS, nPAYLOADS, nSTATUSES;
00014
00015 private:
00016 std::vector<const char*> sERROR, sWARNING, sERROR_, sWARNING_, sDMBExpectedPayload, sDMBEventStaus;
00017 ExaminerStatusType bERROR, bWARNING;
00018 bool fERROR [29];
00019 bool fWARNING[5];
00020
00021 std::set<CSCIdType> fCHAMB_ERR[29];
00022 std::set<CSCIdType> fCHAMB_WRN[5];
00023 std::map<CSCIdType,ExaminerStatusType> bCHAMB_ERR;
00024 std::map<CSCIdType,ExaminerStatusType> bCHAMB_WRN;
00025 std::map<CSCIdType,ExaminerStatusType> bCHAMB_PAYLOAD;
00026 std::map<CSCIdType,ExaminerStatusType> bCHAMB_STATUS;
00027 std::map<DDUIdType,ExaminerStatusType> bDDU_ERR;
00028 std::map<DDUIdType,ExaminerStatusType> bDDU_WRN;
00029
00030 class OStream : public std::ostream {
00031 private:
00032 class buffer : public std::streambuf{};
00033 buffer buff;
00034 std::streambuf *stream;
00035 std::streambuf *null;
00036 std::string name;
00037
00038 public:
00039 void show(void){ rdbuf(stream); }
00040 void hide(void){ rdbuf(null); }
00041 void sign(std::string nm) { name=nm; }
00042 void sign(const char *nm){ name=nm; }
00043
00044 void redirect(std::ostream &str){
00045 stream = str.rdbuf(); tie(&str);
00046 if( rdbuf() != null ) rdbuf(stream);
00047 }
00048
00049 template<class T> std::ostream& operator<<(const T& val){
00050 return (*(std::ostream*)this)<<name<<val;
00051 }
00052
00053 OStream(void):std::ostream(std::cout.rdbuf()),buff(),stream(std::cout.rdbuf()),null(&buff),name(""){}
00054 OStream(std::ostream &str):std::ostream(str.rdbuf()),buff(),stream(str.rdbuf()),null(&buff),name(""){}
00055 };
00056
00057 OStream cout, cerr;
00058
00059 CSCIdType currentChamber;
00060
00061 const uint16_t *buf_2, *buf_1, *buf0, *buf1, *buf2;
00062 uint16_t tmpbuf[16];
00063
00064 bool fDCC_Header;
00065 bool fDCC_Trailer;
00066 bool fDDU_Header;
00067 bool fDDU_Trailer;
00068 bool fDMB_Header;
00069 bool fDMB_Trailer;
00070 bool fALCT_Header;
00071 bool fTMB_Header;
00072 bool fTMB_Format2007;
00073 bool fALCT_Format2007;
00074
00075 bool uniqueALCT, uniqueTMB;
00076
00077 bool DAV_ALCT;
00078 bool DAV_TMB;
00079 int DAV_CFEB;
00080 int DAV_DMB;
00081 int DMB_Active, nDMBs;
00082
00083 public:
00084 uint32_t cntDDU_Headers;
00085 uint32_t cntDDU_Trailers;
00086 std::map<CSCIdType,uint32_t> cntCHAMB_Headers;
00087 std::map<CSCIdType,uint32_t> cntCHAMB_Trailers;
00088
00089 private:
00090 void clear();
00091 void zeroCounts();
00093 void checkDAVs();
00094 void checkTriggerHeadersAndTrailers();
00095
00096 inline int scanbuf(const uint16_t* &buf, int32_t length, uint16_t sig, uint16_t mask=0xFFFF);
00097
00098 uint32_t DDU_WordsSinceLastHeader;
00099 uint32_t DDU_WordCount;
00100 uint32_t DDU_WordMismatch_Occurrences;
00101 uint32_t DDU_WordsSinceLastTrailer;
00102
00103 uint32_t ALCT_WordsSinceLastHeader;
00104 uint32_t ALCT_WordsSinceLastHeaderZeroSuppressed;
00105 uint32_t ALCT_WordCount;
00106 uint32_t ALCT_WordsExpected;
00107 uint32_t ALCT_ZSE;
00108 uint32_t nWG_round_up;
00109
00110 uint32_t TMB_WordsSinceLastHeader;
00111 uint32_t TMB_WordCount;
00112 uint32_t TMB_WordsExpected;
00113 uint32_t TMB_Tbins;
00114 uint32_t TMB_WordsRPC;
00115 uint32_t TMB_Firmware_Revision;
00116
00117 uint32_t CFEB_SampleWordCount;
00118 uint32_t CFEB_SampleCount;
00119 uint32_t CFEB_BSampleCount;
00120
00121 bool checkCrcALCT;
00122 uint32_t ALCT_CRC;
00123 bool checkCrcTMB;
00124 uint32_t TMB_CRC;
00125 bool checkCrcCFEB;
00126 uint32_t CFEB_CRC;
00127
00128 bool modeDDUonly;
00129 DDUIdType sourceID;
00130 ExaminerMaskType examinerMask;
00131
00132
00133
00134
00135 std::map<DDUIdType,const uint16_t*> dduBuffers;
00136 std::map<DDUIdType,std::map<CSCIdType,const uint16_t*> > dmbBuffers;
00137 std::map<DDUIdType,uint32_t> dduOffsets;
00138 std::map<DDUIdType,std::map<CSCIdType,uint32_t> > dmbOffsets;
00139 std::map<DDUIdType,uint32_t> dduSize;
00140 std::map<DDUIdType,std::map<CSCIdType,uint32_t> > dmbSize;
00141 const uint16_t *buffer_start;
00142
00143 public:
00144 OStream& output1(void){ return cout; }
00145 OStream& output2(void){ return cerr; }
00146
00147 int32_t check(const uint16_t* &buffer, int32_t length);
00148
00149 void setMask(ExaminerMaskType mask) {examinerMask=mask;}
00150 ExaminerMaskType getMask() const {return examinerMask;}
00151
00152 ExaminerStatusType errors (void) const { return bERROR; }
00153 ExaminerStatusType warnings(void) const { return bWARNING; }
00154
00155 const char* errName(int num) const { if(num>=0&&num<nERRORS) return sERROR[num]; else return ""; }
00156 const char* wrnName(int num) const { if(num>=0&&num<nWARNINGS) return sWARNING[num]; else return ""; }
00157
00158 const char* errorName (int num) const { if(num>=0&&num<nERRORS) return sERROR_[num]; else return ""; }
00159 const char* warningName(int num) const { if(num>=0&&num<nWARNINGS) return sWARNING_[num]; else return ""; }
00160
00161 const char* payloadName(int num) const { if(num>=0&&num<nPAYLOADS) return sDMBExpectedPayload[num]; else return ""; }
00162 const char* statusName (int num) const { if(num>=0&&num<nSTATUSES) return sDMBEventStaus [num]; else return ""; }
00163
00164 bool error (int num) const { if(num>=0&&num<nERRORS) return fERROR [num]; else return 0; }
00165 bool warning(int num) const { if(num>=0&&num<nWARNINGS) return fWARNING[num]; else return 0; }
00166
00167 std::set<CSCIdType> chambersWithError (int num) const { if(num>=0&&num<nERRORS) return fCHAMB_ERR[num]; else return std::set<int>(); }
00168 std::set<CSCIdType> chambersWithWarning(int num) const { if(num>=0&&num<nWARNINGS) return fCHAMB_WRN[num]; else return std::set<int>(); }
00169
00170 ExaminerStatusType payloadForChamber(CSCIdType chamber) const {
00171 std::map<CSCIdType,ExaminerStatusType>::const_iterator item = bCHAMB_PAYLOAD.find(chamber);
00172 if( item != bCHAMB_PAYLOAD.end() ) return item->second; else return 0;
00173 }
00174
00175 ExaminerStatusType statusForChamber(CSCIdType chamber) const {
00176 std::map<CSCIdType,ExaminerStatusType>::const_iterator item = bCHAMB_STATUS.find(chamber);
00177 if( item != bCHAMB_STATUS.end() ) return item->second; else return 0;
00178 }
00179
00180 ExaminerStatusType errorsForChamber(CSCIdType chamber) const {
00181 std::map<CSCIdType,ExaminerStatusType>::const_iterator item = bCHAMB_ERR.find(chamber);
00183
00184
00185
00186
00187 item = bCHAMB_ERR.find(chamber);
00188 if( item != bCHAMB_ERR.end() ) return item->second; else return 0;
00189 }
00190
00191 ExaminerStatusType warningsForChamber(CSCIdType chamber) const {
00192 std::map<CSCIdType,ExaminerStatusType>::const_iterator item = bCHAMB_WRN.find(chamber);
00193 if( item != bCHAMB_WRN.end() ) return item->second; else return 0;
00194 }
00195
00196 ExaminerStatusType errorsForDDU(DDUIdType dduSourceID) const {
00197 std::map<DDUIdType,ExaminerStatusType>::const_iterator item = bDDU_ERR.find(dduSourceID);
00198 if( item != bDDU_ERR.end() ) return item->second; else return 0;
00199 }
00200 ExaminerStatusType warningsForDDU(DDUIdType dduSourceID) const {
00201 std::map<DDUIdType,ExaminerStatusType>::const_iterator item = bDDU_WRN.find(dduSourceID);
00202 if( item != bDDU_WRN.end() ) return item->second; else return 0;
00203 }
00204 std::vector<DDUIdType> listOfDDUs(void) const {
00205 std::vector<DDUIdType> DDUs;
00206 std::map<DDUIdType,ExaminerStatusType>::const_iterator item = bDDU_ERR.begin();
00207 while( item != bDDU_ERR.end() ){ DDUs.push_back(item->first); item++; }
00208 return DDUs;
00209 }
00210
00211 std::map<DDUIdType,ExaminerStatusType> errorsDetailedDDU (void) const { return bDDU_ERR; }
00212
00213 std::map<CSCIdType,ExaminerStatusType> errorsDetailed (void) const { return bCHAMB_ERR; }
00214 std::map<CSCIdType,ExaminerStatusType> warningsDetailed(void) const { return bCHAMB_WRN; }
00215 std::map<CSCIdType,ExaminerStatusType> payloadDetailed (void) const { return bCHAMB_PAYLOAD; }
00216 std::map<CSCIdType,ExaminerStatusType> statusDetailed (void) const { return bCHAMB_STATUS; }
00217
00218
00219
00220 void crcALCT(bool enable);
00221 void crcTMB (bool enable);
00222 void crcCFEB(bool enable);
00223
00224 void modeDDU(bool enable);
00225
00226 DDUIdType dduSourceID(void){ return sourceID; }
00227
00228 std::map<DDUIdType,const uint16_t*> DDU_block(void) const { return dduBuffers; }
00229 std::map<DDUIdType,std::map<CSCIdType,const uint16_t*> > DMB_block(void) const { return dmbBuffers; }
00230
00231 std::map<DDUIdType,uint32_t> DDU_ptrOffsets(void) const { return dduOffsets; }
00232 std::map<DDUIdType,std::map<CSCIdType,uint32_t> > DMB_ptrOffsets(void) const { return dmbOffsets; }
00233
00234 std::map<DDUIdType,uint32_t> DDU_size(void) const { return dduSize; }
00235 std::map<DDUIdType,std::map<CSCIdType,uint32_t> > DMB_size(void) const { return dmbSize; }
00236
00237 CSCDCCExaminer(ExaminerMaskType mask=0x1);
00238 ~CSCDCCExaminer(void){}
00239 };
00240
00241 #endif