45 unsigned char d0[3][10];
46 unsigned char counter;
51 #define CHIPEMPTYFRAME 2
63 int is_an_odd_row = the_row & 1;
67 thebit = (encoder_id*2) + ( ( address &1) ^ 1 );
71 thebit = (encoder_id*2) + ( address&1);
78 unsigned int mask = 0xffffffff;
79 if (width<8) mask = ((1 << width*4)-1);
81 for (
int i=0;
i<
width;
i++) out <<
" ";
83 out << std::hex << SETW(width) << std::setfill('0') << ((data>>shift) & mask);
88 return (row << 16) +
col;
103 if (ruchn<=0)
return false;
104 if (mask<0)
return false;
105 return (((mask >> (ruchn-1)) & 1) == 1);
116 unsigned char *the_end = (
unsigned char *) &payload[
dlength];
118 unsigned char *
pos = (
unsigned char *) payload;
128 felix_counter[
i] = 0;
131 while ( pos < the_end )
137 if (d32->
ruid > IDMVTXV1_MAXRUID)
139 cout << __FILE__ <<
" " << __LINE__ <<
" --- invalid ruid " << hex << (int) d32->
ruid <<
" at pos " << (
long) pos << dec << endl;
149 int counter_increment = (d32->
counter + 256 - felix_counter[d32->
ruid])%256;
150 if (counter_increment > 3)
162 for (
int ichnk = 0; ichnk < counter_increment; ichnk++)
164 unsigned char ruchn = d32->
d0[ichnk][9];
177 cout << __FILE__ <<
" " << __LINE__ <<
" --- invalid ruchn " << hex << ruchn <<
", full RU word: ";
178 for (
int ibyte=9;ibyte>=0;ibyte--)
180 cout << setfill(
'0') << setw(2) << hex << (
unsigned int) d32->
d0[ichnk][ibyte] <<
" ";
182 cout << setfill(
' ') << setw(0) << dec << endl;
184 else for (
int ibyte = 0; ibyte < 9; ibyte++)
187 ruchn_stream[d32->
ruid][ruchn].push_back(d32->
d0[ichnk][ibyte]);
202 for (
int ruid = 1; ruid < IDMVTXV1_MAXRUID+1; ruid++)
207 bool header_seen=
false;
209 int ibyte_endofdata = -1;
211 unsigned int address = 0;
212 unsigned int encoder_id = 0;
213 for (
unsigned int ibyte = 0; ibyte < ruchn_stream[ruid][ruchn].size(); ibyte++)
215 b = ruchn_stream[ruid][ruchn].at(ibyte);
236 ibyte_endofdata = ibyte;
245 if ( the_region >= 0 && encoder_id >=0 )
247 int the_row = (address >> 1);
250 cout << __FILE__ <<
" " << __LINE__ <<
" impossible row: " << the_row
251 <<
" encoder " << encoder_id <<
" addr " << address << endl;
258 unsigned short col = the_region*32 + thebit;
273 if ( (b & 0x80) != 0)
284 if (
ihit==0 || ((b >> (
ihit-1)) & 1))
286 int hit_address = address +
ihit;
287 if ( the_region >= 0 && encoder_id >=0 )
289 int the_row = (hit_address >> 1);
292 cout << __FILE__ <<
" " << __LINE__ <<
" impossible row: " << the_row
293 <<
" encoder " << encoder_id <<
" addr " << hit_address << endl;
297 int thebit =
decode_thebit(the_row, encoder_id, hit_address);
300 unsigned short col = the_region*32 + thebit;
312 if (ibyte_endofdata != -1)
break;
320 else if ( ( b >> 4) == 0xa)
327 else if ( ( b >> 4) == 0xb)
331 ibyte_endofdata = ibyte;
344 else if ( ( b >> 4) == 0xE)
351 else if ( ( b >> 5) == 0x6)
353 unsigned int region_id = (b & 0x1f);
356 the_region = region_id;
360 cout << __FILE__ <<
" " << __LINE__ <<
" wrong region header, id= " << hex << region_id << dec << endl;
364 else if ( ( b >> 6) == 0x1)
366 encoder_id = ( b>>2) & 0xf;
367 address = (b & 0x3) << 8;
371 else if ( ( b >> 6) == 0x0)
373 encoder_id = ( b>>2) & 0xf;
374 address = (b & 0x3) << 8;
393 if (ibyte==0 && !header_seen)
break;
398 for (
unsigned int ibyte = ibyte_endofdata+1; ibyte < ruchn_stream[ruid][ruchn].size(); ibyte++)
400 b = ruchn_stream[ruid][ruchn].at(ibyte);
417 if ( strcmp(what,
"MAXRUID") == 0 )
421 else if ( strcmp(what,
"MAXRUCHN") == 0 )
429 if ( strcmp(what,
"UNEXPECTED_FELIX_COUNTERS") == 0 )
434 else if ( strcmp(what,
"BAD_RUIDS") == 0 )
442 if ( strcmp(what,
"BAD_RUCHNS") == 0 )
447 else if ( strcmp(what,
"LANE_STOPS") == 0 )
452 else if ( strcmp(what,
"LANE_TIMEOUTS") == 0 )
475 if ( strcmp(what,
"CHIP_ID") == 0 )
480 else if ( strcmp(what,
"BAD_BYTES") == 0 )
485 else if ( strcmp(what,
"EXCESS_BYTES") == 0 )
490 else if ( strcmp(what,
"BUNCHCOUNTER") == 0 )
495 else if ( strcmp(what,
"HEADER_FOUND") == 0 )
500 else if ( strcmp(what,
"TRAILER_FOUND") == 0 )
505 else if ( strcmp(what,
"READOUT_FLAGS") == 0 )
544 os <<
"RU ID: " << ruid;
545 os <<
", bad_ruchns=" <<
iValue(ruid,
"BAD_RUCHNS");
546 os << hex << setfill(
'0');
547 os <<
", lanes_active 0x" << setw(7) <<
iValue(ruid);
561 os << hex << setfill(
'0');
562 os <<
"), lane_stops=0x" << setw(7) <<
iValue(ruid,
"LANE_STOPS");
566 for (
int ruchn = 0; ruchn < IDMVTXV1_MAXRUCHN+1; ruchn++)
576 os << hex << setfill(
'0');
577 os <<
"), lane_timeouts=0x" << setw(7) <<
iValue(ruid,
"LANE_TIMEOUTS");
581 for (
int ruchn = 0; ruchn < IDMVTXV1_MAXRUCHN+1; ruchn++)
592 os << dec << setfill(
' ') << endl;
593 for (
int ruchn = 0; ruchn < IDMVTXV1_MAXRUCHN+1; ruchn++)
595 if (
iValue(ruid,ruchn)!=-1)
597 os <<
"RU channel " << setw(2) << ruchn;
598 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");
599 os <<
" bunchcounter=" << setw(3) <<
iValue(ruid,ruchn,
"BUNCHCOUNTER") <<
" flags=" <<
iValue(ruid,ruchn,
"READOUT_FLAGS");
600 os <<
", chip ID " <<
iValue(ruid,ruchn,
"CHIP_ID") <<
", " <<
iValue(ruid,ruchn) <<
" hits: ";
603 int hit =
iValue(ruid,ruchn,
i);
624 const int DWORDS_PER_WORD = 8;
636 out <<
SETW(5) << current_offset <<
" | ";
640 print_stuff(out, SubeventData[current_offset+7], 4, 16, (dwords_remaining<=7));
644 print_stuff(out, SubeventData[current_offset+7], 4, 0, (dwords_remaining<=7));
645 print_stuff(out, SubeventData[current_offset+6], 8, 0, (dwords_remaining<=6));
646 print_stuff(out, SubeventData[current_offset+5], 8, 0, (dwords_remaining<=5));
650 print_stuff(out, SubeventData[current_offset+4], 8, 0, (dwords_remaining<=4));
651 print_stuff(out, SubeventData[current_offset+3], 8, 0, (dwords_remaining<=3));
652 print_stuff(out, SubeventData[current_offset+2], 4, 16, (dwords_remaining<=2));
656 print_stuff(out, SubeventData[current_offset+2], 4, 0, (dwords_remaining<=2));
657 print_stuff(out, SubeventData[current_offset+1], 8, 0, (dwords_remaining<=1));
658 print_stuff(out, SubeventData[current_offset+0], 8, 0, (dwords_remaining<=0));
659 out <<
" " << std::dec << std::endl << std::setfill(
' ');
661 if (dwords_remaining<8)
break;
663 current_offset += DWORDS_PER_WORD;
671 out << std::dec << std::endl <<
SETW(5) << j <<
" | ";
675 out <<
SETW(10) << SubeventData[j++] <<
" ";