21 memset (
chip_row, 0, 9*512*32*
sizeof(
unsigned int));
22 memset (
chip_rowmap, 0, 9*512*
sizeof(
unsigned int));
44 unsigned char d0[3][10];
50 #define CHIPEMPTYFRAME 2
62 int is_an_odd_row = the_row & 1;
66 thebit = (encoder_id*2) + ( ( address &1) ^ 1 );
70 thebit = (encoder_id*2) + ( address&1);
77 unsigned int mask = 0xffffffff;
78 if (width<8) mask = ((1 << width*4)-1);
80 for (
int i=0;
i<
width;
i++) out <<
" ";
82 out << std::hex << SETW(width) << std::setfill('0') << ((data>>shift) & mask);
93 unsigned char *the_end = (
unsigned char *) &payload[
dlength+1];
95 unsigned char *
pos = (
unsigned char *) payload;
103 vector<unsigned char> ruchn_stream[
MAXRUCHN+1];
105 unsigned char felix_counter = 0;
107 while ( pos < the_end )
120 int counter_increment = (d32->
counter + 256 - felix_counter)%256;
121 if (counter_increment > 3)
133 for (
int ichnk = 0; ichnk < counter_increment; ichnk++)
135 unsigned int ruchn = (
unsigned int)d32->
d0[ichnk][9];
157 cout << __FILE__ <<
" " << __LINE__ <<
" --- invalid ruchn " << hex << ruchn <<
", full RU word: ";
158 for (
int ibyte=9;ibyte>=0;ibyte--)
160 cout << setfill(
'0') << setw(2) << hex << (
unsigned int) d32->
d0[ichnk][ibyte] <<
" ";
162 cout << setfill(
' ') << setw(0) << dec << endl;
164 else for (
int ibyte = 0; ibyte < 9; ibyte++)
167 ruchn_stream[ruchn].push_back(d32->
d0[ichnk][ibyte]);
182 for (
int ruchn = 1; ruchn <
MAXRUCHN+1; ruchn++)
185 bool header_seen=
false;
187 int ibyte_endofdata = -1;
189 unsigned int address=0;
190 unsigned int encoder_id = 0;
191 for (
unsigned int ibyte = 0; ibyte < ruchn_stream[ruchn].size(); ibyte++)
193 b = ruchn_stream[ruchn].at(ibyte);
223 ibyte_endofdata = ibyte;
232 if ( the_region >= 0 && encoder_id >=0 )
234 int the_row = (address >> 1);
237 cout << __FILE__ <<
" " << __LINE__ <<
" impossible row: " << the_row
238 <<
" encoder " << encoder_id <<
" addr " << address << endl;
245 chip_row[ruchn][the_row][the_region] |= ( 1<<thebit);
262 if ( (b & 0x80) != 0)
273 if (
ihit==0 || ((b >> (
ihit-1)) & 1))
275 int hit_address = address +
ihit;
276 if ( the_region >= 0 && encoder_id >=0 )
278 int the_row = (hit_address >> 1);
281 cout << __FILE__ <<
" " << __LINE__ <<
" impossible row: " << the_row
282 <<
" encoder " << encoder_id <<
" addr " << hit_address << endl;
286 int thebit =
decode_thebit(the_row, encoder_id, hit_address);
289 chip_row[ruchn][the_row][the_region] |= ( 1<<thebit);
304 if (ibyte_endofdata != -1)
break;
312 else if ( ( b >> 4) == 0xa)
319 else if ( ( b >> 4) == 0xb)
323 ibyte_endofdata = ibyte;
329 else if ( ( b >> 4) == 0xE)
336 else if ( ( b >> 5) == 0x6)
338 unsigned int region_id = (b & 0x1f);
341 the_region = region_id;
346 cout << __FILE__ <<
" " << __LINE__ <<
" wrong region header, id= " << hex << region_id << dec << endl;
350 else if ( ( b >> 6) == 0x1)
352 encoder_id = ( b>>2) & 0xf;
353 address = (b & 0x3) << 8;
357 else if ( ( b >> 6) == 0x0)
359 encoder_id = ( b>>2) & 0xf;
360 address = (b & 0x3) << 8;
379 if (ibyte==0 && !header_seen)
break;
384 for (
unsigned int ibyte = ibyte_endofdata+1; ibyte < ruchn_stream[ruchn].size(); ibyte++)
386 b = ruchn_stream[ruchn].at(ibyte);
403 if ( strcmp(what,
"UNEXPECTED_FELIX_COUNTER") == 0 )
408 else if ( strcmp(what,
"BAD_RUID") == 0 )
413 else if ( strcmp(what,
"BAD_RUCHNS") == 0 )
418 else if ( strcmp(what,
"BAD_CHIPIDS") == 0 )
423 else if ( strcmp(what,
"HIGHEST_CHIP") == 0 )
428 else if ( strcmp(what,
"CHIP_ID") == 0 )
434 else if ( strcmp(what,
"HIGHEST_REGION") == 0 )
440 else if ( strcmp(what,
"HIGHEST_ROW") == 0 )
445 else if ( strcmp(what,
"EXCESS_DATA_BYTES") == 0 )
450 else if ( strcmp(what,
"UNEXPECTED_BYTES") == 0 )
456 else if ( strcmp(what,
"BUNCHCOUNTER") == 0 )
462 else if ( strcmp(what,
"HEADER_FOUND") == 0 )
468 else if ( strcmp(what,
"TRAILER_FOUND") == 0 )
474 else if ( strcmp(what,
"READOUT_FLAGS") == 0 )
489 if ( region < 0 || region > 31 )
return 0;
490 if ( row < 0 || row > 511)
return 0;
500 if ( row < 0 || row > 511)
return 0;
513 os <<
"Highest chip: " << setw(4) <<
iValue(0,
"HIGHEST_CHIP") +1<< endl;
515 for (
int ichip = 0; ichip <
iValue(0,
"HIGHEST_CHIP") +1; ichip++)
517 os << setw(4) <<
iValue(ichip,
"HIGHEST_REGION");
520 os <<
"Highest populated row " <<
iValue(0,
"HIGHEST_ROW") << endl;
524 for (
int ichip = 0; ichip <
iValue(0,
"HIGHEST_CHIP")+1; ichip++)
526 if (
iValue(ichip,
"HIGHEST_REGION") == -1)
continue;
527 os <<
" *** Chip " << ichip <<
", chip ID " <<
iValue(ichip,
"CHIP_ID") <<
" ***" << endl;
528 for (
int irow = 0; irow <
iValue(0,
"HIGHEST_ROW")+1; irow++)
530 bool has_hit =
false;
531 for (
int iregion = 0; iregion <
iValue(ichip,
"HIGHEST_REGION")+1; iregion++)
533 if (
iValue(ichip,iregion, irow) != 0)
541 os <<
" Row Region" << endl;
542 for (
int iregion = 0; iregion <
iValue(ichip,
"HIGHEST_REGION")+1; iregion++)
544 os << setw(4) << irow <<
" " << setw(4) << iregion <<
" | ";
545 unsigned int bits =
iValue(ichip,iregion, irow);
546 for (
int i = 0;
i < 32;
i++)
548 if ( (bits >>
i) & 1)
575 const int DWORDS_PER_WORD = 8;
586 out <<
SETW(5) << current_offset <<
" | ";
590 print_stuff(out, SubeventData[current_offset+7], 4, 16, (dwords_remaining<=7));
594 print_stuff(out, SubeventData[current_offset+7], 4, 0, (dwords_remaining<=7));
595 print_stuff(out, SubeventData[current_offset+6], 8, 0, (dwords_remaining<=6));
596 print_stuff(out, SubeventData[current_offset+5], 8, 0, (dwords_remaining<=5));
600 print_stuff(out, SubeventData[current_offset+4], 8, 0, (dwords_remaining<=4));
601 print_stuff(out, SubeventData[current_offset+3], 8, 0, (dwords_remaining<=3));
602 print_stuff(out, SubeventData[current_offset+2], 4, 16, (dwords_remaining<=2));
606 print_stuff(out, SubeventData[current_offset+2], 4, 0, (dwords_remaining<=2));
607 print_stuff(out, SubeventData[current_offset+1], 8, 0, (dwords_remaining<=1));
608 print_stuff(out, SubeventData[current_offset+0], 8, 0, (dwords_remaining<=0));
609 out <<
" " << std::dec << std::endl << std::setfill(
' ');
613 if (dwords_remaining<8)
break;
615 current_offset += DWORDS_PER_WORD;
623 out << std::dec << std::endl <<
SETW(5) << j <<
" | ";
627 out <<
SETW(10) << SubeventData[j++] <<
" ";