CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/EventFilter/CSCRawToDigi/interface/CSCDCCExaminer.h

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