6 #define coutfl cout << __FILE__<< " " << __LINE__ << " "
7 #define cerrfl cerr << __FILE__<< " " << __LINE__ << " "
36 #define HEADER_LENGTH 9
46 unsigned int index = 0;
57 while (buffer[index] != 0xfeee && buffer[index+1] != 0xba5e)
62 unsigned short word_count;
63 unsigned short link_count;
64 unsigned short link_enabled;
68 for (
int a = 0;
a < 16;
a++) locked[
a] = 0;
71 while ( index < payload_length)
74 if (buffer[index] == 0xfeee && buffer[index+1] == 0xba5e)
77 word_count = (buffer[index+2] >> 4) + 1;
78 link_count = buffer[index+2] & 0xf;
79 link_enabled = buffer[index+3];
88 unsigned short offset_table[16] = {0};
91 for (
int bitcnt = 0 ; bitcnt < 16; bitcnt++)
93 if ( (link_enabled & (1 << bitcnt)) != 0)
95 offset_table[offset_idx] = bitcnt;
106 for (index += 4, idx=0; idx < word_count * link_count ; idx++, index++)
108 link = offset_table[idx % link_count];
112 fee_data[link].push_back(buffer[index]);
114 else if (buffer[index] == 0xfeed)
118 fee_data[link].push_back(buffer[index]);
127 cout << __FILE__<<
" " << __LINE__ <<
" corrupted FEE data missing 0xfeee 0xba5e marker. Stop further decoding "<< endl;
141 unsigned int record_len = 0;
143 unsigned int channel;
144 unsigned int sampa_addr;
145 unsigned int bx_count;
147 unsigned int old_bxcount = 0;
148 unsigned int first_bx = 0xffffff;
149 unsigned int rollover_offset = 0;
151 for ( index = 0; index <
fee_data[fee].size(); index += record_len + 2 )
163 record_len =
fee_data[fee].at(index+1);
164 if ( index + record_len + 2 >=
fee_data[fee].size())
break;
167 channel =
fee_data[fee].at(index+3) & 0x1f;
168 sampa_addr = (
fee_data[fee].at(index+3) >> 5) & 0xf;
173 if ( bx_count < old_bxcount )
175 rollover_offset += 0x100000;
178 old_bxcount = bx_count;
180 if ( first_bx == 0xffffff )
191 unsigned short crc_value =
crc16( fee, index, record_len+1);
192 if ( index + record_len +1 >=
fee_data[fee].size() )
194 cerrfl <<
"index out of range " << index + record_len + 1 <<
" " <<
fee_data[fee].size() <<
" record_len " << record_len << endl;
198 if ( crc_value !=
fee_data[fee].
at(index + record_len +1) )
208 if ( channel >= 32 || sampa_addr > 7 )
210 cout << __FILE__<<
" " << __LINE__ <<
" FEE " << fee
211 <<
" illegal value, sampa address " << sampa_addr <<
" channel " << channel << endl;
215 unsigned int fee_channel = sampa_addr * 32 + channel;
221 cerrfl <<
"index out of range " << index +
s <<
" " <<
fee_data[fee].size() <<
" record_len " << record_len << endl;
239 unsigned int maxvectorsize;
274 sample < 0 || (
unsigned int) sample >=
fee_samples[fee][ch].size() )
return 0;
287 sample < 0 || (
unsigned int) sample >=
fee_samples[fee][ch].size() )
return 0;
290 if ( strcmp(what,
"BXRAW") == 0 )
292 return fee_samples[fee][ch].at(sample).bx_time_raw;
294 else if ( strcmp(what,
"BX") == 0 )
306 if ( strcmp(what,
"NR_SAMPLES") == 0 )
322 if ( strcmp(what,
"MAX_SAMPLES") == 0 )
329 else if ( strcmp(what,
"IS_PRESENT") == 0 )
337 else if ( strcmp(what,
"LOWEST_BX") == 0 )
344 else if ( strcmp(what,
"HIGHEST_BX") == 0 )
351 else if ( strcmp(what,
"MAX_FEECOUNT") == 0 )
357 else if ( strcmp(what,
"BROKEN") == 0 )
372 for (
int i = 0 ; i <
iValue(0,
"MAX_FEECOUNT"); i++)
374 os << setw(9) <<
iValue(i,
"MAX_SAMPLES") <<
" ";
379 for (
int i = 0 ; i <
iValue(0,
"MAX_FEECOUNT"); i++)
381 os << setw(9) << (
unsigned int)
iValue(i,
"LOWEST_BX") <<
" ";
385 os <<
"Highest BX: ";
386 for (
int i = 0 ; i <
iValue(0,
"MAX_FEECOUNT"); i++)
388 os << setw(9) << (
unsigned int)
iValue(i,
"HIGHEST_BX") <<
" ";
393 const int dwidth = 16;
395 for (
int fee = 0; fee <
iValue(0,
"MAX_FEECOUNT") ; fee++)
399 if ( iValue (fee,
"IS_PRESENT") )
401 cout <<
" +++++++++++++++ FEE " << fee <<
" channels " << chblock <<
" through " << chblock + dwidth <<
" ++++++++" << endl;
404 os << setw(3) <<
"nrs" <<
" | " ;
405 for (
int ch = chblock; ch < chblock + dwidth; ch++)
407 os << setw(10) <<
iValue(fee,ch,
"NR_SAMPLES") <<
" " ;
413 for (
int s = 0;
s <
iValue(fee,
"MAX_SAMPLES");
s++)
416 os << setw(3) <<
s <<
" | " ;
417 for (
int ch = chblock; ch < chblock + dwidth; ch++)
419 os << setw(6) << hex <<
iValue(fee,ch,s,
"BX") <<
" " << setw(4) <<
iValue(fee,ch,s) << dec <<
" ";
434 unsigned short n =
x;
435 n = ((n >> 1) & 0x55555555) | ((n << 1) & 0xaaaaaaaa);
436 n = ((n >> 2) & 0x33333333) | ((n << 2) & 0xcccccccc);
437 n = ((n >> 4) & 0x0f0f0f0f) | ((n << 4) & 0xf0f0f0f0);
438 n = ((n >> 8) & 0x00ff00ff) | ((n << 8) & 0xff00ff00);
449 unsigned short crc = 0xffff;
453 unsigned short x =
fee_data[fee].at(i++);
456 for (
unsigned short k = 0;
k < 16;
k++)
458 crc = crc & 1 ? (crc >> 1) ^ 0xa001 : crc >> 1;