CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/EventFilter/CSCRawToDigi/src/CSCTMBTrailer.cc

Go to the documentation of this file.
00001 #include "EventFilter/CSCRawToDigi/interface/CSCTMBTrailer.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <iostream>
00004 #include <cassert>
00005 
00006 CSCTMBTrailer::CSCTMBTrailer(int wordCount, int firmwareVersion) 
00007 : theFirmwareVersion(firmwareVersion)
00008 {
00009   //FIXME do firmware version
00010   theData[0] = 0x6e0c;
00011   // all the necessary lines from this thing first
00012   wordCount += 5;
00013   // see if we need thePadding to make a multiple of 4
00014   thePadding = 0;
00015 
00016   if(wordCount%4==2) 
00017     {
00018       theData[1] = 0x2AAA;
00019       theData[2] = 0x5555;
00020       thePadding = 2;
00021       wordCount += thePadding;
00022     }
00023   // the next four words start with 11011, or a D
00024   for(int i = 1; i < 5; ++i) 
00025     {
00026       theData[i+thePadding] = 0xD800;
00027     }
00028   theData[de0fOffset()] = 0xde0f;
00029   // word count excludes the trailer
00030   theData[4+thePadding] |= wordCount;
00031 }
00032 
00033 
00034 CSCTMBTrailer::CSCTMBTrailer(unsigned short * buf, unsigned short int firmwareVersion) 
00035 : theFirmwareVersion(firmwareVersion)
00036 {
00037   // take a little too much, maybe
00038   memcpy(theData, buf, 14);
00039   switch (firmwareVersion){
00040   case 2006:
00041     // if there's padding, there'll be a de0f in the 6th word.
00042     // If not, you'll be in CFEB-land, where they won't be de0f.
00043     thePadding = (theData[5] == 0xde0f ? 2 : 0);
00044     break;
00045   case 2007:
00047     // =VB= check for 1st word to be 0xDE0F, then check 3rd 
00048     // to handle freaky cases of double 0xDE0F signatures in trailer 
00049     thePadding = (theData[1] == 0xde0f ? 0 : (theData[3] == 0xde0f ? 2 : 0)); 
00050 //    thePadding = (theData[3] == 0xde0f ? 2 : 0);
00051     break;
00052   default: 
00053     edm::LogError("CSCTMBTrailer|CSCRawToDigi")
00054       <<"failed to contruct: firmware version is bad/not defined!";
00055   }
00056 }
00057 
00058 unsigned int CSCTMBTrailer::crc22() const 
00059 {  
00060   return (theData[crcOffset()] & 0x07ff) +
00061             ((theData[crcOffset()+1] & 0x07ff) << 11);
00062 }
00063 
00064 
00065 void CSCTMBTrailer::setCRC(int crc) 
00066 {
00067   theData[crcOffset()] |= (crc & 0x07ff);
00068   theData[crcOffset()+1] |= ((crc>>11) & 0x07ff);
00069 }
00070 
00071 
00072 int CSCTMBTrailer::wordCount() const {return theData[4+thePadding] & 0x7ff;}
00073 
00074 
00075 
00076 void CSCTMBTrailer::selfTest()
00077 {
00078   CSCTMBTrailer trailer(104, 2006);
00079   unsigned int crc = 0xb00b1;
00080   trailer.setCRC(crc);
00081   assert(trailer.crc22() == 0xb00b1);
00082 
00083   CSCTMBTrailer trailer2(104, 2007);
00084   crc = 0xb00b1;
00085   trailer2.setCRC(crc);
00086   assert(trailer2.crc22() == 0xb00b1);
00087 
00088 }
00089