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