CMS 3D CMS Logo

CSCTMBTrailer.cc
Go to the documentation of this file.
3 #include <iostream>
4 #include <cassert>
5 
6 CSCTMBTrailer::CSCTMBTrailer(int wordCount, int firmwareVersion)
7 : theFirmwareVersion(firmwareVersion)
8 {
9  //FIXME do firmware version
10  theData[0] = 0x6e0c;
11  // all the necessary lines from this thing first
12  wordCount += 5;
13  // see if we need thePadding to make a multiple of 4
14  thePadding = 0;
15 
16  if(wordCount%4==2)
17  {
18  theData[1] = 0x2AAA;
19  theData[2] = 0x5555;
20  thePadding = 2;
21  wordCount += thePadding;
22  }
23  // the next four words start with 11011, or a D
24  for(int i = 1; i < 5; ++i)
25  {
26  theData[i+thePadding] = 0xD800;
27  }
28  theData[de0fOffset()] = 0xde0f;
29  // word count excludes the trailer
31 }
32 
33 
34 CSCTMBTrailer::CSCTMBTrailer(unsigned short * buf, unsigned short int firmwareVersion)
35 : theFirmwareVersion(firmwareVersion)
36 {
37  // take a little too much, maybe
38  memcpy(theData, buf, 14);
39  switch (firmwareVersion){
40  case 2006:
41  // if there's padding, there'll be a de0f in the 6th word.
42  // If not, you'll be in CFEB-land, where they won't be de0f.
43  thePadding = (theData[5] == 0xde0f ? 2 : 0);
44  break;
45  case 2007:
47  // =VB= check for 1st word to be 0xDE0F, then check 3rd
48  // to handle freaky cases of double 0xDE0F signatures in trailer
49  thePadding = (theData[1] == 0xde0f ? 0 : (theData[3] == 0xde0f ? 2 : 0));
50 // thePadding = (theData[3] == 0xde0f ? 2 : 0);
51  break;
52  default:
53  edm::LogError("CSCTMBTrailer|CSCRawToDigi")
54  <<"failed to contruct: firmware version is bad/not defined!";
55  }
56 }
57 
58 unsigned int CSCTMBTrailer::crc22() const
59 {
60  return (theData[crcOffset()] & 0x07ff) +
61  ((theData[crcOffset()+1] & 0x07ff) << 11);
62 }
63 
64 
65 void CSCTMBTrailer::setCRC(int crc)
66 {
67  theData[crcOffset()] |= (crc & 0x07ff);
68  theData[crcOffset()+1] |= ((crc>>11) & 0x07ff);
69 }
70 
71 
72 int CSCTMBTrailer::wordCount() const {return theData[4+thePadding] & 0x7ff;}
73 
74 
75 
77 {
78  CSCTMBTrailer trailer(104, 2006);
79  unsigned int crc = 0xb00b1;
80  trailer.setCRC(crc);
81  assert(trailer.crc22() == 0xb00b1);
82 
83  CSCTMBTrailer trailer2(104, 2007);
84  crc = 0xb00b1;
85  trailer2.setCRC(crc);
86  assert(trailer2.crc22() == 0xb00b1);
87 
88 }
89 
int wordCount() const
unsigned short int theFirmwareVersion
Definition: CSCTMBTrailer.h:58
int crcOffset() const
Definition: CSCTMBTrailer.h:53
CSCTMBTrailer(int wordCount, int firmwareVersion)
don&#39;t forget to pass in the size of the tmb header + clct data
Definition: CSCTMBTrailer.cc:6
unsigned int crc22() const
unsigned short theData[7]
Definition: CSCTMBTrailer.h:56
void setCRC(int crc)
static void selfTest()
int de0fOffset() const
Definition: CSCTMBTrailer.h:54