CMS 3D CMS Logo

CSCALCTTrailer.h

Go to the documentation of this file.
00001 #ifndef CSCALCTTrailer_h
00002 #define CSCALCTTrailer_h
00003 
00008 #include <string.h> // memcpy
00009 #include "DataFormats/CSCDigi/interface/CSCALCTStatusDigi.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 
00012 struct CSCALCTTrailer2006 {
00013   CSCALCTTrailer2006() {
00014     bzero(this,  sizeInWords()*2); 
00015       e0dLine = 0xDE0D;
00016       d_0=0xD;
00017       d_1=0xD;
00018       zero_0 = 0;
00019       zero_1 = 0;
00020       d_3 = 0xD;
00021       reserved_3 = 1;
00022   }
00023   void setSize(int size) {frameCount = size;}
00024   short unsigned int sizeInWords() const { 
00025     return 4;
00026   }
00027   unsigned crc0:11, zero_0:1, d_0:4;
00028   unsigned crc1:11, zero_1:1, d_1:4;
00029   unsigned e0dLine:16;
00030   unsigned frameCount:11, reserved_3:1, d_3:4;
00031 };
00032 
00033 struct CSCALCTTrailer2007 {
00034   CSCALCTTrailer2007() {
00035     bzero(this,  sizeInWords()*2); 
00036   }
00037   short unsigned int sizeInWords() const { 
00038     return 4;
00039   }
00040   unsigned e0dLine:16;
00041   unsigned crc0:11, reserved_0:5;
00042   unsigned crc1:11, reserved_1:5;
00043   unsigned frameCount:11, reserved_3:1, reserved_4:4;
00044 };
00045 
00046 
00047 
00048 class CSCALCTTrailer
00049 {
00050 public:
00052   CSCALCTTrailer(int size, int firmVersion);
00053   CSCALCTTrailer(const unsigned short * buf);
00054   CSCALCTTrailer(const CSCALCTStatusDigi & digi) {
00055     CSCALCTTrailer(digi.trailer());
00056   }
00057 
00058   static void setDebug(bool debugValue) {debug = debugValue;}
00059 
00060   unsigned short * data() {
00061     switch (firmwareVersion) {
00062     case 2006:
00063       memcpy(theOriginalBuffer, &trailer2006, trailer2006.sizeInWords()*2);
00064       break;
00065     case 2007:
00066       memcpy(theOriginalBuffer, &trailer2007, trailer2007.sizeInWords()*2);
00067       break;
00068     default:
00069       edm::LogError("CSCALCTTrailer|CSCRawToDigi")
00070         <<"couldn't access data: ALCT firmware version is bad/not defined!";
00071       break;
00072     }
00073     return theOriginalBuffer;
00074   }
00075 
00077   static int sizeInWords() {return 4;}
00078 
00079   int getCRC() { 
00080     switch (firmwareVersion) {
00081     case 2006:
00082       return ((trailer2006.crc1&0x7ff)<<11) | (trailer2006.crc0&0x7ff);
00083     case 2007:
00084       return ((trailer2007.crc1&0x7ff)<<11) | (trailer2007.crc0&0x7ff);
00085     default:
00086       edm::LogError("CSCALCTTrailer|CSCRawToDigi")
00087         <<"couldn't getCRC: ALCT firmware version is bad/not defined!";
00088       return 0;
00089     }
00090   }
00091 
00092   bool check() const {
00093     switch (firmwareVersion) {
00094     case 2006:
00095       return (trailer2006.e0dLine & 0xfff) == 0xe0d;
00096     case 2007:
00097       return (trailer2007.e0dLine & 0xffff) == 0xde0d;
00098     default:
00099       edm::LogError("CSCALCTTrailer|CSCRawToDigi")
00100         <<"couldn't check: ALCT firmware version is bad/not defined!";
00101       return 0;
00102     }
00103   }
00104   
00105   int wordCount() const {
00106     switch (firmwareVersion) {
00107     case 2006:
00108       return trailer2006.frameCount;
00109     case 2007:
00110       return trailer2007.frameCount;
00111     default:
00112       edm::LogError("CSCALCTTrailer|CSCRawToDigi")
00113         <<"couldn't wordCount: ALCT firmware version is bad/not defined!";
00114       return 0;
00115     }
00116   }
00117   
00118   unsigned alctCRCCheck() const { 
00119     switch (firmwareVersion) {
00120     case 2006:
00121       return trailer2006.reserved_3;
00122     case 2007:
00123       return trailer2007.reserved_3;  
00124     default:
00125       edm::LogError("CSCALCTTrailer|CSCRawToDigi")
00126         <<"couldn't CRCcheck: ALCT firmware version is bad/not defined!";
00127       return 0;
00128     }
00129   }
00130   
00131   unsigned FrameCount() const { return wordCount(); }
00132 
00133   CSCALCTTrailer2006 alctTrailer2006() {return trailer2006;}
00134   CSCALCTTrailer2007 alctTrailer2007() {return trailer2007;}
00135 
00136 private:
00137   static bool debug;
00138   static unsigned short int firmwareVersion;
00139   CSCALCTTrailer2006 trailer2006;
00140   CSCALCTTrailer2007 trailer2007;
00141   unsigned short int theOriginalBuffer[4];
00142 
00143 };
00144 
00145 #endif
00146 

Generated on Tue Jun 9 17:34:21 2009 for CMSSW by  doxygen 1.5.4