18 : theOriginalBuffer(0),
21 theTMBHeader(2007, 0x50c3),
22 theCLCTData(&theTMBHeader),
23 theTMBScopeIsPresent(
false),
25 theTMBMiniScopeIsPresent(
false),
27 theBlockedCFEBIsPresent(
false),
29 theTMBTrailer(theTMBHeader.sizeInWords()+theCLCTData.sizeInWords(), 2007),
32 theRPCDataIsPresent(
false)
39 : theOriginalBuffer(0),
42 theTMBHeader(firmwareVersion, firmwareRevision),
43 theCLCTData(&theTMBHeader),
44 theTMBScopeIsPresent(
false),
46 theTMBMiniScopeIsPresent(
false),
48 theBlockedCFEBIsPresent(
false),
50 theTMBTrailer(theTMBHeader.sizeInWords()+theCLCTData.sizeInWords(), firmwareVersion),
53 theRPCDataIsPresent(
false)
64 : theOriginalBuffer(buf),
65 theTMBHeader(2007, 0x50c3),
66 theCLCTData(&theTMBHeader),
67 theTMBScopeIsPresent(
false),
69 theTMBMiniScopeIsPresent(
false),
71 theBlockedCFEBIsPresent(
false),
73 theTMBTrailer(theTMBHeader.sizeInWords()+theCLCTData.sizeInWords(), 2007),
74 theRPCDataIsPresent(
false){
81 theOriginalBuffer(data.theOriginalBuffer),
82 theB0CLine(data.theB0CLine), theE0FLine(data.theE0FLine),
83 theTMBHeader(data.theTMBHeader),
84 theCLCTData(data.theCLCTData), theRPCData(data.theRPCData),
85 theTMBScopeIsPresent(data.theTMBScopeIsPresent),
86 theTMBMiniScopeIsPresent(data.theTMBMiniScopeIsPresent),
87 theBlockedCFEBIsPresent(data.theBlockedCFEBIsPresent),
88 theTMBTrailer(data.theTMBTrailer),
90 theRPCDataIsPresent(data.theRPCDataIsPresent)
135 for(
int i = first;
i < maxToDo; ++
i) {
136 if(buf[
i] == marker) {
150 if ( theTotalTMBData.size() > 0 ) {
151 std::bitset<22> CRC=
calCRC22(theTotalTMBData);
152 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
" Test here " << CRC.to_ulong();
153 return CRC.to_ulong();
156 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"theTotalTMBData doesn't exist";
163 unsigned short int firmwareVersion=0;
165 int NHeaderFrames = 0;
172 NHeaderFrames++; NHeaderFrames--;
174 if (buf[b0cLine]==0xdb0c) {
175 firmwareVersion=2007;
176 Ntbins = buf[b0cLine+19]&0xF8;
177 NRPCtbins = (buf[b0cLine+36]>>5)&0x1F;
178 NHeaderFrames = buf[b0cLine+5]&0x3F;
180 else if (buf[b0cLine]==0x6b0c) {
181 firmwareVersion=2006;
182 Ntbins = buf[b0cLine+1]&0x1f ;
184 NHeaderFrames = buf[b0cLine+4]&0x1f;
187 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ Can't find b0C flag";
190 if ((firmwareVersion==2007)&&(!(((buf[b0cLine]&0xFFFF)==0xDB0C)&&((buf[b0cLine+1]&0xf000)==0xD000)
191 &&((buf[b0cLine+2]&0xf000)==0xD000)&&((buf[b0cLine+3]&0xf000)==0xD000)))){
192 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: error in header in 2007 format!";
195 int MaxSizeRPC = 1+NRPCtbins*2*4+1;
198 switch (firmwareVersion) {
206 edm::LogError(
"CSCTMBData|CSCRawToDigi") <<
"+++ undetermined firmware format - cant find e0bLine";
212 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: Bad TMB header e0bLine=" << std::hex << buf[e0bLine];
222 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: Bad CLCT data";
233 int b04Line = currentPosition;
235 if(buf[b04Line]==0x6b04) {
237 int e04Line =
findLine(buf, 0x6e04, currentPosition, currentPosition+MaxSizeRPC);
244 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"CSCTMBData::corrupt RPC data! Failed to find end! ";
250 switch (firmwareVersion) {
252 TotTMBReadout= 43+Ntbins*6*5+1+NRPCtbins*2*4+2+8*256+8;
255 TotTMBReadout= 27+Ntbins*6*5+1+NRPCtbins*2*4+2+8*256+8;
258 edm::LogError(
"CSCTMBData|CSCRawToDigi") <<
"can't find TotTMBReadout - unknown firmware version!";
263 if (buf[currentPosition]==0x6b05) {
264 int b05Line = currentPosition;
265 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"found scope!";
266 int e05Line =
findLine(buf, 0x6e05, currentPosition, TotTMBReadout-currentPosition);
273 currentPosition+=(e05Line-b05Line+1);
277 <<
"+++ CSCTMBData warning: found 0x6b05 line, but not 0x6e05! +++";
282 if (buf[currentPosition]==0x6b07){
283 int Line6b07 = currentPosition;
284 LogTrace(
"CSCTMBData") <<
" TMBData ---> Begin of MiniScope found " ;
285 int Line6E07 =
findLine(buf, 0x6E07, currentPosition, TotTMBReadout-currentPosition);
287 LogTrace(
"CSCTMBData") <<
" TMBData --> End of MiniScope found " << Line6E07-Line6b07+1 <<
" words ";
290 currentPosition += (Line6E07-Line6b07+1);
294 <<
"+++ CSCTMBData warning MiniScope!: found 0x6b07 line, but not 0x6e07! +++";
300 if (buf[currentPosition]==0x6BCB){
301 int Line6BCB = currentPosition;
302 LogTrace(
"CSCTMBData") <<
" TMBData ---> Begin of Blocked CFEB found " ;
303 int Line6ECB =
findLine(buf, 0x6ECB, currentPosition, TotTMBReadout-currentPosition);
305 LogTrace(
"CSCTMBData") <<
" TMBData --> End of Blocked CFEB found " << Line6ECB-Line6BCB+1 <<
" words ";
308 currentPosition += (Line6ECB-Line6BCB+1);
312 <<
"+++ CSCTMBData warning Blocked CFEB!: found 0x6BCB line, but not 0x6ECB! +++";
317 int maxLine =
findLine(buf, 0xde0f, currentPosition, TotTMBReadout-currentPosition);
320 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: No e0f line!";
330 int e0cLine =
findLine(buf, 0x6e0c, currentPosition, maxLine);
333 LogTrace(
"CSCTMBData|CSCRawToDigi") <<
"+++ CSCTMBData warning: No e0c line!";
346 LogTrace(
"CSCTMBData") <<
"Dump of TMB data:";
349 <<
"Adr= " << std::setw(4) <<
line
350 <<
" Data= " << std::setfill(
'0') << std::setw(5)
351 << std::uppercase << std::hex << buf[
line] << std::dec << std::endl;
370 for(
unsigned int i=0;
i<datain.size()-3;++
i)
398 const std::bitset<22>&
C)
400 std::bitset<22> NewCRC;
402 NewCRC[ 0] = D[ 0] ^ C[ 6];
403 NewCRC[ 1] = D[ 1] ^ D[ 0] ^ C[ 6] ^ C[ 7];
404 NewCRC[ 2] = D[ 2] ^ D[ 1] ^ C[ 7] ^ C[ 8];
405 NewCRC[ 3] = D[ 3] ^ D[ 2] ^ C[ 8] ^ C[ 9];
406 NewCRC[ 4] = D[ 4] ^ D[ 3] ^ C[ 9] ^ C[10];
407 NewCRC[ 5] = D[ 5] ^ D[ 4] ^ C[10] ^ C[11];
408 NewCRC[ 6] = D[ 6] ^ D[ 5] ^ C[11] ^ C[12];
409 NewCRC[ 7] = D[ 7] ^ D[ 6] ^ C[12] ^ C[13];
410 NewCRC[ 8] = D[ 8] ^ D[ 7] ^ C[13] ^ C[14];
411 NewCRC[ 9] = D[ 9] ^ D[ 8] ^ C[14] ^ C[15];
412 NewCRC[10] = D[10] ^ D[ 9] ^ C[15] ^ C[16];
413 NewCRC[11] = D[11] ^ D[10] ^ C[16] ^ C[17];
414 NewCRC[12] = D[12] ^ D[11] ^ C[17] ^ C[18];
415 NewCRC[13] = D[13] ^ D[12] ^ C[18] ^ C[19];
416 NewCRC[14] = D[14] ^ D[13] ^ C[19] ^ C[20];
417 NewCRC[15] = D[15] ^ D[14] ^ C[20] ^ C[21];
418 NewCRC[16] = D[15] ^ C[ 0] ^ C[21];
436 boost::dynamic_bitset<> newResult =
result;
444 std::vector<std::bitset<16> > wordVector;
446 for(
unsigned pos = 0; pos < result.size()-16; pos += 16)
448 std::bitset<16> word;
449 for(
int i = 0;
i < 16; ++
i)
451 word[
i] = result[pos+
i];
453 wordVector.push_back(word);
int sizeInWords() const
in 16-bit words
CSCTMBTrailer * tmbTrailer()
CSCTMBTrailer theTMBTrailer
static void selfTest()
tests packing
unsigned short * theOriginalBuffer
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
CSCTMBBlockedCFEB & tmbBlockedCFEB() const
bool cscClassPackerCompare(T &t)
std::bitset< 22 > calCRC22(const std::vector< std::bitset< 16 > > &datain)
CSCTMBHeader theTMBHeader
CSCTMBBlockedCFEB * theTMBBlockedCFEB
CSCTMBScope & tmbScope() const
CSCTMBMiniScope * theTMBMiniScope
bool theTMBScopeIsPresent
The TMB scope is not present in most of data hence its dynamic.
CSCTMBScope * theTMBScope
char data[epos_bytes_allocation]
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...
volatile std::atomic< bool > shutdown_flag false
int UnpackTMB(unsigned short *buf)
DecomposeProduct< arg, typename Div::arg > D
CSCTMBMiniScope & tmbMiniScope() const
int findLine(unsigned short *buf, unsigned short marker, int first, int maxToDo)