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
0008 theData[0] = 0x6e0c;
0009
0010 wordCount += 5;
0011
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
0021 for (int i = 1; i < 5; ++i) {
0022 theData[i + thePadding] = 0xD800;
0023 }
0024 theData[de0fOffset()] = 0xde0f;
0025
0026 theData[4 + thePadding] |= wordCount;
0027 }
0028
0029 CSCTMBTrailer::CSCTMBTrailer(const uint16_t* buf, unsigned short int firmwareVersion)
0030 : theFirmwareVersion(firmwareVersion) {
0031
0032 memcpy(theData, buf, 14);
0033 switch (firmwareVersion) {
0034 case 2006:
0035
0036
0037 thePadding = (theData[5] == 0xde0f ? 2 : 0);
0038 break;
0039 case 2007:
0040
0041
0042
0043 thePadding = (theData[1] == 0xde0f ? 0 : (theData[3] == 0xde0f ? 2 : 0));
0044
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 }