CMS 3D CMS Logo

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