CMS 3D CMS Logo

CSCDCCExaminer.cc
Go to the documentation of this file.
2 
3 #ifdef LOCAL_UNPACK
4 #include <string.h>
5 
6 #else
7 
8 #include <cstring>
9 #include <cassert>
10 
11 /*
12 #ifdef CSC_DEBUG
13 #include <iostream>
14 #define COUT std::COUT
15 #define CERR std::CERR
16 #else
17 #include "FWCore/MessageLogger/interface/MessageLogger.h"
18 #define COUT LogTrace("CSCDCCExaminer")
19 // #define CERR edm::LogWarning("CSCDCCExaminer")
20 #define CERR LogDebug("CSCDCCExaminer")
21 #endif
22 */
23 
24 #endif
25 
26 #include <iomanip>
27 using namespace std;
28 
30 {
31  checkCrcALCT = enable;
32  if( checkCrcALCT )
33  sERROR[10] = "ALCT CRC Error ";
34  else
35  sERROR[10] = "ALCT CRC Error ( disabled ) ";
36 }
37 
39 {
40  checkCrcTMB = enable;
41  if( checkCrcTMB )
42  sERROR[15] = "TMB CRC Error ";
43  else
44  sERROR[15] = "TMB CRC Error ( disabled ) ";
45 }
46 
48 {
49  checkCrcCFEB = enable;
50  if( checkCrcCFEB )
51  sERROR[18] = "CFEB CRC Error ";
52  else
53  sERROR[18] = "CFEB CRC Error ( disabled ) ";
54 }
55 
57 {
58  modeDDUonly = enable;
59  if( modeDDUonly)
60  {
61  sERROR[25] = "DCC Trailer Missing ";
62  sERROR[26] = "DCC Header Missing ";
63  }
64  else
65  {
66  sERROR[25] = "DCC Trailer Missing (disabled) ";
67  sERROR[26] = "DCC Header Missing (disabled) ";
68  }
69 
70 }
71 
72 
74  :nERRORS(29),nWARNINGS(5),nPAYLOADS(16),nSTATUSES(29),sERROR(nERRORS),sWARNING(nWARNINGS),sERROR_(nERRORS),sWARNING_(nWARNINGS),sDMBExpectedPayload(nPAYLOADS),sDMBEventStaus(nSTATUSES),examinerMask(mask)
75 {
76 
77 #ifdef LOCAL_UNPACK
78  COUT.redirect(std::cout);
79  CERR.redirect(std::cerr);
80 #endif
81 
82  sERROR[0] = " Any errors ";
83  sERROR[1] = " DDU Trailer Missing ";
84  sERROR[2] = " DDU Header Missing ";
85  sERROR[3] = " DDU CRC Error (not yet implemented) ";
86  sERROR[4] = " DDU Word Count Error ";
87  sERROR[5] = " DMB Trailer Missing ";
88  sERROR[6] = " DMB Header Missing ";
89  sERROR[7] = " ALCT Trailer Missing ";
90  sERROR[8] = " ALCT Header Missing ";
91  sERROR[9] = " ALCT Word Count Error ";
92  sERROR[10] = "ALCT CRC Error ";
93  sERROR[11] = "ALCT Trailer Bit Error ";
94  // ^^^ This is due to seeing many events in ddu293 (also, some in ddu294)
95  // with some bits in the 1st ALCT D-Header being lost. This causes a chain of errors:
96  // - TMB Trailer is not identified and TMB word count mismatch occur when Trailer is found
97  // - CFEB sample count is not reset on ALCT Trailer.
98  // To merge all these errors in one,
99  // the D-signature in the 1st ALCT Trailer will not be required for identifying the ALCT Trailer;
100  // However, if these bits are found to be missing, ERROR[11] will be flagged.
101  // This is just a temporary patch to make the output look less clattered.
102  sERROR[12] = "TMB Trailer Missing ";
103  sERROR[13] = "TMB Header Missing ";
104  sERROR[14] = "TMB Word Count Error ";
105  sERROR[15] = "TMB CRC Error ";
106  sERROR[16] = "CFEB Word Count Per Sample Error ";
107  sERROR[17] = "CFEB Sample Count Error ";
108  sERROR[18] = "CFEB CRC Error ";
109  sERROR[19] = "DDU Event Size Limit Error ";
110  sERROR[20] = "C-Words ";
111  sERROR[21] = "ALCT DAV Error ";
112  sERROR[22] = "TMB DAV Error ";
113  sERROR[23] = "CFEB DAV Error ";
114  sERROR[24] = "DMB Active Error ";
115  sERROR[25] = "DCC Trailer Missing ";
116  sERROR[26] = "DCC Header Missing ";
117  sERROR[27] = "DMB DAV vs. DMB Active mismatch Error ";
118  sERROR[28] = "Extra words between DDU Header and first DMB header";
119 
120  // sERROR[21] = "DDU Header vs. Trailer mismatch for DAV or Avtive"; // oboslete since 16.09.05
121 
122  sWARNING[0] = " Extra words between DDU Trailer and DDU Header ";
123  sWARNING[1] = " DDU Header Incomplete ";
124 
125  sDMBExpectedPayload[0] = "CFEB1_ACTIVE";
126  sDMBExpectedPayload[1] = "CFEB2_ACTIVE";
127  sDMBExpectedPayload[2] = "CFEB3_ACTIVE";
128  sDMBExpectedPayload[3] = "CFEB4_ACTIVE";
129  sDMBExpectedPayload[4] = "CFEB5_ACTIVE";
130  sDMBExpectedPayload[5] = "ALCT_DAV";
131  sDMBExpectedPayload[6] = "TMB_DAV";
132  sDMBExpectedPayload[7] = "CFEB1_DAV";
133  sDMBExpectedPayload[8] = "CFEB2_DAV";
134  sDMBExpectedPayload[9] = "CFEB3_DAV";
135  sDMBExpectedPayload[10] = "CFEB4_DAV";
136  sDMBExpectedPayload[11] = "CFEB5_DAV";
138  sDMBExpectedPayload[12] = "CFEB6_DAV";
139  sDMBExpectedPayload[13] = "CFEB7_DAV";
140  sDMBExpectedPayload[14] = "CFEB6_ACTIVE";
141  sDMBExpectedPayload[15] = "CFEB7_ACTIVE";
142 
143 
144  sDMBEventStaus[0] = "ALCT_FIFO_FULL";
145  sDMBEventStaus[1] = "TMB_FIFO_FULL";
146  sDMBEventStaus[2] = "CFEB1_FIFO_FULL";
147  sDMBEventStaus[3] = "CFEB2_FIFO_FULL";
148  sDMBEventStaus[4] = "CFEB3_FIFO_FULL";
149  sDMBEventStaus[5] = "CFEB4_FIFO_FULL";
150  sDMBEventStaus[6] = "CFEB5_FIFO_FULL";
151  sDMBEventStaus[7] = "ALCT_START_TIMEOUT";
152  sDMBEventStaus[8] = "TMB_START_TIMEOUT";
153  sDMBEventStaus[9] = "CFEB1_START_TIMEOUT";
154  sDMBEventStaus[10] = "CFEB2_START_TIMEOUT";
155  sDMBEventStaus[11] = "CFEB3_START_TIMEOUT";
156  sDMBEventStaus[12] = "CFEB4_START_TIMEOUT";
157  sDMBEventStaus[13] = "CFEB5_START_TIMEOUT";
158  sDMBEventStaus[14] = "ALCT_END_TIMEOUT";
159  sDMBEventStaus[15] = "TMB_END_TIMEOUT";
160  sDMBEventStaus[16] = "CFEB1_END_TIMEOUT";
161  sDMBEventStaus[17] = "CFEB2_END_TIMEOUT";
162  sDMBEventStaus[18] = "CFEB3_END_TIMEOUT";
163  sDMBEventStaus[19] = "CFEB4_END_TIMEOUT";
164  sDMBEventStaus[20] = "CFEB5_END_TIMEOUT";
165  sDMBEventStaus[21] = "CFEB Active-DAV mismatch";
166  sDMBEventStaus[22] = "B-words found";
168  sDMBEventStaus[23] = "CFEB6_FIFO_FULL";
169  sDMBEventStaus[24] = "CFEB7_FIFO_FULL";
170  sDMBEventStaus[25] = "CFEB6_START_TIMEOUT";
171  sDMBEventStaus[26] = "CFEB7_START_TIMEOUT";
172  sDMBEventStaus[27] = "CFEB6_END_TIMEOUT";
173  sDMBEventStaus[28] = "CFEB7_END_TIMEOUT";
174 
175 
176 
177  sERROR_[0] = " Any errors: 00";
178  sERROR_[1] = " DDU Trailer Missing: 01";
179  sERROR_[2] = " DDU Header Missing: 02";
180  sERROR_[3] = " DDU CRC Error (not yet implemented): 03";
181  sERROR_[4] = " DDU Word Count Error: 04";
182  sERROR_[5] = " DMB Trailer Missing: 05";
183  sERROR_[6] = " DMB Header Missing: 06";
184  sERROR_[7] = " ALCT Trailer Missing: 07";
185  sERROR_[8] = " ALCT Header Missing: 08";
186  sERROR_[9] = " ALCT Word Count Error: 09";
187  sERROR_[10] = "ALCT CRC Error: 10";
188  sERROR_[11] = "ALCT Trailer Bit Error: 11";
189  sERROR_[12] = "TMB Trailer Missing: 12";
190  sERROR_[13] = "TMB Header Missing: 13";
191  sERROR_[14] = "TMB Word Count Error: 14";
192  sERROR_[15] = "TMB CRC Error: 15";
193  sERROR_[16] = "CFEB Word Count Per Sample Error: 16";
194  sERROR_[17] = "CFEB Sample Count Error: 17";
195  sERROR_[18] = "CFEB CRC Error: 18";
196  sERROR_[19] = "DDU Event Size Limit Error: 19";
197  sERROR_[20] = "C-Words: 20";
198  sERROR_[21] = "ALCT DAV Error: 21";
199  sERROR_[22] = "TMB DAV Error: 22";
200  sERROR_[23] = "CFEB DAV Error: 23";
201  sERROR_[24] = "DMB Active Error: 24";
202  sERROR_[25] = "DCC Trailer Missing: 25";
203  sERROR_[26] = "DCC Header Missing: 26";
204  sERROR_[27] = "DMB DAV vs. DMB Active mismatch Error: 27";
205  sERROR_[28] = "Extra words between DDU Header and first DMB header: 28";
206  // sERROR_[21] = "DDU Header vs. Trailer mismatch for DAV or Avtive: 21"; // oboslete since 16.09.05
207 
208  sWARNING_[0] = " Extra words between DDU Trailer and DDU Header: 00";
209  sWARNING_[1] = " DDU Header Incomplete: 02";
210 
211  fDCC_Header = false;
212  fDCC_Trailer = false;
213  fDDU_Header = false;
214  fDDU_Trailer = false;
215  fDMB_Header = false;
216  fDMB_Trailer = false;
217  fALCT_Header = false;
218  fTMB_Header = false;
219  fALCT_Format2007 = true;
220  fTMB_Format2007 = true;
221  fFormat2013 = false;
222 
223  cntDDU_Headers = 0;
224  cntDDU_Trailers = 0;
225  cntCHAMB_Headers.clear();
226  cntCHAMB_Trailers.clear();
227 
228  DAV_ALCT = false;
229  DAV_TMB = false;
230  DAV_CFEB = 0;
231  DMB_Active = 0;
232  nDMBs = 0;
234  DDU_WordCount = 0;
237  ALCT_ZSE = 0;
238  nWG_round_up = 0;
239 
240  TMB_WordsRPC = 0;
243  zeroCounts();
244 
245  checkCrcALCT = false;
246  ALCT_CRC=0;
247  checkCrcTMB = false;
248  TMB_CRC=0;
249  checkCrcCFEB = false;
250  CFEB_CRC=0;
251 
252  modeDDUonly = false;
253  sourceID = 0xFFF;
254  currentChamber = -1;
255 
256  //headerDAV_Active = -1; // Trailer vs. Header check // Obsolete since 16.09.05
257 
258  clear();
259  buf_1 = &(tmpbuf[0]);
260  buf0 = &(tmpbuf[4]);
261  buf1 = &(tmpbuf[8]);
262  buf2 = &(tmpbuf[12]);
263 
264  bzero(tmpbuf, sizeof(uint16_t)*16);
265 }
266 
267 int32_t CSCDCCExaminer::check(const uint16_t* &buffer, int32_t length)
268 {
269  if( length<=0 ) return -1;
270 
273 
274 
276  bool fTMB_MiniScope_Start = false;
277  bool fTMB_RPC_Start = false;
278  bool fTMB_BlockedCFEBs_Start = false;
279 
280  bool fTMB_MiniScope = false;
281  bool fTMB_RPC = false;
282  bool fTMB_BlockedCFEBs = false;
283 
284  while( length>0 )
285  {
286  // == Store last 4 read buffers in pipeline-like memory (note that memcpy works quite slower!)
287  buf_2 = buf_1; // This bufer was not needed so far
288  buf_1 = buf0;
289  buf0 = buf1;
290  buf1 = buf2;
291  buf2 = buffer;
292 
293  // check for too long event
294  if(!fERROR[19] && DDU_WordsSinceLastHeader>100000 )
295  {
296  fERROR[19] = true;
297  bERROR |= 0x80000;
298  }
299 
300  // increment counter of 64-bit words since last DDU Header
301  // this counter is reset if DDU Header is found
302  if ( fDDU_Header )
303  {
305  }
306 
307  // increment counter of 64-bit words since last DDU Trailer
308  // this counter is reset if DDU Trailer is found
309  if ( fDDU_Trailer )
310  {
312  }
313 
316  if ( fALCT_Header )
317  {
319  if(ALCT_ZSE)
320  {
321  for(int g=0; g<4; g++)
322  {
323  if(buf0[g]==0x1000)
324  {
326  }
328  }
329  }
333  }
334 
335  // increment counter of 16-bit words since last DMB*TMB Header match
336  // this counter is reset if TMB Header is found right after DMB Header or ALCT Trailer
337  if ( fTMB_Header )
338  {
340  }
341 
342  // increment counter of 16-bit words since last of DMB Header, ALCT Trailer, TMB Trailer,
343  // CFEB Sample Trailer, CFEB B-word; this counter is reset by all these conditions
344  if ( fDMB_Header )
345  {
347  }
348 
349  // If DDU header is missing we set unphysical 0xFFF value for DDU id
350  if( !fDDU_Header )
351  {
352  sourceID=0xFFF;
353  }
354 
355 
356  if (!modeDDUonly)
357  {
358  // DCC Header 1 && DCC Header 2
359  // =VB= Added support for Sep. 2008 CMS DAQ DCC format
360  if ( ( ( (buf0[3]&0xF000) == 0x5000 && (buf0[0]&0x00FF) == 0x005F )
361  ||
362  ( (buf0[3]&0xF000) == 0x5000 && (buf0[0]&0x000F) == 0x0008 ) )
363  &&
364  // =VB= Why 0xD900 signature word if only 0xD part is constant???
365  // (buf1[3]&0xFF00) == 0xD900 )
366  (buf1[3]&0xF000) == 0xD000 )
367  {
368  if( fDCC_Header )
369  {
370  // == Another DCC Header before encountering DCC Trailer!
371  fERROR[25]=true;
372  bERROR|=0x2000000;
373  fERROR[0]=true;
374  bERROR|=0x1;
375 #ifdef LOCAL_UNPACK
376  CERR<<"\n\nDCC Header Occurrence ";
377  CERR<<" ERROR 25 "<<sERROR[25]<<endl;
378 #endif
379  fDDU_Header = false;
380 
381  // go backward for 3 DDU words ( buf2, buf1, and buf0 )
382  buffer-=12;
383  buf_1 = &(tmpbuf[0]); // Just for safety
384  buf0 = &(tmpbuf[4]); // Just for safety
385  buf1 = &(tmpbuf[8]); // Just for safety
386  buf2 = &(tmpbuf[12]); // Just for safety
387  bzero(tmpbuf,sizeof(uint16_t)*16);
388  sync_stats();
389  return length+12;
390  }
391 
392  fDCC_Header = true;
393  clear();
394  }
395  }
396  // == Check for Format Control Words, set proper flags, perform self-consistency checks
397 
398  // C-words anywhere besides DDU Header
399  if( fDDU_Header && ( (buf0[0]&0xF000)==0xC000 || (buf0[1]&0xF000)==0xC000 || (buf0[2]&0xF000)==0xC000 || (buf0[3]&0xF000)==0xC000 ) &&
400  ( /*buf_1[0]!=0x8000 ||*/ buf_1[1]!=0x8000 || buf_1[2]!=0x0001 || buf_1[3]!=0x8000 ) )
401  {
402  fERROR[0] = true;
403  bERROR |= 0x1;
404  fERROR[20] = true;
405  bERROR |= 0x100000;
406  // fCHAMB_ERR[20].insert(currentChamber);
407  // bCHAMB_ERR[currentChamber] |= 0x100000;
408 #ifdef LOCAL_UNPACK
409  CERR<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
410  CERR<<" ERROR 20 "<<sERROR[20]<<endl;
411 #endif
412  }
413 
414  // == DDU Header found
415  if( /*buf0[0]==0x8000 &&*/ buf0[1]==0x8000 && buf0[2]==0x0001 && buf0[3]==0x8000 )
416  {
417  // headerDAV_Active = (buf1[1]<<16) | buf1[0]; // Obsolete since 16.09.05
419  checkDAVs();
422 
423  if( fDDU_Header )
424  {
425  // == Another DDU Header before encountering DDU Trailer!
426  fERROR[1]=true;
427  bERROR|=0x2;
428  fERROR[0] = true;
429  bERROR|=0x1;
430 #ifdef LOCAL_UNPACK
431  CERR<<"\n\nDDU Header Occurrence = "<<cntDDU_Headers;
432  CERR<<" ERROR 1 "<<sERROR[1]<<endl;
433 #endif
434  fDDU_Header = false;
435 
436  // Part of work for chambers that hasn't been done in absent trailer
437  if( fDMB_Header || fDMB_Trailer )
438  {
439  fERROR[5] = true;
440  bERROR |= 0x20;
441  // Since here there are no chances to know what this chamber was, force it to be -2
442  if( currentChamber == -1 ) currentChamber = -2;
443  fCHAMB_ERR[5].insert(currentChamber);
444  bCHAMB_ERR[currentChamber] |= 0x20;
445  fCHAMB_ERR[0].insert(currentChamber);
446  bCHAMB_ERR[currentChamber] |= 0x1;
447 #ifdef LOCAL_UNPACK
448  CERR<<"\n\nDDU Header Occurrence = "<<cntDDU_Headers;
449  CERR<<" ERROR 5 "<<sERROR[5]<<endl;
450 #endif
451  } // One of DMB Trailers is missing ( or both )
452  fDMB_Header = false;
453  fDMB_Trailer = false;
454 
455  if( DMB_Active!=nDMBs )
456  {
457  fERROR[24] = true;
458  bERROR |= 0x1000000;
459  }
460  DMB_Active = 0;
461  nDMBs = 0;
462 
463  // Unknown chamber denoted as -2
464  // If it still remains in any of errors - put it in error 0
465  for(int err=1; err<nERRORS; ++err)
466  if( fCHAMB_ERR[err].find(-2) != fCHAMB_ERR[err].end() )
467  {
468  fCHAMB_ERR[0].insert(-2);
469  bCHAMB_ERR[-2] |= 0x1;
470  }
471 
474 
475  // go backward for 3 DDU words ( buf2, buf1, and buf0 )
476  buffer-=12;
477  buf_1 = &(tmpbuf[0]); // Just for safety
478  buf0 = &(tmpbuf[4]); // Just for safety
479  buf1 = &(tmpbuf[8]); // Just for safety
480  buf2 = &(tmpbuf[12]); // Just for safety
481  bzero(tmpbuf,sizeof(uint16_t)*16);
482  sync_stats();
483  return length+12;
484  }
485 
486 
487  currentChamber = -1; // Unknown yet
488 
490  {
491  // == Counted extraneous words between last DDU Trailer and this DDU Header
492  fWARNING[0]=true;
493  bWARNING|=0x1;
494 #ifdef LOCAL_UNPACK
495  CERR<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
496  CERR<<" WARNING 0 "<<sWARNING[0]<<" "<<DDU_WordsSinceLastTrailer<<" extra 64-bit words"<<endl;
497 #endif
498  }
499 
500  sourceID = ((buf_1[1]&0xF)<<8) | ((buf_1[0]&0xFF00)>>8);
501 
503  DDU_Firmware_Revision = (buf_1[0] >> 4) & 0xF;
504  if (DDU_Firmware_Revision > 6)
505  {
506  fFormat2013 = true;
507  modeDDUonly = true; // =VB= Force to use DDU only mode (no DCC Data)
508  }
509 
510  fDDU_Header = true;
511  fDDU_Trailer = false;
512  DDU_WordCount = 0;
513  fDMB_Header = false;
514  fDMB_Trailer = false;
515  fALCT_Header = false;
516  fALCT_Format2007= true;
517  fTMB_Header = false;
518  fTMB_Format2007= true;
519  uniqueALCT = true;
520  uniqueTMB = true;
521  zeroCounts();
522 
523  if (modeDDUonly)
524  {
525  fDCC_Header = true;
526  clear();
527  }
528 
531  dduSize [sourceID] = 0;
532  dmbBuffers[sourceID].clear();
533  dmbOffsets[sourceID].clear();
534  dmbSize [sourceID].clear();
535 
536  // Reset all Error and Warning flags to be false
537  bDDU_ERR[sourceID] = 0;
538  bDDU_WRN[sourceID] = 0;
539  bERROR = 0;
540  bWARNING = 0;
541  bzero(fERROR, sizeof(bool)*nERRORS);
542  bzero(fWARNING, sizeof(bool)*nWARNINGS);
543 
544  nDMBs = 0;
545  DMB_Active = buf1[0]&0xF;
546  DAV_DMB = buf1[1]&0x7FFF;
547 
548  int nDAV_DMBs=0;
549  for(int bit=0; bit<15; bit++) if( DAV_DMB&(1<<bit) ) nDAV_DMBs++;
550  if(DMB_Active!=nDAV_DMBs)
551  {
552  fERROR[27] = true;
553  bERROR |= 0x8000000;
554  }
555 
556  if( (buf_1[3]&0xF000)!=0x5000 )
557  {
558  fWARNING[1]=true;
559  bWARNING|=0x2;
560 #ifdef LOCAL_UNPACK
561  CERR<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
562  CERR<<" WARNING 1 "<<sWARNING[1]<<". What must have been Header 1: 0x"<<std::hex<<buf_1[0]<<" 0x"<<buf_1[1]<<" 0x"<<buf_1[2]<<" 0x"<<buf_1[3]<<std::dec<<endl;
563 #endif
564  }
565 
566  ++cntDDU_Headers;
567  DDU_WordsSinceLastHeader=0; // Reset counter of DDU Words since last DDU Header
568 #ifdef LOCAL_UNPACK
569  COUT<<"\n----------------------------------------------------------"<<endl;
570  COUT<<"DDU Header Occurrence "<<cntDDU_Headers<< " L1A = " << ( ((buf_1[2]&0xFFFF) + ((buf_1[3]&0x00FF) << 16)) ) <<endl;
571 #endif
572 
573  }
574 
575  // == DMB Header found
576  if( (buf0[0]&0xF000)==0xA000 && (buf0[1]&0xF000)==0xA000 && (buf0[2]&0xF000)==0xA000 && (buf0[3]&0xF000)==0xA000 )
577  {
579  checkDAVs();
582 
584  {
585  fERROR[28]=true;
586  bERROR|=0x10000000;;
587  }
588 
589  if( fDMB_Header || fDMB_Trailer ) // F or E DMB Trailer is missed
590  {
591  fERROR[5]=true;
592  bERROR|=0x20;
593  fCHAMB_ERR[5].insert(currentChamber);
594  bCHAMB_ERR[currentChamber] |= 0x20;
595  fCHAMB_ERR[0].insert(currentChamber);
596  bCHAMB_ERR[currentChamber] |= 0x1;
597  }
598  fDMB_Header = true;
599  fDMB_Trailer = false;
600 
601  // If previous DMB record was not assigned to any chamber ( it still has -1 indentificator )
602  // let's free -1 identificator for current use and call undefined chamber from previous record -2
603  // ( -2 may already exists in this sets but we have nothing to do with it )
604  for(int err=0; err<nERRORS; ++err)
605  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
606  {
607  fCHAMB_ERR[err].erase(-1);
608  fCHAMB_ERR[err].insert(-2);
609  }
610 // Two lines below are commented out because payloads never get filled if 0xA header is missing
611 // bCHAMB_PAYLOAD[-2] |= bCHAMB_PAYLOAD[-1];
612 // fCHAMB_PAYLOAD[-1] = 0;
613  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
614  bCHAMB_STATUS[-1] = 0;
615  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
616  bCHAMB_ERR[-1] = 0;
617  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
618  bCHAMB_WRN[-1] = 0;
619 
620  // Chamber id ( DMB_ID + (DMB_CRATE<<4) ) from header
621  currentChamber = buf0[1]&0x0FFF;
623  bCHAMB_ERR[currentChamber] |= 0; //Victor's line
624 
625  fALCT_Header = false;
626  fALCT_Format2007= true;
627  fTMB_Header = false;
628  fTMB_Format2007= true;
629  uniqueALCT = true;
630  uniqueTMB = true;
631 
632  fTMB_MiniScope_Start = false;
633  fTMB_RPC_Start = false;
634  fTMB_BlockedCFEBs_Start = false;
635 
636  fTMB_MiniScope = false;
637  fTMB_RPC = false;
638  fTMB_BlockedCFEBs = false;
639 
640 
641  zeroCounts();
642  CFEB_CRC = 0;
643 
644  nDMBs++;
645 
649 
650 #ifdef LOCAL_UNPACK
651  // Print DMB_ID from DMB Header
652  COUT<< "Crate=" << setw(3) << setfill('0') << ((buf0[1]>>4)&0x00FF) << " DMB="<<setw(2)<<setfill('0')<<(buf0[1]&0x000F)<<" ";
653  // Print ALCT_DAV and TMB_DAV from DMB Header
654  //COUT<<setw(1)<<((buf0[0]&0x0020)>>5)<<" "<<((buf0[0]&0x0040)>>6)<<" ";
655  COUT<<setw(1)<<((buf0[0]&0x0200)>>9)<<" "<<((buf0[0]&0x0800)>>11)<<" "; //change of format 16.09.05
656  // Print CFEB_DAV from DMB Header
657  COUT<<setw(1)<<((buf0[0]&0x0010)>>4)<<((buf0[0]&0x0008)>>3)<<((buf0[0]&0x0004)>>2)<<((buf0[0]&0x0002)>>1)<<(buf0[0]&0x0001);
658  // Print DMB Header Tag
659  COUT << " {";
660 #endif
661 
662  if (fFormat2013)
663  {
664 
665  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
666  DAV_ALCT = (buf0[0]&0x0800)>>11;
667  DAV_TMB = (buf0[0]&0x0400)>>10;
668  DAV_CFEB = 0;
669  if( buf0[0]&0x0001 ) ++DAV_CFEB;
670  if( buf0[0]&0x0002 ) ++DAV_CFEB;
671  if( buf0[0]&0x0004 ) ++DAV_CFEB;
672  if( buf0[0]&0x0008 ) ++DAV_CFEB;
673  if( buf0[0]&0x0010 ) ++DAV_CFEB;
674  if( buf0[0]&0x0020 ) ++DAV_CFEB;
675  if( buf0[0]&0x0040 ) ++DAV_CFEB;
676  if( DAV_ALCT ) bCHAMB_PAYLOAD[currentChamber] |= 0x20;
677  if( DAV_TMB ) bCHAMB_PAYLOAD[currentChamber] |= 0x40;
678 
680  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0]&0x007f)<<7;
681  bCHAMB_PAYLOAD[currentChamber] |= (buf_1[2]&0x001f);
682  bCHAMB_PAYLOAD[currentChamber] |= ((buf_1[2]>>5)&0x0003)<<14;
683  bCHAMB_STATUS [currentChamber] |= (buf0[0]&0x0080)<<15;
684 
685  }
686  else
687  {
688 
689  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
690  DAV_ALCT = (buf0[0]&0x0200)>>9;
691  DAV_TMB = (buf0[0]&0x0800)>>11;
692  DAV_CFEB = 0;
693  if( buf0[0]&0x0001 ) ++DAV_CFEB;
694  if( buf0[0]&0x0002 ) ++DAV_CFEB;
695  if( buf0[0]&0x0004 ) ++DAV_CFEB;
696  if( buf0[0]&0x0008 ) ++DAV_CFEB;
697  if( buf0[0]&0x0010 ) ++DAV_CFEB;
698  if( DAV_ALCT ) bCHAMB_PAYLOAD[currentChamber] |= 0x20;
699  if( DAV_TMB ) bCHAMB_PAYLOAD[currentChamber] |= 0x40;
700  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0]&0x001f)<<7;
701  bCHAMB_PAYLOAD[currentChamber] |=((buf_1[2]>>5)&0x001f);
702  bCHAMB_STATUS [currentChamber] |= (buf0[0]&0x0040)<<15;
703  }
704 
705  }
706 
707 
708  // New ALCT data format:
709  if( ( buf0[0]==0xDB0A && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xF000)==0xD000 && (buf0[3]&0xF000)==0xD000)
710  &&
711  ( (buf_1[0]&0xF000)==0xA000 && (buf_1[1]&0xF000)==0xA000 && (buf_1[2]&0xF000)==0xA000 && (buf_1[3]&0xF000)==0xA000 ) )
712  {
713  fALCT_Header = true;
714  fALCT_Format2007 = true;
715  ALCT_CRC = 0;
718 
719  // Calculate expected number of ALCT words
720  ALCT_WordsExpected = 12; // header and trailer always exists
721 
722  // Aauxilary variables
723  // number of wire groups per layer:
724  int nWGs_per_layer = ( (buf1[2]&0x0007) + 1 ) * 16 ;
725  // words in the layer
726  nWG_round_up = int(nWGs_per_layer/12)+(nWGs_per_layer%3?1:0);
727  // configuration present:
728  bool config_present = buf1[0]&0x4000;
729  // lct overflow:
730  bool lct_overflow = buf1[0]&0x2000;
731  // raw overflow:
732  bool raw_overflow = buf1[0]&0x1000;
733  // l1a_window:
734  int lct_tbins = (buf1[3]&0x01E0)>>5;
735  // fifo_tbins:
736  int raw_tbins = (buf1[3]&0x001F);
737 
739  ALCT_ZSE = (buf1[1]&0x1000)>>12;
740 
741  if (ALCT_ZSE)
742  {
743  for (int g=0; g<4; g++)
744  {
745  if (buf1[g]==0x1000) ALCT_WordsSinceLastHeader -= (nWG_round_up - 1);
746  }
747  }
748 #ifdef LOCAL_UNPACK
749 // COUT << " Number of Wire Groups: " << nWG_round_up << std::endl;
751 // COUT << " raw_tbins: " << std::dec << raw_tbins << std::endl;
752 // COUT << " LCT Tbins: " << lct_tbins << std::endl;
753 #endif
754 
755  // Data block sizes:
756  // 3 words of Vertex ID register + 5 words of config. register bits:
757  int config_size = ( config_present ? 3 + 5 : 0 );
758  // collision mask register:
759  int colreg_size = ( config_present ? nWGs_per_layer/4 : 0 );
760  // hot channel mask:
761  int hot_ch_size = ( config_present ? nWG_round_up*6 : 0 );
762  // ALCT0,1 (best tracks):
763  int alct_0_1_size = ( !lct_overflow ? 2*lct_tbins : 0 );
764  // raw hit dump size:
765  int raw_hit_dump_size=(!raw_overflow ? nWG_round_up*6*raw_tbins : 0 );
766 
767 #ifdef LOCAL_UNPACK
768  // COUT << " Raw Hit Dump: " << std::dec << raw_hit_dump_size << std::endl;
769 #endif
770 
771  ALCT_WordsExpected += config_size + colreg_size + hot_ch_size + alct_0_1_size + raw_hit_dump_size;
772 
773 #ifdef LOCAL_UNPACK
774  COUT<<" <A";
775 #endif
776 
777  }
778  else
779  {
780  // Old ALCT data format
781 
782  // == ALCT Header found right after DMB Header
783  // (check for all currently reserved/fixed bits in ALCT first 4 words)
784  // if( ( (buf0 [0]&0xF800)==0x6000 && (buf0 [1]&0xFF80)==0x0080 && (buf0 [2]&0xF000)==0x0000 && (buf0 [3]&0xc000)==0x0000 )
785  if( ( (buf0 [0]&0xF800)==0x6000 && (buf0 [1]&0x8F80)==0x0080 && (buf0 [2]&0x8000)==0x0000 && (buf0 [3]&0xc000)==0x0000 )
786  &&
787  ( (buf_1[0]&0xF000)==0xA000 && (buf_1[1]&0xF000)==0xA000 && (buf_1[2]&0xF000)==0xA000 && (buf_1[3]&0xF000)==0xA000 ) )
788  {
789  fALCT_Header = true;
790  fALCT_Format2007 = false;
791  ALCT_CRC = 0;
793 
794  // Calculate expected number of ALCT words
795  if( (buf0[3]&0x0003)==0 )
796  {
797  ALCT_WordsExpected = 12; // Short Readout
798  }
799 
800  if( (buf0[1]&0x0003)==1 ) // Full Readout
801  {
802  ALCT_WordsExpected = ((buf0[1]&0x007c) >> 2) *
803  ( ((buf0[3]&0x0001) )+((buf0[3]&0x0002)>>1)+
804  ((buf0[3]&0x0004)>>2)+((buf0[3]&0x0008)>>3)+
805  ((buf0[3]&0x0010)>>4)+((buf0[3]&0x0020)>>5)+
806  ((buf0[3]&0x0040)>>6) ) * 12 + 12;
807  }
808 #ifdef LOCAL_UNPACK
809  COUT<<" <A";
810 #endif
811  }
812  }
813 #ifdef LOCAL_UNPACK
814  //COUT << " ALCT Word Expected: " << ALCT_WordsExpected << std::endl;
815 #endif
816 
817  if( (buf0[0]&0xFFFF)==0xDB0C )
818  {
819 
820  // =VB= Handles one of the OTMB corrupted data cases.
821  // Double TMB data block with 2nd TMB Header is found.
822  // Set missing TMB Trailer error.
823  if (fTMB_Header) {
824  fERROR[12]=true; // TMB Trailer is missing
825  bERROR |= 0x1000;
826  fCHAMB_ERR[12].insert(currentChamber);
827  bCHAMB_ERR[currentChamber] |= 0x1000;
828  }
829 
830  fTMB_Header = true;
831  fTMB_Format2007 = true;
832  TMB_CRC = 0;
834  TMB_WordsExpected = 0;
835 
836  // Calculate expected number of TMB words (whether RPC included will be known later)
837  if ( (buf1[1]&0x3000) == 0x3000)
838  {
839  TMB_WordsExpected = 12; // Short Header Only
840  }
841  if ( (buf1[1]&0x3000) == 0x0000)
842  {
843  TMB_WordsExpected = 48; // Long Header Only
844  }
845 
846 #ifdef LOCAL_UNPACK
847  COUT << " <T";
848 #endif
849  }
850  else
851  {
852  // == TMB Header found right after DMB Header or right after ALCT Trailer
853  if( (buf0 [0]&0xFFFF)==0x6B0C && (
854  ( (buf_1[0]&0xF000)==0xA000 && (buf_1[1]&0xF000)==0xA000 && (buf_1[2]&0xF000)==0xA000 && (buf_1[3]&0xF000)==0xA000 )
855  ||
856  ( (buf_1[0]&0x0800)==0x0000 && (buf_1[1]&0xF800)==0xD000 && (buf_1[2]&0xFFFF)==0xDE0D && (buf_1[3]&0xF000)==0xD000 )
857  // should've been (buf_1[0]&0xF800)==0xD000 - see comments for sERROR[11]
858  ) )
859  {
860  //if( (buf_1[2]&0xFFFF)==0xDE0D && (buf_1[3]&0xFC00)!=0xD000 && summer2004 ) ???
861 
862  fTMB_Header = true;
863  fTMB_Format2007 = false;
864  TMB_CRC = 0;
866 
867  // Calculate expected number of TMB words (whether RPC included will be known later)
868  if ( (buf0[1]&0x3000) == 0x3000)
869  {
870  TMB_WordsExpected = 8; // Short Header Only
871  }
872  if ( (buf0[1]&0x3000) == 0x0000)
873  {
874  TMB_WordsExpected = 32; // Long Header Only
875  }
876 
877  if ( (buf0[1]&0x3000) == 0x1000)
878  {
879  // Full Readout = 28 + (#Tbins * #CFEBs * 6)
880  TMB_Tbins=(buf0[1]&0x001F);
881  TMB_WordsExpected = 28 + TMB_Tbins * ((buf1[0]&0x00E0)>>5) * 6;
882  }
883 #ifdef LOCAL_UNPACK
884  COUT << " <T";
885 #endif
886  }
887  }
888  // New TMB format => very long header Find Firmware revision
890  {
892  }
893 
894  // New TMB format => very long header
896  {
897  // Full Readout = 44 + (#Tbins * #CFEBs * 6)
898  TMB_Tbins=(buf0[3]&0x00F8)>>3;
899  TMB_WordsExpected = 44 + TMB_Tbins * (buf0[3]&0x0007) * 6;
900  }
901 
902  // == ALCT Trailer found
903  if(
904  // New ALCT data format:
905  ( buf0[0]==0xDE0D && (buf0[1]&0xF800)==0xD000 && (buf0[2]&0xF800)==0xD000 && (buf0[3]&0xF000)==0xD000 && fALCT_Format2007 ) ||
906  // Old ALCT data format; last check is added to avoid confusion with new TMB header (may not be needed):
907  ( (buf0[0]&0x0800)==0x0000 && (buf0[1]&0xF800)==0xD000 && (buf0[2]&0xFFFF)==0xDE0D && (buf0[3]&0xF000)==0xD000 && !fALCT_Format2007 && !(fTMB_Header&&fTMB_Format2007) )
908  )
909  {
910  // should've been (buf0[0]&0xF800)==0xD000 - see comments for sERROR[11]
911 
912  // Second ALCT -> Lost both previous DMB Trailer and current DMB Header
913  if( !uniqueALCT ) currentChamber = -1;
914  // Check if this ALCT record have to exist according to DMB Header
915  if( DAV_ALCT ) DAV_ALCT = false;
916  else DAV_ALCT = true;
917 
918  if( !fALCT_Header )
919  {
920  fERROR[8] = true;
921  bERROR |= 0x100;
922  fCHAMB_ERR[8].insert(currentChamber);
923  bCHAMB_ERR[currentChamber] |= 0x100;
924  fCHAMB_ERR[0].insert(currentChamber);
925  bCHAMB_ERR[currentChamber] |= 0x1;
926  } // ALCT Header is missing
927 
928  if( !fALCT_Format2007 && (buf0[0]&0xF800)!=0xD000 )
929  {
930  fERROR[11] = true;
931  bERROR |= 0x800;
932  fCHAMB_ERR[11].insert(currentChamber);
933  bCHAMB_ERR[currentChamber] |= 0x800;
934  fCHAMB_ERR[0].insert(currentChamber);
935  bCHAMB_ERR[currentChamber] |= 0x1;
936  } // some bits in 1st D-Trailer are lost
937 
938 #ifdef LOCAL_UNPACK
939  /*
941  COUT << " ALCT Word Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
942  COUT << " ALCT Word Expected: " << ALCT_WordsExpected << std::endl;
943  COUT << " ALCT Word Since Last Header Zero Supressed: " << ALCT_WordsSinceLastHeaderZeroSuppressed << std::endl;
944  */
945 #endif
946  if( checkCrcALCT )
948  {
949  uint32_t crc = ( fALCT_Format2007 ? buf0[1] : buf0[0] ) & 0x7ff;
950  crc |= ((uint32_t)( ( fALCT_Format2007 ? buf0[2] : buf0[1] ) & 0x7ff)) << 11;
951  if( ALCT_CRC != crc )
952  {
953  fERROR[10] = true;
954  bERROR |= 0x400;
955  fCHAMB_ERR[10].insert(currentChamber);
956  bCHAMB_ERR[currentChamber] |= 0x400;
957  fCHAMB_ERR[0].insert(currentChamber);
958  bCHAMB_ERR[currentChamber] |= 0x1;
959  }
960  }
961 
962  fALCT_Header = false;
963  uniqueALCT = false;
964  CFEB_CRC = 0;
965  //ALCT_WordCount = (buf0[3]&0x03FF);
966  ALCT_WordCount = (buf0[3]&0x07FF);
967  //ALCT_WordCount = (buf0[3]&0x0FFF);
969 #ifdef LOCAL_UNPACK
970  COUT << "A> ";
971 #endif
972  }
973 
974  // Calculation of CRC sum ( algorithm is written by Madorsky )
975  if( fALCT_Header && checkCrcALCT )
976  {
977  for(uint16_t j=0, w=0; j<4; ++j)
978  {
980  w = buf0[j] & (fALCT_Format2007 ? 0xffff : 0x7fff);
981  for(uint32_t i=15, t=0, ncrc=0; i<16; i--)
982  {
983  t = ((w >> i) & 1) ^ ((ALCT_CRC >> 21) & 1);
984  ncrc = (ALCT_CRC << 1) & 0x3ffffc;
985  ncrc |= (t ^ (ALCT_CRC & 1)) << 1;
986  ncrc |= t;
987  ALCT_CRC = ncrc;
988  }
989  }
990  }
991 
992  // == Find Correction for TMB_WordsExpected due to RPC raw hits,
993  // should it turn out to be the new RPC-aware format
994  if( fTMB_Header && ((buf0[2]&0xFFFF)==0x6E0B) )
995  {
996  if (fTMB_Format2007)
997  {
998  /* Checks for TMB2007 firmware revisions ranges to detect data format
999  * rev.0x50c3 - first revision with changed format
1000  * rev.0x42D5 - oldest known from 06/21/2007
1001  * There is 4-bits year value rollover in revision number (0 in 2016)
1002  */
1003  if ((TMB_Firmware_Revision >= 0x50c3) || (TMB_Firmware_Revision < 0x42D5))
1004  {
1005  // On/off * nRPCs * nTimebins * 2 words/RPC/bin
1006  TMB_WordsRPC = ((buf_1[0]&0x0010)>>4) * ((buf_1[0]&0x000c)>>2) * ((buf_1[0]>>5) & 0x1F) * 2;
1007  }
1008  else // original TMB2007 data format (may not work since TMB_Tbins != RPC_Tbins)
1009  {
1010  TMB_WordsRPC = ((buf_1[0]&0x0040)>>6) * ((buf_1[0]&0x0030)>>4) * TMB_Tbins * 2;
1011  }
1012  }
1013  else // Old format 2006
1014  {
1015  TMB_WordsRPC = ((buf_1[2]&0x0040)>>6) * ((buf_1[2]&0x0030)>>4) * TMB_Tbins * 2;
1016  }
1017  TMB_WordsRPC += 2; // add header/trailer for block of RPC raw hits
1018  }
1019 
1020 
1021 
1022  // Check for RPC data
1023  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B04)>=0) )
1024  {
1025  fTMB_RPC_Start = true;
1026  }
1027 
1028  // Check for Mini-Scope data
1029  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B07)>=0) )
1030  {
1031  fTMB_MiniScope_Start = true;
1032  }
1033 
1034  // Check for Blocked CFEBs data
1035  if ( fTMB_Header && (scanbuf(buf0,4, 0x6BCB)>=0) )
1036  {
1037  fTMB_BlockedCFEBs_Start = true;
1038  }
1039 
1040 
1041  // Check for end of RPC data
1042  if ( fTMB_Header && fTMB_RPC_Start
1043  && (scanbuf(buf0,4, 0x6E04)>=0) )
1044  {
1045  fTMB_RPC = true;
1046  }
1047 
1048  // Check for end of Mini-Scope data
1049  if ( fTMB_Header && fTMB_MiniScope_Start
1050  && (scanbuf(buf0,4, 0x6E07)>=0) )
1051  {
1052  fTMB_MiniScope = true;
1053  }
1054 
1055  // Check for end of Blocked CFEBs data
1056  if ( fTMB_Header && fTMB_BlockedCFEBs_Start
1057  && (scanbuf(buf0,4, 0x6ECB)>=0) )
1058  {
1059  fTMB_BlockedCFEBs = true;
1060  }
1061 
1062  /*
1063  if ( fTMB_Header && (scanbuf(buf0,4, 0x6E04)>=0) ) {
1064  TMB_WordsExpected += TMB_WordsRPC;
1065  }
1066  */
1067 
1068  // == TMB Trailer found
1069  if(
1070  // Old TMB data format; last condition in needed not to confuse if with new ALCT data header
1071  ((buf0[0]&0xF000)==0xD000 && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xFFFF)==0xDE0F && (buf0[3]&0xF000)==0xD000 && !fTMB_Format2007 && !(fALCT_Header&&fALCT_Format2007)) ||
1072  // New TMB data format
1073  ( buf0[0]== 0xDE0F && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xF000)==0xD000 && (buf0[3]&0xF000)==0xD000 && fTMB_Format2007 )
1074  )
1075  {
1076 
1077  // Second TMB -> Lost both previous DMB Trailer and current DMB Header
1078  if( !uniqueTMB ) currentChamber = -1;
1079  // Check if this TMB record have to exist according to DMB Header
1080  if( DAV_TMB ) DAV_TMB = false;
1081  else DAV_TMB = true;
1082 
1083  if(!fTMB_Header)
1084  {
1085  fERROR[13] = true;
1086  bERROR |= 0x2000;
1087  fCHAMB_ERR[13].insert(currentChamber);
1088  bCHAMB_ERR[currentChamber] |= 0x2000;
1089  fCHAMB_ERR[0].insert(currentChamber);
1090  bCHAMB_ERR[currentChamber] |= 0x1;
1091  } // TMB Header is missing
1092 
1093  // Check calculated CRC sum against reported
1094  if( checkCrcTMB )
1095  {
1096  uint32_t crc = ( fTMB_Format2007 ? buf0[1]&0x7ff : buf0[0]&0x7ff );
1097  crc |= ((uint32_t)( ( fTMB_Format2007 ? buf0[2]&0x7ff : buf0[1] & 0x7ff ) )) << 11;
1098  if( TMB_CRC != crc )
1099  {
1100  fERROR[15] = true;
1101  bERROR |= 0x8000;
1102  fCHAMB_ERR[15].insert(currentChamber);
1103  bCHAMB_ERR[currentChamber] |= 0x8000;
1104  fCHAMB_ERR[0].insert(currentChamber);
1105  bCHAMB_ERR[currentChamber] |= 0x1;
1106  }
1107  }
1108 
1109  fTMB_Header = false;
1110  uniqueTMB = false;
1111  CFEB_CRC = 0;
1112  TMB_WordCount = (buf0[3]&0x07FF);
1113 
1114  // == Correct TMB_WordsExpected
1115  // 1) for 2 optional 0x2AAA and 0x5555 Words in the Trailer
1116  // 2) for extra 4 frames in the new TMB trailer and
1117  // for RPC raw hit data, if present
1118  //
1119  // If the scope data was enabled in readout, scope data markers (0x6B05
1120  // and 0x6E05) appear before 0x6E0C, and the optional 0x2AAA and 0x5555
1121  // trailer words are suppressed. So far, we only have data with the
1122  // empty scope content, so more corrections will be needed once
1123  // non-empty scope data is available. -SV, 5 Nov 2008.
1124  //
1125  // If word count is not multiple of 4, add 2 optional words and
1126  // 4 trailer words.
1127 
1128  int pos = scanbuf(buf_1,4,0x6E0C);
1129  if (pos==1)
1130  {
1131  TMB_WordsExpected += 6;
1132  }
1133  // If word count is multiple of 4, add 4 trailer words.
1134  else if (pos==3)
1135  {
1136  TMB_WordsExpected += 4;
1137  }
1138 
1139  // Correct expected wordcount by RPC data size
1140  if (fTMB_RPC)
1142 
1143  // Correct expected wordcount by MiniScope data size (22 words + 2 signature words)
1144  if (fTMB_MiniScope)
1145  TMB_WordsExpected += 24;
1146 
1147  // Correct expected wordcount by BlockedCFEBs data size (20 words + 2 signature words)
1148  if (fTMB_BlockedCFEBs)
1149  TMB_WordsExpected += 22;
1150 
1152 #ifdef LOCAL_UNPACK
1153  COUT << "T> ";
1154 #endif
1155  }
1156 
1157  if( fTMB_Header && checkCrcTMB )
1158  {
1159  for(uint16_t j=0, w=0; j<4; ++j)
1160  {
1162  w = buf0[j] & (fTMB_Format2007 ? 0xffff : 0x7fff);
1163  for(uint32_t i=15, t=0, ncrc=0; i<16; i--)
1164  {
1165  t = ((w >> i) & 1) ^ ((TMB_CRC >> 21) & 1);
1166  ncrc = (TMB_CRC << 1) & 0x3ffffc;
1167  ncrc |= (t ^ (TMB_CRC & 1)) << 1;
1168  ncrc |= t;
1169  TMB_CRC = ncrc;
1170  }
1171  }
1172  }
1173 
1174 
1175  // == CFEB Sample Trailer found
1176 
1177  if( ((buf0[1]&0xF000)==0x7000) &&
1178  ((buf0[2]&0xF000)==0x7000) &&
1179  ((buf0[1]!=0x7FFF) || (buf0[2]!=0x7FFF)) &&
1180  ( ((buf0[3]&0xFFFF)==0x7FFF) || // old format
1181  ( (buf0[3]&buf0[0])==0x0000 && (buf0[3]+buf0[0])==0x7FFF ) // 2007 format
1182  ) )
1183  {
1184 #ifdef LOCAL_UNPACK
1185  if((CFEB_SampleCount%8) == 0 )
1186  {
1187  COUT<<" <";
1188  }
1189  if( CFEB_SampleWordCount == 100 )
1190  {
1191  COUT<<"+";
1192  }
1193 #endif
1194  if( CFEB_SampleWordCount != 100 )
1195  {
1196 #ifdef LOCAL_UNPACK
1197  COUT<<"-";
1198 #endif
1199 
1200  fERROR[16] = true;
1201  bERROR |= 0x10000;
1202  fCHAMB_ERR[16].insert(currentChamber);
1203  bCHAMB_ERR[currentChamber] |= 0x10000;
1204  fCHAMB_ERR[0].insert(currentChamber);
1205  bCHAMB_ERR[currentChamber] |= 0x1;
1206  }
1207 
1208  ++CFEB_SampleCount;
1209 
1210  if( (CFEB_SampleCount%8)==0 )
1211  {
1212 #ifdef LOCAL_UNPACK
1213  COUT<<">";
1214 #endif
1216  // Count CFEBs
1217  DAV_CFEB--;
1218  }
1219 
1220  // Check calculated CRC sum against reported
1221  if( checkCrcCFEB && CFEB_CRC!=buf0[0] )
1222  {
1223  fERROR[18] = true;
1224  bERROR |= 0x40000;
1225  fCHAMB_ERR[18].insert(currentChamber);
1226  bCHAMB_ERR[currentChamber] |= 0x40000;
1227  fCHAMB_ERR[0].insert(currentChamber);
1228  bCHAMB_ERR[currentChamber] |= 0x1;
1229  }
1230 
1231  CFEB_CRC = 0;
1233  }
1234 
1235 
1236  // == CFEB B-word found
1237  if( (buf0[0]&0xF000)==0xB000 && (buf0[1]&0xF000)==0xB000 && (buf0[2]&0xF000)==0xB000 && (buf0[3]&0xF000)==0xB000 )
1238  {
1239  bCHAMB_STATUS[currentChamber] |= 0x400000;
1240 
1241 #ifdef LOCAL_UNPACK
1242  if( (CFEB_SampleCount%8)==0 )
1243  {
1244  COUT<<" <";
1245  }
1246  COUT<<"B";
1247 #endif
1248 
1249  ++CFEB_SampleCount;
1251 
1252  if( (CFEB_SampleCount%8)==0 )
1253  {
1254 #ifdef LOCAL_UNPACK
1255  COUT << ">";
1256 #endif
1258  DAV_CFEB--;
1259  }
1260 
1262  }
1263 
1264  // == If it is neither ALCT record nor TMB - probably it is CFEB record and we try to count CRC sum.
1265  // It very few words of CFEB occasionaly will be misinterpreted as ALCT or TMB header the result
1266  // for the CRC sum will be wrong, but other errors of Trailers counting will appear as well
1268  for(int pos=0; pos<4; ++pos)
1269  CFEB_CRC=(buf0[pos]&0x1fff)^((buf0[pos]&0x1fff)<<1)^(((CFEB_CRC&0x7ffc)>>2)|((0x0003&CFEB_CRC)<<13))^((CFEB_CRC&0x7ffc)>>1);
1270 
1271 
1272  // == DMB F-Trailer found
1273  if( (buf0[0]&0xF000)==0xF000 && (buf0[1]&0xF000)==0xF000 && (buf0[2]&0xF000)==0xF000 && (buf0[3]&0xF000)==0xF000 )
1274  {
1275  if(!fDMB_Header)
1276  {
1277  currentChamber = buf0[3]&0x0FFF;
1278  fERROR[6] = true;
1279  bERROR |= 0x40;
1280  fCHAMB_ERR[6].insert(currentChamber);
1281  bCHAMB_ERR[currentChamber] |= 0x40;
1282  nDMBs++;
1283  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
1284  if( buf0[0]&0x0400 ) bCHAMB_PAYLOAD[currentChamber] |= 0x20;
1285  if( buf0[0]&0x0800 ) bCHAMB_PAYLOAD[currentChamber] |= 0x40;
1286  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0]&0x001f)<<7;
1287  bCHAMB_PAYLOAD[currentChamber] |=((buf0[0]>>5)&0x1f);
1288 
1289  } // DMB Header is missing
1290  fDMB_Header = false;
1291  fDMB_Trailer = true;
1292  uniqueALCT = true;
1293  uniqueTMB = true;
1294 
1296 
1297  // Finally check if DAVs were correct
1298  checkDAVs();
1299 
1300  // If F-Trailer is lost then do necessary work here
1301  if( (buf1[0]&0xF000)!=0xE000 || (buf1[1]&0xF000)!=0xE000 || (buf1[2]&0xF000)!=0xE000 || (buf1[3]&0xF000)!=0xE000 )
1302  {
1303  for(int err=1; err<nERRORS; ++err)
1304  if( fCHAMB_ERR[err].find(currentChamber) != fCHAMB_ERR[err].end() )
1305  {
1306  fCHAMB_ERR[0].insert(currentChamber);
1307  bCHAMB_ERR[currentChamber] |= 0x1;
1308  }
1309  // Reset chamber id
1310  currentChamber=-1;
1311  /*
1312  for(int err=0; err<nERRORS; err++)
1313  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1314  fCHAMB_ERR[err].erase(-1);
1315  bCHAMB_ERR[-1] = 0;
1316  bCHAMB_WRN[-1] = 0;
1317  */
1318  }
1319 #ifdef LOCAL_UNPACK
1320  // Print DMB F-Trailer marker
1321  COUT << " }";
1322 #endif
1323  }
1324 
1325  // == DMB E-Trailer found
1326  if( (buf0[0]&0xF000)==0xE000 && (buf0[1]&0xF000)==0xE000 && (buf0[2]&0xF000)==0xE000 && (buf0[3]&0xF000)==0xE000 )
1327  {
1328  if( !fDMB_Header && !fDMB_Trailer ) nDMBs++; // both DMB Header and DMB F-Trailer were missing
1329 
1330  if (fFormat2013)
1331  {
1333  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0800)>>11;
1334  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0400)>>9;
1335  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0080)<<8;
1336 
1337  if( fDMB_Trailer ) // F-Trailer exists
1338  {
1339  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0E00)>>7;
1340  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0003)<<3;
1341  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x000C)<<21;
1342  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0800)>>4;
1343  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0100);
1344  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x01f0)<<5;
1345  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0600)<<16;
1346  bCHAMB_STATUS[currentChamber] |= (buf_1[0]&0x0800)<<3;
1347  bCHAMB_STATUS[currentChamber] |= (buf_1[1]&0x001f)<<16;
1348  bCHAMB_STATUS[currentChamber] |= (buf_1[1]&0x0060)<<21;
1349 
1350  }
1351 
1352  }
1353  else
1354  {
1355  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0800)>>11;
1356  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0400)>>9;
1357  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x03E0)>>3;
1358 
1359  if( fDMB_Trailer ) // F-Trailer exists
1360  {
1361  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0002)<<6;
1362  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0001)<<8;
1363  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x001f)<<9;
1364  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0040)<<8;
1365  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0020)<<10;
1366  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0f80)<<9;
1367  }
1368 
1369  }
1370  fDMB_Header = false;
1371 
1372  // If chamber id is unknown it is time to find it out
1373  if( currentChamber==-1 )
1374  {
1375  currentChamber = buf0[1]&0x0FFF;
1376  for(int err=0; err<nERRORS; ++err)
1377  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1378  {
1379  fCHAMB_ERR[err].insert(currentChamber);
1380  fCHAMB_ERR[err].erase(-1);
1381  }
1383  bCHAMB_STATUS[-1] = 0;
1385  bCHAMB_ERR[-1] = 0;
1387  bCHAMB_WRN[-1] = 0;
1388  }
1389  ++cntCHAMB_Trailers[buf0[1]&0x0FFF];
1390 
1392 
1393  // Lost DMB F-Trailer before
1394  if( !fDMB_Trailer )
1395  {
1396  fERROR[6] = true;
1397  bERROR |= 0x40;
1398  fCHAMB_ERR[6].insert(currentChamber);
1399  bCHAMB_ERR[currentChamber] |= 0x40;
1400  fCHAMB_ERR[0].insert(currentChamber);
1401  bCHAMB_ERR[currentChamber] |= 0x1;
1402  // Check if DAVs were correct here
1403  checkDAVs();
1404  }
1405  fDMB_Trailer = false;
1406 
1407 #ifdef LOCAL_UNPACK
1408  // Print DMB E-Trailer marker
1409  COUT<<" DMB="<<(buf0[1]&0x000F);
1410  COUT << "; "
1411  << ALCT_WordsSinceLastHeader << "-"
1412  << ALCT_WordCount << "-"
1414  << " "
1415  << TMB_WordsSinceLastHeader << "-"
1416  << TMB_WordCount << "-"
1418  << endl;
1419 #endif
1420 
1422 
1423  //
1424  for(int err=0; err<nERRORS; ++err)
1425  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1426  {
1427  fCHAMB_ERR[err].erase(-1);
1428  fCHAMB_ERR[err].insert(-2);
1429  }
1430  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1431  bCHAMB_STATUS[-1] = 0;
1432  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1433  bCHAMB_ERR[-1] = 0;
1434  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1435  bCHAMB_WRN[-1] = 0;
1436 
1437  if( currentChamber != -1 )
1438  for(int err=1; err<nERRORS; ++err)
1439  if( fCHAMB_ERR[err].find(currentChamber) != fCHAMB_ERR[err].end() )
1440  {
1441  fCHAMB_ERR[0].insert(currentChamber);
1442  bCHAMB_ERR[currentChamber] |= 0x1;
1443  }
1444 
1445  currentChamber=-1;
1446 #ifdef LOCAL_UNPACK
1447  /*
1448  // Print DMB E-Trailer marker
1449  COUT<<" DMB="<<(buf0[1]&0x000F);
1450  COUT << "; "
1451  << ALCT_WordsSinceLastHeader << "-"
1452  << ALCT_WordCount << "-"
1453  << ALCT_WordsExpected
1454  << " "
1455  << TMB_WordsSinceLastHeader << "-"
1456  << TMB_WordCount << "-"
1457  << TMB_WordsExpected
1458  << endl;
1459  */
1460 #endif
1461  }
1462 
1463  // == DDU Trailer found
1464  if( buf0[0]==0x8000 && buf0[1]==0x8000 && buf0[2]==0xFFFF && buf0[3]==0x8000 )
1465  {
1466 
1468  checkDAVs();
1469 
1471 
1473 
1474  if( DDU_WordsSinceLastHeader>3 && !nDMBs )
1475  {
1476  fERROR[28]=true;
1477  bERROR|=0x10000000;;
1478  }
1479 
1480  if(fDDU_Trailer)
1481  {
1482  fERROR[2] = true;
1483  bERROR |= 0x4;
1484  } // DDU Header is missing
1485  fDDU_Trailer=true;
1486  fDDU_Header=false;
1487 
1488  if( fDMB_Header || fDMB_Trailer )
1489  {
1490 #ifdef LOCAL_UNPACK
1491  COUT << " Ex-Err: DMB (Header, Trailer) " << std::endl;
1492 #endif
1493  fERROR[5] = true;
1494  bERROR |= 0x20;
1495  fCHAMB_ERR[5].insert(currentChamber);
1496  bCHAMB_ERR[currentChamber] |= 0x20;
1497  fCHAMB_ERR[0].insert(currentChamber);
1498  bCHAMB_ERR[currentChamber] |= 0x20;
1499  } // DMB Trailer is missing
1500  fDMB_Header = false;
1501  fDMB_Trailer = false;
1502 
1503  currentChamber=-1;
1504 
1505  for(int err=0; err<nERRORS; ++err)
1506  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1507  {
1508  fCHAMB_ERR[err].erase(-1);
1509  fCHAMB_ERR[err].insert(-2);
1510  }
1511  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1512  bCHAMB_STATUS[-1] = 0;
1513  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1514  bCHAMB_ERR[-1] = 0;
1515  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1516  bCHAMB_WRN[-1] = 0;
1517 
1518  for(int err=1; err<nERRORS; ++err)
1519  if( fCHAMB_ERR[err].find(-2) != fCHAMB_ERR[err].end() )
1520  {
1521  fCHAMB_ERR[0].insert(-2);
1522  bCHAMB_ERR[-2] |= 0x1;
1523  }
1524 
1526 
1527  ++cntDDU_Trailers; // Increment DDUTrailer counter
1528 
1529  // == Combining 2 words into 24bit value
1530  DDU_WordCount = buf2[2] | ((buf2[3] & 0xFF) <<16) ;
1531 
1533  {
1534  fERROR[4] = true;
1535  bERROR |= 0x10;
1536  }
1537 
1538  if( DMB_Active!=nDMBs )
1539  {
1540  fERROR[24] = true;
1541  bERROR |= 0x1000000;
1542  }
1543 
1544 #ifdef LOCAL_UNPACK
1545  COUT<<"DDU Trailer Occurrence "<<cntDDU_Trailers<<endl;
1546  COUT<<"----------------------------------------------------------"<<endl;
1547  COUT<<"DDU 64-bit words = Actual - DDUcounted ="<<DDU_WordsSinceLastHeader+4<<"-"<<DDU_WordCount<<endl;
1548 #endif
1549 
1550  // increment statistics Errors and Warnings (i=0 case is handled in DDU Header)
1551  for(int err=1; err<nERRORS; ++err)
1552  {
1553  if( fERROR[err] )
1554  {
1555  fERROR[0] = true;
1556  bERROR |= 0x1;
1557 #ifdef LOCAL_UNPACK
1558  CERR<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
1559  CERR<<" ERROR "<<err<<" " <<sERROR[err]<<endl;
1560 #endif
1561  }
1562  }
1563 
1564 #ifdef LOCAL_UNPACK
1565  for(int wrn=1; wrn<nWARNINGS; ++wrn)
1566  {
1567  if( fWARNING[wrn] )
1568  {
1569  COUT<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
1570  COUT<<" WARNING "<<wrn<<" "<<sWARNING[wrn]<<endl;
1571  }
1572  }
1573 #endif
1574 
1575  bDDU_ERR[sourceID] |= bERROR;
1577  sync_stats();
1578 
1581  if (modeDDUonly)
1582  {
1583  buffer+=4;
1584  buf_1 = &(tmpbuf[0]); // Just for safety
1585  buf0 = &(tmpbuf[4]); // Just for safety
1586  buf1 = &(tmpbuf[8]); // Just for safety
1587  buf2 = &(tmpbuf[12]); // Just for safety
1588  bzero(tmpbuf, sizeof(uint16_t)*16);
1589  return length-4;
1590  }
1591  }
1592 
1593  if (!modeDDUonly)
1594  {
1595  // DCC Trailer 1 && DCC Trailer 2
1596  // =VB= Added support for Sep. 2008 CMS DAQ DCC format
1597  // =VB= 04.18.09 Removed (buf2[0]&0x0003) == 0x3 check for old DCC format to satisfy older format of simulated data
1598  if( (buf1[3]&0xFF00) == 0xEF00 &&
1599  ( ((buf2[3]&0xFF00) == 0xAF00 )
1600  ||
1601  (( buf2[3]&0xFF00) == 0xA000 && (buf2[0]&0x0003) == 0x0) ) )
1602  {
1603  // =VB= Added check that there is no DCCHeader detected to set missing DCC Header error
1604  if(!fDCC_Header || fDCC_Trailer)
1605  {
1606  fERROR[26] = true;
1607  bERROR|=0x4000000;
1608  fERROR[0] = true;
1609  bERROR|=0x1;
1610  } // DCC Header is missing
1611  fDCC_Trailer=true;
1612  fDCC_Header=false;
1613 
1614  if( fDDU_Header )
1615  {
1616  // == DDU Trailer is missing
1617  fERROR[1]=true;
1618  bERROR|=0x2;
1619  fERROR[0] = true;
1620  bERROR|=0x1;
1621  }
1622 
1623  buffer+=4;
1624  buf_1 = &(tmpbuf[0]); // Just for safety
1625  buf0 = &(tmpbuf[4]); // Just for safety
1626  buf1 = &(tmpbuf[8]); // Just for safety
1627  buf2 = &(tmpbuf[12]); // Just for safety
1628  bzero(tmpbuf, sizeof(uint16_t)*16);
1629  sync_stats();
1630  return length-4;
1631  }
1632  }
1633 
1634  length-=4;
1635  buffer+=4;
1636  }
1637  //Store the tail of the buffer
1638  buf_1 = &(tmpbuf[0]);
1639  buf0 = &(tmpbuf[4]);
1640  buf1 = &(tmpbuf[8]);
1641  buf2 = &(tmpbuf[12]);
1642  memcpy((void*)tmpbuf,(void*)(buffer-16),sizeof(short)*16);
1643 
1644  if (!modeDDUonly && !fDCC_Trailer && !fDCC_Header)
1645  {
1646  fERROR[26] = true;
1647  bERROR|=0x4000000;
1648  fERROR[25] = true;
1649  bERROR|=0x2000000;
1650  fERROR[0]=true;
1651  bERROR|=0x1;
1652  sync_stats();
1653  return length;
1654 
1655  }
1656 
1657  return -2;
1658 }
1659 
1660 
1662 {
1663  bzero(fERROR, sizeof(bool)*nERRORS);
1664  bzero(fWARNING, sizeof(bool)*nWARNINGS);
1665  bzero(fSUM_ERROR, sizeof(bool)*nERRORS);
1666  bzero(fSUM_WARNING, sizeof(bool)*nWARNINGS);
1667  bERROR = 0;
1668  bWARNING = 0;
1669  bSUM_ERROR = 0;
1670  bSUM_WARNING = 0;
1671  for(int err=0; err<nERRORS; ++err) fCHAMB_ERR[err].clear();
1672  for(int wrn=0; wrn<nWARNINGS; ++wrn) fCHAMB_WRN[wrn].clear();
1673  bCHAMB_ERR.clear();
1674  bCHAMB_WRN.clear();
1675  bCHAMB_PAYLOAD.clear();
1676  bCHAMB_STATUS.clear();
1677  bDDU_ERR.clear();
1678  bDDU_WRN.clear();
1679  dduBuffers.clear();
1680  dduOffsets.clear();
1681  dmbBuffers.clear();
1682  dmbOffsets.clear();
1683  dduSize.clear();
1684  dmbSize.clear();
1685 }
1686 
1687 
1689 {
1692  ALCT_WordCount = 0;
1693  ALCT_WordsExpected = 0;
1694  ALCT_ZSE = 0;
1696  TMB_WordCount = 0;
1697  TMB_WordsExpected = 0;
1698  TMB_Tbins = 0;
1700  CFEB_SampleCount = 0;
1701  CFEB_BSampleCount = 0;
1702 }
1703 
1704 
1706 {
1707  if( DAV_ALCT )
1708  {
1709  fERROR[21] = true;
1710  bERROR |= 0x200000;
1711  fCHAMB_ERR[21].insert(currentChamber);
1712  bCHAMB_ERR[currentChamber] |= 0x200000;
1713  DAV_ALCT = false;
1714  }
1715  if( DAV_TMB )
1716  {
1717  fERROR[22] = true;
1718  bERROR |= 0x400000;
1719  fCHAMB_ERR[22].insert(currentChamber);
1720  bCHAMB_ERR[currentChamber] |= 0x400000;
1721  DAV_TMB = false;
1722  }
1723  if( DAV_CFEB && DAV_CFEB!=-16)
1724  {
1725  fERROR[23] = true;
1726  bERROR |= 0x800000;
1727  fCHAMB_ERR[23].insert(currentChamber);
1728  bCHAMB_ERR[currentChamber] |= 0x800000;
1729  DAV_CFEB = 0;
1730  }
1731 }
1732 
1733 
1735 {
1736 #ifdef LOCAL_UNPACK
1737  /*
1738  COUT << " Ex-ALCT-Word-count " << std::endl;
1739  COUT << " ALCT Words Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
1740  COUT << " ALCT Word Count: " << ALCT_WordCount << std::endl;
1741  COUT << " ALCT Words Expected: " << ALCT_WordsExpected << std::endl;
1742  */
1743 #endif
1745  && ALCT_ZSE==0 )
1746  {
1747  fERROR[9] = true;
1748  bERROR |= 0x200;
1749  fCHAMB_ERR[9].insert(currentChamber);
1750  bCHAMB_ERR[currentChamber] |= 0x200;
1752  ALCT_WordCount = 0;
1754  ALCT_WordsExpected = 0;
1755  } // ALCT Word Count Error
1756 
1759  {
1760  fERROR[9] = true;
1761  bERROR |= 0x200;
1762  fCHAMB_ERR[9].insert(currentChamber);
1763  bCHAMB_ERR[currentChamber] |= 0x200;
1766  ALCT_WordCount = 0;
1768  ALCT_WordsExpected = 0;
1769  } // ALCT Word Count Error With zero suppression
1770 
1772  {
1773  fERROR[14] = true;
1774  bERROR |= 0x4000;
1775  fCHAMB_ERR[14].insert(currentChamber);
1776  bCHAMB_ERR[currentChamber] |= 0x4000;
1778  TMB_WordCount = 0;
1780  TMB_WordsExpected = 0;
1781  } // TMB Word Count Error
1782 
1783  if( (CFEB_SampleCount%8)!=0 )
1784  {
1785  fERROR[17] = true;
1786  bERROR |= 0x20000;
1787  fCHAMB_ERR[17].insert(currentChamber);
1788  bCHAMB_ERR[currentChamber] |= 0x20000;
1789  CFEB_SampleCount = 0;
1790  } // Number of CFEB samples != 8*n
1791 
1792  if(fALCT_Header)
1793  {
1794  fERROR[7] = true; // ALCT Trailer is missing
1795  bERROR |= 0x80;
1796  fCHAMB_ERR[7].insert(currentChamber);
1797  bCHAMB_ERR[currentChamber] |= 0x80;
1800  ALCT_WordsExpected = 0;
1801  fALCT_Header = false;
1802  }
1803 
1804  if(fTMB_Header)
1805  {
1806  fERROR[12]=true; // TMB Trailer is missing
1807  bERROR |= 0x1000;
1808  fCHAMB_ERR[12].insert(currentChamber);
1809  bCHAMB_ERR[currentChamber] |= 0x1000;
1811  TMB_WordsExpected = 0;
1812  fTMB_Header = false;
1813  }
1814 }
1815 
1817 {
1818  for (int err=0; err<nERRORS; ++err)
1819  fSUM_ERROR[err] |= fERROR[err];
1820  for (int wrn=0; wrn<nWARNINGS; ++wrn)
1821  fSUM_WARNING[wrn] |= fWARNING[wrn];
1822  bSUM_ERROR |= bERROR;
1824 }
1825 
1826 inline int CSCDCCExaminer::scanbuf(const uint16_t* &buffer, int32_t length, uint16_t sig, uint16_t mask)
1827 {
1828  for (int i=0; i<length; i++)
1829  {
1830  if ( (buffer[i]&mask) == sig)
1831  {
1832  return i;
1833  }
1834  }
1835  return -1;
1836 }
1837 
uint32_t DDU_WordsSinceLastHeader
uint32_t TMB_WordCount
const uint16_t * buf0
const uint16_t * buffer_start
void crcCFEB(bool enable)
uint32_t CFEB_SampleWordCount
std::map< CSCIdType, ExaminerStatusType > bCHAMB_ERR
std::set< CSCIdType > fCHAMB_ERR[29]
const double w
Definition: UKUtility.cc:23
const uint16_t * buf2
int scanbuf(const uint16_t *&buf, int32_t length, uint16_t sig, uint16_t mask=0xFFFF)
void modeDDU(bool enable)
uint32_t ALCT_WordsSinceLastHeader
const uint16_t * buf1
ExaminerStatusType bSUM_WARNING
uint32_t ALCT_WordCount
const uint16_t nERRORS
std::map< DDUIdType, uint32_t > dduSize
uint32_t DDU_WordsSinceLastTrailer
uint32_t cntDDU_Headers
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void crcALCT(bool enable)
#define COUT
uint32_t ALCT_WordsExpected
std::map< CSCIdType, uint32_t > cntCHAMB_Trailers
std::vector< const char * > sERROR
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
uint32_t TMB_Firmware_Revision
CSCIdType currentChamber
std::map< CSCIdType, ExaminerStatusType > bCHAMB_PAYLOAD
std::map< CSCIdType, uint32_t > cntCHAMB_Headers
uint32_t nWG_round_up
check zero suppression mode
const uint16_t nWARNINGS
std::map< DDUIdType, std::map< CSCIdType, uint32_t > > dmbOffsets
std::vector< const char * > sDMBExpectedPayload
std::vector< const char * > sWARNING_
std::set< CSCIdType > fCHAMB_WRN[5]
bool fSUM_ERROR[29]
uint32_t DDU_WordMismatch_Occurrences
std::map< DDUIdType, ExaminerStatusType > bDDU_ERR
uint32_t CFEB_SampleCount
void crcTMB(bool enable)
ExaminerStatusType bSUM_ERROR
uint32_t TMB_WordsRPC
uint32_t TMB_Tbins
#define end
Definition: vmac.h:39
uint32_t TMB_WordsExpected
const uint16_t * buf_2
const uint16_t * buf_1
uint32_t CFEB_BSampleCount
std::map< CSCIdType, ExaminerStatusType > bCHAMB_WRN
uint32_t TMB_WordsSinceLastHeader
to decode if zero suppression enabled
ExaminerStatusType bERROR
CSCDCCExaminer(ExaminerMaskType mask=0x1)
uint16_t tmpbuf[16]
uint32_t DDU_Firmware_Revision
bool fSUM_WARNING[5]
void checkTriggerHeadersAndTrailers()
std::vector< const char * > sWARNING
DDUIdType sourceID
std::map< DDUIdType, std::map< CSCIdType, const uint16_t * > > dmbBuffers
uint32_t ALCT_WordsSinceLastHeaderZeroSuppressed
std::map< CSCIdType, ExaminerStatusType > bCHAMB_STATUS
int32_t check(const uint16_t *&buffer, int32_t length)
uint32_t DDU_WordCount
std::map< DDUIdType, const uint16_t * > dduBuffers
void checkDAVs()
checks DAV_ALCT, DAV_TMB, and DAV_CFEB
ExaminerStatusType bWARNING
std::map< DDUIdType, std::map< CSCIdType, uint32_t > > dmbSize
std::vector< const char * > sDMBEventStaus
std::map< DDUIdType, uint32_t > dduOffsets
uint32_t ExaminerMaskType
std::vector< const char * > sERROR_
std::map< DDUIdType, ExaminerStatusType > bDDU_WRN
uint32_t cntDDU_Trailers