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