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),
44 theTMBHeader(firmwareVersion, firmwareRevision),
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) {
64 : theOriginalBuffer(buf),
65 theTMBHeader(2007, 0x50c3),
66 theComparatorData(&theTMBHeader),
68 theTMBScopeIsPresent(
false),
70 theTMBMiniScopeIsPresent(
false),
71 theTMBMiniScope(nullptr),
72 theBlockedCFEBIsPresent(
false),
73 theTMBBlockedCFEB(nullptr),
74 theTMBTrailer(theTMBHeader.sizeInWords() + theComparatorData.sizeInWords(), 2007),
75 theRPCDataIsPresent(
false),
76 theGEMDataIsPresent(
false) {
83 : theOriginalBuffer(data.theOriginalBuffer),
84 theB0CLine(data.theB0CLine),
85 theE0FLine(data.theE0FLine),
86 theTMBHeader(data.theTMBHeader),
87 theComparatorData(data.theComparatorData),
88 theRPCData(data.theRPCData),
89 theGEMData(data.theGEMData),
90 theTMBScopeIsPresent(data.theTMBScopeIsPresent),
91 theTMBMiniScopeIsPresent(data.theTMBMiniScopeIsPresent),
92 theBlockedCFEBIsPresent(data.theBlockedCFEBIsPresent),
93 theTMBTrailer(data.theTMBTrailer),
95 cWordCnt(data.cWordCnt),
96 theRPCDataIsPresent(data.theRPCDataIsPresent),
97 theGEMDataIsPresent(data.theGEMDataIsPresent) {
148 for (
int i = first;
i < maxToDo; ++
i) {
149 if (buf[
i] == marker) {
163 if (!theTotalTMBData.empty()) {
164 std::bitset<22> CRC =
calCRC22(theTotalTMBData);
165 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
" Test here " << CRC.to_ulong();
166 return CRC.to_ulong();
168 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"theTotalTMBData doesn't exist";
175 unsigned short int firmwareVersion = 0;
176 unsigned short int firmwareRevision = 0;
181 int GEMFibersMask = 0;
182 bool isGEMfirmware =
false;
188 if (buf[b0cLine] == 0xdb0c) {
189 firmwareVersion = 2007;
190 firmwareRevision = buf[b0cLine + 7] & 0x7fff;
191 Ntbins = buf[b0cLine + 19] & 0xF8;
192 if ((firmwareRevision < 0x4000)
193 && (((firmwareRevision >> 9) & 0x2) == 0x2))
194 isGEMfirmware =
true;
197 GEMFibersMask = buf[b0cLine + 36] & 0xf;
202 NGEMtbins = (buf[b0cLine + 36] >> 5) & 0x1F;
206 NRPCtbins = (buf[b0cLine + 36] >> 5) & 0x1F;
208 }
else if (buf[b0cLine] == 0x6b0c) {
209 firmwareVersion = 2006;
210 Ntbins = buf[b0cLine + 1] & 0x1f;
213 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ Can't find b0C flag";
216 if ((firmwareVersion == 2007) &&
217 (!(((buf[b0cLine] & 0xFFFF) == 0xDB0C) && ((buf[b0cLine + 1] & 0xf000) == 0xD000) &&
218 ((buf[b0cLine + 2] & 0xf000) == 0xD000) && ((buf[b0cLine + 3] & 0xf000) == 0xD000)))) {
219 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: error in header in 2007 format!";
222 int MaxSizeRPC = 1 + NRPCtbins * 2 * 4 + 1;
223 int MaxSizeGEM = 1 + NGEMEnabled * NGEMtbins * 4 + 1;
226 switch (firmwareVersion) {
234 edm::LogError(
"CSCTMBData|CSCRawToDigi") <<
"+++ undetermined firmware format - cant find e0bLine";
240 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: Bad TMB header e0bLine=" << std::hex
252 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: Bad CLCT data";
258 int b04Line = currentPosition;
260 if (buf[b04Line] == 0x6b04) {
262 int e04Line =
findLine(buf, 0x6e04, currentPosition, currentPosition + MaxSizeRPC);
268 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"CSCTMBData::corrupt RPC data! Failed to find end! ";
274 int c04Line = currentPosition;
276 if (buf[c04Line] == 0x6c04) {
278 int d04Line =
findLine(buf, 0x6d04, currentPosition, currentPosition + MaxSizeGEM);
285 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"CSCTMBData::corrupt GEM data! Failed to find end! ";
290 int TotTMBReadout = 0;
291 switch (firmwareVersion) {
294 TotTMBReadout = 43 + Ntbins * 6 * 5 + 1 + NGEMEnabled * NGEMtbins * 4 + 2 + 8 * 256 + 8;
296 TotTMBReadout = 43 + Ntbins * 6 * 5 + 1 + NRPCtbins * 2 * 4 + 2 + 8 * 256 + 8;
301 27 + Ntbins * 6 * 5 + 1 + NRPCtbins * 2 * 4 + 2 + 8 * 256 + 8;
304 edm::LogError(
"CSCTMBData|CSCRawToDigi") <<
"can't find TotTMBReadout - unknown firmware version!";
309 if (buf[currentPosition] == 0x6b05) {
310 int b05Line = currentPosition;
311 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"found scope!";
312 int e05Line =
findLine(buf, 0x6e05, currentPosition, TotTMBReadout - currentPosition);
319 currentPosition += (e05Line - b05Line + 1);
321 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: found 0x6b05 line, but not 0x6e05! +++";
326 if (buf[currentPosition] == 0x6b07) {
327 int Line6b07 = currentPosition;
328 LogTrace(
"CSCTMBData") <<
" TMBData ---> Begin of MiniScope found ";
329 int Line6E07 =
findLine(buf, 0x6E07, currentPosition, TotTMBReadout - currentPosition);
330 if (Line6E07 != -1) {
331 LogTrace(
"CSCTMBData") <<
" TMBData --> End of MiniScope found " << Line6E07 - Line6b07 + 1 <<
" words ";
334 currentPosition += (Line6E07 - Line6b07 + 1);
336 LogTrace(
"CSCTMBData") <<
"+++ CSCTMBData warning MiniScope!: found 0x6b07 line, but not 0x6e07! +++";
342 if (buf[currentPosition] == 0x6BCB) {
343 int Line6BCB = currentPosition;
344 LogTrace(
"CSCTMBData") <<
" TMBData ---> Begin of Blocked CFEB found ";
345 int Line6ECB =
findLine(buf, 0x6ECB, currentPosition, TotTMBReadout - currentPosition);
346 if (Line6ECB != -1) {
347 LogTrace(
"CSCTMBData") <<
" TMBData --> End of Blocked CFEB found " << Line6ECB - Line6BCB + 1 <<
" words ";
350 currentPosition += (Line6ECB - Line6BCB + 1);
352 LogTrace(
"CSCTMBData") <<
"+++ CSCTMBData warning Blocked CFEB!: found 0x6BCB line, but not 0x6ECB! +++";
357 int maxLine =
findLine(buf, 0xde0f, currentPosition, TotTMBReadout - currentPosition);
359 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: No e0f line!";
369 int e0cLine =
findLine(buf, 0x6e0c, currentPosition, maxLine);
371 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: No e0c line!";
381 LogTrace(
"CSCTMBData") <<
"Dump of TMB data:";
383 LogTrace(
"CSCTMBData") <<
"Adr= " << std::setw(4) <<
line <<
" Data= " << std::setfill(
'0') << std::setw(5)
384 << std::uppercase << std::hex << buf[
line] <<
std::dec << std::endl;
401 for (
unsigned int i = 0;
i < datain.size() - 3; ++
i) {
409 throw(
"No TMBScope in this chamber");
415 throw(
"No TMBScope in this chamber");
421 throw(
"No GEM Data in this chamber");
426 std::bitset<22> NewCRC;
428 NewCRC[0] = D[0] ^ C[6];
429 NewCRC[1] = D[1] ^ D[0] ^ C[6] ^ C[7];
430 NewCRC[2] = D[2] ^ D[1] ^ C[7] ^ C[8];
431 NewCRC[3] = D[3] ^ D[2] ^ C[8] ^ C[9];
432 NewCRC[4] = D[4] ^ D[3] ^ C[9] ^ C[10];
433 NewCRC[5] = D[5] ^ D[4] ^ C[10] ^ C[11];
434 NewCRC[6] = D[6] ^ D[5] ^ C[11] ^ C[12];
435 NewCRC[7] = D[7] ^ D[6] ^ C[12] ^ C[13];
436 NewCRC[8] = D[8] ^ D[7] ^ C[13] ^ C[14];
437 NewCRC[9] = D[9] ^ D[8] ^ C[14] ^ C[15];
438 NewCRC[10] = D[10] ^ D[9] ^ C[15] ^ C[16];
439 NewCRC[11] = D[11] ^ D[10] ^ C[16] ^ C[17];
440 NewCRC[12] = D[12] ^ D[11] ^ C[17] ^ C[18];
441 NewCRC[13] = D[13] ^ D[12] ^ C[18] ^ C[19];
442 NewCRC[14] = D[14] ^ D[13] ^ C[19] ^ C[20];
443 NewCRC[15] = D[15] ^ D[14] ^ C[20] ^ C[21];
444 NewCRC[16] = D[15] ^ C[0] ^ C[21];
455 boost::dynamic_bitset<>
result =
460 boost::dynamic_bitset<> newResult =
result;
468 std::vector<std::bitset<16> > wordVector;
470 for (
unsigned pos = 0; pos < result.size() - 16; pos += 16) {
471 std::bitset<16>
word;
472 for (
int i = 0;
i < 16; ++
i) {
473 word[
i] = result[pos +
i];
475 wordVector.push_back(word);
CSCTMBTrailer * tmbTrailer()
CSCTMBTrailer theTMBTrailer
static void selfTest()
tests packing
boost::dynamic_bitset pack()
not const because it sets size int TMBTrailer
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
int sizeInWords() const
in 16-bit frames
Log< level::Error, false > LogError
bool cscClassPackerCompare(T &t)
int sizeInWords() const
in 16-bit words
std::bitset< 22 > calCRC22(const std::vector< std::bitset< 16 > > &datain)
CSCTMBHeader theTMBHeader
static std::atomic< bool > debug
CSCTMBBlockedCFEB * theTMBBlockedCFEB
const uint16_t * theOriginalBuffer
CSCTMBScope & tmbScope() const
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.
CSCTMBScope * theTMBScope
CSCGEMData * gemData() const
char data[epos_bytes_allocation]
int findLine(const uint16_t *buf, uint16_t marker, int first, int maxToDo)
bool checkSize() const
sees if the size adds up to the word count
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)
CSCTMBMiniScope & tmbMiniScope() const