CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
29 void CSCDCCExaminer::crcALCT(bool enable)
30 {
31  checkCrcALCT = enable;
32  if( checkCrcALCT )
33  sERROR[10] = "ALCT CRC Error ";
34  else
35  sERROR[10] = "ALCT CRC Error ( disabled ) ";
36 }
37 
38 void CSCDCCExaminer::crcTMB(bool enable)
39 {
40  checkCrcTMB = enable;
41  if( checkCrcTMB )
42  sERROR[15] = "TMB CRC Error ";
43  else
44  sERROR[15] = "TMB CRC Error ( disabled ) ";
45 }
46 
47 void CSCDCCExaminer::crcCFEB(bool enable)
48 {
49  checkCrcCFEB = enable;
50  if( checkCrcCFEB )
51  sERROR[18] = "CFEB CRC Error ";
52  else
53  sERROR[18] = "CFEB CRC Error ( disabled ) ";
54 }
55 
56 void CSCDCCExaminer::modeDDU(bool enable)
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 
272  buffer_start = buffer;
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  fTMB_Header = true;
826  fTMB_Format2007 = true;
827  TMB_CRC = 0;
829  TMB_WordsExpected = 0;
830 
831  // Calculate expected number of TMB words (whether RPC included will be known later)
832  if ( (buf1[1]&0x3000) == 0x3000)
833  {
834  TMB_WordsExpected = 12; // Short Header Only
835  }
836  if ( (buf1[1]&0x3000) == 0x0000)
837  {
838  TMB_WordsExpected = 48; // Long Header Only
839  }
840 
841 #ifdef LOCAL_UNPACK
842  COUT << " <T";
843 #endif
844  }
845  else
846  {
847  // == TMB Header found right after DMB Header or right after ALCT Trailer
848  if( (buf0 [0]&0xFFFF)==0x6B0C && (
849  ( (buf_1[0]&0xF000)==0xA000 && (buf_1[1]&0xF000)==0xA000 && (buf_1[2]&0xF000)==0xA000 && (buf_1[3]&0xF000)==0xA000 )
850  ||
851  ( (buf_1[0]&0x0800)==0x0000 && (buf_1[1]&0xF800)==0xD000 && (buf_1[2]&0xFFFF)==0xDE0D && (buf_1[3]&0xF000)==0xD000 )
852  // should've been (buf_1[0]&0xF800)==0xD000 - see comments for sERROR[11]
853  ) )
854  {
855  //if( (buf_1[2]&0xFFFF)==0xDE0D && (buf_1[3]&0xFC00)!=0xD000 && summer2004 ) ???
856 
857  fTMB_Header = true;
858  fTMB_Format2007 = false;
859  TMB_CRC = 0;
861 
862  // Calculate expected number of TMB words (whether RPC included will be known later)
863  if ( (buf0[1]&0x3000) == 0x3000)
864  {
865  TMB_WordsExpected = 8; // Short Header Only
866  }
867  if ( (buf0[1]&0x3000) == 0x0000)
868  {
869  TMB_WordsExpected = 32; // Long Header Only
870  }
871 
872  if ( (buf0[1]&0x3000) == 0x1000)
873  {
874  // Full Readout = 28 + (#Tbins * #CFEBs * 6)
875  TMB_Tbins=(buf0[1]&0x001F);
876  TMB_WordsExpected = 28 + TMB_Tbins * ((buf1[0]&0x00E0)>>5) * 6;
877  }
878 #ifdef LOCAL_UNPACK
879  COUT << " <T";
880 #endif
881  }
882  }
883  // New TMB format => very long header Find Firmware revision
885  {
887  }
888 
889  // New TMB format => very long header
891  {
892  // Full Readout = 44 + (#Tbins * #CFEBs * 6)
893  TMB_Tbins=(buf0[3]&0x00F8)>>3;
894  TMB_WordsExpected = 44 + TMB_Tbins * (buf0[3]&0x0007) * 6;
895  }
896 
897  // == ALCT Trailer found
898  if(
899  // New ALCT data format:
900  ( buf0[0]==0xDE0D && (buf0[1]&0xF800)==0xD000 && (buf0[2]&0xF800)==0xD000 && (buf0[3]&0xF000)==0xD000 && fALCT_Format2007 ) ||
901  // Old ALCT data format; last check is added to avoid confusion with new TMB header (may not be needed):
902  ( (buf0[0]&0x0800)==0x0000 && (buf0[1]&0xF800)==0xD000 && (buf0[2]&0xFFFF)==0xDE0D && (buf0[3]&0xF000)==0xD000 && !fALCT_Format2007 && !(fTMB_Header&&fTMB_Format2007) )
903  )
904  {
905  // should've been (buf0[0]&0xF800)==0xD000 - see comments for sERROR[11]
906 
907  // Second ALCT -> Lost both previous DMB Trailer and current DMB Header
908  if( !uniqueALCT ) currentChamber = -1;
909  // Check if this ALCT record have to exist according to DMB Header
910  if( DAV_ALCT ) DAV_ALCT = false;
911  else DAV_ALCT = true;
912 
913  if( !fALCT_Header )
914  {
915  fERROR[8] = true;
916  bERROR |= 0x100;
917  fCHAMB_ERR[8].insert(currentChamber);
918  bCHAMB_ERR[currentChamber] |= 0x100;
919  fCHAMB_ERR[0].insert(currentChamber);
920  bCHAMB_ERR[currentChamber] |= 0x1;
921  } // ALCT Header is missing
922 
923  if( !fALCT_Format2007 && (buf0[0]&0xF800)!=0xD000 )
924  {
925  fERROR[11] = true;
926  bERROR |= 0x800;
927  fCHAMB_ERR[11].insert(currentChamber);
928  bCHAMB_ERR[currentChamber] |= 0x800;
929  fCHAMB_ERR[0].insert(currentChamber);
930  bCHAMB_ERR[currentChamber] |= 0x1;
931  } // some bits in 1st D-Trailer are lost
932 
933 #ifdef LOCAL_UNPACK
934  /*
936  COUT << " ALCT Word Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
937  COUT << " ALCT Word Expected: " << ALCT_WordsExpected << std::endl;
938  COUT << " ALCT Word Since Last Header Zero Supressed: " << ALCT_WordsSinceLastHeaderZeroSuppressed << std::endl;
939  */
940 #endif
941  if( checkCrcALCT )
943  {
944  uint32_t crc = ( fALCT_Format2007 ? buf0[1] : buf0[0] ) & 0x7ff;
945  crc |= ((uint32_t)( ( fALCT_Format2007 ? buf0[2] : buf0[1] ) & 0x7ff)) << 11;
946  if( ALCT_CRC != crc )
947  {
948  fERROR[10] = true;
949  bERROR |= 0x400;
950  fCHAMB_ERR[10].insert(currentChamber);
951  bCHAMB_ERR[currentChamber] |= 0x400;
952  fCHAMB_ERR[0].insert(currentChamber);
953  bCHAMB_ERR[currentChamber] |= 0x1;
954  }
955  }
956 
957  fALCT_Header = false;
958  uniqueALCT = false;
959  CFEB_CRC = 0;
960  //ALCT_WordCount = (buf0[3]&0x03FF);
961  ALCT_WordCount = (buf0[3]&0x07FF);
962  //ALCT_WordCount = (buf0[3]&0x0FFF);
964 #ifdef LOCAL_UNPACK
965  COUT << "A> ";
966 #endif
967  }
968 
969  // Calculation of CRC sum ( algorithm is written by Madorsky )
970  if( fALCT_Header && checkCrcALCT )
971  {
972  for(uint16_t j=0, w=0; j<4; ++j)
973  {
975  w = buf0[j] & (fALCT_Format2007 ? 0xffff : 0x7fff);
976  for(uint32_t i=15, t=0, ncrc=0; i<16; i--)
977  {
978  t = ((w >> i) & 1) ^ ((ALCT_CRC >> 21) & 1);
979  ncrc = (ALCT_CRC << 1) & 0x3ffffc;
980  ncrc |= (t ^ (ALCT_CRC & 1)) << 1;
981  ncrc |= t;
982  ALCT_CRC = ncrc;
983  }
984  }
985  }
986 
987  // == Find Correction for TMB_WordsExpected due to RPC raw hits,
988  // should it turn out to be the new RPC-aware format
989  if( fTMB_Header && ((buf0[2]&0xFFFF)==0x6E0B) )
990  {
991  if (fTMB_Format2007)
992  {
993  if (TMB_Firmware_Revision >= 0x50c3) // TMB2007 rev.0x50c3
994  {
995  // On/off * nRPCs * nTimebins * 2 words/RPC/bin
996  TMB_WordsRPC = ((buf_1[0]&0x0010)>>4) * ((buf_1[0]&0x000c)>>2) * ((buf_1[0]>>5) & 0x1F) * 2;
997  }
998  else // TMB2007 (may not work since TMB_Tbins != RPC_Tbins)
999  {
1000  TMB_WordsRPC = ((buf_1[0]&0x0040)>>6) * ((buf_1[0]&0x0030)>>4) * TMB_Tbins * 2;
1001  }
1002  }
1003  else // Old format
1004  {
1005  TMB_WordsRPC = ((buf_1[2]&0x0040)>>6) * ((buf_1[2]&0x0030)>>4) * TMB_Tbins * 2;
1006  }
1007  TMB_WordsRPC += 2; // add header/trailer for block of RPC raw hits
1008  }
1009 
1010 
1011 
1012  // Check for RPC data
1013  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B04)>=0) )
1014  {
1015  fTMB_RPC_Start = true;
1016  }
1017 
1018  // Check for Scope data
1019  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B05)>=0) )
1020  {
1021  fTMB_Scope_Start = true;
1022  }
1023 
1024  // Check for Mini-Scope data
1025  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B07)>=0) )
1026  {
1027  fTMB_MiniScope_Start = true;
1028  }
1029 
1030  // Check for Blocked CFEBs data
1031  if ( fTMB_Header && (scanbuf(buf0,4, 0x6BCB)>=0) )
1032  {
1033  fTMB_BlockedCFEBs_Start = true;
1034  }
1035 
1036 
1037  // Check for end of RPC data
1038  if ( fTMB_Header && fTMB_RPC_Start
1039  && (scanbuf(buf0,4, 0x6E04)>=0) )
1040  {
1041  fTMB_RPC = true;
1042  }
1043 
1044  // Check for end of Scope data
1045  if ( fTMB_Header && fTMB_Scope_Start
1046  && (scanbuf(buf0,4, 0x6E05)>=0) )
1047  {
1048  fTMB_Scope = true;
1049  }
1050 
1051  // Check for end of Mini-Scope data
1052  if ( fTMB_Header && fTMB_MiniScope_Start
1053  && (scanbuf(buf0,4, 0x6E07)>=0) )
1054  {
1055  fTMB_MiniScope = true;
1056  }
1057 
1058  // Check for end of Blocked CFEBs data
1059  if ( fTMB_Header && fTMB_BlockedCFEBs_Start
1060  && (scanbuf(buf0,4, 0x6ECB)>=0) )
1061  {
1062  fTMB_BlockedCFEBs = true;
1063  }
1064 
1065  /*
1066  if ( fTMB_Header && (scanbuf(buf0,4, 0x6E04)>=0) ) {
1067  TMB_WordsExpected += TMB_WordsRPC;
1068  }
1069  */
1070 
1071  // == TMB Trailer found
1072  if(
1073  // Old TMB data format; last condition in needed not to confuse if with new ALCT data header
1074  ((buf0[0]&0xF000)==0xD000 && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xFFFF)==0xDE0F && (buf0[3]&0xF000)==0xD000 && !fTMB_Format2007 && !(fALCT_Header&&fALCT_Format2007)) ||
1075  // New TMB data format
1076  ( buf0[0]== 0xDE0F && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xF000)==0xD000 && (buf0[3]&0xF000)==0xD000 && fTMB_Format2007 )
1077  )
1078  {
1079 
1080  // Second TMB -> Lost both previous DMB Trailer and current DMB Header
1081  if( !uniqueTMB ) currentChamber = -1;
1082  // Check if this TMB record have to exist according to DMB Header
1083  if( DAV_TMB ) DAV_TMB = false;
1084  else DAV_TMB = true;
1085 
1086  if(!fTMB_Header)
1087  {
1088  fERROR[13] = true;
1089  bERROR |= 0x2000;
1090  fCHAMB_ERR[13].insert(currentChamber);
1091  bCHAMB_ERR[currentChamber] |= 0x2000;
1092  fCHAMB_ERR[0].insert(currentChamber);
1093  bCHAMB_ERR[currentChamber] |= 0x1;
1094  } // TMB Header is missing
1095 
1096  // Check calculated CRC sum against reported
1097  if( checkCrcTMB )
1098  {
1099  uint32_t crc = ( fTMB_Format2007 ? buf0[1]&0x7ff : buf0[0]&0x7ff );
1100  crc |= ((uint32_t)( ( fTMB_Format2007 ? buf0[2]&0x7ff : buf0[1] & 0x7ff ) )) << 11;
1101  if( TMB_CRC != crc )
1102  {
1103  fERROR[15] = true;
1104  bERROR |= 0x8000;
1105  fCHAMB_ERR[15].insert(currentChamber);
1106  bCHAMB_ERR[currentChamber] |= 0x8000;
1107  fCHAMB_ERR[0].insert(currentChamber);
1108  bCHAMB_ERR[currentChamber] |= 0x1;
1109  }
1110  }
1111 
1112  fTMB_Header = false;
1113  uniqueTMB = false;
1114  CFEB_CRC = 0;
1115  TMB_WordCount = (buf0[3]&0x07FF);
1116 
1117  // == Correct TMB_WordsExpected
1118  // 1) for 2 optional 0x2AAA and 0x5555 Words in the Trailer
1119  // 2) for extra 4 frames in the new TMB trailer and
1120  // for RPC raw hit data, if present
1121  //
1122  // If the scope data was enabled in readout, scope data markers (0x6B05
1123  // and 0x6E05) appear before 0x6E0C, and the optional 0x2AAA and 0x5555
1124  // trailer words are suppressed. So far, we only have data with the
1125  // empty scope content, so more corrections will be needed once
1126  // non-empty scope data is available. -SV, 5 Nov 2008.
1127  //
1128  // If word count is not multiple of 4, add 2 optional words and
1129  // 4 trailer words.
1130 
1131  int pos = scanbuf(buf_1,4,0x6E0C);
1132  if (pos==1)
1133  {
1134  TMB_WordsExpected += 6;
1135  }
1136  // If word count is multiple of 4, add 4 trailer words.
1137  else if (pos==3)
1138  {
1139  TMB_WordsExpected += 4;
1140  }
1141 
1142  // Correct expected wordcount by RPC data size
1143  if (fTMB_RPC)
1145 
1146  // Correct expected wordcount by MiniScope data size (22 words + 2 signature words)
1147  if (fTMB_MiniScope)
1148  TMB_WordsExpected += 24;
1149 
1150  // Correct expected wordcount by BlockedCFEBs data size (20 words + 2 signature words)
1151  if (fTMB_BlockedCFEBs)
1152  TMB_WordsExpected += 22;
1153 
1155 #ifdef LOCAL_UNPACK
1156  COUT << "T> ";
1157 #endif
1158  }
1159 
1160  if( fTMB_Header && checkCrcTMB )
1161  {
1162  for(uint16_t j=0, w=0; j<4; ++j)
1163  {
1165  w = buf0[j] & (fTMB_Format2007 ? 0xffff : 0x7fff);
1166  for(uint32_t i=15, t=0, ncrc=0; i<16; i--)
1167  {
1168  t = ((w >> i) & 1) ^ ((TMB_CRC >> 21) & 1);
1169  ncrc = (TMB_CRC << 1) & 0x3ffffc;
1170  ncrc |= (t ^ (TMB_CRC & 1)) << 1;
1171  ncrc |= t;
1172  TMB_CRC = ncrc;
1173  }
1174  }
1175  }
1176 
1177 
1178  // == CFEB Sample Trailer found
1179 
1180  if( ((buf0[1]&0xF000)==0x7000) &&
1181  ((buf0[2]&0xF000)==0x7000) &&
1182  ((buf0[1]!=0x7FFF) || (buf0[2]!=0x7FFF)) &&
1183  ( ((buf0[3]&0xFFFF)==0x7FFF) || // old format
1184  ( (buf0[3]&buf0[0])==0x0000 && (buf0[3]+buf0[0])==0x7FFF ) // 2007 format
1185  ) )
1186  {
1187 #ifdef LOCAL_UNPACK
1188  if((CFEB_SampleCount%8) == 0 )
1189  {
1190  COUT<<" <";
1191  }
1192  if( CFEB_SampleWordCount == 100 )
1193  {
1194  COUT<<"+";
1195  }
1196 #endif
1197  if( CFEB_SampleWordCount != 100 )
1198  {
1199 #ifdef LOCAL_UNPACK
1200  COUT<<"-";
1201 #endif
1202 
1203  fERROR[16] = true;
1204  bERROR |= 0x10000;
1205  fCHAMB_ERR[16].insert(currentChamber);
1206  bCHAMB_ERR[currentChamber] |= 0x10000;
1207  fCHAMB_ERR[0].insert(currentChamber);
1208  bCHAMB_ERR[currentChamber] |= 0x1;
1209  }
1210 
1211  ++CFEB_SampleCount;
1212 
1213  if( (CFEB_SampleCount%8)==0 )
1214  {
1215 #ifdef LOCAL_UNPACK
1216  COUT<<">";
1217 #endif
1219  // Count CFEBs
1220  DAV_CFEB--;
1221  }
1222 
1223  // Check calculated CRC sum against reported
1224  if( checkCrcCFEB && CFEB_CRC!=buf0[0] )
1225  {
1226  fERROR[18] = true;
1227  bERROR |= 0x40000;
1228  fCHAMB_ERR[18].insert(currentChamber);
1229  bCHAMB_ERR[currentChamber] |= 0x40000;
1230  fCHAMB_ERR[0].insert(currentChamber);
1231  bCHAMB_ERR[currentChamber] |= 0x1;
1232  }
1233 
1234  CFEB_CRC = 0;
1236  }
1237 
1238 
1239  // == CFEB B-word found
1240  if( (buf0[0]&0xF000)==0xB000 && (buf0[1]&0xF000)==0xB000 && (buf0[2]&0xF000)==0xB000 && (buf0[3]&0xF000)==0xB000 )
1241  {
1242  bCHAMB_STATUS[currentChamber] |= 0x400000;
1243 
1244 #ifdef LOCAL_UNPACK
1245  if( (CFEB_SampleCount%8)==0 )
1246  {
1247  COUT<<" <";
1248  }
1249  COUT<<"B";
1250 #endif
1251 
1252  ++CFEB_SampleCount;
1254 
1255  if( (CFEB_SampleCount%8)==0 )
1256  {
1257 #ifdef LOCAL_UNPACK
1258  COUT << ">";
1259 #endif
1261  DAV_CFEB--;
1262  }
1263 
1265  }
1266 
1267  // == If it is neither ALCT record nor TMB - probably it is CFEB record and we try to count CRC sum.
1268  // It very few words of CFEB occasionaly will be misinterpreted as ALCT or TMB header the result
1269  // for the CRC sum will be wrong, but other errors of Trailers counting will appear as well
1271  for(int pos=0; pos<4; ++pos)
1272  CFEB_CRC=(buf0[pos]&0x1fff)^((buf0[pos]&0x1fff)<<1)^(((CFEB_CRC&0x7ffc)>>2)|((0x0003&CFEB_CRC)<<13))^((CFEB_CRC&0x7ffc)>>1);
1273 
1274 
1275  // == DMB F-Trailer found
1276  if( (buf0[0]&0xF000)==0xF000 && (buf0[1]&0xF000)==0xF000 && (buf0[2]&0xF000)==0xF000 && (buf0[3]&0xF000)==0xF000 )
1277  {
1278  if(!fDMB_Header)
1279  {
1280  currentChamber = buf0[3]&0x0FFF;
1281  fERROR[6] = true;
1282  bERROR |= 0x40;
1283  fCHAMB_ERR[6].insert(currentChamber);
1284  bCHAMB_ERR[currentChamber] |= 0x40;
1285  nDMBs++;
1286  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
1287  if( buf0[0]&0x0400 ) bCHAMB_PAYLOAD[currentChamber] |= 0x20;
1288  if( buf0[0]&0x0800 ) bCHAMB_PAYLOAD[currentChamber] |= 0x40;
1289  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0]&0x001f)<<7;
1290  bCHAMB_PAYLOAD[currentChamber] |=((buf0[0]>>5)&0x1f);
1291 
1292  } // DMB Header is missing
1293  fDMB_Header = false;
1294  fDMB_Trailer = true;
1295  uniqueALCT = true;
1296  uniqueTMB = true;
1297 
1299 
1300  // Finally check if DAVs were correct
1301  checkDAVs();
1302 
1303  // If F-Trailer is lost then do necessary work here
1304  if( (buf1[0]&0xF000)!=0xE000 || (buf1[1]&0xF000)!=0xE000 || (buf1[2]&0xF000)!=0xE000 || (buf1[3]&0xF000)!=0xE000 )
1305  {
1306  for(int err=1; err<nERRORS; ++err)
1307  if( fCHAMB_ERR[err].find(currentChamber) != fCHAMB_ERR[err].end() )
1308  {
1309  fCHAMB_ERR[0].insert(currentChamber);
1310  bCHAMB_ERR[currentChamber] |= 0x1;
1311  }
1312  // Reset chamber id
1313  currentChamber=-1;
1314  /*
1315  for(int err=0; err<nERRORS; err++)
1316  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1317  fCHAMB_ERR[err].erase(-1);
1318  bCHAMB_ERR[-1] = 0;
1319  bCHAMB_WRN[-1] = 0;
1320  */
1321  }
1322 #ifdef LOCAL_UNPACK
1323  // Print DMB F-Trailer marker
1324  COUT << " }";
1325 #endif
1326  }
1327 
1328  // == DMB E-Trailer found
1329  if( (buf0[0]&0xF000)==0xE000 && (buf0[1]&0xF000)==0xE000 && (buf0[2]&0xF000)==0xE000 && (buf0[3]&0xF000)==0xE000 )
1330  {
1331  if( !fDMB_Header && !fDMB_Trailer ) nDMBs++; // both DMB Header and DMB F-Trailer were missing
1332 
1333  if (fFormat2013)
1334  {
1336  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0800)>>11;
1337  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0400)>>9;
1338  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0080)<<8;
1339 
1340  if( fDMB_Trailer ) // F-Trailer exists
1341  {
1342  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0E00)>>9;
1343  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0003)<<3;
1344  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x000C)<<21;
1345  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0800)>>4;
1346  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0100);
1347  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x01f0)<<5;
1348  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0600)<<16;
1349  bCHAMB_STATUS[currentChamber] |= (buf_1[0]&0x0800)<<3;
1350  bCHAMB_STATUS[currentChamber] |= (buf_1[1]&0x001f)<<16;
1351  bCHAMB_STATUS[currentChamber] |= (buf_1[1]&0x0060)<<21;
1352 
1353  }
1354 
1355  }
1356  else
1357  {
1358  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0800)>>11;
1359  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0400)>>9;
1360  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x03E0)>>3;
1361 
1362  if( fDMB_Trailer ) // F-Trailer exists
1363  {
1364  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0002)<<6;
1365  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0001)<<8;
1366  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x001f)<<9;
1367  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0040)<<8;
1368  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0020)<<10;
1369  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0f80)<<9;
1370  }
1371 
1372  }
1373  fDMB_Header = false;
1374 
1375  // If chamber id is unknown it is time to find it out
1376  if( currentChamber==-1 )
1377  {
1378  currentChamber = buf0[1]&0x0FFF;
1379  for(int err=0; err<nERRORS; ++err)
1380  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1381  {
1382  fCHAMB_ERR[err].insert(currentChamber);
1383  fCHAMB_ERR[err].erase(-1);
1384  }
1386  bCHAMB_STATUS[-1] = 0;
1388  bCHAMB_ERR[-1] = 0;
1390  bCHAMB_WRN[-1] = 0;
1391  }
1392  ++cntCHAMB_Trailers[buf0[1]&0x0FFF];
1393 
1395 
1396  // Lost DMB F-Trailer before
1397  if( !fDMB_Trailer )
1398  {
1399  fERROR[6] = true;
1400  bERROR |= 0x40;
1401  fCHAMB_ERR[6].insert(currentChamber);
1402  bCHAMB_ERR[currentChamber] |= 0x40;
1403  fCHAMB_ERR[0].insert(currentChamber);
1404  bCHAMB_ERR[currentChamber] |= 0x1;
1405  // Check if DAVs were correct here
1406  checkDAVs();
1407  }
1408  fDMB_Trailer = false;
1409 
1410 #ifdef LOCAL_UNPACK
1411  // Print DMB E-Trailer marker
1412  COUT<<" DMB="<<(buf0[1]&0x000F);
1413  COUT << "; "
1414  << ALCT_WordsSinceLastHeader << "-"
1415  << ALCT_WordCount << "-"
1417  << " "
1418  << TMB_WordsSinceLastHeader << "-"
1419  << TMB_WordCount << "-"
1421  << endl;
1422 #endif
1423 
1425 
1426  //
1427  for(int err=0; err<nERRORS; ++err)
1428  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1429  {
1430  fCHAMB_ERR[err].erase(-1);
1431  fCHAMB_ERR[err].insert(-2);
1432  }
1433  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1434  bCHAMB_STATUS[-1] = 0;
1435  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1436  bCHAMB_ERR[-1] = 0;
1437  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1438  bCHAMB_WRN[-1] = 0;
1439 
1440  if( currentChamber != -1 )
1441  for(int err=1; err<nERRORS; ++err)
1442  if( fCHAMB_ERR[err].find(currentChamber) != fCHAMB_ERR[err].end() )
1443  {
1444  fCHAMB_ERR[0].insert(currentChamber);
1445  bCHAMB_ERR[currentChamber] |= 0x1;
1446  }
1447 
1448  currentChamber=-1;
1449 #ifdef LOCAL_UNPACK
1450  /*
1451  // Print DMB E-Trailer marker
1452  COUT<<" DMB="<<(buf0[1]&0x000F);
1453  COUT << "; "
1454  << ALCT_WordsSinceLastHeader << "-"
1455  << ALCT_WordCount << "-"
1456  << ALCT_WordsExpected
1457  << " "
1458  << TMB_WordsSinceLastHeader << "-"
1459  << TMB_WordCount << "-"
1460  << TMB_WordsExpected
1461  << endl;
1462  */
1463 #endif
1464  }
1465 
1466  // == DDU Trailer found
1467  if( buf0[0]==0x8000 && buf0[1]==0x8000 && buf0[2]==0xFFFF && buf0[3]==0x8000 )
1468  {
1469 
1471  checkDAVs();
1472 
1474 
1476 
1477  if( DDU_WordsSinceLastHeader>3 && !nDMBs )
1478  {
1479  fERROR[28]=true;
1480  bERROR|=0x10000000;;
1481  }
1482 
1483  if(fDDU_Trailer)
1484  {
1485  fERROR[2] = true;
1486  bERROR |= 0x4;
1487  } // DDU Header is missing
1488  fDDU_Trailer=true;
1489  fDDU_Header=false;
1490 
1491  if( fDMB_Header || fDMB_Trailer )
1492  {
1493 #ifdef LOCAL_UNPACK
1494  COUT << " Ex-Err: DMB (Header, Trailer) " << std::endl;
1495 #endif
1496  fERROR[5] = true;
1497  bERROR |= 0x20;
1498  fCHAMB_ERR[5].insert(currentChamber);
1499  bCHAMB_ERR[currentChamber] |= 0x20;
1500  fCHAMB_ERR[0].insert(currentChamber);
1501  bCHAMB_ERR[currentChamber] |= 0x20;
1502  } // DMB Trailer is missing
1503  fDMB_Header = false;
1504  fDMB_Trailer = false;
1505 
1506  currentChamber=-1;
1507 
1508  for(int err=0; err<nERRORS; ++err)
1509  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1510  {
1511  fCHAMB_ERR[err].erase(-1);
1512  fCHAMB_ERR[err].insert(-2);
1513  }
1514  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1515  bCHAMB_STATUS[-1] = 0;
1516  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1517  bCHAMB_ERR[-1] = 0;
1518  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1519  bCHAMB_WRN[-1] = 0;
1520 
1521  for(int err=1; err<nERRORS; ++err)
1522  if( fCHAMB_ERR[err].find(-2) != fCHAMB_ERR[err].end() )
1523  {
1524  fCHAMB_ERR[0].insert(-2);
1525  bCHAMB_ERR[-2] |= 0x1;
1526  }
1527 
1529 
1530  ++cntDDU_Trailers; // Increment DDUTrailer counter
1531 
1532  // == Combining 2 words into 24bit value
1533  DDU_WordCount = buf2[2] | ((buf2[3] & 0xFF) <<16) ;
1534 
1536  {
1537  fERROR[4] = true;
1538  bERROR |= 0x10;
1539  }
1540 
1541  if( DMB_Active!=nDMBs )
1542  {
1543  fERROR[24] = true;
1544  bERROR |= 0x1000000;
1545  }
1546 
1547 #ifdef LOCAL_UNPACK
1548  COUT<<"DDU Trailer Occurrence "<<cntDDU_Trailers<<endl;
1549  COUT<<"----------------------------------------------------------"<<endl;
1550  COUT<<"DDU 64-bit words = Actual - DDUcounted ="<<DDU_WordsSinceLastHeader+4<<"-"<<DDU_WordCount<<endl;
1551 #endif
1552 
1553  // increment statistics Errors and Warnings (i=0 case is handled in DDU Header)
1554  for(int err=1; err<nERRORS; ++err)
1555  {
1556  if( fERROR[err] )
1557  {
1558  fERROR[0] = true;
1559  bERROR |= 0x1;
1560 #ifdef LOCAL_UNPACK
1561  CERR<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
1562  CERR<<" ERROR "<<err<<" " <<sERROR[err]<<endl;
1563 #endif
1564  }
1565  }
1566 
1567 #ifdef LOCAL_UNPACK
1568  for(int wrn=1; wrn<nWARNINGS; ++wrn)
1569  {
1570  if( fWARNING[wrn] )
1571  {
1572  COUT<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
1573  COUT<<" WARNING "<<wrn<<" "<<sWARNING[wrn]<<endl;
1574  }
1575  }
1576 #endif
1577 
1578  bDDU_ERR[sourceID] |= bERROR;
1580  sync_stats();
1581 
1584  if (modeDDUonly)
1585  {
1586  buffer+=4;
1587  buf_1 = &(tmpbuf[0]); // Just for safety
1588  buf0 = &(tmpbuf[4]); // Just for safety
1589  buf1 = &(tmpbuf[8]); // Just for safety
1590  buf2 = &(tmpbuf[12]); // Just for safety
1591  bzero(tmpbuf, sizeof(uint16_t)*16);
1592  return length-4;
1593  }
1594  }
1595 
1596  if (!modeDDUonly)
1597  {
1598  // DCC Trailer 1 && DCC Trailer 2
1599  // =VB= Added support for Sep. 2008 CMS DAQ DCC format
1600  // =VB= 04.18.09 Removed (buf2[0]&0x0003) == 0x3 check for old DCC format to satisfy older format of simulated data
1601  if( (buf1[3]&0xFF00) == 0xEF00 &&
1602  ( ((buf2[3]&0xFF00) == 0xAF00 )
1603  ||
1604  (( buf2[3]&0xFF00) == 0xA000 && (buf2[0]&0x0003) == 0x0) ) )
1605  {
1606  // =VB= Added check that there is no DCCHeader detected to set missing DCC Header error
1607  if(!fDCC_Header || fDCC_Trailer)
1608  {
1609  fERROR[26] = true;
1610  bERROR|=0x4000000;
1611  fERROR[0] = true;
1612  bERROR|=0x1;
1613  } // DCC Header is missing
1614  fDCC_Trailer=true;
1615  fDCC_Header=false;
1616 
1617  if( fDDU_Header )
1618  {
1619  // == DDU Trailer is missing
1620  fERROR[1]=true;
1621  bERROR|=0x2;
1622  fERROR[0] = true;
1623  bERROR|=0x1;
1624  }
1625 
1626  buffer+=4;
1627  buf_1 = &(tmpbuf[0]); // Just for safety
1628  buf0 = &(tmpbuf[4]); // Just for safety
1629  buf1 = &(tmpbuf[8]); // Just for safety
1630  buf2 = &(tmpbuf[12]); // Just for safety
1631  bzero(tmpbuf, sizeof(uint16_t)*16);
1632  sync_stats();
1633  return length-4;
1634  }
1635  }
1636 
1637  length-=4;
1638  buffer+=4;
1639  }
1640  //Store the tail of the buffer
1641  buf_1 = &(tmpbuf[0]);
1642  buf0 = &(tmpbuf[4]);
1643  buf1 = &(tmpbuf[8]);
1644  buf2 = &(tmpbuf[12]);
1645  memcpy((void*)tmpbuf,(void*)(buffer-16),sizeof(short)*16);
1646 
1647  if (!modeDDUonly && !fDCC_Trailer && !fDCC_Header)
1648  {
1649  fERROR[26] = true;
1650  bERROR|=0x4000000;
1651  fERROR[25] = true;
1652  bERROR|=0x2000000;
1653  fERROR[0]=true;
1654  bERROR|=0x1;
1655  sync_stats();
1656  return length;
1657 
1658  }
1659 
1660  return -2;
1661 }
1662 
1663 
1665 {
1666  bzero(fERROR, sizeof(bool)*nERRORS);
1667  bzero(fWARNING, sizeof(bool)*nWARNINGS);
1668  bzero(fSUM_ERROR, sizeof(bool)*nERRORS);
1669  bzero(fSUM_WARNING, sizeof(bool)*nWARNINGS);
1670  bERROR = 0;
1671  bWARNING = 0;
1672  bSUM_ERROR = 0;
1673  bSUM_WARNING = 0;
1674  for(int err=0; err<nERRORS; ++err) fCHAMB_ERR[err].clear();
1675  for(int wrn=0; wrn<nWARNINGS; ++wrn) fCHAMB_WRN[wrn].clear();
1676  bCHAMB_ERR.clear();
1677  bCHAMB_WRN.clear();
1678  bCHAMB_PAYLOAD.clear();
1679  bCHAMB_STATUS.clear();
1680  bDDU_ERR.clear();
1681  bDDU_WRN.clear();
1682  dduBuffers.clear();
1683  dduOffsets.clear();
1684  dmbBuffers.clear();
1685  dmbOffsets.clear();
1686  dduSize.clear();
1687  dmbSize.clear();
1688 }
1689 
1690 
1692 {
1695  ALCT_WordCount = 0;
1696  ALCT_WordsExpected = 0;
1697  ALCT_ZSE = 0;
1699  TMB_WordCount = 0;
1700  TMB_WordsExpected = 0;
1701  TMB_Tbins = 0;
1703  CFEB_SampleCount = 0;
1704  CFEB_BSampleCount = 0;
1705 }
1706 
1707 
1709 {
1710  if( DAV_ALCT )
1711  {
1712  fERROR[21] = true;
1713  bERROR |= 0x200000;
1714  fCHAMB_ERR[21].insert(currentChamber);
1715  bCHAMB_ERR[currentChamber] |= 0x200000;
1716  DAV_ALCT = false;
1717  }
1718  if( DAV_TMB )
1719  {
1720  fERROR[22] = true;
1721  bERROR |= 0x400000;
1722  fCHAMB_ERR[22].insert(currentChamber);
1723  bCHAMB_ERR[currentChamber] |= 0x400000;
1724  DAV_TMB = false;
1725  }
1726  if( DAV_CFEB && DAV_CFEB!=-16)
1727  {
1728  fERROR[23] = true;
1729  bERROR |= 0x800000;
1730  fCHAMB_ERR[23].insert(currentChamber);
1731  bCHAMB_ERR[currentChamber] |= 0x800000;
1732  DAV_CFEB = 0;
1733  }
1734 }
1735 
1736 
1738 {
1739 #ifdef LOCAL_UNPACK
1740  /*
1741  COUT << " Ex-ALCT-Word-count " << std::endl;
1742  COUT << " ALCT Words Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
1743  COUT << " ALCT Word Count: " << ALCT_WordCount << std::endl;
1744  COUT << " ALCT Words Expected: " << ALCT_WordsExpected << std::endl;
1745  */
1746 #endif
1748  && ALCT_ZSE==0 )
1749  {
1750  fERROR[9] = true;
1751  bERROR |= 0x200;
1752  fCHAMB_ERR[9].insert(currentChamber);
1753  bCHAMB_ERR[currentChamber] |= 0x200;
1755  ALCT_WordCount = 0;
1757  ALCT_WordsExpected = 0;
1758  } // ALCT Word Count Error
1759 
1762  {
1763  fERROR[9] = true;
1764  bERROR |= 0x200;
1765  fCHAMB_ERR[9].insert(currentChamber);
1766  bCHAMB_ERR[currentChamber] |= 0x200;
1769  ALCT_WordCount = 0;
1771  ALCT_WordsExpected = 0;
1772  } // ALCT Word Count Error With zero suppression
1773 
1775  {
1776  fERROR[14] = true;
1777  bERROR |= 0x4000;
1778  fCHAMB_ERR[14].insert(currentChamber);
1779  bCHAMB_ERR[currentChamber] |= 0x4000;
1781  TMB_WordCount = 0;
1783  TMB_WordsExpected = 0;
1784  } // TMB Word Count Error
1785 
1786  if( (CFEB_SampleCount%8)!=0 )
1787  {
1788  fERROR[17] = true;
1789  bERROR |= 0x20000;
1790  fCHAMB_ERR[17].insert(currentChamber);
1791  bCHAMB_ERR[currentChamber] |= 0x20000;
1792  CFEB_SampleCount = 0;
1793  } // Number of CFEB samples != 8*n
1794 
1795  if(fALCT_Header)
1796  {
1797  fERROR[7] = true; // ALCT Trailer is missing
1798  bERROR |= 0x80;
1799  fCHAMB_ERR[7].insert(currentChamber);
1800  bCHAMB_ERR[currentChamber] |= 0x80;
1803  ALCT_WordsExpected = 0;
1804  fALCT_Header = 0;
1805  }
1806 
1807  if(fTMB_Header)
1808  {
1809  fERROR[12]=true; // TMB Trailer is missing
1810  bERROR |= 0x1000;
1811  fCHAMB_ERR[12].insert(currentChamber);
1812  bCHAMB_ERR[currentChamber] |= 0x1000;
1814  TMB_WordsExpected = 0;
1815  fTMB_Header = false;
1816  }
1817 }
1818 
1820 {
1821  for (int err=0; err<nERRORS; ++err)
1822  fSUM_ERROR[err] |= fERROR[err];
1823  for (int wrn=0; wrn<nWARNINGS; ++wrn)
1824  fSUM_WARNING[wrn] |= fWARNING[wrn];
1825  bSUM_ERROR |= bERROR;
1827 }
1828 
1829 inline int CSCDCCExaminer::scanbuf(const uint16_t* &buffer, int32_t length, uint16_t sig, uint16_t mask)
1830 {
1831  for (int i=0; i<length; i++)
1832  {
1833  if ( (buffer[i]&mask) == sig)
1834  {
1835  return i;
1836  }
1837  }
1838  return -1;
1839 }
1840 
uint32_t DDU_WordsSinceLastHeader
uint32_t TMB_WordCount
const uint16_t * buf0
const uint16_t * buffer_start
void crcCFEB(bool enable)
int i
Definition: DBlmapReader.cc:9
uint32_t CFEB_SampleWordCount
std::map< CSCIdType, ExaminerStatusType > bCHAMB_ERR
std::set< CSCIdType > fCHAMB_ERR[29]
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:7
void crcALCT(bool enable)
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)
int j
Definition: DBlmapReader.cc:9
ExaminerStatusType bSUM_ERROR
uint32_t TMB_WordsRPC
uint32_t TMB_Tbins
#define end
Definition: vmac.h:37
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
#define COUT
tuple cout
Definition: gather_cfg.py:121
std::vector< const char * > sDMBEventStaus
T w() const
std::map< DDUIdType, uint32_t > dduOffsets
uint32_t ExaminerMaskType
std::vector< const char * > sERROR_
std::map< DDUIdType, ExaminerStatusType > bDDU_WRN
uint32_t cntDDU_Trailers