Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:28

0001 #include "EventFilter/CSCRawToDigi/interface/CSCTMBTrailer.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include <iostream>
0004 #include <cassert>
0005 
0006 CSCTMBTrailer::CSCTMBTrailer(int wordCount, int firmwareVersion) : theFirmwareVersion(firmwareVersion) {
0007   //FIXME do firmware version
0008   theData[0] = 0x6e0c;
0009   // all the necessary lines from this thing first
0010   wordCount += 5;
0011   // see if we need thePadding to make a multiple of 4
0012   thePadding = 0;
0013 
0014   if (wordCount % 4 == 2) {
0015     theData[1] = 0x2AAA;
0016     theData[2] = 0x5555;
0017     thePadding = 2;
0018     wordCount += thePadding;
0019   }
0020   // the next four words start with 11011, or a D
0021   for (int i = 1; i < 5; ++i) {
0022     theData[i + thePadding] = 0xD800;
0023   }
0024   theData[de0fOffset()] = 0xde0f;
0025   // word count excludes the trailer
0026   theData[4 + thePadding] |= wordCount;
0027 }
0028 
0029 CSCTMBTrailer::CSCTMBTrailer(const uint16_t* buf, unsigned short int firmwareVersion)
0030     : theFirmwareVersion(firmwareVersion) {
0031   // take a little too much, maybe
0032   memcpy(theData, buf, 14);
0033   switch (firmwareVersion) {
0034     case 2006:
0035       // if there's padding, there'll be a de0f in the 6th word.
0036       // If not, you'll be in CFEB-land, where they won't be de0f.
0037       thePadding = (theData[5] == 0xde0f ? 2 : 0);
0038       break;
0039     case 2007:
0040       ///in 2007 format de0f line moved
0041       // =VB= check for 1st word to be 0xDE0F, then check 3rd
0042       // to handle freaky cases of double 0xDE0F signatures in trailer
0043       thePadding = (theData[1] == 0xde0f ? 0 : (theData[3] == 0xde0f ? 2 : 0));
0044       //    thePadding = (theData[3] == 0xde0f ? 2 : 0);
0045       break;
0046     default:
0047       edm::LogError("CSCTMBTrailer|CSCRawToDigi") << "failed to contruct: firmware version is bad/not defined!";
0048   }
0049 }
0050 
0051 unsigned int CSCTMBTrailer::crc22() const {
0052   return (theData[crcOffset()] & 0x07ff) + ((theData[crcOffset() + 1] & 0x07ff) << 11);
0053 }
0054 
0055 void CSCTMBTrailer::setCRC(int crc) {
0056   theData[crcOffset()] |= (crc & 0x07ff);
0057   theData[crcOffset() + 1] |= ((crc >> 11) & 0x07ff);
0058 }
0059 
0060 int CSCTMBTrailer::wordCount() const { return theData[4 + thePadding] & 0x7ff; }
0061 
0062 void CSCTMBTrailer::selfTest() {
0063   CSCTMBTrailer trailer(104, 2006);
0064   unsigned int crc = 0xb00b1;
0065   trailer.setCRC(crc);
0066   assert(trailer.crc22() == 0xb00b1);
0067 
0068   CSCTMBTrailer trailer2(104, 2007);
0069   crc = 0xb00b1;
0070   trailer2.setCRC(crc);
0071   assert(trailer2.crc22() == 0xb00b1);
0072 }