6 #define coutfl cout << __FILE__<< " " << __LINE__ << " "
7 #define cerrfl cerr << __FILE__<< " " << __LINE__ << " "
66 unsigned char *gtm = (
unsigned char *)dat;
69 payload->
pkt_type = gtm[0] | ((
unsigned short)gtm[1] << 8);
79 payload->
bco = ((
unsigned long long)gtm[2] << 0)
80 | ((
unsigned long long)gtm[3] << 8)
81 | ((
unsigned long long)gtm[4] << 16)
82 | ((
unsigned long long)gtm[5] << 24)
83 | ((
unsigned long long)gtm[6] << 32)
84 | (((
unsigned long long)gtm[7]) << 40);
85 payload->
lvl1_count = ((
unsigned int)gtm[8] << 0)
86 | ((
unsigned int)gtm[9] << 8)
87 | ((
unsigned int)gtm[10] << 16)
88 | ((
unsigned int)gtm[11] << 24);
90 | ((
unsigned int)gtm[13] << 8)
91 | ((
unsigned int)gtm[14] << 16)
92 | ((
unsigned int)gtm[15] << 24);
93 payload->
last_bco = ((
unsigned long long)gtm[16] << 0)
94 | ((
unsigned long long)gtm[17] << 8)
95 | ((
unsigned long long)gtm[18] << 16)
96 | ((
unsigned long long)gtm[19] << 24)
97 | ((
unsigned long long)gtm[20] << 32)
98 | (((
unsigned long long)gtm[21]) << 40);
114 unsigned int index = 0;
120 while (index < payload_length)
123 const unsigned int datalength = 0xf;
128 unsigned int fee_id = buffer[
index] & 0xff;
133 for (
unsigned int i = 0;
i < datalength;
i++)
136 if (index >= payload_length)
break;
138 fee_data[fee_id].push_back(buffer[index++]);
142 unsigned short buf[16];
145 for (
unsigned int i = 0;
i < 16;
i++) {
146 buf[
i] = buffer[index++];
154 index += datalength + 1;
174 for ( pos = 0; pos <
fee_data[ifee].size() ; )
178 if ( skip_amount < 0)
break;
183 unsigned int startpos =
pos;
203 sw->
channel = header[1] & 0x1ff;
205 | ((header[2] & 0x3ff) << 1)
209 unsigned short data_size = header[5] -1 ;
216 for (
int i = 0 ;
i < data_size ;
i++)
222 unsigned short crc =
crc16(ifee, startpos, header[0]-1);
256 if (strcmp(what,
"N_TAGGER") == 0)
261 else if (strcmp(what,
"TAGGER_TYPE") == 0 )
269 else if (strcmp(what,
"IS_ENDAT") == 0 )
277 else if (strcmp(what,
"IS_LEVEL1_TRIGGER") == 0 )
285 else if (strcmp(what,
"BCO") == 0 )
293 else if (strcmp(what,
"LEVEL1_COUNT") == 0 )
301 else if (strcmp(what,
"ENDAT_COUNT") == 0 )
309 else if (strcmp(what,
"LAST_BCO") == 0 )
317 else if (strcmp(what,
"MODEBITS") == 0 )
330 if ( n < 0)
return 0;
336 unsigned int m = sample;
352 if ( strcmp(what,
"NR_WF") == 0 )
357 else if ( strcmp(what,
"MAX_FEECOUNT") == 0 )
363 else if ( strcmp(what,
"SAMPLES") == 0 )
372 else if ( strcmp(what,
"FEE") == 0 )
381 else if ( strcmp(what,
"SAMPAADDRESS") == 0 )
390 else if ( strcmp(what,
"SAMPACHANNEL") == 0 )
399 else if ( strcmp(what,
"CHANNEL") == 0 )
408 else if ( strcmp(what,
"BCO") == 0 )
417 else if ( strcmp(what,
"CHECKSUM") == 0 )
426 else if ( strcmp(what,
"CHECKSUMERROR") == 0 )
444 unsigned int pos = yy;
445 std::vector<unsigned short> header_candidate;
455 if ( pos >= orig.size())
460 header_candidate.push_back(orig[pos]);
469 if (header_candidate[4] ==
MAGIC_KEY_0 && header_candidate[6] ==
MAGIC_KEY_1 && (header_candidate[0] - header_candidate[5] == HEADER_LENGTH))
477 if ( pos >= orig.size())
483 header_candidate.erase(header_candidate.begin());
484 header_candidate.push_back(orig[pos]);
496 if (
lValue(0,
"N_TAGGER") == 0)
497 os <<
" No lvl1 and Endat taggers" << endl;
500 os <<
" TAGGER_TYPE BCO LEVEL1 CNT ENDAT CNT LAST_BCO MODEBITS" << endl;
502 for (
int i = 0;
i <
lValue(0,
"N_TAGGER"); ++
i)
504 os <<
" 0x" << setw(4) << hex <<
lValue(
i,
"TAGGER_TYPE") << dec
505 <<
" (" << (
lValue(
i,
"IS_ENDAT") ?
"ENDAT" :
"") << (
lValue(
i,
"IS_LEVEL1_TRIGGER") ?
"LVL1 " :
"")
507 << setw(12) << hex <<
lValue(
i,
"BCO") << dec <<
" "
508 << setw(10) <<
lValue(
i,
"LEVEL1_COUNT") <<
" "
509 << setw(10) <<
lValue(
i,
"ENDAT_COUNT") <<
" "
510 << setw(12) << hex <<
lValue(
i,
"LAST_BCO") << dec
511 <<
" 0x" << std::setfill(
'0') << setw(2) << hex <<
lValue(
i,
"MODEBITS") << std::setfill(
' ')<< dec
518 os <<
" number of waveforms " <<
iValue(0,
"NR_WF") << endl;
520 for (
int i = 0;
i <
iValue(0,
"NR_WF") ;
i++)
522 os <<
" FEE Channel Sampachannel Samples BCO CRC_ERR" << endl;
524 os << setw(5) <<
iValue(
i,
"FEE") <<
" "
525 << setw(9) <<
iValue(
i,
"CHANNEL") <<
" "
526 << setw(9) <<
iValue(
i,
"SAMPACHANNEL") <<
" "
527 << setw(12) <<
iValue(
i,
"SAMPLES") <<
" "
528 <<
" 0x" << setw(5) << hex <<
iValue(
i,
"BCO") << dec
530 << setw(4) <<
iValue(
i,
"CHECKSUMERROR")
533 for (
int j = 0;
j <
iValue(
i,
"SAMPLES") ;
j += 10)
536 for (
int k = 0;
k < 10 ;
k++)
551 unsigned short n =
x;
552 n = ((n >> 1) & 0x55555555) | ((n << 1) & 0xaaaaaaaa);
553 n = ((n >> 2) & 0x33333333) | ((n << 2) & 0xcccccccc);
554 n = ((n >> 4) & 0x0f0f0f0f) | ((n << 4) & 0xf0f0f0f0);
555 n = ((n >> 8) & 0x00ff00ff) | ((n << 8) & 0xff00ff00);
565 unsigned short crc = 0xffff;
567 for (
int i = 0;
i < l;
i++)
572 for (
unsigned short k = 0;
k < 16;
k++)
574 crc = crc & 1 ? (crc >> 1) ^ 0xa001 : crc >> 1;