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