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;
237  TMB_WordsGEM = 0;
240  zeroCounts();
241 
242  checkCrcALCT = false;
243  ALCT_CRC = 0;
244  checkCrcTMB = false;
245  TMB_CRC = 0;
246  checkCrcCFEB = false;
247  CFEB_CRC = 0;
248 
249  modeDDUonly = false;
250  sourceID = 0xFFF;
251  currentChamber = -1;
252 
253  //headerDAV_Active = -1; // Trailer vs. Header check // Obsolete since 16.09.05
254 
255  clear();
256  buf_1 = &(tmpbuf[0]);
257  buf0 = &(tmpbuf[4]);
258  buf1 = &(tmpbuf[8]);
259  buf2 = &(tmpbuf[12]);
260 
261  bzero(tmpbuf, sizeof(uint16_t) * 16);
262 }
263 
264 int32_t CSCDCCExaminer::check(const uint16_t*& buffer, int32_t length) {
265  if (length <= 0)
266  return -1;
267 
270 
272  bool fTMB_MiniScope_Start = false;
273  bool fTMB_RPC_Start = false;
274  bool fTMB_GEM_Start = false;
275  bool fTMB_BlockedCFEBs_Start = false;
276 
277  bool fTMB_MiniScope = false;
278  bool fTMB_RPC = false;
279  bool fTMB_GEM = false;
280  bool fTMB_BlockedCFEBs = false;
281 
282  while (length > 0) {
283  // == Store last 4 read buffers in pipeline-like memory (note that memcpy works quite slower!)
284  buf_2 = buf_1; // This bufer was not needed so far
285  buf_1 = buf0;
286  buf0 = buf1;
287  buf1 = buf2;
288  buf2 = buffer;
289 
290  // check for too long event
291  if (!fERROR[19] && DDU_WordsSinceLastHeader > 100000) {
292  fERROR[19] = true;
293  bERROR |= 0x80000;
294  }
295 
296  // increment counter of 64-bit words since last DDU Header
297  // this counter is reset if DDU Header is found
298  if (fDDU_Header) {
300  }
301 
302  // increment counter of 64-bit words since last DDU Trailer
303  // this counter is reset if DDU Trailer is found
304  if (fDDU_Trailer) {
306  }
307 
310  if (fALCT_Header) {
315  for (int g = 0; g < 4; g++) {
316  if (buf0[g] == 0x1000) {
318  } else if (buf0[g] != 0x3000)
320  }
321  } else
325  }
326 
327  // increment counter of 16-bit words since last DMB*TMB Header match
328  // this counter is reset if TMB Header is found right after DMB Header or ALCT Trailer
329  if (fTMB_Header) {
331  }
332 
333  // increment counter of 16-bit words since last of DMB Header, ALCT Trailer, TMB Trailer,
334  // CFEB Sample Trailer, CFEB B-word; this counter is reset by all these conditions
335  if (fDMB_Header) {
337  }
338 
339  // If DDU header is missing we set unphysical 0xFFF value for DDU id
340  if (!fDDU_Header) {
341  sourceID = 0xFFF;
342  }
343 
344  if (!modeDDUonly) {
345  // DCC Header 1 && DCC Header 2
346  // =VB= Added support for Sep. 2008 CMS DAQ DCC format
347  if ((((buf0[3] & 0xF000) == 0x5000 && (buf0[0] & 0x00FF) == 0x005F) ||
348  ((buf0[3] & 0xF000) == 0x5000 && (buf0[0] & 0x000F) == 0x0008)) &&
349  // =VB= Why 0xD900 signature word if only 0xD part is constant???
350  // (buf1[3]&0xFF00) == 0xD900 )
351  (buf1[3] & 0xF000) == 0xD000) {
352  if (fDCC_Header) {
353  // == Another DCC Header before encountering DCC Trailer!
354  fERROR[25] = true;
355  bERROR |= 0x2000000;
356  fERROR[0] = true;
357  bERROR |= 0x1;
358 #ifdef LOCAL_UNPACK
359  CERR << "\n\nDCC Header Occurrence ";
360  CERR << " ERROR 25 " << sERROR[25] << endl;
361 #endif
362  fDDU_Header = false;
363 
364  // go backward for 3 DDU words ( buf2, buf1, and buf0 )
365  buffer -= 12;
366  buf_1 = &(tmpbuf[0]); // Just for safety
367  buf0 = &(tmpbuf[4]); // Just for safety
368  buf1 = &(tmpbuf[8]); // Just for safety
369  buf2 = &(tmpbuf[12]); // Just for safety
370  bzero(tmpbuf, sizeof(uint16_t) * 16);
371  sync_stats();
372  return length + 12;
373  }
374 
375  fDCC_Header = true;
376  clear();
377  }
378  }
379  // == Check for Format Control Words, set proper flags, perform self-consistency checks
380 
381  // C-words anywhere besides DDU Header
382  if (fDDU_Header &&
383  ((buf0[0] & 0xF000) == 0xC000 || (buf0[1] & 0xF000) == 0xC000 || (buf0[2] & 0xF000) == 0xC000 ||
384  (buf0[3] & 0xF000) == 0xC000) &&
385  (/*buf_1[0]!=0x8000 ||*/ buf_1[1] != 0x8000 || buf_1[2] != 0x0001 || buf_1[3] != 0x8000)) {
386  fERROR[0] = true;
387  bERROR |= 0x1;
388  fERROR[20] = true;
389  bERROR |= 0x100000;
390  // fCHAMB_ERR[20].insert(currentChamber);
391  // bCHAMB_ERR[currentChamber] |= 0x100000;
392 #ifdef LOCAL_UNPACK
393  CERR << "\nDDU Header Occurrence = " << cntDDU_Headers;
394  CERR << " ERROR 20 " << sERROR[20] << endl;
395 #endif
396  }
397 
398  // == DDU Header found
399  if (/*buf0[0]==0x8000 &&*/ buf0[1] == 0x8000 && buf0[2] == 0x0001 && buf0[3] == 0x8000) {
400  // headerDAV_Active = (buf1[1]<<16) | buf1[0]; // Obsolete since 16.09.05
402  checkDAVs();
405 
406  if (fDDU_Header) {
407  // == Another DDU Header before encountering DDU Trailer!
408  fERROR[1] = true;
409  bERROR |= 0x2;
410  fERROR[0] = true;
411  bERROR |= 0x1;
412 #ifdef LOCAL_UNPACK
413  CERR << "\n\nDDU Header Occurrence = " << cntDDU_Headers;
414  CERR << " ERROR 1 " << sERROR[1] << endl;
415 #endif
416  fDDU_Header = false;
417 
418  // Part of work for chambers that hasn't been done in absent trailer
419  if (fDMB_Header || fDMB_Trailer) {
420  fERROR[5] = true;
421  bERROR |= 0x20;
422  // Since here there are no chances to know what this chamber was, force it to be -2
423  if (currentChamber == -1)
424  currentChamber = -2;
425  fCHAMB_ERR[5].insert(currentChamber);
426  bCHAMB_ERR[currentChamber] |= 0x20;
427  fCHAMB_ERR[0].insert(currentChamber);
428  bCHAMB_ERR[currentChamber] |= 0x1;
429 #ifdef LOCAL_UNPACK
430  CERR << "\n\nDDU Header Occurrence = " << cntDDU_Headers;
431  CERR << " ERROR 5 " << sERROR[5] << endl;
432 #endif
433  } // One of DMB Trailers is missing ( or both )
434  fDMB_Header = false;
435  fDMB_Trailer = false;
436 
437  if (DMB_Active != nDMBs) {
438  fERROR[24] = true;
439  bERROR |= 0x1000000;
440  }
441  DMB_Active = 0;
442  nDMBs = 0;
443 
444  // Unknown chamber denoted as -2
445  // If it still remains in any of errors - put it in error 0
446  for (int err = 1; err < nERRORS; ++err)
447  if (fCHAMB_ERR[err].find(-2) != fCHAMB_ERR[err].end()) {
448  fCHAMB_ERR[0].insert(-2);
449  bCHAMB_ERR[-2] |= 0x1;
450  }
451 
454 
455  // go backward for 3 DDU words ( buf2, buf1, and buf0 )
456  buffer -= 12;
457  buf_1 = &(tmpbuf[0]); // Just for safety
458  buf0 = &(tmpbuf[4]); // Just for safety
459  buf1 = &(tmpbuf[8]); // Just for safety
460  buf2 = &(tmpbuf[12]); // Just for safety
461  bzero(tmpbuf, sizeof(uint16_t) * 16);
462  sync_stats();
463  return length + 12;
464  }
465 
466  currentChamber = -1; // Unknown yet
467 
469  // == Counted extraneous words between last DDU Trailer and this DDU Header
470  fWARNING[0] = true;
471  bWARNING |= 0x1;
472 #ifdef LOCAL_UNPACK
473  CERR << "\nDDU Header Occurrence = " << cntDDU_Headers;
474  CERR << " WARNING 0 " << sWARNING[0] << " " << DDU_WordsSinceLastTrailer << " extra 64-bit words" << endl;
475 #endif
476  }
477 
478  sourceID = ((buf_1[1] & 0xF) << 8) | ((buf_1[0] & 0xFF00) >> 8);
479 
481  DDU_Firmware_Revision = (buf_1[0] >> 4) & 0xF;
482  if (DDU_Firmware_Revision > 6) {
483  fFormat2013 = true;
484  modeDDUonly = true; // =VB= Force to use DDU only mode (no DCC Data)
485  }
486 
487  fDDU_Header = true;
488  fDDU_Trailer = false;
489  DDU_WordCount = 0;
490  fDMB_Header = false;
491  fDMB_Trailer = false;
492  fALCT_Header = false;
493  fALCT_Format2007 = true;
494  fTMB_Header = false;
495  fTMB_Format2007 = true;
496  uniqueALCT = true;
497  uniqueTMB = true;
498  zeroCounts();
499 
500  if (modeDDUonly) {
501  fDCC_Header = true;
502  clear();
503  }
504 
507  dduSize[sourceID] = 0;
508  dmbBuffers[sourceID].clear();
509  dmbOffsets[sourceID].clear();
510  dmbSize[sourceID].clear();
511 
512  // Reset all Error and Warning flags to be false
513  bDDU_ERR[sourceID] = 0;
514  bDDU_WRN[sourceID] = 0;
515  bERROR = 0;
516  bWARNING = 0;
517  bzero(fERROR, sizeof(bool) * nERRORS);
518  bzero(fWARNING, sizeof(bool) * nWARNINGS);
519 
520  nDMBs = 0;
521  DMB_Active = buf1[0] & 0xF;
522  DAV_DMB = buf1[1] & 0x7FFF;
523 
524  int nDAV_DMBs = 0;
525  for (int bit = 0; bit < 15; bit++)
526  if (DAV_DMB & (1 << bit))
527  nDAV_DMBs++;
528  if (DMB_Active != nDAV_DMBs) {
529  fERROR[27] = true;
530  bERROR |= 0x8000000;
531  }
532 
533  if ((buf_1[3] & 0xF000) != 0x5000) {
534  fWARNING[1] = true;
535  bWARNING |= 0x2;
536 #ifdef LOCAL_UNPACK
537  CERR << "\nDDU Header Occurrence = " << cntDDU_Headers;
538  CERR << " WARNING 1 " << sWARNING[1] << ". What must have been Header 1: 0x" << std::hex << buf_1[0] << " 0x"
539  << buf_1[1] << " 0x" << buf_1[2] << " 0x" << buf_1[3] << std::dec << endl;
540 #endif
541  }
542 
543  ++cntDDU_Headers;
544  DDU_WordsSinceLastHeader = 0; // Reset counter of DDU Words since last DDU Header
545 #ifdef LOCAL_UNPACK
546  COUT << "\n----------------------------------------------------------" << endl;
547  COUT << "DDU Header Occurrence " << cntDDU_Headers
548  << " L1A = " << (((buf_1[2] & 0xFFFF) + ((buf_1[3] & 0x00FF) << 16))) << endl;
549 #endif
550  }
551 
552  // == DMB Header found
553  if ((buf0[0] & 0xF000) == 0xA000 && (buf0[1] & 0xF000) == 0xA000 && (buf0[2] & 0xF000) == 0xA000 &&
554  (buf0[3] & 0xF000) == 0xA000) {
556  checkDAVs();
559 
561  fERROR[28] = true;
562  bERROR |= 0x10000000;
563  ;
564  }
565 
566  if (fDMB_Header || fDMB_Trailer) // F or E DMB Trailer is missed
567  {
568  fERROR[5] = true;
569  bERROR |= 0x20;
570  fCHAMB_ERR[5].insert(currentChamber);
571  bCHAMB_ERR[currentChamber] |= 0x20;
572  fCHAMB_ERR[0].insert(currentChamber);
573  bCHAMB_ERR[currentChamber] |= 0x1;
574  }
575  fDMB_Header = true;
576  fDMB_Trailer = false;
577 
578  // If previous DMB record was not assigned to any chamber ( it still has -1 indentificator )
579  // let's free -1 identificator for current use and call undefined chamber from previous record -2
580  // ( -2 may already exists in this sets but we have nothing to do with it )
581  for (int err = 0; err < nERRORS; ++err)
582  if (fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end()) {
583  fCHAMB_ERR[err].erase(-1);
584  fCHAMB_ERR[err].insert(-2);
585  }
586  // Two lines below are commented out because payloads never get filled if 0xA header is missing
587  // bCHAMB_PAYLOAD[-2] |= bCHAMB_PAYLOAD[-1];
588  // fCHAMB_PAYLOAD[-1] = 0;
589  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
590  bCHAMB_STATUS[-1] = 0;
591  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
592  bCHAMB_ERR[-1] = 0;
593  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
594  bCHAMB_WRN[-1] = 0;
595 
596  // Chamber id ( DMB_ID + (DMB_CRATE<<4) ) from header
597  currentChamber = buf0[1] & 0x0FFF;
599  bCHAMB_ERR[currentChamber] |= 0; //Victor's line
600 
601  fALCT_Header = false;
602  fALCT_Format2007 = true;
603  fTMB_Header = false;
604  fTMB_Format2007 = true;
605  uniqueALCT = true;
606  uniqueTMB = true;
607 
608  fTMB_MiniScope_Start = false;
609  fTMB_RPC_Start = false;
610  fTMB_GEM_Start = false;
611  fTMB_BlockedCFEBs_Start = false;
612 
613  fTMB_MiniScope = false;
614  fTMB_RPC = false;
615  fTMB_GEM = false;
616  fTMB_BlockedCFEBs = false;
617 
618  zeroCounts();
619  CFEB_CRC = 0;
620 
621  nDMBs++;
622 
626 
627 #ifdef LOCAL_UNPACK
628  // Print DMB_ID from DMB Header
629  COUT << "Crate=" << setw(3) << setfill('0') << ((buf0[1] >> 4) & 0x00FF) << " DMB=" << setw(2) << setfill('0')
630  << (buf0[1] & 0x000F) << " ";
631  // Print ALCT_DAV and TMB_DAV from DMB Header
632  //COUT<<setw(1)<<((buf0[0]&0x0020)>>5)<<" "<<((buf0[0]&0x0040)>>6)<<" ";
633  COUT << setw(1) << ((buf0[0] & 0x0200) >> 9) << " " << ((buf0[0] & 0x0800) >> 11)
634  << " "; //change of format 16.09.05
635  // Print CFEB_DAV from DMB Header
636  COUT << setw(1) << ((buf0[0] & 0x0010) >> 4) << ((buf0[0] & 0x0008) >> 3) << ((buf0[0] & 0x0004) >> 2)
637  << ((buf0[0] & 0x0002) >> 1) << (buf0[0] & 0x0001);
638  // Print DMB Header Tag
639  COUT << " {";
640 #endif
641 
642  if (fFormat2013)
643  {
644  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
645  DAV_ALCT = (buf0[0] & 0x0800) >> 11;
646  DAV_TMB = (buf0[0] & 0x0400) >> 10;
647  DAV_CFEB = 0;
648  if (buf0[0] & 0x0001)
649  ++DAV_CFEB;
650  if (buf0[0] & 0x0002)
651  ++DAV_CFEB;
652  if (buf0[0] & 0x0004)
653  ++DAV_CFEB;
654  if (buf0[0] & 0x0008)
655  ++DAV_CFEB;
656  if (buf0[0] & 0x0010)
657  ++DAV_CFEB;
658  if (buf0[0] & 0x0020)
659  ++DAV_CFEB;
660  if (buf0[0] & 0x0040)
661  ++DAV_CFEB;
662  if (DAV_ALCT)
664  if (DAV_TMB)
666 
668  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0] & 0x007f) << 7;
669  bCHAMB_PAYLOAD[currentChamber] |= (buf_1[2] & 0x001f);
670  bCHAMB_PAYLOAD[currentChamber] |= ((buf_1[2] >> 5) & 0x0003) << 14;
671  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0080) << 14;
672 
673  } else
674  {
675  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
676  DAV_ALCT = (buf0[0] & 0x0200) >> 9;
677  DAV_TMB = (buf0[0] & 0x0800) >> 11;
678  DAV_CFEB = 0;
679  if (buf0[0] & 0x0001)
680  ++DAV_CFEB;
681  if (buf0[0] & 0x0002)
682  ++DAV_CFEB;
683  if (buf0[0] & 0x0004)
684  ++DAV_CFEB;
685  if (buf0[0] & 0x0008)
686  ++DAV_CFEB;
687  if (buf0[0] & 0x0010)
688  ++DAV_CFEB;
689  if (DAV_ALCT)
691  if (DAV_TMB)
693  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0] & 0x001f) << 7;
694  bCHAMB_PAYLOAD[currentChamber] |= ((buf_1[2] >> 5) & 0x001f);
695  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0040) << 15;
696  }
697  }
698 
699  // New ALCT data format:
700  if ((buf0[0] == 0xDB0A && (buf0[1] & 0xF000) == 0xD000 && (buf0[2] & 0xF000) == 0xD000 &&
701  (buf0[3] & 0xF000) == 0xD000) &&
702  ((buf_1[0] & 0xF000) == 0xA000 && (buf_1[1] & 0xF000) == 0xA000 && (buf_1[2] & 0xF000) == 0xA000 &&
703  (buf_1[3] & 0xF000) == 0xA000)) {
704  fALCT_Header = true;
705  fALCT_Format2007 = true;
706  ALCT_CRC = 0;
709 
710  // Calculate expected number of ALCT words
711  ALCT_WordsExpected = 12; // header and trailer always exists
712 
713  // Aauxilary variables
714  // number of wire groups per layer:
715  int nWGs_per_layer = ((buf1[2] & 0x0007) + 1) * 16;
716  // words in the layer
717  nWG_round_up = int(nWGs_per_layer / 12) + (nWGs_per_layer % 3 ? 1 : 0);
718  // configuration present:
719  bool config_present = buf1[0] & 0x4000;
720  // lct overflow:
721  bool lct_overflow = buf1[0] & 0x2000;
722  // raw overflow:
723  bool raw_overflow = buf1[0] & 0x1000;
724  // l1a_window:
725  int lct_tbins = (buf1[3] & 0x01E0) >> 5;
726  // fifo_tbins:
727  int raw_tbins = (buf1[3] & 0x001F);
728 
730  ALCT_ZSE = (buf1[1] & 0x1000) >> 12;
731 
732 #ifdef LOCAL_UNPACK
733 /*
734  COUT << " Number of Wire Groups: " << nWG_round_up << std::endl;
735  COUT << " ALCT_ZSE: " << ALCT_ZSE << std::endl;
736  COUT << " raw_tbins: " << std::dec << raw_tbins << std::endl;
737  COUT << " LCT Tbins: " << lct_tbins << std::endl;
738 */
739 #endif
740 
741  // Data block sizes:
742  // 3 words of Vertex ID register + 5 words of config. register bits:
743  int config_size = (config_present ? 3 + 5 : 0);
744  // collision mask register:
745  int colreg_size = (config_present ? nWGs_per_layer / 4 : 0);
746  // hot channel mask:
747  int hot_ch_size = (config_present ? nWG_round_up * 6 : 0);
748  // ALCT0,1 (best tracks):
749  int alct_0_1_size = (!lct_overflow ? 2 * lct_tbins : 0);
750  // raw hit dump size:
751  int raw_hit_dump_size = (!raw_overflow ? nWG_round_up * 6 * raw_tbins : 0);
752 
753 #ifdef LOCAL_UNPACK
754  // COUT << " Raw Hit Dump: " << std::dec << raw_hit_dump_size << std::endl;
755 #endif
756 
757  ALCT_WordsExpected += config_size + colreg_size + hot_ch_size + alct_0_1_size + raw_hit_dump_size;
758  ALCT_WordsBeforeRaw = 8 + config_size + colreg_size + hot_ch_size + alct_0_1_size;
759 
760 #ifdef LOCAL_UNPACK
761  COUT << " <A";
762 #endif
763 
764  } else {
765  // Old ALCT data format
766 
767  // == ALCT Header found right after DMB Header
768  // (check for all currently reserved/fixed bits in ALCT first 4 words)
769  // if( ( (buf0 [0]&0xF800)==0x6000 && (buf0 [1]&0xFF80)==0x0080 && (buf0 [2]&0xF000)==0x0000 && (buf0 [3]&0xc000)==0x0000 )
770  if (((buf0[0] & 0xF800) == 0x6000 && (buf0[1] & 0x8F80) == 0x0080 && (buf0[2] & 0x8000) == 0x0000 &&
771  (buf0[3] & 0xc000) == 0x0000) &&
772  ((buf_1[0] & 0xF000) == 0xA000 && (buf_1[1] & 0xF000) == 0xA000 && (buf_1[2] & 0xF000) == 0xA000 &&
773  (buf_1[3] & 0xF000) == 0xA000)) {
774  fALCT_Header = true;
775  fALCT_Format2007 = false;
776  ALCT_CRC = 0;
778 
779  // Calculate expected number of ALCT words
780  if ((buf0[3] & 0x0003) == 0) {
781  ALCT_WordsExpected = 12; // Short Readout
782  }
783 
784  if ((buf0[1] & 0x0003) == 1) // Full Readout
785  {
786  ALCT_WordsExpected = ((buf0[1] & 0x007c) >> 2) *
787  (((buf0[3] & 0x0001)) + ((buf0[3] & 0x0002) >> 1) + ((buf0[3] & 0x0004) >> 2) +
788  ((buf0[3] & 0x0008) >> 3) + ((buf0[3] & 0x0010) >> 4) + ((buf0[3] & 0x0020) >> 5) +
789  ((buf0[3] & 0x0040) >> 6)) *
790  12 +
791  12;
792  }
793 #ifdef LOCAL_UNPACK
794  COUT << " <A";
795 #endif
796  }
797  }
798 #ifdef LOCAL_UNPACK
799  //COUT << " ALCT Word Expected: " << ALCT_WordsExpected << std::endl;
800 #endif
801 
802  if ((buf0[0] & 0xFFFF) == 0xDB0C) {
803  // =VB= Handles one of the OTMB corrupted data cases.
804  // Double TMB data block with 2nd TMB Header is found.
805  // Set missing TMB Trailer error.
806  if (fTMB_Header) {
807  fERROR[12] = true; // TMB Trailer is missing
808  bERROR |= 0x1000;
809  fCHAMB_ERR[12].insert(currentChamber);
810  bCHAMB_ERR[currentChamber] |= 0x1000;
811  }
812 
813  fTMB_Header = true;
814  fTMB_Format2007 = true;
815  TMB_CRC = 0;
817  TMB_WordsExpected = 0;
818 
819  // Calculate expected number of TMB words (whether RPC included will be known later)
820  if ((buf1[1] & 0x3000) == 0x3000) {
821  TMB_WordsExpected = 12; // Short Header Only
822  }
823  if ((buf1[1] & 0x3000) == 0x0000) {
824  TMB_WordsExpected = 48; // Long Header Only
825  }
826 
827 #ifdef LOCAL_UNPACK
828  COUT << " <T";
829 #endif
830  } else {
831  // == TMB Header found right after DMB Header or right after ALCT Trailer
832  if ((buf0[0] & 0xFFFF) == 0x6B0C && (((buf_1[0] & 0xF000) == 0xA000 && (buf_1[1] & 0xF000) == 0xA000 &&
833  (buf_1[2] & 0xF000) == 0xA000 && (buf_1[3] & 0xF000) == 0xA000) ||
834  ((buf_1[0] & 0x0800) == 0x0000 && (buf_1[1] & 0xF800) == 0xD000 &&
835  (buf_1[2] & 0xFFFF) == 0xDE0D && (buf_1[3] & 0xF000) == 0xD000)
836  // should've been (buf_1[0]&0xF800)==0xD000 - see comments for sERROR[11]
837  )) {
838  //if( (buf_1[2]&0xFFFF)==0xDE0D && (buf_1[3]&0xFC00)!=0xD000 && summer2004 ) ???
839 
840  fTMB_Header = true;
841  fTMB_Format2007 = false;
842  TMB_CRC = 0;
844 
845  // Calculate expected number of TMB words (whether RPC included will be known later)
846  if ((buf0[1] & 0x3000) == 0x3000) {
847  TMB_WordsExpected = 8; // Short Header Only
848  }
849  if ((buf0[1] & 0x3000) == 0x0000) {
850  TMB_WordsExpected = 32; // Long Header Only
851  }
852 
853  if ((buf0[1] & 0x3000) == 0x1000) {
854  // Full Readout = 28 + (#Tbins * #CFEBs * 6)
855  TMB_Tbins = (buf0[1] & 0x001F);
856  TMB_WordsExpected = 28 + TMB_Tbins * ((buf1[0] & 0x00E0) >> 5) * 6;
857  }
858 #ifdef LOCAL_UNPACK
859  COUT << " <T";
860 #endif
861  }
862  }
863  // New TMB format => very long header Find Firmware revision
866  }
867 
868  // New TMB format => very long header
870  // Full Readout = 44 + (#Tbins * #CFEBs * 6)
871  TMB_Tbins = (buf0[3] & 0x00F8) >> 3;
872  TMB_WordsExpected = 44 + TMB_Tbins * (buf0[3] & 0x0007) * 6;
873  }
874 
875  // == ALCT Trailer found
876  if (
877  // New ALCT data format:
878  (buf0[0] == 0xDE0D && (buf0[1] & 0xF800) == 0xD000 && (buf0[2] & 0xF800) == 0xD000 &&
879  (buf0[3] & 0xF000) == 0xD000 && fALCT_Format2007) ||
880  // Old ALCT data format; last check is added to avoid confusion with new TMB header (may not be needed):
881  ((buf0[0] & 0x0800) == 0x0000 && (buf0[1] & 0xF800) == 0xD000 && (buf0[2] & 0xFFFF) == 0xDE0D &&
882  (buf0[3] & 0xF000) == 0xD000 && !fALCT_Format2007 && !(fTMB_Header && fTMB_Format2007))) {
883  // should've been (buf0[0]&0xF800)==0xD000 - see comments for sERROR[11]
884 
885  // Second ALCT -> Lost both previous DMB Trailer and current DMB Header
886  if (!uniqueALCT)
887  currentChamber = -1;
888  // Check if this ALCT record have to exist according to DMB Header
889  if (DAV_ALCT)
890  DAV_ALCT = false;
891  else
892  DAV_ALCT = true;
893 
894  if (!fALCT_Header) {
895  fERROR[8] = true;
896  bERROR |= 0x100;
897  fCHAMB_ERR[8].insert(currentChamber);
898  bCHAMB_ERR[currentChamber] |= 0x100;
899  fCHAMB_ERR[0].insert(currentChamber);
900  bCHAMB_ERR[currentChamber] |= 0x1;
901  } // ALCT Header is missing
902 
903  if (!fALCT_Format2007 && (buf0[0] & 0xF800) != 0xD000) {
904  fERROR[11] = true;
905  bERROR |= 0x800;
906  fCHAMB_ERR[11].insert(currentChamber);
907  bCHAMB_ERR[currentChamber] |= 0x800;
908  fCHAMB_ERR[0].insert(currentChamber);
909  bCHAMB_ERR[currentChamber] |= 0x1;
910  } // some bits in 1st D-Trailer are lost
911 
912 #ifdef LOCAL_UNPACK
913 /*
915  COUT << " ALCT Word Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
916  COUT << " ALCT Words Before RawHits : " << ALCT_WordsBeforeRaw << std::endl;
917  COUT << " ALCT Word Expected: " << ALCT_WordsExpected << std::endl;
918  COUT << " ALCT Word Since Last Header Zero Supressed: " << ALCT_WordsSinceLastHeaderZeroSuppressed << std::endl;
919 */
920 #endif
921  if (checkCrcALCT) {
923  uint32_t crc = (fALCT_Format2007 ? buf0[1] : buf0[0]) & 0x7ff;
924  crc |= ((uint32_t)((fALCT_Format2007 ? buf0[2] : buf0[1]) & 0x7ff)) << 11;
925  if (ALCT_CRC != crc) {
926  fERROR[10] = true;
927  bERROR |= 0x400;
928  fCHAMB_ERR[10].insert(currentChamber);
929  bCHAMB_ERR[currentChamber] |= 0x400;
930  fCHAMB_ERR[0].insert(currentChamber);
931  bCHAMB_ERR[currentChamber] |= 0x1;
932  }
933  }
934 
935  fALCT_Header = false;
936  uniqueALCT = false;
937  CFEB_CRC = 0;
938  //ALCT_WordCount = (buf0[3]&0x03FF);
939  ALCT_WordCount = (buf0[3] & 0x07FF);
940  //ALCT_WordCount = (buf0[3]&0x0FFF);
942 #ifdef LOCAL_UNPACK
943  COUT << "A> ";
944 #endif
945  }
946 
947  // Calculation of CRC sum ( algorithm is written by Madorsky )
948  if (fALCT_Header && checkCrcALCT) {
949  for (uint16_t j = 0, w = 0; j < 4; ++j) {
951  w = buf0[j] & (fALCT_Format2007 ? 0xffff : 0x7fff);
952  for (uint32_t i = 15, t = 0, ncrc = 0; i < 16; i--) {
953  t = ((w >> i) & 1) ^ ((ALCT_CRC >> 21) & 1);
954  ncrc = (ALCT_CRC << 1) & 0x3ffffc;
955  ncrc |= (t ^ (ALCT_CRC & 1)) << 1;
956  ncrc |= t;
957  ALCT_CRC = ncrc;
958  }
959  }
960  }
961 
962  // == Find Correction for TMB_WordsExpected due to RPC raw hits,
963  // should it turn out to be the new RPC-aware format
964  if (fTMB_Header && ((buf0[2] & 0xFFFF) == 0x6E0B)) {
965  if (fTMB_Format2007) {
966  /* Checks for TMB2007 firmware revisions ranges to detect data format
967  ----------------
968  * rev. code <0x4000 - TMB/OTMB firmware with changed firmware revision format
969  * 4 bits [12:9] = Data Format Version for the unpacker (can include TMB vs. OTMB etc here)
970  * 4 bits [8:5] = Major Version (major features which breaks compatibility, requires changes to other board firmware)
971  * 5 bits [4:0] = Minor version (minor features, internal fixes, bug fixes, etc).
972  * ----------------
973  * rev.0x50c3 - first revision with changed format
974  * rev.0x42D5 - oldest known from 06/21/2007
975  * There is 4-bits year value rollover in revision number (0 in 2016)
976  */
977  if ((TMB_Firmware_Revision >= 0x50c3) || (TMB_Firmware_Revision < 0x42D5)) {
978  bool isGEMfirmware = false;
979  if ((TMB_Firmware_Revision < 0x4000) &&
980  (TMB_Firmware_Revision > 0x0)) { /* New TMB firmware revision format */
981  /* Data Format Version codes
982  * 0=TMB
983  * 1=OTMB standard
984  * 2=OTMB+CCLUT+HMT Run3 data format
985  * 3=OTMB+CCLUT+HMT+GEM Run3 data format
986  */
987  if (((TMB_Firmware_Revision >> 9) & 0x3) == 0x3)
988  isGEMfirmware = true;
989  }
990 
991  if (isGEMfirmware) {
992  uint16_t Enabled_GEMs = 0;
993  /* GEM output format, based on the number of enabled fibers, not yet implemented in the firmware */
994  /*
995  for (int i = 0; i < 4; i++)
996  Enabled_GEMs += (buf_1[0] >> i) & 0x1;
997  */
998  Enabled_GEMs = 4; // Currently always assume that all 4 fibers are enabled
999  // Number of enabled GEM Fibers * nTimebins
1000  TMB_WordsGEM = Enabled_GEMs * ((buf_1[0] >> 5) & 0x1F) * 4;
1001  TMB_WordsGEM += 2; // add header/trailer for block of GEM raw hits
1002  }
1003  // On/off * nRPCs * nTimebins * 2 words/RPC/bin
1004  TMB_WordsRPC = ((buf_1[0] & 0x0010) >> 4) * ((buf_1[0] & 0x000c) >> 2) * ((buf_1[0] >> 5) & 0x1F) * 2;
1005  } else // original TMB2007 data format (may not work since TMB_Tbins != RPC_Tbins)
1006  {
1007  TMB_WordsRPC = ((buf_1[0] & 0x0040) >> 6) * ((buf_1[0] & 0x0030) >> 4) * TMB_Tbins * 2;
1008  }
1009  } else // Old format 2006
1010  {
1011  TMB_WordsRPC = ((buf_1[2] & 0x0040) >> 6) * ((buf_1[2] & 0x0030) >> 4) * TMB_Tbins * 2;
1012  }
1013  TMB_WordsRPC += 2; // add header/trailer for block of RPC raw hits
1014  }
1015 
1016  // Check for RPC data
1017  if (fTMB_Header && (scanbuf(buf0, 4, 0x6B04) >= 0)) {
1018  fTMB_RPC_Start = true;
1019  }
1020 
1021  // Check for GEM data
1022  if (fTMB_Header && (scanbuf(buf0, 4, 0x6C04) >= 0)) {
1023  fTMB_GEM_Start = true;
1024  }
1025 
1026  // Check for Mini-Scope data
1027  if (fTMB_Header && (scanbuf(buf0, 4, 0x6B07) >= 0)) {
1028  fTMB_MiniScope_Start = true;
1029  }
1030 
1031  // Check for Blocked CFEBs data
1032  if (fTMB_Header && (scanbuf(buf0, 4, 0x6BCB) >= 0)) {
1033  fTMB_BlockedCFEBs_Start = true;
1034  }
1035 
1036  // Check for end of RPC data
1037  if (fTMB_Header && fTMB_RPC_Start && (scanbuf(buf0, 4, 0x6E04) >= 0)) {
1038  fTMB_RPC = true;
1039  }
1040 
1041  // Check for end of GEM data
1042  if (fTMB_Header && fTMB_GEM_Start && (scanbuf(buf0, 4, 0x6D04) >= 0)) {
1043  fTMB_GEM = true;
1044  }
1045 
1046  // Check for end of Mini-Scope data
1047  if (fTMB_Header && fTMB_MiniScope_Start && (scanbuf(buf0, 4, 0x6E07) >= 0)) {
1048  fTMB_MiniScope = true;
1049  }
1050 
1051  // Check for end of Blocked CFEBs data
1052  if (fTMB_Header && fTMB_BlockedCFEBs_Start && (scanbuf(buf0, 4, 0x6ECB) >= 0)) {
1053  fTMB_BlockedCFEBs = true;
1054  }
1055 
1056  // == TMB Trailer found
1057  if (
1058  // Old TMB data format; last condition in needed not to confuse if with new ALCT data header
1059  ((buf0[0] & 0xF000) == 0xD000 && (buf0[1] & 0xF000) == 0xD000 && (buf0[2] & 0xFFFF) == 0xDE0F &&
1060  (buf0[3] & 0xF000) == 0xD000 && !fTMB_Format2007 && !(fALCT_Header && fALCT_Format2007)) ||
1061  // New TMB data format
1062  (buf0[0] == 0xDE0F && (buf0[1] & 0xF000) == 0xD000 && (buf0[2] & 0xF000) == 0xD000 &&
1063  (buf0[3] & 0xF000) == 0xD000 && fTMB_Format2007)) {
1064  // Second TMB -> Lost both previous DMB Trailer and current DMB Header
1065  if (!uniqueTMB)
1066  currentChamber = -1;
1067  // Check if this TMB record have to exist according to DMB Header
1068  if (DAV_TMB)
1069  DAV_TMB = false;
1070  else
1071  DAV_TMB = true;
1072 
1073  if (!fTMB_Header) {
1074  fERROR[13] = true;
1075  bERROR |= 0x2000;
1076  fCHAMB_ERR[13].insert(currentChamber);
1077  bCHAMB_ERR[currentChamber] |= 0x2000;
1078  fCHAMB_ERR[0].insert(currentChamber);
1079  bCHAMB_ERR[currentChamber] |= 0x1;
1080  } // TMB Header is missing
1081 
1082  // Check calculated CRC sum against reported
1083  if (checkCrcTMB) {
1084  uint32_t crc = (fTMB_Format2007 ? buf0[1] & 0x7ff : buf0[0] & 0x7ff);
1085  crc |= ((uint32_t)((fTMB_Format2007 ? buf0[2] & 0x7ff : buf0[1] & 0x7ff))) << 11;
1086  if (TMB_CRC != crc) {
1087  fERROR[15] = true;
1088  bERROR |= 0x8000;
1089  fCHAMB_ERR[15].insert(currentChamber);
1090  bCHAMB_ERR[currentChamber] |= 0x8000;
1091  fCHAMB_ERR[0].insert(currentChamber);
1092  bCHAMB_ERR[currentChamber] |= 0x1;
1093  }
1094  }
1095 
1096  fTMB_Header = false;
1097  uniqueTMB = false;
1098  CFEB_CRC = 0;
1099  TMB_WordCount = (buf0[3] & 0x07FF);
1100 
1101  // == Correct TMB_WordsExpected
1102  // 1) for 2 optional 0x2AAA and 0x5555 Words in the Trailer
1103  // 2) for extra 4 frames in the new TMB trailer and
1104  // for RPC raw hit data, if present
1105  //
1106  // If the scope data was enabled in readout, scope data markers (0x6B05
1107  // and 0x6E05) appear before 0x6E0C, and the optional 0x2AAA and 0x5555
1108  // trailer words are suppressed. So far, we only have data with the
1109  // empty scope content, so more corrections will be needed once
1110  // non-empty scope data is available. -SV, 5 Nov 2008.
1111  //
1112  // If word count is not multiple of 4, add 2 optional words and
1113  // 4 trailer words.
1114 
1115  int pos = scanbuf(buf_1, 4, 0x6E0C);
1116  if (pos == 1) {
1117  TMB_WordsExpected += 6;
1118  }
1119  // If word count is multiple of 4, add 4 trailer words.
1120  else if (pos == 3) {
1121  TMB_WordsExpected += 4;
1122  }
1123 
1124  // Correct expected wordcount by RPC data size
1125  if (fTMB_RPC)
1127 
1128  // Correct expected wordcount by GEM data size
1129  if (fTMB_GEM)
1131 
1132  // Correct expected wordcount by MiniScope data size (22 words + 2 signature words)
1133  if (fTMB_MiniScope)
1134  TMB_WordsExpected += 24;
1135 
1136  // Correct expected wordcount by BlockedCFEBs data size (20 words + 2 signature words)
1137  if (fTMB_BlockedCFEBs)
1138  TMB_WordsExpected += 22;
1139 
1141 #ifdef LOCAL_UNPACK
1142  COUT << "T> ";
1143 #endif
1144  }
1145 
1146  if (fTMB_Header && checkCrcTMB) {
1147  for (uint16_t j = 0, w = 0; j < 4; ++j) {
1149  w = buf0[j] & (fTMB_Format2007 ? 0xffff : 0x7fff);
1150  for (uint32_t i = 15, t = 0, ncrc = 0; i < 16; i--) {
1151  t = ((w >> i) & 1) ^ ((TMB_CRC >> 21) & 1);
1152  ncrc = (TMB_CRC << 1) & 0x3ffffc;
1153  ncrc |= (t ^ (TMB_CRC & 1)) << 1;
1154  ncrc |= t;
1155  TMB_CRC = ncrc;
1156  }
1157  }
1158  }
1159 
1160  // == CFEB Sample Trailer found
1161 
1162  if (!fTMB_Header && ((buf0[1] & 0xF000) == 0x7000) && ((buf0[2] & 0xF000) == 0x7000) &&
1163  ((buf0[1] != 0x7FFF) || (buf0[2] != 0x7FFF)) &&
1164  (((buf0[3] & 0xFFFF) == 0x7FFF) || // old format
1165  ((buf0[3] & buf0[0]) == 0x0000 && (buf0[3] + buf0[0]) == 0x7FFF) // 2007 format
1166  )) {
1167 #ifdef LOCAL_UNPACK
1168  if ((CFEB_SampleCount % 8) == 0) {
1169  COUT << " <";
1170  }
1171  if (CFEB_SampleWordCount == 100) {
1172  COUT << "+";
1173  }
1174 #endif
1175  if (CFEB_SampleWordCount != 100) {
1176 #ifdef LOCAL_UNPACK
1177  COUT << "-";
1178 #endif
1179 
1180  fERROR[16] = true;
1181  bERROR |= 0x10000;
1182  fCHAMB_ERR[16].insert(currentChamber);
1183  bCHAMB_ERR[currentChamber] |= 0x10000;
1184  fCHAMB_ERR[0].insert(currentChamber);
1185  bCHAMB_ERR[currentChamber] |= 0x1;
1186  }
1187 
1188  ++CFEB_SampleCount;
1189 
1190  if ((CFEB_SampleCount % 8) == 0) {
1191 #ifdef LOCAL_UNPACK
1192  COUT << ">";
1193 #endif
1194  CFEB_BSampleCount = 0;
1195  // Count CFEBs
1196  DAV_CFEB--;
1197  }
1198 
1199  // Check calculated CRC sum against reported
1200  if (checkCrcCFEB && CFEB_CRC != buf0[0]) {
1201  fERROR[18] = true;
1202  bERROR |= 0x40000;
1203  fCHAMB_ERR[18].insert(currentChamber);
1204  bCHAMB_ERR[currentChamber] |= 0x40000;
1205  fCHAMB_ERR[0].insert(currentChamber);
1206  bCHAMB_ERR[currentChamber] |= 0x1;
1207  }
1208 
1209  CFEB_CRC = 0;
1211  }
1212 
1213  // == CFEB B-word found
1214  if (!fTMB_Header && (buf0[0] & 0xF000) == 0xB000 && (buf0[1] & 0xF000) == 0xB000 && (buf0[2] & 0xF000) == 0xB000 &&
1215  (buf0[3] & 0xF000) == 0xB000) {
1216  bCHAMB_STATUS[currentChamber] |= 0x400000;
1217 
1218 #ifdef LOCAL_UNPACK
1219  if ((CFEB_SampleCount % 8) == 0) {
1220  COUT << " <";
1221  }
1222  COUT << "B";
1223 #endif
1224 
1225  ++CFEB_SampleCount;
1227 
1228  if ((CFEB_SampleCount % 8) == 0) {
1229 #ifdef LOCAL_UNPACK
1230  COUT << ">";
1231 #endif
1232  CFEB_BSampleCount = 0;
1233  DAV_CFEB--;
1234  }
1235 
1237  }
1238 
1239  // == If it is neither ALCT record nor TMB - probably it is CFEB record and we try to count CRC sum.
1240  // It very few words of CFEB occasionaly will be misinterpreted as ALCT or TMB header the result
1241  // for the CRC sum will be wrong, but other errors of Trailers counting will appear as well
1243  for (int pos = 0; pos < 4; ++pos)
1244  CFEB_CRC = (buf0[pos] & 0x1fff) ^ ((buf0[pos] & 0x1fff) << 1) ^
1245  (((CFEB_CRC & 0x7ffc) >> 2) | ((0x0003 & CFEB_CRC) << 13)) ^ ((CFEB_CRC & 0x7ffc) >> 1);
1246 
1247  // == DMB F-Trailer found
1248  if ((buf0[0] & 0xF000) == 0xF000 && (buf0[1] & 0xF000) == 0xF000 && (buf0[2] & 0xF000) == 0xF000 &&
1249  (buf0[3] & 0xF000) == 0xF000) {
1250  if (!fDMB_Header) {
1251  currentChamber = buf0[3] & 0x0FFF;
1252  fERROR[6] = true;
1253  bERROR |= 0x40;
1254  fCHAMB_ERR[6].insert(currentChamber);
1255  bCHAMB_ERR[currentChamber] |= 0x40;
1256  nDMBs++;
1257  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
1258  if (buf0[0] & 0x0400)
1259  bCHAMB_PAYLOAD[currentChamber] |= 0x20;
1260  if (buf0[0] & 0x0800)
1261  bCHAMB_PAYLOAD[currentChamber] |= 0x40;
1262  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0] & 0x001f) << 7;
1263  bCHAMB_PAYLOAD[currentChamber] |= ((buf0[0] >> 5) & 0x1f);
1264 
1265  } // DMB Header is missing
1266  fDMB_Header = false;
1267  fDMB_Trailer = true;
1268  uniqueALCT = true;
1269  uniqueTMB = true;
1270 
1272 
1273  // Finally check if DAVs were correct
1274  checkDAVs();
1275 
1276  // If F-Trailer is lost then do necessary work here
1277  if ((buf1[0] & 0xF000) != 0xE000 || (buf1[1] & 0xF000) != 0xE000 || (buf1[2] & 0xF000) != 0xE000 ||
1278  (buf1[3] & 0xF000) != 0xE000) {
1279  for (int err = 1; err < nERRORS; ++err)
1281  fCHAMB_ERR[0].insert(currentChamber);
1282  bCHAMB_ERR[currentChamber] |= 0x1;
1283  }
1284  // Reset chamber id
1285  currentChamber = -1;
1286  /*
1287  for(int err=0; err<nERRORS; err++)
1288  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1289  fCHAMB_ERR[err].erase(-1);
1290  bCHAMB_ERR[-1] = 0;
1291  bCHAMB_WRN[-1] = 0;
1292  */
1293  }
1294 #ifdef LOCAL_UNPACK
1295  // Print DMB F-Trailer marker
1296  COUT << " }";
1297 #endif
1298  }
1299 
1300  // == DMB E-Trailer found
1301  if ((buf0[0] & 0xF000) == 0xE000 && (buf0[1] & 0xF000) == 0xE000 && (buf0[2] & 0xF000) == 0xE000 &&
1302  (buf0[3] & 0xF000) == 0xE000) {
1303  if (!fDMB_Header && !fDMB_Trailer)
1304  nDMBs++; // both DMB Header and DMB F-Trailer were missing
1305 
1306  if (fFormat2013)
1307  {
1309  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0800) >> 11;
1310  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0400) >> 9;
1311  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0080) << 8;
1312 
1313  if (fDMB_Trailer) // F-Trailer exists
1314  {
1315  bCHAMB_STATUS[currentChamber] |= (buf_1[2] & 0x0E00) >> 7;
1316  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x0003) << 3;
1317  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x000C) << 21;
1318  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x0800) >> 4;
1319  bCHAMB_STATUS[currentChamber] |= (buf_1[2] & 0x0100);
1320  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x01f0) << 5;
1321  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x0600) << 16;
1322  bCHAMB_STATUS[currentChamber] |= (buf_1[0] & 0x0800) << 3;
1323  bCHAMB_STATUS[currentChamber] |= (buf_1[1] & 0x001f) << 16;
1324  bCHAMB_STATUS[currentChamber] |= (buf_1[1] & 0x0060) << 21;
1325  }
1326 
1327  } else {
1328  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0800) >> 11;
1329  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x0400) >> 9;
1330  bCHAMB_STATUS[currentChamber] |= (buf0[0] & 0x03E0) >> 3;
1331 
1332  if (fDMB_Trailer) // F-Trailer exists
1333  {
1334  bCHAMB_STATUS[currentChamber] |= (buf_1[2] & 0x0002) << 6;
1335  bCHAMB_STATUS[currentChamber] |= (buf_1[2] & 0x0001) << 8;
1336  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x001f) << 9;
1337  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x0040) << 8;
1338  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x0020) << 10;
1339  bCHAMB_STATUS[currentChamber] |= (buf_1[3] & 0x0f80) << 9;
1340  }
1341  }
1342  fDMB_Header = false;
1343 
1344  // If chamber id is unknown it is time to find it out
1345  if (currentChamber == -1) {
1346  currentChamber = buf0[1] & 0x0FFF;
1347  for (int err = 0; err < nERRORS; ++err)
1348  if (fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end()) {
1349  fCHAMB_ERR[err].insert(currentChamber);
1350  fCHAMB_ERR[err].erase(-1);
1351  }
1353  bCHAMB_STATUS[-1] = 0;
1355  bCHAMB_ERR[-1] = 0;
1357  bCHAMB_WRN[-1] = 0;
1358  }
1359  ++cntCHAMB_Trailers[buf0[1] & 0x0FFF];
1360 
1362 
1363  // Lost DMB F-Trailer before
1364  if (!fDMB_Trailer) {
1365  fERROR[6] = true;
1366  bERROR |= 0x40;
1367  fCHAMB_ERR[6].insert(currentChamber);
1368  bCHAMB_ERR[currentChamber] |= 0x40;
1369  fCHAMB_ERR[0].insert(currentChamber);
1370  bCHAMB_ERR[currentChamber] |= 0x1;
1371  // Check if DAVs were correct here
1372  checkDAVs();
1373  }
1374  fDMB_Trailer = false;
1375 
1376 #ifdef LOCAL_UNPACK
1377  // Print DMB E-Trailer marker
1378  COUT << " DMB=" << (buf0[1] & 0x000F);
1379  COUT << "; " << ALCT_WordsSinceLastHeader << "-" << ALCT_WordCount << "-" << ALCT_WordsExpected << " "
1380  << TMB_WordsSinceLastHeader << "-" << TMB_WordCount << "-" << TMB_WordsExpected << endl;
1381 #endif
1382 
1384 
1385  //
1386  for (int err = 0; err < nERRORS; ++err)
1387  if (fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end()) {
1388  fCHAMB_ERR[err].erase(-1);
1389  fCHAMB_ERR[err].insert(-2);
1390  }
1391  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1392  bCHAMB_STATUS[-1] = 0;
1393  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1394  bCHAMB_ERR[-1] = 0;
1395  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1396  bCHAMB_WRN[-1] = 0;
1397 
1398  if (currentChamber != -1)
1399  for (int err = 1; err < nERRORS; ++err)
1401  fCHAMB_ERR[0].insert(currentChamber);
1402  bCHAMB_ERR[currentChamber] |= 0x1;
1403  }
1404 
1405  currentChamber = -1;
1406 #ifdef LOCAL_UNPACK
1407  /*
1408  // Print DMB E-Trailer marker
1409  COUT<<" DMB="<<(buf0[1]&0x000F);
1410  COUT << "; "
1411  << ALCT_WordsSinceLastHeader << "-"
1412  << ALCT_WordCount << "-"
1413  << ALCT_WordsExpected
1414  << " "
1415  << TMB_WordsSinceLastHeader << "-"
1416  << TMB_WordCount << "-"
1417  << TMB_WordsExpected
1418  << endl;
1419  */
1420 #endif
1421  }
1422 
1423  // == DDU Trailer found
1424  if (buf0[0] == 0x8000 && buf0[1] == 0x8000 && buf0[2] == 0xFFFF && buf0[3] == 0x8000) {
1426  checkDAVs();
1427 
1429 
1431 
1432  if (DDU_WordsSinceLastHeader > 3 && !nDMBs) {
1433  fERROR[28] = true;
1434  bERROR |= 0x10000000;
1435  ;
1436  }
1437 
1438  if (fDDU_Trailer) {
1439  fERROR[2] = true;
1440  bERROR |= 0x4;
1441  } // DDU Header is missing
1442  fDDU_Trailer = true;
1443  fDDU_Header = false;
1444 
1445  if (fDMB_Header || fDMB_Trailer) {
1446 #ifdef LOCAL_UNPACK
1447  COUT << " Ex-Err: DMB (Header, Trailer) " << std::endl;
1448 #endif
1449  fERROR[5] = true;
1450  bERROR |= 0x20;
1451  fCHAMB_ERR[5].insert(currentChamber);
1452  bCHAMB_ERR[currentChamber] |= 0x20;
1453  fCHAMB_ERR[0].insert(currentChamber);
1454  bCHAMB_ERR[currentChamber] |= 0x20;
1455  } // DMB Trailer is missing
1456  fDMB_Header = false;
1457  fDMB_Trailer = false;
1458 
1459  currentChamber = -1;
1460 
1461  for (int err = 0; err < nERRORS; ++err)
1462  if (fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end()) {
1463  fCHAMB_ERR[err].erase(-1);
1464  fCHAMB_ERR[err].insert(-2);
1465  }
1466  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1467  bCHAMB_STATUS[-1] = 0;
1468  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1469  bCHAMB_ERR[-1] = 0;
1470  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1471  bCHAMB_WRN[-1] = 0;
1472 
1473  for (int err = 1; err < nERRORS; ++err)
1474  if (fCHAMB_ERR[err].find(-2) != fCHAMB_ERR[err].end()) {
1475  fCHAMB_ERR[0].insert(-2);
1476  bCHAMB_ERR[-2] |= 0x1;
1477  }
1478 
1480 
1481  ++cntDDU_Trailers; // Increment DDUTrailer counter
1482 
1483  // == Combining 2 words into 24bit value
1484  DDU_WordCount = buf2[2] | ((buf2[3] & 0xFF) << 16);
1485 
1486  if ((DDU_WordsSinceLastHeader + 4) != DDU_WordCount) {
1487  fERROR[4] = true;
1488  bERROR |= 0x10;
1489  }
1490 
1491  if (DMB_Active != nDMBs) {
1492  fERROR[24] = true;
1493  bERROR |= 0x1000000;
1494  }
1495 
1496 #ifdef LOCAL_UNPACK
1497  COUT << "DDU Trailer Occurrence " << cntDDU_Trailers << endl;
1498  COUT << "----------------------------------------------------------" << endl;
1499  COUT << "DDU 64-bit words = Actual - DDUcounted =" << DDU_WordsSinceLastHeader + 4 << "-" << DDU_WordCount
1500  << endl;
1501 #endif
1502 
1503  // increment statistics Errors and Warnings (i=0 case is handled in DDU Header)
1504  for (int err = 1; err < nERRORS; ++err) {
1505  if (fERROR[err]) {
1506  fERROR[0] = true;
1507  bERROR |= 0x1;
1508 #ifdef LOCAL_UNPACK
1509  CERR << "\nDDU Header Occurrence = " << cntDDU_Headers;
1510  CERR << " ERROR " << err << " " << sERROR[err] << endl;
1511 #endif
1512  }
1513  }
1514 
1515 #ifdef LOCAL_UNPACK
1516  for (int wrn = 1; wrn < nWARNINGS; ++wrn) {
1517  if (fWARNING[wrn]) {
1518  COUT << "\nDDU Header Occurrence = " << cntDDU_Headers;
1519  COUT << " WARNING " << wrn << " " << sWARNING[wrn] << endl;
1520  }
1521  }
1522 #endif
1523 
1524  bDDU_ERR[sourceID] |= bERROR;
1526  sync_stats();
1527 
1530  if (modeDDUonly) {
1531  buffer += 4;
1532  buf_1 = &(tmpbuf[0]); // Just for safety
1533  buf0 = &(tmpbuf[4]); // Just for safety
1534  buf1 = &(tmpbuf[8]); // Just for safety
1535  buf2 = &(tmpbuf[12]); // Just for safety
1536  bzero(tmpbuf, sizeof(uint16_t) * 16);
1537  return length - 4;
1538  }
1539  }
1540 
1541  if (!modeDDUonly) {
1542  // DCC Trailer 1 && DCC Trailer 2
1543  // =VB= Added support for Sep. 2008 CMS DAQ DCC format
1544  // =VB= 04.18.09 Removed (buf2[0]&0x0003) == 0x3 check for old DCC format to satisfy older format of simulated data
1545  if ((buf1[3] & 0xFF00) == 0xEF00 &&
1546  (((buf2[3] & 0xFF00) == 0xAF00) || ((buf2[3] & 0xFF00) == 0xA000 && (buf2[0] & 0x0003) == 0x0))) {
1547  // =VB= Added check that there is no DCCHeader detected to set missing DCC Header error
1548  if (!fDCC_Header || fDCC_Trailer) {
1549  fERROR[26] = true;
1550  bERROR |= 0x4000000;
1551  fERROR[0] = true;
1552  bERROR |= 0x1;
1553  } // DCC Header is missing
1554  fDCC_Trailer = true;
1555  fDCC_Header = false;
1556 
1557  if (fDDU_Header) {
1558  // == DDU Trailer is missing
1559  fERROR[1] = true;
1560  bERROR |= 0x2;
1561  fERROR[0] = true;
1562  bERROR |= 0x1;
1563  }
1564 
1565  buffer += 4;
1566  buf_1 = &(tmpbuf[0]); // Just for safety
1567  buf0 = &(tmpbuf[4]); // Just for safety
1568  buf1 = &(tmpbuf[8]); // Just for safety
1569  buf2 = &(tmpbuf[12]); // Just for safety
1570  bzero(tmpbuf, sizeof(uint16_t) * 16);
1571  sync_stats();
1572  return length - 4;
1573  }
1574  }
1575 
1576  length -= 4;
1577  buffer += 4;
1578  }
1579  //Store the tail of the buffer
1580  buf_1 = &(tmpbuf[0]);
1581  buf0 = &(tmpbuf[4]);
1582  buf1 = &(tmpbuf[8]);
1583  buf2 = &(tmpbuf[12]);
1584  memcpy((void*)tmpbuf, (void*)(buffer - 16), sizeof(short) * 16);
1585 
1586  if (!modeDDUonly && !fDCC_Trailer && !fDCC_Header) {
1587  fERROR[26] = true;
1588  bERROR |= 0x4000000;
1589  fERROR[25] = true;
1590  bERROR |= 0x2000000;
1591  fERROR[0] = true;
1592  bERROR |= 0x1;
1593  sync_stats();
1594  return length;
1595  }
1596 
1597  return -2;
1598 }
1599 
1601  bzero(fERROR, sizeof(bool) * nERRORS);
1602  bzero(fWARNING, sizeof(bool) * nWARNINGS);
1603  bzero(fSUM_ERROR, sizeof(bool) * nERRORS);
1604  bzero(fSUM_WARNING, sizeof(bool) * nWARNINGS);
1605  bERROR = 0;
1606  bWARNING = 0;
1607  bSUM_ERROR = 0;
1608  bSUM_WARNING = 0;
1609  for (int err = 0; err < nERRORS; ++err)
1610  fCHAMB_ERR[err].clear();
1611  for (int wrn = 0; wrn < nWARNINGS; ++wrn)
1612  fCHAMB_WRN[wrn].clear();
1613  bCHAMB_ERR.clear();
1614  bCHAMB_WRN.clear();
1615  bCHAMB_PAYLOAD.clear();
1616  bCHAMB_STATUS.clear();
1617  bDDU_ERR.clear();
1618  bDDU_WRN.clear();
1619  dduBuffers.clear();
1620  dduOffsets.clear();
1621  dmbBuffers.clear();
1622  dmbOffsets.clear();
1623  dduSize.clear();
1624  dmbSize.clear();
1625 }
1626 
1630  ALCT_WordCount = 0;
1631  ALCT_WordsExpected = 0;
1632  ALCT_WordsBeforeRaw = 0;
1633  ALCT_ZSE = 0;
1635  TMB_WordCount = 0;
1636  TMB_WordsExpected = 0;
1637  TMB_Tbins = 0;
1639  CFEB_SampleCount = 0;
1640  CFEB_BSampleCount = 0;
1641 }
1642 
1644  if (DAV_ALCT) {
1645  fERROR[21] = true;
1646  bERROR |= 0x200000;
1647  fCHAMB_ERR[21].insert(currentChamber);
1648  bCHAMB_ERR[currentChamber] |= 0x200000;
1649  DAV_ALCT = false;
1650  }
1651  if (DAV_TMB) {
1652  fERROR[22] = true;
1653  bERROR |= 0x400000;
1654  fCHAMB_ERR[22].insert(currentChamber);
1655  bCHAMB_ERR[currentChamber] |= 0x400000;
1656  DAV_TMB = false;
1657  }
1658  if (DAV_CFEB && DAV_CFEB != -16) {
1659  fERROR[23] = true;
1660  bERROR |= 0x800000;
1661  fCHAMB_ERR[23].insert(currentChamber);
1662  bCHAMB_ERR[currentChamber] |= 0x800000;
1663  DAV_CFEB = 0;
1664  }
1665 }
1666 
1668 #ifdef LOCAL_UNPACK
1669  /*
1670  COUT << " Ex-ALCT-Word-count " << std::endl;
1671  COUT << " ALCT Words Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
1672  COUT << " ALCT Word Count: " << ALCT_WordCount << std::endl;
1673  COUT << " ALCT Words Expected: " << ALCT_WordsExpected << std::endl;
1674  */
1675 #endif
1676  if (!fALCT_Header &&
1678  ALCT_ZSE == 0) {
1679  fERROR[9] = true;
1680  bERROR |= 0x200;
1681  fCHAMB_ERR[9].insert(currentChamber);
1682  bCHAMB_ERR[currentChamber] |= 0x200;
1684  ALCT_WordCount = 0;
1686  ALCT_WordsExpected = 0;
1687  ALCT_WordsBeforeRaw = 0;
1688  } // ALCT Word Count Error
1689 
1690  if (!fALCT_Header &&
1692  ALCT_ZSE != 0) {
1693  fERROR[9] = true;
1694  bERROR |= 0x200;
1695  fCHAMB_ERR[9].insert(currentChamber);
1696  bCHAMB_ERR[currentChamber] |= 0x200;
1699  ALCT_WordCount = 0;
1701  ALCT_WordsExpected = 0;
1702  ALCT_WordsBeforeRaw = 0;
1703  } // ALCT Word Count Error With zero suppression
1704 
1706  fERROR[14] = true;
1707  bERROR |= 0x4000;
1708  fCHAMB_ERR[14].insert(currentChamber);
1709  bCHAMB_ERR[currentChamber] |= 0x4000;
1711  TMB_WordCount = 0;
1713  TMB_WordsExpected = 0;
1714  } // TMB Word Count Error
1715 
1716  if ((CFEB_SampleCount % 8) != 0) {
1717  fERROR[17] = true;
1718  bERROR |= 0x20000;
1719  fCHAMB_ERR[17].insert(currentChamber);
1720  bCHAMB_ERR[currentChamber] |= 0x20000;
1721  CFEB_SampleCount = 0;
1722  } // Number of CFEB samples != 8*n
1723 
1724  if (fALCT_Header) {
1725  fERROR[7] = true; // ALCT Trailer is missing
1726  bERROR |= 0x80;
1727  fCHAMB_ERR[7].insert(currentChamber);
1728  bCHAMB_ERR[currentChamber] |= 0x80;
1731  ALCT_WordsExpected = 0;
1732  ALCT_WordsBeforeRaw = 0;
1733  fALCT_Header = false;
1734  }
1735 
1736  if (fTMB_Header) {
1737  fERROR[12] = true; // TMB Trailer is missing
1738  bERROR |= 0x1000;
1739  fCHAMB_ERR[12].insert(currentChamber);
1740  bCHAMB_ERR[currentChamber] |= 0x1000;
1742  TMB_WordsExpected = 0;
1743  fTMB_Header = false;
1744  }
1745 }
1746 
1748  for (int err = 0; err < nERRORS; ++err)
1749  fSUM_ERROR[err] |= fERROR[err];
1750  for (int wrn = 0; wrn < nWARNINGS; ++wrn)
1751  fSUM_WARNING[wrn] |= fWARNING[wrn];
1752  bSUM_ERROR |= bERROR;
1754 }
1755 
1756 inline int CSCDCCExaminer::scanbuf(const uint16_t*& buffer, int32_t length, uint16_t sig, uint16_t mask) {
1757  for (int i = 0; i < length; i++) {
1758  if ((buffer[i] & mask) == sig) {
1759  return i;
1760  }
1761  }
1762  return -1;
1763 }
uint32_t DDU_WordsSinceLastHeader
uint32_t TMB_WordCount
const uint16_t * buf0
const uint16_t * buffer_start
std::map< CSCIdType, ExaminerStatusType > bCHAMB_ERR
void crcCFEB(bool enable)
std::map< DDUIdType, ExaminerStatusType > bDDU_ERR
uint32_t CFEB_SampleWordCount
std::map< DDUIdType, ExaminerStatusType > bDDU_WRN
std::set< CSCIdType > fCHAMB_ERR[29]
std::map< DDUIdType, uint32_t > dduOffsets
std::map< DDUIdType, uint32_t > dduSize
const uint16_t * buf2
int scanbuf(const uint16_t *&buf, int32_t length, uint16_t sig, uint16_t mask=0xFFFF)
void modeDDU(bool enable)
T w() const
uint32_t ALCT_WordsSinceLastHeader
const uint16_t * buf1
ExaminerStatusType bSUM_WARNING
uint32_t ALCT_WordCount
const uint16_t nERRORS
uint32_t TMB_WordsGEM
uint32_t DDU_WordsSinceLastTrailer
std::map< CSCIdType, ExaminerStatusType > bCHAMB_PAYLOAD
uint32_t cntDDU_Headers
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void crcALCT(bool enable)
uint32_t ALCT_WordsExpected
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
std::map< DDUIdType, const uint16_t * > dduBuffers
uint32_t TMB_Firmware_Revision
CSCIdType currentChamber
uint32_t nWG_round_up
check zero suppression mode
std::map< CSCIdType, uint32_t > cntCHAMB_Trailers
const uint16_t nWARNINGS
std::map< DDUIdType, std::map< CSCIdType, uint32_t > > dmbSize
std::vector< const char * > sDMBExpectedPayload
std::vector< const char * > sWARNING_
std::set< CSCIdType > fCHAMB_WRN[5]
uint32_t ALCT_ZSE
number of ALCT words before anode raw data
bool fSUM_ERROR[29]
uint32_t DDU_WordMismatch_Occurrences
uint32_t CFEB_SampleCount
void crcTMB(bool enable)
ExaminerStatusType bSUM_ERROR
std::map< CSCIdType, ExaminerStatusType > bCHAMB_WRN
uint32_t TMB_WordsRPC
uint32_t TMB_Tbins
uint32_t TMB_WordsExpected
#define COUT
enable
Messages.
Definition: DiMuonV_cfg.py:93
const uint16_t * buf_2
const uint16_t * buf_1
uint32_t CFEB_BSampleCount
std::map< DDUIdType, std::map< CSCIdType, uint32_t > > dmbOffsets
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
uint32_t ALCT_WordsSinceLastHeaderZeroSuppressed
int32_t check(const uint16_t *&buffer, int32_t length)
uint32_t DDU_WordCount
std::map< CSCIdType, ExaminerStatusType > bCHAMB_STATUS
uint32_t ALCT_WordsBeforeRaw
void checkDAVs()
checks DAV_ALCT, DAV_TMB, and DAV_CFEB
ExaminerStatusType bWARNING
std::vector< const char * > sDMBEventStaus
uint32_t ExaminerMaskType
std::map< DDUIdType, std::map< CSCIdType, const uint16_t * > > dmbBuffers
std::vector< const char * > sERROR_
std::map< CSCIdType, uint32_t > cntCHAMB_Headers
uint32_t cntDDU_Trailers