CMS 3D CMS Logo

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