22 : theOriginalBuffer(nullptr),
25 theTMBHeader(2007, 0x50c3),
26 theComparatorData(&theTMBHeader),
28 theTMBScopeIsPresent(
false),
30 theTMBMiniScopeIsPresent(
false),
31 theTMBMiniScope(nullptr),
32 theBlockedCFEBIsPresent(
false),
33 theTMBBlockedCFEB(nullptr),
34 theTMBTrailer(theTMBHeader.sizeInWords() + theComparatorData.sizeInWords(), 2007),
37 theRPCDataIsPresent(
false),
38 theGEMDataIsPresent(
false) {}
41 : theOriginalBuffer(nullptr),
45 theComparatorData(&theTMBHeader),
47 theTMBScopeIsPresent(
false),
49 theTMBMiniScopeIsPresent(
false),
50 theTMBMiniScope(nullptr),
51 theBlockedCFEBIsPresent(
false),
52 theTMBBlockedCFEB(nullptr),
53 theTMBTrailer(theTMBHeader.sizeInWords() + theComparatorData.sizeInWords(),
firmwareVersion),
56 theRPCDataIsPresent(
false),
57 theGEMDataIsPresent(
false) {
62 if ((
firmwareVersion == 2020) && (((firmwareRevision >> 9) & 0x3) == 3)) {
70 : theOriginalBuffer(
buf),
71 theTMBHeader(2007, 0x50c3),
72 theComparatorData(&theTMBHeader),
73 theTMBScopeIsPresent(
false),
75 theTMBMiniScopeIsPresent(
false),
76 theTMBMiniScope(nullptr),
77 theBlockedCFEBIsPresent(
false),
78 theTMBBlockedCFEB(nullptr),
79 theTMBTrailer(theTMBHeader.sizeInWords() + theComparatorData.sizeInWords(), 2007),
80 theRPCDataIsPresent(
false),
81 theGEMDataIsPresent(
false) {
88 : theOriginalBuffer(
data.theOriginalBuffer),
89 theB0CLine(
data.theB0CLine),
90 theE0FLine(
data.theE0FLine),
91 theTMBHeader(
data.theTMBHeader),
92 theComparatorData(
data.theComparatorData),
93 theRPCData(
data.theRPCData),
94 theGEMData(
data.theGEMData),
95 theTMBScopeIsPresent(
data.theTMBScopeIsPresent),
96 theTMBMiniScopeIsPresent(
data.theTMBMiniScopeIsPresent),
97 theBlockedCFEBIsPresent(
data.theBlockedCFEBIsPresent),
98 theTMBTrailer(
data.theTMBTrailer),
100 cWordCnt(
data.cWordCnt),
101 theRPCDataIsPresent(
data.theRPCDataIsPresent),
102 theGEMDataIsPresent(
data.theGEMDataIsPresent) {
142 for (
int i =
first;
i < maxToDo; ++
i) {
143 if (
buf[
i] == marker) {
157 if (!theTotalTMBData.empty()) {
159 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
" Test here " <<
CRC.to_ulong();
160 return CRC.to_ulong();
162 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"theTotalTMBData doesn't exist";
170 unsigned short int firmwareRevision = 0;
175 int GEMFibersMask = 0;
176 bool isGEMfirmware =
false;
182 if (
buf[b0cLine] == 0xdb0c) {
184 firmwareRevision =
buf[b0cLine + 7] & 0x7fff;
185 Ntbins =
buf[b0cLine + 19] & 0xF8;
186 if ((firmwareRevision < 0x4000)
187 && (((firmwareRevision >> 9) & 0x3) == 0x3))
188 isGEMfirmware =
true;
191 GEMFibersMask =
buf[b0cLine + 36] & 0xf;
196 NGEMtbins = (
buf[b0cLine + 36] >> 5) & 0x1F;
198 NRPCtbins = (
buf[b0cLine + 36] >> 5) & 0x1F;
199 }
else if (
buf[b0cLine] == 0x6b0c) {
201 Ntbins =
buf[b0cLine + 1] & 0x1f;
204 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ Can't find b0C flag";
208 (!(((
buf[b0cLine] & 0xFFFF) == 0xDB0C) && ((
buf[b0cLine + 1] & 0xf000) == 0xD000) &&
209 ((
buf[b0cLine + 2] & 0xf000) == 0xD000) && ((
buf[b0cLine + 3] & 0xf000) == 0xD000)))) {
210 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: error in header in 2007 format!";
213 int MaxSizeRPC = 1 + NRPCtbins * 2 * 4 + 1;
214 int MaxSizeGEM = 1 + NGEMEnabled * NGEMtbins * 4 + 1;
225 edm::LogError(
"CSCTMBData|CSCRawToDigi") <<
"+++ undetermined firmware format - cant find e0bLine";
231 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: Bad TMB header e0bLine=" << std::hex
243 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: Bad CLCT data";
249 int b04Line = currentPosition;
251 if (
buf[b04Line] == 0x6b04) {
253 int e04Line =
findLine(
buf, 0x6e04, currentPosition, currentPosition + MaxSizeRPC);
259 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"CSCTMBData::corrupt RPC data! Failed to find end! ";
265 int c04Line = currentPosition;
267 if (
buf[c04Line] == 0x6c04) {
269 int d04Line =
findLine(
buf, 0x6d04, currentPosition, currentPosition + MaxSizeGEM);
275 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"CSCTMBData::corrupt GEM data! Failed to find end! ";
280 int TotTMBReadout = 0;
284 TotTMBReadout = 43 + Ntbins * 6 * 5 + 1 + NGEMEnabled * NGEMtbins * 4 + 2 + 8 * 256 + 8;
286 TotTMBReadout = 43 + Ntbins * 6 * 5 + 1 + NRPCtbins * 2 * 4 + 2 + 8 * 256 + 8;
291 27 + Ntbins * 6 * 5 + 1 + NRPCtbins * 2 * 4 + 2 + 8 * 256 + 8;
294 edm::LogError(
"CSCTMBData|CSCRawToDigi") <<
"can't find TotTMBReadout - unknown firmware version!";
299 if (
buf[currentPosition] == 0x6b05) {
300 int b05Line = currentPosition;
301 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"found scope!";
302 int e05Line =
findLine(
buf, 0x6e05, currentPosition, TotTMBReadout - currentPosition);
309 currentPosition += (e05Line - b05Line + 1);
311 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: found 0x6b05 line, but not 0x6e05! +++";
316 if (
buf[currentPosition] == 0x6b07) {
317 int Line6b07 = currentPosition;
318 LogTrace(
"CSCTMBData") <<
" TMBData ---> Begin of MiniScope found ";
319 int Line6E07 =
findLine(
buf, 0x6E07, currentPosition, TotTMBReadout - currentPosition);
320 if (Line6E07 != -1) {
321 LogTrace(
"CSCTMBData") <<
" TMBData --> End of MiniScope found " << Line6E07 - Line6b07 + 1 <<
" words ";
324 currentPosition += (Line6E07 - Line6b07 + 1);
326 LogTrace(
"CSCTMBData") <<
"+++ CSCTMBData warning MiniScope!: found 0x6b07 line, but not 0x6e07! +++";
332 if (
buf[currentPosition] == 0x6BCB) {
333 int Line6BCB = currentPosition;
334 LogTrace(
"CSCTMBData") <<
" TMBData ---> Begin of Blocked CFEB found ";
335 int Line6ECB =
findLine(
buf, 0x6ECB, currentPosition, TotTMBReadout - currentPosition);
336 if (Line6ECB != -1) {
337 LogTrace(
"CSCTMBData") <<
" TMBData --> End of Blocked CFEB found " << Line6ECB - Line6BCB + 1 <<
" words ";
340 currentPosition += (Line6ECB - Line6BCB + 1);
342 LogTrace(
"CSCTMBData") <<
"+++ CSCTMBData warning Blocked CFEB!: found 0x6BCB line, but not 0x6ECB! +++";
347 int maxLine =
findLine(
buf, 0xde0f, currentPosition, TotTMBReadout - currentPosition);
349 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: No e0f line!";
359 int e0cLine =
findLine(
buf, 0x6e0c, currentPosition, maxLine);
361 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: No e0c line!";
371 LogTrace(
"CSCTMBData") <<
"Dump of TMB data:";
373 LogTrace(
"CSCTMBData") <<
"Adr= " << std::setw(4) <<
line <<
" Data= " << std::setfill(
'0') << std::setw(5)
391 for (
unsigned int i = 0;
i < datain.size() - 3; ++
i) {
399 throw(
"No TMBScope in this chamber");
405 throw(
"No TMBScope in this chamber");
411 throw(
"No GEM Data in this chamber");
416 std::bitset<22> NewCRC;
418 NewCRC[0] =
D[0] ^
C[6];
419 NewCRC[1] =
D[1] ^
D[0] ^
C[6] ^
C[7];
420 NewCRC[2] =
D[2] ^
D[1] ^
C[7] ^
C[8];
421 NewCRC[3] =
D[3] ^
D[2] ^
C[8] ^
C[9];
422 NewCRC[4] =
D[4] ^
D[3] ^
C[9] ^
C[10];
423 NewCRC[5] =
D[5] ^
D[4] ^
C[10] ^
C[11];
424 NewCRC[6] =
D[6] ^
D[5] ^
C[11] ^
C[12];
425 NewCRC[7] =
D[7] ^
D[6] ^
C[12] ^
C[13];
426 NewCRC[8] =
D[8] ^
D[7] ^
C[13] ^
C[14];
427 NewCRC[9] =
D[9] ^
D[8] ^
C[14] ^
C[15];
428 NewCRC[10] =
D[10] ^
D[9] ^
C[15] ^
C[16];
429 NewCRC[11] =
D[11] ^
D[10] ^
C[16] ^
C[17];
430 NewCRC[12] =
D[12] ^
D[11] ^
C[17] ^
C[18];
431 NewCRC[13] =
D[13] ^
D[12] ^
C[18] ^
C[19];
432 NewCRC[14] =
D[14] ^
D[13] ^
C[19] ^
C[20];
433 NewCRC[15] =
D[15] ^
D[14] ^
C[20] ^
C[21];
434 NewCRC[16] =
D[15] ^
C[0] ^
C[21];
445 boost::dynamic_bitset<>
result =
453 boost::dynamic_bitset<>
gemData =
458 boost::dynamic_bitset<> newResult =
result;
465 std::vector<std::bitset<16> > wordVector;
468 std::bitset<16>
word;
469 for (
int i = 0;
i < 16; ++
i) {
472 wordVector.push_back(
word);
CSCTMBMiniScope & tmbMiniScope() const
CSCTMBTrailer * tmbTrailer()
CSCTMBTrailer theTMBTrailer
static void selfTest()
tests packing
CSCTMBScope & tmbScope() const
boost::dynamic_bitset pack()
not const because it sets size int TMBTrailer
int sizeInWords() const
in 16-bit words
bool theBlockedCFEBIsPresent
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
std::bitset< 22 > nextCRC22_D16(const std::bitset< 16 > &D, const std::bitset< 22 > &C)
bool theTMBMiniScopeIsPresent
Log< level::Error, false > LogError
bool cscClassPackerCompare(T &t)
std::bitset< 22 > calCRC22(const std::vector< std::bitset< 16 > > &datain)
CSCTMBHeader theTMBHeader
static std::atomic< bool > debug
CSCTMBBlockedCFEB * theTMBBlockedCFEB
const uint16_t * theOriginalBuffer
bool checkSize() const
sees if the size adds up to the word count
CSCComparatorData theComparatorData
CSCTMBMiniScope * theTMBMiniScope
DecomposeProduct< arg, typename Div::arg > D
CSCComparatorData * comparatorData()
bool theTMBScopeIsPresent
The TMB scope is not present in most of data hence its dynamic.
int sizeInWords() const
in 16-bit frames
CSCTMBScope * theTMBScope
char data[epos_bytes_allocation]
int findLine(const uint16_t *buf, uint16_t marker, int first, int maxToDo)
boost::dynamic_bitset ushortToBitset(const unsigned int numberOfBits, unsigned short *buf)
this method takes numberOfBits bits from unsigned short * array and returns them in the bitset obj...
int UnpackTMB(const uint16_t *buf)