48 unsigned char d0[3][10];
49 unsigned char counter;
56 unsigned int mask = 0xffffffff;
57 if (width<8) mask = ((1 << width*4)-1);
59 for (
int i=0;
i<
width;
i++) out <<
" ";
61 out << std::hex << SETW(width) << std::setfill('0') << ((data>>shift) & mask);
66 return (row << 16) +
col;
81 if (ruchn<=0)
return false;
82 if (mask<0)
return false;
83 return (((mask >> (ruchn-1)) & 1) == 1);
95 unsigned char *the_end = (
unsigned char *) &payload[
dlength];
97 unsigned char *
pos = (
unsigned char *) payload;
107 felix_counter[
i] = 0;
110 while ( pos < the_end )
116 if (d32->
ruid > IDMVTXV2_MAXRUID)
118 cout << __FILE__ <<
" " << __LINE__ <<
" --- invalid ruid " << hex << (int) d32->
ruid <<
" at pos " << (
long) pos << dec << endl;
129 int counter_increment = (d32->
counter + 256 - felix_counter[d32->
ruid])%256;
130 if (counter_increment > 3)
142 for (
int ichnk = 0; ichnk < counter_increment; ichnk++)
144 unsigned char ruchn = d32->
d0[ichnk][9];
145 if (ruchn >> 4 == 0x2) {
161 cout << __FILE__ <<
" " << __LINE__ <<
" --- invalid ruchn " << hex << ruchn <<
", full RU word: ";
163 for (
int ibyte=9;ibyte>=0;ibyte--)
165 cout << setfill(
'0') << setw(2) << hex << (
unsigned int) d32->
d0[ichnk][ibyte] <<
" ";
167 cout << setfill(
' ') << setw(0) << dec << endl;
169 else for (
int ibyte = 0; ibyte < 9; ibyte++)
172 ruchn_stream[d32->
ruid][ruchn].push_back(d32->
d0[ichnk][ibyte]);
187 for (
int ruid = 1; ruid < IDMVTXV2_MAXRUID+1; ruid++)
192 bool header_seen=
false;
194 int ibyte_endofdata = -1;
196 unsigned int address = 0;
197 unsigned int encoder_id = 0;
198 for (
unsigned int ibyte = 0; ibyte < ruchn_stream[ruid][ruchn].size(); ibyte++)
200 b = ruchn_stream[ruid][ruchn].at(ibyte);
221 ibyte_endofdata = ibyte;
235 if ( the_region >= 0 && encoder_id >=0 )
237 unsigned int row = (address >> 1);
238 unsigned int col = (the_region * 32);
239 col += (encoder_id * 2) + ( (row & 1) ? ( (address & 1) ^ 1 ) : (address & 1) );
240 if ( row < 0 || row >=
NROW || col < 0 || col >=
NCOL )
242 cout << __FILE__ <<
" " << __LINE__ <<
" impossible pixel coord: " << row
243 <<
", " << col <<
"." << endl;
244 cout <<
"Check region " << the_region <<
", encoder " << encoder_id
245 <<
", addr " << address << endl;
261 if ( (b & 0x80) != 0)
272 if (
ihit==0 || ((b >> (
ihit-1)) & 1))
274 int hit_address = address +
ihit;
275 if ( the_region >= 0 && encoder_id >=0 )
277 unsigned int row = (hit_address >> 1);
278 unsigned int col = the_region*32;
279 col += (encoder_id * 2) + ( (row & 1) ? ( (hit_address & 1) ^ 1 ) : (hit_address & 1) );
280 if ( row < 0 || row >=
NROW || col < 0 || col >=
NCOL )
282 cout << __FILE__ <<
" " << __LINE__ <<
" impossible pixel coord: " << row
283 <<
", " << col <<
"." << endl;
284 cout <<
"Check region " << the_region <<
", encoder " << encoder_id
285 <<
", addr " << hit_address << endl;
298 if (ibyte_endofdata != -1)
break;
306 else if ( ( b >> 4) == 0xa)
313 else if ( ( b >> 4) == 0xb)
317 ibyte_endofdata = ibyte;
330 else if ( ( b >> 4) == 0xE)
337 else if ( ( b >> 5) == 0x6)
339 unsigned int region_id = (b & 0x1f);
342 the_region = region_id;
346 cout << __FILE__ <<
" " << __LINE__ <<
" wrong region header, id= " << hex << region_id << dec << endl;
351 else if ( ( b >> 6) == 0x1)
353 encoder_id = ( b>>2) & 0xf;
354 address = (b & 0x3) << 8;
358 else if ( ( b >> 6) == 0x0)
360 encoder_id = ( b>>2) & 0xf;
361 address = (b & 0x3) << 8;
377 cout << __FILE__ <<
" " << __LINE__ <<
" unexpected word " << hex << (
unsigned int) b << dec <<
" at ibyte " << ibyte << endl;
382 if (ibyte==0 && !header_seen)
384 cout << __FILE__ <<
" " << __LINE__ <<
" " <<
"first byte of the ALPIDE stream must be a chip header or chip empty;" <<endl;
385 cout <<
"Aborting so we don't get confused by bad data." << endl;
393 for (
unsigned int ibyte = ibyte_endofdata+1; ibyte < ruchn_stream[ruid][ruchn].size(); ibyte++)
395 b = ruchn_stream[ruid][ruchn].at(ibyte);
416 if ( strcmp(what,
"DECODER_ERROR") == 0 )
420 if ( strcmp(what,
"UNEXPECTED_FELIX_COUNTERS") == 0 )
425 else if ( strcmp(what,
"BAD_RUIDS") == 0 )
433 if ( strcmp(what,
"BAD_RUCHNS") == 0 )
438 else if ( strcmp(what,
"LANE_STOPS") == 0 )
443 else if ( strcmp(what,
"LANE_TIMEOUTS") == 0 )
448 else if ( strcmp(what,
"CHECK_BC") == 0 )
471 if ( strcmp(what,
"CHIP_ID") == 0 )
476 else if ( strcmp(what,
"BAD_BYTES") == 0 )
481 else if ( strcmp(what,
"EXCESS_BYTES") == 0 )
486 else if ( strcmp(what,
"BUNCHCOUNTER") == 0 )
491 else if ( strcmp(what,
"HEADER_FOUND") == 0 )
496 else if ( strcmp(what,
"TRAILER_FOUND") == 0 )
501 else if ( strcmp(what,
"READOUT_FLAGS") == 0 )
540 os <<
"RU ID: " << ruid;
541 os <<
", bad_ruchns=" <<
iValue(ruid,
"BAD_RUCHNS");
542 os << hex << setfill(
'0');
543 os <<
", lanes_active 0x" << setw(7) <<
iValue(ruid);
557 os <<
"), inconsistent_bc=" << setw(1) <<
iValue(ruid,
"CHECK_BC");
558 os << hex << setfill(
'0');
559 os <<
", lane_stops=0x" << setw(7) <<
iValue(ruid,
"LANE_STOPS");
563 for (
int ruchn = 0; ruchn < IDMVTXV2_MAXRUCHN+1; ruchn++)
573 os << hex << setfill(
'0');
574 os <<
"), lane_timeouts=0x" << setw(7) <<
iValue(ruid,
"LANE_TIMEOUTS");
578 for (
int ruchn = 0; ruchn < IDMVTXV2_MAXRUCHN+1; ruchn++)
589 os << dec << setfill(
' ') << endl;
590 for (
int ruchn = 0; ruchn < IDMVTXV2_MAXRUCHN+1; ruchn++)
592 if (
iValue(ruid,ruchn)!=-1)
594 os <<
"RU channel " << setw(2) << ruchn;
595 os <<
" bad_bytes=" <<
iValue(ruid,ruchn,
"BAD_BYTES") <<
" excess_bytes=" <<
iValue(ruid,ruchn,
"EXCESS_BYTES") <<
" header_found=" <<
iValue(ruid,ruchn,
"HEADER_FOUND") <<
" trailer_found=" <<
iValue(ruid,ruchn,
"TRAILER_FOUND");
596 os <<
" bunchcounter=" << setw(3) <<
iValue(ruid,ruchn,
"BUNCHCOUNTER") <<
" flags=" <<
iValue(ruid,ruchn,
"READOUT_FLAGS");
597 os <<
", chip ID " <<
iValue(ruid,ruchn,
"CHIP_ID") <<
", " <<
iValue(ruid,ruchn) <<
" hits: ";
600 int hit =
iValue(ruid,ruchn,
i);
619 const int DWORDS_PER_WORD = 8;
631 out <<
SETW(5) << current_offset <<
" | ";
635 print_stuff(out, SubeventData[current_offset+7], 4, 16, (dwords_remaining<=7));
639 print_stuff(out, SubeventData[current_offset+7], 4, 0, (dwords_remaining<=7));
640 print_stuff(out, SubeventData[current_offset+6], 8, 0, (dwords_remaining<=6));
641 print_stuff(out, SubeventData[current_offset+5], 8, 0, (dwords_remaining<=5));
645 print_stuff(out, SubeventData[current_offset+4], 8, 0, (dwords_remaining<=4));
646 print_stuff(out, SubeventData[current_offset+3], 8, 0, (dwords_remaining<=3));
647 print_stuff(out, SubeventData[current_offset+2], 4, 16, (dwords_remaining<=2));
651 print_stuff(out, SubeventData[current_offset+2], 4, 0, (dwords_remaining<=2));
652 print_stuff(out, SubeventData[current_offset+1], 8, 0, (dwords_remaining<=1));
653 print_stuff(out, SubeventData[current_offset+0], 8, 0, (dwords_remaining<=0));
654 out <<
" " << std::dec << std::endl << std::setfill(
' ');
656 if (dwords_remaining<8)
break;
658 current_offset += DWORDS_PER_WORD;
666 out << std::dec << std::endl <<
SETW(5) << j <<
" | ";
670 out <<
SETW(10) << SubeventData[j++] <<
" ";
686 bool first_active =
true;
687 unsigned int first_active_lane;
694 first_active_lane = iruchn;
695 first_active =
false;