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 
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  if (TMB_Firmware_Revision >= 0x50c3) // TMB2007 rev.0x50c3
1005  {
1006  // On/off * nRPCs * nTimebins * 2 words/RPC/bin
1007  TMB_WordsRPC = ((buf_1[0]&0x0010)>>4) * ((buf_1[0]&0x000c)>>2) * ((buf_1[0]>>5) & 0x1F) * 2;
1008  }
1009  else // TMB2007 (may not work since TMB_Tbins != RPC_Tbins)
1010  {
1011  TMB_WordsRPC = ((buf_1[0]&0x0040)>>6) * ((buf_1[0]&0x0030)>>4) * TMB_Tbins * 2;
1012  }
1013  }
1014  else // Old format
1015  {
1016  TMB_WordsRPC = ((buf_1[2]&0x0040)>>6) * ((buf_1[2]&0x0030)>>4) * TMB_Tbins * 2;
1017  }
1018  TMB_WordsRPC += 2; // add header/trailer for block of RPC raw hits
1019  }
1020 
1021 
1022 
1023  // Check for RPC data
1024  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B04)>=0) )
1025  {
1026  fTMB_RPC_Start = true;
1027  }
1028 
1029  // Check for Scope data
1030  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B05)>=0) )
1031  {
1032  fTMB_Scope_Start = true;
1033  }
1034 
1035  // Check for Mini-Scope data
1036  if ( fTMB_Header && (scanbuf(buf0,4, 0x6B07)>=0) )
1037  {
1038  fTMB_MiniScope_Start = true;
1039  }
1040 
1041  // Check for Blocked CFEBs data
1042  if ( fTMB_Header && (scanbuf(buf0,4, 0x6BCB)>=0) )
1043  {
1044  fTMB_BlockedCFEBs_Start = true;
1045  }
1046 
1047 
1048  // Check for end of RPC data
1049  if ( fTMB_Header && fTMB_RPC_Start
1050  && (scanbuf(buf0,4, 0x6E04)>=0) )
1051  {
1052  fTMB_RPC = true;
1053  }
1054 
1055  // Check for end of Scope data
1056  if ( fTMB_Header && fTMB_Scope_Start
1057  && (scanbuf(buf0,4, 0x6E05)>=0) )
1058  {
1059  fTMB_Scope = true;
1060  }
1061 
1062  // Check for end of Mini-Scope data
1063  if ( fTMB_Header && fTMB_MiniScope_Start
1064  && (scanbuf(buf0,4, 0x6E07)>=0) )
1065  {
1066  fTMB_MiniScope = true;
1067  }
1068 
1069  // Check for end of Blocked CFEBs data
1070  if ( fTMB_Header && fTMB_BlockedCFEBs_Start
1071  && (scanbuf(buf0,4, 0x6ECB)>=0) )
1072  {
1073  fTMB_BlockedCFEBs = true;
1074  }
1075 
1076  /*
1077  if ( fTMB_Header && (scanbuf(buf0,4, 0x6E04)>=0) ) {
1078  TMB_WordsExpected += TMB_WordsRPC;
1079  }
1080  */
1081 
1082  // == TMB Trailer found
1083  if(
1084  // Old TMB data format; last condition in needed not to confuse if with new ALCT data header
1085  ((buf0[0]&0xF000)==0xD000 && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xFFFF)==0xDE0F && (buf0[3]&0xF000)==0xD000 && !fTMB_Format2007 && !(fALCT_Header&&fALCT_Format2007)) ||
1086  // New TMB data format
1087  ( buf0[0]== 0xDE0F && (buf0[1]&0xF000)==0xD000 && (buf0[2]&0xF000)==0xD000 && (buf0[3]&0xF000)==0xD000 && fTMB_Format2007 )
1088  )
1089  {
1090 
1091  // Second TMB -> Lost both previous DMB Trailer and current DMB Header
1092  if( !uniqueTMB ) currentChamber = -1;
1093  // Check if this TMB record have to exist according to DMB Header
1094  if( DAV_TMB ) DAV_TMB = false;
1095  else DAV_TMB = true;
1096 
1097  if(!fTMB_Header)
1098  {
1099  fERROR[13] = true;
1100  bERROR |= 0x2000;
1101  fCHAMB_ERR[13].insert(currentChamber);
1102  bCHAMB_ERR[currentChamber] |= 0x2000;
1103  fCHAMB_ERR[0].insert(currentChamber);
1104  bCHAMB_ERR[currentChamber] |= 0x1;
1105  } // TMB Header is missing
1106 
1107  // Check calculated CRC sum against reported
1108  if( checkCrcTMB )
1109  {
1110  uint32_t crc = ( fTMB_Format2007 ? buf0[1]&0x7ff : buf0[0]&0x7ff );
1111  crc |= ((uint32_t)( ( fTMB_Format2007 ? buf0[2]&0x7ff : buf0[1] & 0x7ff ) )) << 11;
1112  if( TMB_CRC != crc )
1113  {
1114  fERROR[15] = true;
1115  bERROR |= 0x8000;
1116  fCHAMB_ERR[15].insert(currentChamber);
1117  bCHAMB_ERR[currentChamber] |= 0x8000;
1118  fCHAMB_ERR[0].insert(currentChamber);
1119  bCHAMB_ERR[currentChamber] |= 0x1;
1120  }
1121  }
1122 
1123  fTMB_Header = false;
1124  uniqueTMB = false;
1125  CFEB_CRC = 0;
1126  TMB_WordCount = (buf0[3]&0x07FF);
1127 
1128  // == Correct TMB_WordsExpected
1129  // 1) for 2 optional 0x2AAA and 0x5555 Words in the Trailer
1130  // 2) for extra 4 frames in the new TMB trailer and
1131  // for RPC raw hit data, if present
1132  //
1133  // If the scope data was enabled in readout, scope data markers (0x6B05
1134  // and 0x6E05) appear before 0x6E0C, and the optional 0x2AAA and 0x5555
1135  // trailer words are suppressed. So far, we only have data with the
1136  // empty scope content, so more corrections will be needed once
1137  // non-empty scope data is available. -SV, 5 Nov 2008.
1138  //
1139  // If word count is not multiple of 4, add 2 optional words and
1140  // 4 trailer words.
1141 
1142  int pos = scanbuf(buf_1,4,0x6E0C);
1143  if (pos==1)
1144  {
1145  TMB_WordsExpected += 6;
1146  }
1147  // If word count is multiple of 4, add 4 trailer words.
1148  else if (pos==3)
1149  {
1150  TMB_WordsExpected += 4;
1151  }
1152 
1153  // Correct expected wordcount by RPC data size
1154  if (fTMB_RPC)
1156 
1157  // Correct expected wordcount by MiniScope data size (22 words + 2 signature words)
1158  if (fTMB_MiniScope)
1159  TMB_WordsExpected += 24;
1160 
1161  // Correct expected wordcount by BlockedCFEBs data size (20 words + 2 signature words)
1162  if (fTMB_BlockedCFEBs)
1163  TMB_WordsExpected += 22;
1164 
1166 #ifdef LOCAL_UNPACK
1167  COUT << "T> ";
1168 #endif
1169  }
1170 
1171  if( fTMB_Header && checkCrcTMB )
1172  {
1173  for(uint16_t j=0, w=0; j<4; ++j)
1174  {
1176  w = buf0[j] & (fTMB_Format2007 ? 0xffff : 0x7fff);
1177  for(uint32_t i=15, t=0, ncrc=0; i<16; i--)
1178  {
1179  t = ((w >> i) & 1) ^ ((TMB_CRC >> 21) & 1);
1180  ncrc = (TMB_CRC << 1) & 0x3ffffc;
1181  ncrc |= (t ^ (TMB_CRC & 1)) << 1;
1182  ncrc |= t;
1183  TMB_CRC = ncrc;
1184  }
1185  }
1186  }
1187 
1188 
1189  // == CFEB Sample Trailer found
1190 
1191  if( ((buf0[1]&0xF000)==0x7000) &&
1192  ((buf0[2]&0xF000)==0x7000) &&
1193  ((buf0[1]!=0x7FFF) || (buf0[2]!=0x7FFF)) &&
1194  ( ((buf0[3]&0xFFFF)==0x7FFF) || // old format
1195  ( (buf0[3]&buf0[0])==0x0000 && (buf0[3]+buf0[0])==0x7FFF ) // 2007 format
1196  ) )
1197  {
1198 #ifdef LOCAL_UNPACK
1199  if((CFEB_SampleCount%8) == 0 )
1200  {
1201  COUT<<" <";
1202  }
1203  if( CFEB_SampleWordCount == 100 )
1204  {
1205  COUT<<"+";
1206  }
1207 #endif
1208  if( CFEB_SampleWordCount != 100 )
1209  {
1210 #ifdef LOCAL_UNPACK
1211  COUT<<"-";
1212 #endif
1213 
1214  fERROR[16] = true;
1215  bERROR |= 0x10000;
1216  fCHAMB_ERR[16].insert(currentChamber);
1217  bCHAMB_ERR[currentChamber] |= 0x10000;
1218  fCHAMB_ERR[0].insert(currentChamber);
1219  bCHAMB_ERR[currentChamber] |= 0x1;
1220  }
1221 
1222  ++CFEB_SampleCount;
1223 
1224  if( (CFEB_SampleCount%8)==0 )
1225  {
1226 #ifdef LOCAL_UNPACK
1227  COUT<<">";
1228 #endif
1230  // Count CFEBs
1231  DAV_CFEB--;
1232  }
1233 
1234  // Check calculated CRC sum against reported
1235  if( checkCrcCFEB && CFEB_CRC!=buf0[0] )
1236  {
1237  fERROR[18] = true;
1238  bERROR |= 0x40000;
1239  fCHAMB_ERR[18].insert(currentChamber);
1240  bCHAMB_ERR[currentChamber] |= 0x40000;
1241  fCHAMB_ERR[0].insert(currentChamber);
1242  bCHAMB_ERR[currentChamber] |= 0x1;
1243  }
1244 
1245  CFEB_CRC = 0;
1247  }
1248 
1249 
1250  // == CFEB B-word found
1251  if( (buf0[0]&0xF000)==0xB000 && (buf0[1]&0xF000)==0xB000 && (buf0[2]&0xF000)==0xB000 && (buf0[3]&0xF000)==0xB000 )
1252  {
1253  bCHAMB_STATUS[currentChamber] |= 0x400000;
1254 
1255 #ifdef LOCAL_UNPACK
1256  if( (CFEB_SampleCount%8)==0 )
1257  {
1258  COUT<<" <";
1259  }
1260  COUT<<"B";
1261 #endif
1262 
1263  ++CFEB_SampleCount;
1265 
1266  if( (CFEB_SampleCount%8)==0 )
1267  {
1268 #ifdef LOCAL_UNPACK
1269  COUT << ">";
1270 #endif
1272  DAV_CFEB--;
1273  }
1274 
1276  }
1277 
1278  // == If it is neither ALCT record nor TMB - probably it is CFEB record and we try to count CRC sum.
1279  // It very few words of CFEB occasionaly will be misinterpreted as ALCT or TMB header the result
1280  // for the CRC sum will be wrong, but other errors of Trailers counting will appear as well
1282  for(int pos=0; pos<4; ++pos)
1283  CFEB_CRC=(buf0[pos]&0x1fff)^((buf0[pos]&0x1fff)<<1)^(((CFEB_CRC&0x7ffc)>>2)|((0x0003&CFEB_CRC)<<13))^((CFEB_CRC&0x7ffc)>>1);
1284 
1285 
1286  // == DMB F-Trailer found
1287  if( (buf0[0]&0xF000)==0xF000 && (buf0[1]&0xF000)==0xF000 && (buf0[2]&0xF000)==0xF000 && (buf0[3]&0xF000)==0xF000 )
1288  {
1289  if(!fDMB_Header)
1290  {
1291  currentChamber = buf0[3]&0x0FFF;
1292  fERROR[6] = true;
1293  bERROR |= 0x40;
1294  fCHAMB_ERR[6].insert(currentChamber);
1295  bCHAMB_ERR[currentChamber] |= 0x40;
1296  nDMBs++;
1297  // Set variables if we are waiting ALCT, TMB and CFEB records to be present in event
1298  if( buf0[0]&0x0400 ) bCHAMB_PAYLOAD[currentChamber] |= 0x20;
1299  if( buf0[0]&0x0800 ) bCHAMB_PAYLOAD[currentChamber] |= 0x40;
1300  bCHAMB_PAYLOAD[currentChamber] |= (buf0[0]&0x001f)<<7;
1301  bCHAMB_PAYLOAD[currentChamber] |=((buf0[0]>>5)&0x1f);
1302 
1303  } // DMB Header is missing
1304  fDMB_Header = false;
1305  fDMB_Trailer = true;
1306  uniqueALCT = true;
1307  uniqueTMB = true;
1308 
1310 
1311  // Finally check if DAVs were correct
1312  checkDAVs();
1313 
1314  // If F-Trailer is lost then do necessary work here
1315  if( (buf1[0]&0xF000)!=0xE000 || (buf1[1]&0xF000)!=0xE000 || (buf1[2]&0xF000)!=0xE000 || (buf1[3]&0xF000)!=0xE000 )
1316  {
1317  for(int err=1; err<nERRORS; ++err)
1318  if( fCHAMB_ERR[err].find(currentChamber) != fCHAMB_ERR[err].end() )
1319  {
1320  fCHAMB_ERR[0].insert(currentChamber);
1321  bCHAMB_ERR[currentChamber] |= 0x1;
1322  }
1323  // Reset chamber id
1324  currentChamber=-1;
1325  /*
1326  for(int err=0; err<nERRORS; err++)
1327  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1328  fCHAMB_ERR[err].erase(-1);
1329  bCHAMB_ERR[-1] = 0;
1330  bCHAMB_WRN[-1] = 0;
1331  */
1332  }
1333 #ifdef LOCAL_UNPACK
1334  // Print DMB F-Trailer marker
1335  COUT << " }";
1336 #endif
1337  }
1338 
1339  // == DMB E-Trailer found
1340  if( (buf0[0]&0xF000)==0xE000 && (buf0[1]&0xF000)==0xE000 && (buf0[2]&0xF000)==0xE000 && (buf0[3]&0xF000)==0xE000 )
1341  {
1342  if( !fDMB_Header && !fDMB_Trailer ) nDMBs++; // both DMB Header and DMB F-Trailer were missing
1343 
1344  if (fFormat2013)
1345  {
1347  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0800)>>11;
1348  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0400)>>9;
1349  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0080)<<8;
1350 
1351  if( fDMB_Trailer ) // F-Trailer exists
1352  {
1353  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0E00)>>9;
1354  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0003)<<3;
1355  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x000C)<<21;
1356  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0800)>>4;
1357  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0100);
1358  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x01f0)<<5;
1359  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0600)<<16;
1360  bCHAMB_STATUS[currentChamber] |= (buf_1[0]&0x0800)<<3;
1361  bCHAMB_STATUS[currentChamber] |= (buf_1[1]&0x001f)<<16;
1362  bCHAMB_STATUS[currentChamber] |= (buf_1[1]&0x0060)<<21;
1363 
1364  }
1365 
1366  }
1367  else
1368  {
1369  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0800)>>11;
1370  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x0400)>>9;
1371  bCHAMB_STATUS[currentChamber] |= (buf0[0]&0x03E0)>>3;
1372 
1373  if( fDMB_Trailer ) // F-Trailer exists
1374  {
1375  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0002)<<6;
1376  bCHAMB_STATUS[currentChamber] |= (buf_1[2]&0x0001)<<8;
1377  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x001f)<<9;
1378  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0040)<<8;
1379  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0020)<<10;
1380  bCHAMB_STATUS[currentChamber] |= (buf_1[3]&0x0f80)<<9;
1381  }
1382 
1383  }
1384  fDMB_Header = false;
1385 
1386  // If chamber id is unknown it is time to find it out
1387  if( currentChamber==-1 )
1388  {
1389  currentChamber = buf0[1]&0x0FFF;
1390  for(int err=0; err<nERRORS; ++err)
1391  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1392  {
1393  fCHAMB_ERR[err].insert(currentChamber);
1394  fCHAMB_ERR[err].erase(-1);
1395  }
1397  bCHAMB_STATUS[-1] = 0;
1399  bCHAMB_ERR[-1] = 0;
1401  bCHAMB_WRN[-1] = 0;
1402  }
1403  ++cntCHAMB_Trailers[buf0[1]&0x0FFF];
1404 
1406 
1407  // Lost DMB F-Trailer before
1408  if( !fDMB_Trailer )
1409  {
1410  fERROR[6] = true;
1411  bERROR |= 0x40;
1412  fCHAMB_ERR[6].insert(currentChamber);
1413  bCHAMB_ERR[currentChamber] |= 0x40;
1414  fCHAMB_ERR[0].insert(currentChamber);
1415  bCHAMB_ERR[currentChamber] |= 0x1;
1416  // Check if DAVs were correct here
1417  checkDAVs();
1418  }
1419  fDMB_Trailer = false;
1420 
1421 #ifdef LOCAL_UNPACK
1422  // Print DMB E-Trailer marker
1423  COUT<<" DMB="<<(buf0[1]&0x000F);
1424  COUT << "; "
1425  << ALCT_WordsSinceLastHeader << "-"
1426  << ALCT_WordCount << "-"
1428  << " "
1429  << TMB_WordsSinceLastHeader << "-"
1430  << TMB_WordCount << "-"
1432  << endl;
1433 #endif
1434 
1436 
1437  //
1438  for(int err=0; err<nERRORS; ++err)
1439  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1440  {
1441  fCHAMB_ERR[err].erase(-1);
1442  fCHAMB_ERR[err].insert(-2);
1443  }
1444  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1445  bCHAMB_STATUS[-1] = 0;
1446  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1447  bCHAMB_ERR[-1] = 0;
1448  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1449  bCHAMB_WRN[-1] = 0;
1450 
1451  if( currentChamber != -1 )
1452  for(int err=1; err<nERRORS; ++err)
1453  if( fCHAMB_ERR[err].find(currentChamber) != fCHAMB_ERR[err].end() )
1454  {
1455  fCHAMB_ERR[0].insert(currentChamber);
1456  bCHAMB_ERR[currentChamber] |= 0x1;
1457  }
1458 
1459  currentChamber=-1;
1460 #ifdef LOCAL_UNPACK
1461  /*
1462  // Print DMB E-Trailer marker
1463  COUT<<" DMB="<<(buf0[1]&0x000F);
1464  COUT << "; "
1465  << ALCT_WordsSinceLastHeader << "-"
1466  << ALCT_WordCount << "-"
1467  << ALCT_WordsExpected
1468  << " "
1469  << TMB_WordsSinceLastHeader << "-"
1470  << TMB_WordCount << "-"
1471  << TMB_WordsExpected
1472  << endl;
1473  */
1474 #endif
1475  }
1476 
1477  // == DDU Trailer found
1478  if( buf0[0]==0x8000 && buf0[1]==0x8000 && buf0[2]==0xFFFF && buf0[3]==0x8000 )
1479  {
1480 
1482  checkDAVs();
1483 
1485 
1487 
1488  if( DDU_WordsSinceLastHeader>3 && !nDMBs )
1489  {
1490  fERROR[28]=true;
1491  bERROR|=0x10000000;;
1492  }
1493 
1494  if(fDDU_Trailer)
1495  {
1496  fERROR[2] = true;
1497  bERROR |= 0x4;
1498  } // DDU Header is missing
1499  fDDU_Trailer=true;
1500  fDDU_Header=false;
1501 
1502  if( fDMB_Header || fDMB_Trailer )
1503  {
1504 #ifdef LOCAL_UNPACK
1505  COUT << " Ex-Err: DMB (Header, Trailer) " << std::endl;
1506 #endif
1507  fERROR[5] = true;
1508  bERROR |= 0x20;
1509  fCHAMB_ERR[5].insert(currentChamber);
1510  bCHAMB_ERR[currentChamber] |= 0x20;
1511  fCHAMB_ERR[0].insert(currentChamber);
1512  bCHAMB_ERR[currentChamber] |= 0x20;
1513  } // DMB Trailer is missing
1514  fDMB_Header = false;
1515  fDMB_Trailer = false;
1516 
1517  currentChamber=-1;
1518 
1519  for(int err=0; err<nERRORS; ++err)
1520  if( fCHAMB_ERR[err].find(-1) != fCHAMB_ERR[err].end() )
1521  {
1522  fCHAMB_ERR[err].erase(-1);
1523  fCHAMB_ERR[err].insert(-2);
1524  }
1525  bCHAMB_STATUS[-2] |= bCHAMB_STATUS[-1];
1526  bCHAMB_STATUS[-1] = 0;
1527  bCHAMB_ERR[-2] |= bCHAMB_ERR[-1];
1528  bCHAMB_ERR[-1] = 0;
1529  bCHAMB_WRN[-2] |= bCHAMB_WRN[-1];
1530  bCHAMB_WRN[-1] = 0;
1531 
1532  for(int err=1; err<nERRORS; ++err)
1533  if( fCHAMB_ERR[err].find(-2) != fCHAMB_ERR[err].end() )
1534  {
1535  fCHAMB_ERR[0].insert(-2);
1536  bCHAMB_ERR[-2] |= 0x1;
1537  }
1538 
1540 
1541  ++cntDDU_Trailers; // Increment DDUTrailer counter
1542 
1543  // == Combining 2 words into 24bit value
1544  DDU_WordCount = buf2[2] | ((buf2[3] & 0xFF) <<16) ;
1545 
1547  {
1548  fERROR[4] = true;
1549  bERROR |= 0x10;
1550  }
1551 
1552  if( DMB_Active!=nDMBs )
1553  {
1554  fERROR[24] = true;
1555  bERROR |= 0x1000000;
1556  }
1557 
1558 #ifdef LOCAL_UNPACK
1559  COUT<<"DDU Trailer Occurrence "<<cntDDU_Trailers<<endl;
1560  COUT<<"----------------------------------------------------------"<<endl;
1561  COUT<<"DDU 64-bit words = Actual - DDUcounted ="<<DDU_WordsSinceLastHeader+4<<"-"<<DDU_WordCount<<endl;
1562 #endif
1563 
1564  // increment statistics Errors and Warnings (i=0 case is handled in DDU Header)
1565  for(int err=1; err<nERRORS; ++err)
1566  {
1567  if( fERROR[err] )
1568  {
1569  fERROR[0] = true;
1570  bERROR |= 0x1;
1571 #ifdef LOCAL_UNPACK
1572  CERR<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
1573  CERR<<" ERROR "<<err<<" " <<sERROR[err]<<endl;
1574 #endif
1575  }
1576  }
1577 
1578 #ifdef LOCAL_UNPACK
1579  for(int wrn=1; wrn<nWARNINGS; ++wrn)
1580  {
1581  if( fWARNING[wrn] )
1582  {
1583  COUT<<"\nDDU Header Occurrence = "<<cntDDU_Headers;
1584  COUT<<" WARNING "<<wrn<<" "<<sWARNING[wrn]<<endl;
1585  }
1586  }
1587 #endif
1588 
1589  bDDU_ERR[sourceID] |= bERROR;
1591  sync_stats();
1592 
1595  if (modeDDUonly)
1596  {
1597  buffer+=4;
1598  buf_1 = &(tmpbuf[0]); // Just for safety
1599  buf0 = &(tmpbuf[4]); // Just for safety
1600  buf1 = &(tmpbuf[8]); // Just for safety
1601  buf2 = &(tmpbuf[12]); // Just for safety
1602  bzero(tmpbuf, sizeof(uint16_t)*16);
1603  return length-4;
1604  }
1605  }
1606 
1607  if (!modeDDUonly)
1608  {
1609  // DCC Trailer 1 && DCC Trailer 2
1610  // =VB= Added support for Sep. 2008 CMS DAQ DCC format
1611  // =VB= 04.18.09 Removed (buf2[0]&0x0003) == 0x3 check for old DCC format to satisfy older format of simulated data
1612  if( (buf1[3]&0xFF00) == 0xEF00 &&
1613  ( ((buf2[3]&0xFF00) == 0xAF00 )
1614  ||
1615  (( buf2[3]&0xFF00) == 0xA000 && (buf2[0]&0x0003) == 0x0) ) )
1616  {
1617  // =VB= Added check that there is no DCCHeader detected to set missing DCC Header error
1618  if(!fDCC_Header || fDCC_Trailer)
1619  {
1620  fERROR[26] = true;
1621  bERROR|=0x4000000;
1622  fERROR[0] = true;
1623  bERROR|=0x1;
1624  } // DCC Header is missing
1625  fDCC_Trailer=true;
1626  fDCC_Header=false;
1627 
1628  if( fDDU_Header )
1629  {
1630  // == DDU Trailer is missing
1631  fERROR[1]=true;
1632  bERROR|=0x2;
1633  fERROR[0] = true;
1634  bERROR|=0x1;
1635  }
1636 
1637  buffer+=4;
1638  buf_1 = &(tmpbuf[0]); // Just for safety
1639  buf0 = &(tmpbuf[4]); // Just for safety
1640  buf1 = &(tmpbuf[8]); // Just for safety
1641  buf2 = &(tmpbuf[12]); // Just for safety
1642  bzero(tmpbuf, sizeof(uint16_t)*16);
1643  sync_stats();
1644  return length-4;
1645  }
1646  }
1647 
1648  length-=4;
1649  buffer+=4;
1650  }
1651  //Store the tail of the buffer
1652  buf_1 = &(tmpbuf[0]);
1653  buf0 = &(tmpbuf[4]);
1654  buf1 = &(tmpbuf[8]);
1655  buf2 = &(tmpbuf[12]);
1656  memcpy((void*)tmpbuf,(void*)(buffer-16),sizeof(short)*16);
1657 
1658  if (!modeDDUonly && !fDCC_Trailer && !fDCC_Header)
1659  {
1660  fERROR[26] = true;
1661  bERROR|=0x4000000;
1662  fERROR[25] = true;
1663  bERROR|=0x2000000;
1664  fERROR[0]=true;
1665  bERROR|=0x1;
1666  sync_stats();
1667  return length;
1668 
1669  }
1670 
1671  return -2;
1672 }
1673 
1674 
1676 {
1677  bzero(fERROR, sizeof(bool)*nERRORS);
1678  bzero(fWARNING, sizeof(bool)*nWARNINGS);
1679  bzero(fSUM_ERROR, sizeof(bool)*nERRORS);
1680  bzero(fSUM_WARNING, sizeof(bool)*nWARNINGS);
1681  bERROR = 0;
1682  bWARNING = 0;
1683  bSUM_ERROR = 0;
1684  bSUM_WARNING = 0;
1685  for(int err=0; err<nERRORS; ++err) fCHAMB_ERR[err].clear();
1686  for(int wrn=0; wrn<nWARNINGS; ++wrn) fCHAMB_WRN[wrn].clear();
1687  bCHAMB_ERR.clear();
1688  bCHAMB_WRN.clear();
1689  bCHAMB_PAYLOAD.clear();
1690  bCHAMB_STATUS.clear();
1691  bDDU_ERR.clear();
1692  bDDU_WRN.clear();
1693  dduBuffers.clear();
1694  dduOffsets.clear();
1695  dmbBuffers.clear();
1696  dmbOffsets.clear();
1697  dduSize.clear();
1698  dmbSize.clear();
1699 }
1700 
1701 
1703 {
1706  ALCT_WordCount = 0;
1707  ALCT_WordsExpected = 0;
1708  ALCT_ZSE = 0;
1710  TMB_WordCount = 0;
1711  TMB_WordsExpected = 0;
1712  TMB_Tbins = 0;
1714  CFEB_SampleCount = 0;
1715  CFEB_BSampleCount = 0;
1716 }
1717 
1718 
1720 {
1721  if( DAV_ALCT )
1722  {
1723  fERROR[21] = true;
1724  bERROR |= 0x200000;
1725  fCHAMB_ERR[21].insert(currentChamber);
1726  bCHAMB_ERR[currentChamber] |= 0x200000;
1727  DAV_ALCT = false;
1728  }
1729  if( DAV_TMB )
1730  {
1731  fERROR[22] = true;
1732  bERROR |= 0x400000;
1733  fCHAMB_ERR[22].insert(currentChamber);
1734  bCHAMB_ERR[currentChamber] |= 0x400000;
1735  DAV_TMB = false;
1736  }
1737  if( DAV_CFEB && DAV_CFEB!=-16)
1738  {
1739  fERROR[23] = true;
1740  bERROR |= 0x800000;
1741  fCHAMB_ERR[23].insert(currentChamber);
1742  bCHAMB_ERR[currentChamber] |= 0x800000;
1743  DAV_CFEB = 0;
1744  }
1745 }
1746 
1747 
1749 {
1750 #ifdef LOCAL_UNPACK
1751  /*
1752  COUT << " Ex-ALCT-Word-count " << std::endl;
1753  COUT << " ALCT Words Since Last Header: " << ALCT_WordsSinceLastHeader << std::endl;
1754  COUT << " ALCT Word Count: " << ALCT_WordCount << std::endl;
1755  COUT << " ALCT Words Expected: " << ALCT_WordsExpected << std::endl;
1756  */
1757 #endif
1759  && ALCT_ZSE==0 )
1760  {
1761  fERROR[9] = true;
1762  bERROR |= 0x200;
1763  fCHAMB_ERR[9].insert(currentChamber);
1764  bCHAMB_ERR[currentChamber] |= 0x200;
1766  ALCT_WordCount = 0;
1768  ALCT_WordsExpected = 0;
1769  } // ALCT Word Count Error
1770 
1773  {
1774  fERROR[9] = true;
1775  bERROR |= 0x200;
1776  fCHAMB_ERR[9].insert(currentChamber);
1777  bCHAMB_ERR[currentChamber] |= 0x200;
1780  ALCT_WordCount = 0;
1782  ALCT_WordsExpected = 0;
1783  } // ALCT Word Count Error With zero suppression
1784 
1786  {
1787  fERROR[14] = true;
1788  bERROR |= 0x4000;
1789  fCHAMB_ERR[14].insert(currentChamber);
1790  bCHAMB_ERR[currentChamber] |= 0x4000;
1792  TMB_WordCount = 0;
1794  TMB_WordsExpected = 0;
1795  } // TMB Word Count Error
1796 
1797  if( (CFEB_SampleCount%8)!=0 )
1798  {
1799  fERROR[17] = true;
1800  bERROR |= 0x20000;
1801  fCHAMB_ERR[17].insert(currentChamber);
1802  bCHAMB_ERR[currentChamber] |= 0x20000;
1803  CFEB_SampleCount = 0;
1804  } // Number of CFEB samples != 8*n
1805 
1806  if(fALCT_Header)
1807  {
1808  fERROR[7] = true; // ALCT Trailer is missing
1809  bERROR |= 0x80;
1810  fCHAMB_ERR[7].insert(currentChamber);
1811  bCHAMB_ERR[currentChamber] |= 0x80;
1814  ALCT_WordsExpected = 0;
1815  fALCT_Header = 0;
1816  }
1817 
1818  if(fTMB_Header)
1819  {
1820  fERROR[12]=true; // TMB Trailer is missing
1821  bERROR |= 0x1000;
1822  fCHAMB_ERR[12].insert(currentChamber);
1823  bCHAMB_ERR[currentChamber] |= 0x1000;
1825  TMB_WordsExpected = 0;
1826  fTMB_Header = false;
1827  }
1828 }
1829 
1831 {
1832  for (int err=0; err<nERRORS; ++err)
1833  fSUM_ERROR[err] |= fERROR[err];
1834  for (int wrn=0; wrn<nWARNINGS; ++wrn)
1835  fSUM_WARNING[wrn] |= fWARNING[wrn];
1836  bSUM_ERROR |= bERROR;
1838 }
1839 
1840 inline int CSCDCCExaminer::scanbuf(const uint16_t* &buffer, int32_t length, uint16_t sig, uint16_t mask)
1841 {
1842  for (int i=0; i<length; i++)
1843  {
1844  if ( (buffer[i]&mask) == sig)
1845  {
1846  return i;
1847  }
1848  }
1849  return -1;
1850 }
1851 
uint32_t DDU_WordsSinceLastHeader
uint32_t TMB_WordCount
const uint16_t * buf0
const uint16_t * buffer_start
void crcCFEB(bool enable)
tuple t
Definition: tree.py:139
int i
Definition: DBlmapReader.cc:9
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:7
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)
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
tuple cout
Definition: gather_cfg.py:121
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