11 #include <DAQ_READER/daq_dta.h>
13 #include <I386/atomic.h>
15 #include "itpcInterpreter.h"
18 static void hammingdecode(
unsigned int buffer[2],
bool& error,
bool& uncorrectable,
bool fix_data) ;
20 struct itpcInterpreter::itpc_config_t
itpcInterpreter::itpc_config[25] ;
23 int itpcInterpreter::itpc_fee_map[24][4][16] = {
25 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
26 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
27 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
28 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
31 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
32 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
35 { 7, 1, 0,12,24,17,13, 8,28, 2,19,20,29,25,21, 3},
36 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
39 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
40 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
41 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
42 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
46 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
47 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
48 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
49 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
53 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
54 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
56 { 7, 1,17,12,24,19,13, 8,28, 2, 3,20,29,25,21, 0},
57 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
61 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
62 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
63 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
64 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
68 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
69 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
70 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
71 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
75 {49,52,46, 0, 0, 54,0,47, 0,50,48,55, 0, 0,51,53},
76 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
77 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
78 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
82 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
83 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
84 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
85 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
89 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
90 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
91 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
92 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
97 {49,52,46,47, 0, 54,0, 0, 0,50, 0,55,48, 0,51,53},
98 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
99 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
100 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
104 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
105 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
106 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
107 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
111 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
112 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
113 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
114 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
117 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
118 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
119 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
120 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
123 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
124 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
125 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
126 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
129 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
130 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
131 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
132 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
136 {49,52, 0, 0,46, 54,0,47, 0,50, 0,55,48, 0,51,53},
137 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
138 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
139 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
142 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
143 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
144 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
145 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
148 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
149 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
150 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
151 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
154 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
155 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
156 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
157 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
161 {49,52,46, 0, 0,54,47, 0, 0,50, 0,55,48, 0,51,53},
162 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
163 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
164 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
167 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
168 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
169 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
170 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
173 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
174 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
175 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
176 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
179 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
180 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
181 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
182 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
186 int itpcInterpreter::fee_map_check()
188 LOG(TERR,
"fee_map_check") ;
190 for(
int s=0;s<24;s++) {
193 memset(padplane,0xFF,
sizeof(padplane)) ;
195 for(
int r=0;r<4;r++) {
196 for(
int p=0;p<16;p++) {
197 int pd = itpc_fee_map[s][r][p] ;
201 if(padplane[pd] == 0xFFFFFFFF) {
202 padplane[pd] = ((r+1)<<8)|(p + 1);
205 int rdo = padplane[pd]>>8 ;
206 int port = padplane[pd]&0xFF ;
207 LOG(ERR,
"S%02d:%d -- port %d, padplane %2d: taken padlane by port %d:%02d",s+1,r+1,p+1,pd,rdo,port) ;
212 for(
int p=0;p<64;p++) {
213 u_int pd = padplane[p] ;
216 if(pd != 0xFFFFFFFF) {
217 LOG(ERR,
"S%02d: illegal padplane %2d",s+1,p) ;
222 LOG(ERR,
"S%02d: padplane %2d missing",s+1,p) ;
232 u_int itpcInterpreter::ifee_mask(
int sec1,
int rdo1)
236 for(
int i=0;i<16;i++) {
237 if(itpc_fee_map[sec1-1][rdo1-1][i]) mask |= (1<<i) ;
254 LOG(ERR,
"WHAT %d???",rdo1) ;
262 int itpcInterpreter::parse_default()
266 memset(&itpc_config,0,
sizeof(itpc_config)) ;
268 for(
int sec=1;sec<=24;sec++) {
270 u_int mask = ifee_mask(sec,
rb+1) ;
272 itpc_config[sec].rdo[
rb].rdo_id =
rb+1 ;
273 itpc_config[sec].rdo[
rb].wire1 = 0 ;
274 itpc_config[sec].rdo[
rb].fee_mask = mask ;
275 itpc_config[sec].rdo[
rb].phase = 90 ;
277 for(
int i=0;i<16;i++) {
278 if(mask & (1<<i)) itpc_config[sec].rdo[
rb].fee_count++ ;
283 for(
int port=0;port<16;port++) {
284 itpc_config[sec].rdo[
rb].fee[port].wire1 = 0 ;
285 itpc_config[sec].rdo[
rb].fee[port].padplane_id = itpc_fee_map[sec-1][
rb][port] ;
286 itpc_config[sec].rdo[
rb].fee[port].sampa_version = 3 ;
295 int itpcInterpreter::parse_config(
const char *fname)
297 LOG(ERR,
"Should not use parse_config") ;
300 if(fname==0) fname =
"/RTS/conf/itpc/itpc_config.txt" ;
302 FILE *f = fopen(fname,
"r") ;
304 LOG(ERR,
"%s: %s [%s]",__PRETTY_FUNCTION__,fname,strerror(errno)) ;
308 memset(&itpc_config,0,
sizeof(itpc_config)) ;
312 int sec,rdo,
rb,phase,port,padplane ;
316 if(fgets(line,
sizeof(line),f)==0) continue ;
318 if(strncmp(line,
"R ",2)==0) {
319 ret = sscanf(line,
"R %d %d %d %X %X %d",&sec,&rdo,&rb,&wire1,&mask,&phase) ;
321 LOG(ERR,
"%s: malformed line [%s]",fname,line) ;
325 itpc_config[sec].rdo[rb].rdo_id = rdo ;
326 itpc_config[sec].rdo[rb].wire1 = wire1 ;
327 itpc_config[sec].rdo[rb].fee_mask = mask ;
328 itpc_config[sec].rdo[rb].phase = phase ;
330 for(
int i=0;i<16;i++) {
331 if(mask & (1<<i)) itpc_config[sec].rdo[rb].fee_count++ ;
333 LOG(TERR,
"RDO %d: fee mask 0x%04X, fee_count %d",rb+1,mask,itpc_config[sec].rdo[rb].fee_count) ;
336 else if(strncmp(line,
"F ",2)==0) {
339 ret = sscanf(line,
"F %d %d %X %d %d",&sec,&rdo,&wire1,&port,&padplane) ;
341 LOG(ERR,
"%s: malformed line [%s]",fname,line) ;
346 if(strstr(line,
"V3")) v = 3 ;
347 else if(strstr(line,
"V4")) v = 4 ;
350 for(
int i=0;i<4;i++) {
351 if(itpc_config[sec].rdo[i].rdo_id == rdo) {
352 itpc_config[sec].rdo[i].fee[port].wire1 = wire1 ;
353 itpc_config[sec].rdo[i].fee[port].padplane_id = padplane ;
354 itpc_config[sec].rdo[i].fee[port].sampa_version = v ;
356 LOG(WARN,
"S%02d:%2d:#%02d: 0x%X SAMPA is V%d",sec+1,i+1,port,wire1,v) ;
371 itpcInterpreter::itpcInterpreter()
389 expected_rdo_version = -1 ;
390 expected_fee_version = -1 ;
393 memset(fee,0,
sizeof(fee)) ;
394 memset(itpc_config,0,
sizeof(itpc_config)) ;
399 atomic_t itpcInterpreter::run_errors[4][16] ;
401 void itpcInterpreter::run_start(u_int run)
408 fprintf(fout,
"***** RUN_START: %08u\n",run_number) ;
412 if(
id==1) memset(run_errors,0,
sizeof(run_errors)) ;
414 LOG(DBG,
"Starting run %08u",run_number) ;
417 void itpcInterpreter::run_err_add(
int rdo1,
int type)
419 atomic_inc(&run_errors[rdo1-1][type]) ;
422 void itpcInterpreter::run_stop()
426 fprintf(fout,
"***** RUN_STOP: %08u\n",run_number) ;
432 LOG(INFO,
"%d: stopping run %08u after %d/%d events",
id,run_number,fee_evt_cou,evt_ix) ;
435 for(
int i=0;i<4;i++) {
436 for(
int j=0;j<16;j++) {
437 if(atomic_read(&run_errors[i][j])) {
438 LOG(ERR,
"RDO %d: error type %d = %u",i+1,j,atomic_read(&run_errors[i][j])) ;
446 void itpcInterpreter::start_event(u_int bytes)
467 memset(evt_err,0,
sizeof(evt_err)) ;
470 void itpcInterpreter::stop_event()
472 for(
int i=0;i<8;i++) {
473 if(evt_err[i]) LOG(ERR,
"%d: event errors[%d] = %u",rdo_id,i,evt_err[i]) ;
480 static inline u_int sw16(u_int d)
486 d |= (tmp & 0xFFFF)<<16 ;
497 u_int *itpcInterpreter::fee_scan(u_int *start, u_int *end)
520 u_int dd_x = d[0] & 0xFFC000FF ;
523 if(dd_x != 0x80000001) {
539 dd_x = dd & 0xFFC000FF ;
542 LOG(NOTE,
"FEE #%d: %u 0x%08X",fee_port,d-start,dd) ;
550 LOG(ERR,
"%d: FEE #%d[%d] END: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X",rdo_id,fee_port,fee_id,
551 d[0],d[1],d[2],d[3],d[4],d[5],d[6]) ;
554 LOG(NOTE,
"FEE #%d[%d] END: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X",fee_port,fee_id,
555 d[0],d[1],d[2],d[3],d[4],d[5],d[6]) ;
559 if((d[-2]&0xFFC00000) != 0x40000000) {
561 if((d[-2]&0xFFC00000) != 0x80000000) {
571 for(
int i=0;i<16;i++) {
573 if(dd == 0x58000009) {
579 LOG(ERR,
"%d: FEE #%d: can't find RDO-END",rdo_id,fee_port) ;
586 u_int t_fee_id = (dd >> 16) & 0x3F ;
588 if((dd_x & 0xFF000000)==0x80000000) fee_id = t_fee_id ;
591 if(fee_id != t_fee_id) {
592 evt_err[ERR_DIFFERENT_FEE_IDS]++ ;
593 LOG(NOTE,
"FEE #%d: IDs differ: expect %d, is %d, 0x%08X",fee_port,fee_id,t_fee_id,dd) ;
603 LOG(ERR,
"%d: FEE #%d: Unexpected 0x%08X",rdo_id,fee_port,dd) ;
606 LOG(ERR,
"%d: FEE #%d: Unexpected 0x%08X",rdo_id,fee_port,dd) ;
611 u_int bx_lo = d[4] & 0xFFFF ;
612 u_int bx_hi = d[5] & 0xFFFF ;
614 bx_lo |= (bx_hi<<16) ;
630 fee_id = (dd>>16)&0x3F ;
633 for(
int i=0;i<4;i++) {
640 expect_mask = 0x0000FFFF ;
643 expect_mask = 0xFFFF0000 ;
650 d = sampa_lane_scan(d,end) ;
654 if(found_ch_mask != expect_mask) {
656 LOG(ERR,
"%d: fee_port %d: missing ch after lane %d: 0x%08X",
657 rdo_id,fee_port,i,found_ch_mask) ;
665 LOG(ERR,
"%d: FEE #%d: %u 0x%08X -- odd",rdo_id,fee_port,d-start,dd) ;
672 LOG(ERR,
"%d: FEE #%d: EVENT error 0x%02X",rdo_id,fee_port,(dd>>8)&0xFF) ;
673 fee[fee_port].event_errs++ ;
704 fee[fee_port].send_config_errs++ ;
705 LOG(ERR,
"FEE #%d: SEND_CONFIG error 0x%02X",fee_port,(dd>>8)&0xFF) ;
711 u_int delta = ((d[3]&0xFFFF)<<16)|(d[2]&0xFFFF) ;
712 int for_me = (d[0] & 0x8000)?1:0 ;
713 int timebins = d[0] & 0x3FF ;
714 int ch = (d[0]>>10)&0x3F ;
715 LOG(TERR,
"FEE #%d: ped: for me %d, ch %d, timebins %d, chsum %u, delta %u",fee_port,for_me,ch,timebins,d[1]&0xFFFF,delta) ;
722 fee[fee_port].pedestal_errs++ ;
723 LOG(ERR,
"FEE #%d: PEDESTAL error 0x%02X",fee_port,(dd>>8)&0xFF) ;
726 LOG(ERR,
"Shouldn't be 0x%X",dd) ;
734 dd_a = dd & 0xFFC0FF00 ;
735 if(dd_a == 0x0000F500 || dd_a==0x00800000) {
736 u_char c = dd & 0xFF ;
739 if(isprint(c) || isspace(c)) ;
742 ascii_dta[ascii_cou++] = c ;
746 ascii_dta[ascii_cou++] = 0 ;
748 fprintf(fout,
"#%02d: %s",fee_port,ascii_dta) ;
753 last = strlen(ascii_dta) - 1 ;
754 if(ascii_dta[last]==
'\n') ascii_dta[last] = 0 ;
756 LOG(TERR,
"FEE_asc %d:#%02d: \"%s\"",rdo_id,fee_port,ascii_dta) ;
761 if(strncmp(ascii_dta,
"1Wire:",6)==0) {
762 char *
id = strstr(ascii_dta,
"ID") ;
764 if(sscanf(
id,
"ID 0x%X",&id1)==1) {
766 fee[fee_port].wire1_id = id1 ;
770 else if(strncmp(ascii_dta,
"Padplane ",9)==0) {
771 if(sscanf(ascii_dta,
"Padplane %d",&id1)==1) {
773 fee[fee_port].padplane_id = id1 ;
777 if(strstr(ascii_dta,
"ERROR")) {
778 last = strlen(ascii_dta) - 1 ;
779 if(ascii_dta[last]==
'\n') ascii_dta[last] = 0 ;
780 LOG(ERR,
"%d: FEE #%d: [%s]",rdo_id,fee_port,ascii_dta) ;
792 evt_err[ERR_UNKNOWN]++ ;
793 LOG(NOTE,
"FEE #%d: %u 0x%08X -- unkown",fee_port,d-start,dd) ;
812 int itpcInterpreter::sampa_ch_scan()
815 int t_stop_last = -1 ;
829 ped_c->fee_id = fee_id ;
831 ped_c->ch_start(fee_ch) ;
835 for(
int i=0;i<tb_cou;) {
838 int t_cou = tb_buff[i++] ;
839 int t_start = tb_buff[i++] ;
843 int t_stop = t_start + t_cou - 1 ;
847 if(t_start <= t_stop_last) {
848 LOG(ERR,
"%d: t_start %d, t_cou %d, t_stop %d, t_stop_last %d",rdo_id,t_start,t_cou,t_stop,t_stop_last) ;
854 LOG(ERR,
"%d: t_start %d, t_cou %d, t_stop %d, t_stop_last %d",rdo_id,t_start,t_cou,t_stop,t_stop_last) ;
859 t_stop_last = t_stop ;
862 for(
int t=t_start;t<=t_stop;t++) {
863 u_short adc = tb_buff[i++] ;
865 ped_c->accum(s,r,p,fee_id,fee_ch,t,adc) ;
870 i += t_stop - t_start + 1 ;
875 if(ped_c) ped_c->ch_done(err) ;
888 u_int *itpcInterpreter::sampa_ch_hunt(u_int *start, u_int *end)
891 u_int *
data = start ;
900 unsigned long long hc ;
906 u_int sampa_id, sampa_ch ;
912 hdr[0] = hdr[1] = 0xFFFFEEEE ;
916 if(data>=end)
goto err_end ;
926 h[0] = (d >> 20) & 0x3FF ;
927 h[1] = (d >> 10) & 0x3FF ;
930 if(data>=end)
goto err_end ;
940 h[3] = (d >> 20) & 0x3FF ;
941 h[4] = (d >> 10) & 0x3FF ;
953 sampa_id = h[2] & 0xF ;
954 sampa_ch = (h[2]>>4) & 0x1F ;
958 l_sampa_bx = (h[2]&0x200) >> 9 ;
959 l_sampa_bx |= (h[3]<<1) ;
960 l_sampa_bx |= (h[4]&0x1FF)<<11 ;
966 for(
int i=0;i<=4;i++) {
967 for(
int j=0;j<10;j++) {
968 if(h[i] & (1<<j)) p_cou++ ;
978 hc = ((
long long)h[4]<<40)|((
long long)h[3]<<30)|(h[2]<<20)|(h[1]<<10)|h[0];
979 hh[0] = hc & 0x3FFFFFFF ;
983 hammingdecode(hh, hamming_err,uncorrectable,0) ;
1000 if(sampa_ch != 21) {
1020 LOG(WARN,
"Found SAMPA %d:%d [0x%08X 0x%08X]",sampa_id,sampa_ch,hdr[0],hdr[1]) ;
1025 LOG(ERR,
"Found no SAMPA channels") ;
1029 u_int *itpcInterpreter::sampa_lane_scan(u_int *start, u_int *end)
1038 int ch_loop_cou = 0 ;
1043 unsigned long long hc ;
1045 bool uncorrectable ;
1059 fee_id = (d >> 16) & 0x3F ;
1060 lane = (d>>24) & 0x3 ;
1062 if((first_b & 0xFC000000)!=0xB0000000) {
1063 LOG(ERR,
"SAMPA FIFO overwrite 0x%08X!",first_b) ;
1076 if(d & 0xC0000000) {
1077 hdr[1] = 0xAABBCCDD ;
1078 memset(h,0xAB,
sizeof(h)) ;
1081 LOG(ERR,
"%d: Bad Hdr 1",rdo_id) ;
1085 h[0] = (d >> 20) & 0x3FF ;
1086 h[1] = (d >> 10) & 0x3FF ;
1092 if(d & 0xC0000000) {
1093 h[3] = h[4] = h[5] = 0x11223344 ;
1095 LOG(ERR,
"%d: Bad Hdr 2",rdo_id) ;
1099 h[3] = (d >> 20) & 0x3FF ;
1100 h[4] = (d >> 10) & 0x3FF ;
1111 sampa_id = h[2] & 0xF ;
1112 sampa_ch = (h[2]>>4) & 0x1F ;
1119 LOG(ERR,
"sampa_id %d, lane %d",sampa_id,lane) ;
1125 LOG(ERR,
"sampa_id %d, lane %d",sampa_id,lane) ;
1133 if(ch_loop_cou==1) {
1139 LOG(WARN,
"first in lane sampa_ch is %d not 0?",sampa_ch) ;
1144 if(sampa_ch != 16) {
1146 LOG(WARN,
"first in lane sampa_ch is %d not 16?",sampa_ch) ;
1153 if(sampa_id & 1) fee_ch = sampa_ch + 32 ;
1154 else fee_ch = sampa_ch ;
1156 l_sampa_bx = (h[2]&0x200) >> 9 ;
1157 l_sampa_bx |= (h[3]<<1) ;
1158 l_sampa_bx |= (h[4]&0x1FF)<<11 ;
1165 for(
int i=0;i<=4;i++) {
1166 for(
int j=0;j<10;j++) {
1167 if(h[i] & (1<<j)) p_cou++ ;
1179 hc = ((
long long)h[4]<<40)|((
long long)h[3]<<30)|(h[2]<<20)|(h[1]<<10)|h[0];
1181 hh[0] = hc & 0x3FFFFFFF ;
1185 hammingdecode(hh, hamming_err,uncorrectable,0) ;
1188 if(parity_err || hamming_err) {
1189 LOG(ERR,
"%d:%d: Type %d, words %d, SAMPA %d:%d, BX %u, errors %d:%d",rdo_id,fee_port,type,words,sampa_id,sampa_ch,l_sampa_bx,parity_err,hamming_err) ;
1201 LOG(WARN,
"%d: Type %d, words %d, SAMPA %d:%d, BX %u, errors %d:%d, fee_port %d, lane_hdr 0x%08X",
1202 rdo_id,type,words,sampa_id,sampa_ch,l_sampa_bx,parity_err,hamming_err,fee_port,lane_hdr) ;
1208 if(sampa_ch != 21) {
1217 LOG(ERR,
"%d: Type %d, words %d, SAMPA %d:%d, BX %u [lane_hdr 0x%08X],fee_port %d",rdo_id,type,words,sampa_id,sampa_ch,l_sampa_bx,lane_hdr,fee_port) ;
1222 LOG(ERR,
"%d: Type %d, words %d, SAMPA %d:%d, BX %u [lane_hdr 0x%08X]",rdo_id,type,words,sampa_id,sampa_ch,l_sampa_bx,lane_hdr) ;
1229 sampa_bx = l_sampa_bx ;
1231 else if(sampa_bx != l_sampa_bx) {
1232 if(abs(sampa_bx - l_sampa_bx)>1) {
1240 word32 = words / 3 + (words%3?1:0) ;
1245 if(ped_c && ped_c->want_data) {
1247 ped_c->sector = sector_id ;
1248 ped_c->rdo = rdo_id ;
1249 ped_c->port = fee_port ;
1251 if(ped_c->do_ch(fee_id, fee_ch, data, words)) {
1260 for(u_int i=0;i<word32;i++) {
1263 if((d&0xC0000000)) {
1264 LOG(ERR,
"%d:%d: %d:%d sampa data word %d/%d = 0x%08X",rdo_id,fee_port,sampa_id,sampa_ch,i,word32,d) ;
1269 LOG(ERR,
"Returning here") ;
1277 tb_buff[t_cou++] = (d>>20) & 0x3FF ;
1278 tb_buff[t_cou++] = (d>>10) & 0x3FF ;
1279 tb_buff[t_cou++] = d & 0x3FF ;
1282 if(sampa_ch_scan()<0) {
1294 run_err_add(rdo_id,6) ;
1296 LOG(ERR,
"%d: Last SAMPA: FEE #%d: %d:%d = 0x%08X [err 0x%0x]",rdo_id,fee_port,sampa_id,sampa_ch,*data,err) ;
1299 if(found_ch_mask & (1<<sampa_ch)) {
1300 LOG(ERR,
"SAMPA ch %d already found!",sampa_ch) ;
1302 found_ch_mask |= (1<<sampa_ch) ;
1303 LOG(NOTE,
"Last SAMPA %d:%d = 0x%08X [err 0x%0x]",sampa_id,sampa_ch,*data,err) ;
1311 if(*data & 0xC0000000) {
1313 if((data[0] & 0xFC000000)!=0x70000000) {
1314 LOG(ERR,
"bad end 0x%08X",data[0]) ;
1319 if(ch_loop_cou != 16) {
1332 LOG(ERR,
"%d: ERR 0x%X: 0x%03X 0x%03X 0x%03X 0x%03X 0x%03X 0x%03X",rdo_id,err,
1333 h[0],h[1],h[2],h[3],h[4],h[5]) ;
1334 LOG(ERR,
" 0x%08X 0x%08X",hdr[0],hdr[1]) ;
1337 u_int *n_data = sampa_ch_hunt(data,end) ;
1349 void itpcInterpreter::fee_dbase(
const char *fname)
1358 strcpy(hname,
"host-unknown") ;
1359 gethostname(hname,
sizeof(hname)) ;
1362 strcpy(uname,
"user-unknown") ;
1363 getlogin_r(uname,
sizeof(uname)) ;
1367 fname =
"/RTScache/fee_dbase.csv" ;
1371 db = fopen(fname,
"a") ;
1374 LOG(ERR,
"%s: %s [%s]",__PRETTY_FUNCTION__,fname,strerror(errno)) ;
1378 time_t tm = time(0) ;
1380 char *ct = ctime(&tm) ;
1381 ct[strlen(ct)-1] = 0 ;
1385 for(
int i=1;i<=16;i++) {
1387 if(fee[i].wire1_id == 0) continue ;
1396 for(
int c=0;c<64;c++) {
1397 if(p_c && p_c->fee_err[sector_id-1][rdo_id-1][i-1][c]) {
1400 int fl = p_c->fee_err[sector_id-1][rdo_id-1][i-1][c] ;
1408 if(c<=31) reflow |= 1 ;
1425 sprintf(err_str,
"PINS_%d ",bad_pin) ;
1430 strcat(err_str,
"REFLOW SAMPA ") ;
1432 else if(bad_pin <= 1) {
1437 strcat(err_str,
"0 ") ;
1441 strcat(err_str,
"and 1") ;
1444 strcat(err_str,
"1") ;
1448 LOG(ERR,
"FEE 0x%08X, port %2d: BAD: %s",fee[i].wire1_id,i,err_str) ;
1454 sprintf(err_str,
"errs%d=0x%X",err,flag) ;
1457 sprintf(err_str,
"NC") ;
1461 fprintf(db,
"0x%08X,%2d,%2d,0x%08X,%d,%s,%s,%s,%s\n",fee[i].wire1_id,fee[i].padplane_id,i,
1462 rdo_wire1_id,rdo_id,uname,hname,ct,err_str) ;
1473 int itpcInterpreter::ana_send_config(u_int *data, u_int *data_end)
1481 if(*data != 0x98000066) {
1482 LOG(ERR,
"data is 0x%08X",*data) ;
1489 while(data<data_end) {
1492 if((d & 0xFFFFFF00)==0x9800F500) {
1494 if(c==
'\n' || ascii_cou==120) {
1495 ascii_dta[ascii_cou++] = 0 ;
1497 LOG(INFO,
"%d: \"%s\"",rdo_id,ascii_dta) ;
1501 ascii_dta[ascii_cou++] = c ;
1506 else LOG(ERR,
"end at 0x%08X [%d]",d,data_end-data) ;
1515 if(d != 0x980000FA) {
1516 LOG(ERR,
"%d: Bad FA 0x%08X",rdo_id,d) ;
1525 rdo_wire1_id = data[7] ;
1532 if(d != 0x580000FB) {
1533 LOG(ERR,
"%d: Bad FB 0x%08X",rdo_id,d) ;
1540 if(d != 0x980000FC) {
1541 LOG(ERR,
"%d: Bad FC 0x%08X",rdo_id,d) ;
1546 while(data<data_end) {
1549 if((d & 0xFFFFFF00)==0x9800F500) {
1551 if(c==
'\n' || ascii_cou==120) {
1552 ascii_dta[ascii_cou++] = 0 ;
1554 LOG(INFO,
"%d: \"%s\"",rdo_id,ascii_dta) ;
1558 ascii_dta[ascii_cou++] = c ;
1563 else LOG(ERR,
"end at 0x%08X [%d]",d,data_end-data) ;
1573 if(d != 0x98000018) {
1574 LOG(ERR,
"%d: Bad 18 0x%08X",rdo_id,d) ;
1581 if((d & 0xFF00FFFF)!=0xA00000A0) {
1582 LOG(ERR,
"%d: bad FEE ASCII 0x%08X",rdo_id,d) ;
1589 while(data<data_end) {
1590 u_int dd_a, dd_b, dd_c ;
1597 dd_a = d & 0xFFC0FF00 ;
1598 dd_b = d & 0xFFC000FF ;
1599 dd_c = d & 0xFFC0000F ;
1601 if(dd_c==0x98000008) {
1602 fee_port = (d >> 4) & 0xFF ;
1605 else if(dd_a==0x0000F500 || dd_a==0x00800000) {
1607 if(c==
'\n' || ascii_cou==120) {
1608 ascii_dta[ascii_cou++] = 0 ;
1612 if(strncmp(ascii_dta,
"1Wire:",6)==0) {
1613 char *
id = strstr(ascii_dta,
"ID") ;
1615 if(sscanf(
id,
"ID 0x%X",&id1)==1) {
1616 fee[fee_port].wire1_id = id1 ;
1620 else if(strncmp(ascii_dta,
"Padplane ",9)==0) {
1621 if(sscanf(ascii_dta,
"Padplane %d",&id1)==1) {
1622 fee[fee_port].padplane_id = id1 ;
1625 else if(strncmp(ascii_dta,
"V: all",6)==0) {
1626 if(sscanf(ascii_dta,
"V: all 0x%X",&id1)==1) {
1627 fpga_fee_v_all = id1 ;
1633 if(strstr(ascii_dta,
"ERROR")) {
1634 LOG(ERR,
"FEE_asc %d:#%02d: \"%s\"",rdo_id,fee_port,ascii_dta) ;
1637 LOG(TERR,
"FEE_asc %d:#%02d: \"%s\"",rdo_id,fee_port,ascii_dta) ;
1644 ascii_dta[ascii_cou++] = c ;
1647 else if(dd_b==0xA00000A0 || dd_b==0x600000A0) {
1658 if((data_end-data)==0) ;
1659 else LOG(ERR,
"at end 0x%08X [%d]",*data,data_end-data) ;
1665 int itpcInterpreter::ana_triggered(u_int *data, u_int *data_end)
1669 u_int soft_err = 0 ;
1671 u_int evt_status = 0 ;
1673 int expect_fee_cou = itpc_config[sector_id].rdo[rdo_id-1].fee_count ;
1680 if(trg==0)
return 0 ;
1692 if(data[0] == 0x98001000)
return 0 ;
1694 if(fee_cou==0) fee_evt_cou++ ;
1709 if(data[0]==0x0FEEC0DE) {
1712 else if((data[0]&0xFF00FFFF)==0x80000010) {
1717 LOG(ERR,
"%d: bad first FEE datum 0x%08X",rdo_id,data[0]) ;
1718 if((data[0]&0x0000FFFF)==0xC0DE) {
1724 if((data[0] & 0xFFC0FFFF)==0x80000001) {
1726 fee_id = (data[0]>>16) & 0xFF ;
1729 u_int f_id[3], d_x[3] ;
1741 f_id[0] = (data[0]>>16) & 0x3F ;
1742 f_id[1] = (data[1]>>16) & 0x3F ;
1743 f_id[2] = (data[2]>>16) & 0x3F ;
1746 d_x[0] = data[0] & 0xFFC0FFFF ;
1747 d_x[1] = data[1] & 0xFFC0FFFF ;
1748 d_x[2] = data[2] & 0xFFC0FFFF ;
1750 if(d_x[0]==0x80000010) {
1752 if(d_x[1]==0x00004321) f_ok |= 2 ;
1753 if(d_x[2]==0x00008765) f_ok |= 4 ;
1755 if(f_id[0]==f_id[1]) f_ok |= 8 ;
1756 if(f_id[1]==f_id[2]) f_ok |= 0x10 ;
1757 if(f_id[0]==f_id[2]) f_ok |= 0x20 ;
1760 u_int w = data[0]>>28 ;
1767 LOG(ERR,
"%d: 0x%08X 0x%08X 0x%08X [0x%02X] (not an error)",rdo_id,data[0],data[1],data[2],f_ok) ;
1768 LOG(ERR,
"%d: 0x%08X 0x%08X 0x%08X [0x%02X] (not an error)",rdo_id,data[-3],data[-2],data[-1],f_ok) ;
1776 run_err_add(rdo_id,0) ;
1780 for(
int i=0;i<3;i++) {
1781 if(d_x[i]==0x00004321) {
1787 if(expected_fee_version >= 0) {
1788 if(fee_version != expected_fee_version) {
1789 LOG(ERR,
"FEE version %d, expected %d",fee_version,expected_fee_version) ;
1797 fee_id = (data[0]>>16) & 0x3F ;
1799 switch(fee_version) {
1801 if(data[0] != ((fee_id<<16)|0x4321)) err |= 0x10000 ;
1802 if(data[1] != ((fee_id<<16)|0x8765)) err |= 0x20000 ;
1804 if((u_int)fee_version != (data[2] & 0xFFFF)) err |= 0x40000 ;
1806 if(data[3]&0xFFF0) err |= 0x40000 ;
1807 fee_port = (data[3] & 0xF) + 1 ;
1810 if(data[6] != ((fee_id<<16)|0x60000010)) err |= 0x80000 ;
1813 run_err_add(rdo_id,3) ;
1837 for(
int i=0;i<4;i++) {
1840 if((*data & 0xFC000000) != 0xB0000000) {
1845 if((*data & 0xF0000000) == 0xB0000000) {
1847 run_err_add(rdo_id,1) ;
1848 LOG(ERR,
"%d:#%02d: lane %d: FIFO overflow 0x%08X",rdo_id,fee_port,i,*data) ;
1852 run_err_add(rdo_id,4) ;
1853 LOG(ERR,
"%d:#%02d: lane %d: bad sig 0x%08X",rdo_id,fee_port,i,*data) ;
1863 expect_mask = 0x0000FFFF ;
1866 expect_mask = 0xFFFF0000 ;
1871 data = sampa_lane_scan(data,data_end) ;
1873 if(found_ch_mask != expect_mask) {
1874 run_err_add(rdo_id,2) ;
1876 LOG(ERR,
"%d: evt %d: fee_port %d: missing channels in lane %d: expect 0x%08X, got 0x%08X",
1877 rdo_id,evt_ix,fee_port,i,expect_mask,found_ch_mask) ;
1881 for(
int j=0;j<32;j++) {
1882 if(expect_mask & (1<<j)) {
1883 if(!(found_ch_mask & (1<<j))) {
1897 LOG(ERR,
"%d:#%d ch %d missing",rdo_id,fee_port,ch) ;
1909 LOG(ERR,
"data 0!!!!") ;
1921 switch(fee_version) {
1927 if(data[0] == ((fee_id<<16)|0xA00000EC)) {
1931 while(data<data_end) {
1932 if(*data == ((fee_id<<16)|0xA0000010)) {
1937 u_int dd_a = data[0] & 0xFFC0FF00 ;
1939 if(dd_a==0x0000F500 || dd_a==0x00800000) {
1940 int c = data[0] & 0xFF ;
1942 if(c==
'\n' || ascii_cou==120) {
1943 ascii_dta[ascii_cou++] = 0 ;
1945 if(strstr(ascii_dta,
"ERROR")) {
1946 LOG(ERR,
"FEE_asc %d:#%02d: \"%s\"",rdo_id,fee_port,ascii_dta) ;
1949 LOG(TERR,
"FEE_asc %d:#%02d: \"%s\"",rdo_id,fee_port,ascii_dta) ;
1956 ascii_dta[ascii_cou++] = c ;
1966 LOG(ERR,
"No monitoring end?") ;
1978 if(data[0] != ((fee_id<<16)|0xA0000010)) {
1980 LOG(ERR,
"%d:#%02d: hdr FEE word 0x%08X",rdo_id,fee_port,data[0]) ;
1989 if(data[7] != ((fee_id<<16)|0x40000010)) {
1990 LOG(ERR,
"%d:#%02d: last FEE word 0x%08X not 0x40..",rdo_id,fee_port,data[7]) ;
1994 if((data[1] & 0xFFFF)||(data[2]&0xFFFF)||(data[3]&0xFFFF)||(data[4]&0xFFFF)) {
1995 LOG(ERR,
"%d:#%02d: FEE event errors: 0x%X 0x%X 0x%X 0x%X",rdo_id,fee_port,
1996 data[1],data[2],data[3],data[4]) ;
2000 run_err_add(rdo_id,5) ;
2011 if(data > data_end)
goto done ;
2013 if(data[0]==0x98001000)
goto done ;
2015 if(data[1]==0x98001000) {
2021 if(data[0]==0x980000FC)
goto done ;
2023 if(itpc_config[sector_id-1].rdo[rdo_id-1].fee_count && (fee_cou>itpc_config[sector_id-1].rdo[rdo_id-1].fee_count)) {
2024 LOG(ERR,
"RDO %d: fee_count %d",rdo_id,fee_cou) ;
2029 if((data[0]&0xFF00FFFF)==0x80000010 && fee_cou==expect_fee_cou) {
2031 if(data[1]==0x980000FC) {
2051 if(err || soft_err) {
2052 run_err_add(rdo_id,7) ;
2054 LOG(ERR,
"%d:#%02d(id %d,cou %d) evt %d: error 0x%X 0x%X",
2055 rdo_id,fee_port,fee_id,fee_cou,evt_ix,err,soft_err) ;
2058 for(
int i=-4;i<8;i++) {
2059 LOG(ERR,
".... %d = 0x%08X",i,data[i]) ;
2063 if(err || soft_err)
return -1 ;
2081 evt_status = data[1] ;
2083 run_err_add(rdo_id,8) ;
2085 LOG(ERR,
"RDO %d: bad event status 0x%08X",rdo_id,data[1]) ;
2089 int trg_cou = data[2] ;
2091 data += 2+trg_cou+1 ;
2094 if(data[0] != 0x58001001) {
2095 LOG(ERR,
"RDO %d: no end-of-trailer 0x%08X",rdo_id,data[0]) ;
2110 while(data<data_end) {
2113 if((d&0xFFFFFF00)==0x9800F500) {
2116 if(c==
'\n' || ascii_cou==120) {
2117 ascii_dta[ascii_cou++] = 0 ;
2119 LOG(INFO,
"RDO_asc %d: \"%s\"",rdo_id,ascii_dta) ;
2124 ascii_dta[ascii_cou++] = c ;
2128 else if(d==0x580000FD)
goto after_fee ;
2129 else LOG(WARN,
".... %d 0x%08X",data_end-data,d) ;
2135 for(
int i=0;i<16;i++) {
2136 LOG(ERR,
"After FEE: %d [%d] = 0x%08X",i,data_end-data,*data) ;
2143 LOG(ERR,
"%d: evt_status 0x%08X",rdo_id,evt_status) ;
2149 int itpcInterpreter::ana_pedestal(u_int *data, u_int *data_end)
2155 while(data<data_end) {
2156 u_int dd_f = data[0] & 0xFF00FFFF ;
2157 u_int dd_r = data[0] & 0xFF00000F ;
2159 if(data[0]==0x5800FD61) {
2160 LOG(INFO,
"pedestal packet done") ;
2164 if((data[0] & 0xFFFFFF00)==0x98AAAA00) {
2165 LOG(TERR,
"-> Done port %d",(data[0]&0xFF)+1) ;
2167 else if((data[0] & 0xFFFFFF00)==0x98BBBB00) {
2168 LOG(TERR,
"--> Done channel %d",data[0]&0xFF) ;
2170 else if(dd_r==0x98000008) {
2171 fee_port = ((data[0])>>4)&0x1F ;
2173 else if(dd_r==0x58000009) {
2176 else if(dd_f==0x80000003) {
2179 int fee_id = (data[0] >> 16) & 0xFF ;
2181 for(
int i=0;i<7;i++) {
2182 s[i] = data[1+i] & 0xFFFF ;
2185 int for_me = s[0]&1 ;
2186 int my_port = (s[0]>>8) & 0xFF ;
2188 int len = s[1] & 0x3FF ;
2189 int ch = (s[1]>>10)&0x3F ;
2191 u_int ticks1 = (s[4]<<16)|s[3] ;
2192 u_int ticks2 = (s[6]<<16)|s[5] ;
2193 LOG(TERR,
"#%02d(%02d): fee_id %02d: for_me %d: ch %2d, len %3d",fee_port,my_port,fee_id,for_me,ch,len) ;
2194 LOG(TERR,
" chsum 0x%04X, ticks %u %u",s[2],ticks1,ticks2) ;
2202 LOG(TERR,
"... 0x%08X",data[0]) ;
2210 int itpcInterpreter::rdo_scan_top(u_int *data,
int words)
2212 u_int *data_end = data + words ;
2213 u_int *data_start = data ;
2219 evt_bytes = words*4 ;
2227 memset(evt_err,0,
sizeof(evt_err)) ;
2231 int w_cou = (words<16)?words:16 ;
2234 for(
int i=0;i<w_cou;i++) {
2237 if((data[i] == 0xCCCC001C)||(data[i] == 0x001CCCCC)) {
2243 w_cou = data_end - data ;
2245 if(data[0]==0xCCCC001C) {
2247 for(
int i=0;i<w_cou;i++) {
2248 data[i] = sw16(data[i]) ;
2259 LOG(ERR,
"%d: First word is not a START comma!? [0x%08X 0x%08X 0x%08X]",rdo_id,data[-1],data[0],data[1]) ;
2269 if((data[0]&0xFF00000F)==0x98000004) {
2270 rdo_version = (data[0]>>4)&0xFF ;
2283 int trl_stop_ix = -1 ;
2287 for(
int i=(words-12);i>=0;i--) {
2288 if(dbg_level>1) LOG(TERR,
"%d: 0x%08X",i,data[i]) ;
2290 if(data[i]==0x98001000) {
2294 if(data[i]==0x58001001) {
2301 LOG(ERR,
"%d: no trailer found, trl_stop_ix %d",rdo_id,trl_stop_ix) ;
2306 evt_status = (data[trl_ix++]) ;
2307 int trg_cou = (data[trl_ix++]) & 0xFFFF ;
2310 if(evt_status != 0 || trl_stop_ix<0) {
2311 LOG(ERR,
"%d: evt_status 0x%08X, trg_cou %d, words %d, trl_ix %d, trl_stop_ix %d",rdo_id,evt_status,trg_cou,words,trl_ix,trl_stop_ix) ;
2314 for(
int i=0;i<8;i++) {
2315 LOG(TERR,
"%d = 0x%08X",i,data[i]) ;
2317 for(
int i=(words-32);i<words;i++) {
2318 LOG(TERR,
"%d = 0x%08X",i,data[i]) ;
2338 ret = ana_send_config(data,data_end) ;
2342 LOG(TERR,
"%d: run_start packet: 0x%08X 0x%08X 0x%08X",rdo_id,data[0],data[1],data[2]) ;
2344 if(data[2] != 0x11223344) {
2345 LOG(ERR,
"%d: run_start: bad signature 0x%08X",rdo_id,data[2]) ;
2350 LOG(ERR,
"%d: run_start: already bad status 0x%08X",rdo_id,data[1]) ;
2358 ret = ana_pedestal(data,data_end) ;
2361 LOG(WARN,
"End of run 0x%08X",d) ;
2364 if((d & 0xFF00000F)==0x98000004) {
2365 rdo_version = (d >> 4) & 0xFF ;
2367 LOG(NOTE,
"rdo_version %d",rdo_version) ;
2369 if(rdo_version==0) {
2370 ret = rdo_scan(data_start,words) ;
2373 ret = ana_triggered(data,data_end) ;
2379 LOG(ERR,
"Unknown packet 0x%08X",d) ;
2387 for(
int i=0;i<8;i++) {
2388 if(evt_err[i]) LOG(ERR,
"%d: event errors[%d] = %u",rdo_id,i,evt_err[i]) ;
2397 for(
int i=0;i<16;i++) {
2398 LOG(TERR,
".... bad evt: %d = 0x%08X",i,data[i]) ;
2407 int itpcInterpreter::rdo_scan(u_int *data,
int words)
2412 u_int *data_end = data + words ;
2413 u_int *data_start = data ;
2414 u_int rh_xing_start = 0 ;
2419 char mon_string[512] ;
2422 if(data[0] != 0xDDDDDDDD) {
2423 LOG(ERR,
"%d: words %d = 0x%08X",rdo_id,words,data[0]) ;
2431 for(
int i=0;i<16;i++) {
2432 LOG(NOTE,
"...%d/%d = 0x%08X",i,words,data[i]) ;
2434 if((data[i] == 0xCCCC001C)||(data[i] == 0x001CCCCC)) {
2443 LOG(ERR,
"%d: words %d = 0x%08X",rdo_id,words,data[0]) ;
2446 if((data[0] == 0xCCCC001C)||(data[0] == 0x001CCCCC)) ;
2448 LOG(ERR,
"%d: words %d = 0x%08X",rdo_id,words,data[0]) ;
2451 if(data[0]==0xCCCC001C) {
2452 LOG(NOTE,
"swapping") ;
2453 for(
int i=0;i<words;i++) {
2454 data[i] = sw16(data[i]) ;
2458 LOG(NOTE,
"%d: words %d = 0x%08X",rdo_id,words,data[0]) ;
2469 LOG(ERR,
"%d: First word is not a START comma!? [0x%08X 0x%08X 0x%08X]",rdo_id,data[-1],data[0],data[1]) ;
2474 while(data<data_end) {
2477 word_ix = data - data_start ;
2481 LOG(NOTE,
"%d/%d = 0x%08X",word_ix,words,d) ;
2487 LOG(INFO,
"END of something [0x%08X]",d) ;
2492 LOG(TERR,
"... %d = 0x%08X",word_ix,d) ;
2496 LOG(WARN,
"End of run (but still %d words)",data_end-data) ;
2503 if((d&0xFFFF0000)==0x00AA0000) {
2504 u_char c = d & 0xFF ;
2506 if(isprint(c) || isspace(c)) ;
2509 ascii_dta[ascii_cou++] = c ;
2511 ascii_dta[ascii_cou++] = 0 ;
2513 printf(
"HERE #%02d: %s",fee_port,ascii_dta) ;
2515 if(strncmp(ascii_dta,
"1Wire ",6)) {
2517 char *
id = strstr(ascii_dta,
"ID") ;
2518 sscanf(
id,
"ID 0x%X",&id1) ;
2519 printf(
"=====> 0x%08X",id1) ;
2526 LOG(ERR,
"Bad: %d = 0x%08X",word_ix,d) ;
2528 state = S_FEE_ASCII_END ;
2531 case S_FEE_ASCII_END :
2532 if((d&0xF80000FF)!=0x600000A1) {
2533 LOG(ERR,
"Bad %d = 0x%08X",word_ix,d) ;
2538 fee_port = (d&0xFF)+1 ;
2539 LOG(NOTE,
"FEE port #%02d",fee_port) ;
2543 LOG(TERR,
"Trg %2d = 0x%08X",d_cou,d) ;
2545 if((d&0xF80000FF)==0x58000005) {
2554 if((d & 0xF80000FF)==0xA00000A0) {
2555 state = S_FEE_ASCII ;
2560 hdr = d & 0xF800FFFF ;
2564 LOG(INFO,
"SEND_CONFIG: start") ;
2568 fprintf(fout,
"%d: 1-wire Id 0x%08X\n",rdo_id,rdo_wire1_id) ;
2571 LOG(INFO,
"SEND_CONFIG: end for RDO ID 0x%08X",rdo_wire1_id) ;
2572 for(
int i=1;i<=16;i++) {
2573 LOG(INFO,
" FEE #%02d: Padplane %02d, 1Wire 0x%08X",i,fee[i].padplane_id,fee[i].wire1_id) ;
2575 fprintf(fout,
" FEE #%02d: Padplane %02d, 1Wire 0x%08X\n",i,fee[i].padplane_id,fee[i].wire1_id) ;
2579 if(fout) fflush(fout) ;
2586 LOG(INFO,
"RUN_START: start") ;
2589 LOG(INFO,
"RUN_START: stop, events %u",evt_ix) ;
2594 if((data[1]&0xFFC00000)!=0x80000000) {
2595 if((data[1]&0xFFC0FFFF)!=0xA00000A0) {
2602 data = fee_scan(data-1, data_end) ;
2605 LOG(TERR,
"Left fee_port %d: %d",fee_port,data_end-data) ;
2609 while(d<=data_end) {
2610 LOG(TERR,
"%d = 0x%08X",data_end-d,*d) ;
2617 fee_port = *data++ ;
2620 LOG(NOTE,
"RDO FEE data: START: fee_port %d",fee_port) ;
2624 LOG(NOTE,
"RDO FEE data: END: fee_port %d",fee_port) ;
2628 LOG(ERR,
"Duplicate hdr") ;
2632 LOG(NOTE,
"RDO Event Header: START") ;
2634 u_int *d_now = data ;
2636 for(
int i=0;i<10;i++) {
2638 LOG(NOTE,
"Event Header %2d = 0x%08X",i,d) ;
2649 if((data-d_now)!=8) {
2650 LOG(ERR,
"RDO Event Header corrupt %d",data-d_now) ;
2656 LOG(ERR,
"RDO Event Header: END (could be spurious)") ;
2660 LOG(NOTE,
"RDO FEE complement: START") ;
2663 LOG(NOTE,
"RDO FEE complement: END") ;
2669 LOG(ERR,
"RDO FEE Readout Status: START: status 0x%08X",d) ;
2672 LOG(NOTE,
"RDO FEE Readout Status: START: status 0x%08X",d) ;
2676 LOG(NOTE,
"RDO FEE Readout Status: END") ;
2681 LOG(NOTE,
"RDO Boottext: START: %d = 0x%08X",word_ix,d) ;
2684 if((d & 0xFFFFFF00)==0x9800F500) {
2687 mon_string[mon_cou++] = 0 ;
2690 fprintf(fout,
"%d: %s\n",rdo_id,mon_string) ;
2693 LOG(INFO,
"%d: \"%s\"",rdo_id,mon_string) ;
2697 mon_string[mon_cou++] = c ;
2702 LOG(NOTE,
"RDO Boottext: END: %d = 0x%08X",word_ix,d) ;
2710 LOG(ERR,
"RDO Boottext: END: %d = 0x%08X",word_ix,d) ;
2714 LOG(NOTE,
"RDO Monitoring: START: %d = 0x%08X",word_ix,d) ;
2717 if((d & 0xFFFFFF00)==0x9800F500) {
2720 mon_string[mon_cou++] = 0 ;
2721 LOG(INFO,
"%d: \"%s\"",rdo_id,mon_string) ;
2723 fprintf(fout,
"%d: \"%s\"\n",rdo_id,mon_string) ;
2729 mon_string[mon_cou++] = c ;
2734 LOG(NOTE,
"RDO Monitoring: END: %d = 0x%08X",word_ix,d) ;
2742 LOG(ERR,
"RDO Monitoring: END: %d = 0x%08X",word_ix,d) ;
2746 LOG(ERR,
"RDO %d: duplicate trailer",rdo_id) ;
2749 LOG(NOTE,
"RDO: Event Trailer Start") ;
2752 u_int *d_now = data ;
2755 if(data[0] != 0xABCD0000) {
2757 LOG(ERR,
"RDO %d: Event Trailer %u/%u = ABCD 0x%08X",rdo_id,word_ix,words,data[0]) ;
2776 if(flags != 0xF) LOG(ERR,
"flags 0x%X",flags) ;
2779 if((data[3+trg_cou+2]&0xF800FFFF)!=0x58001001) suspect = 1 ;
2792 for(
int i=0;i<100;i++) {
2797 LOG(NOTE,
"Event Trailer %2d = 0x%08X",i,d) ;
2799 if((d&0xF800FFFF)==0x58001001) {
2815 int t_len = data - d_now ;
2818 LOG(ERR,
"RDO %d: Event Trailer Suspect %d - %d",rdo_id,suspect,t_len) ;
2819 for(
int i=0;i<16;i++) {
2820 LOG(TERR,
"%d/%d = 0x%08X",d_now-data_start,words,*d_now) ;
2823 data = data_end + 1 ;
2829 LOG(ERR,
"RDO: Event Trailer End") ;
2833 LOG(NOTE,
"RDO Configuration: START: %d = 0x%08X",word_ix,d) ;
2835 rdo_wire1_id = data[7] ;
2839 LOG(NOTE,
"RDO Configuration: END: %d = 0x%08X",word_ix,d) ;
2842 LOG(NOTE,
"RDO FEE DUMP : START") ;
2846 LOG(ERR,
"%d: FEE #%d: stat 0x%08X 0x%08X 0x%08X 0x%08X",rdo_id,fee_port,data[1],data[2],data[3],data[4]) ;
2849 LOG(TERR,
"%d: FEE #%d: stat 0x%08X 0x%08X 0x%08X 0x%08X",rdo_id,fee_port,data[1],data[2],data[3],data[4]) ;
2867 l = (*data++) & 0xFFFF ;
2868 h = (*data++) & 0xFFFF ;
2870 glo_status = (h<<16) | l ;
2873 LOG(ERR,
"FEE SEND_CONFIG: START 0: status 0x%08X",glo_status) ;
2876 LOG(NOTE,
"FEE SEND_CONFIG: START 0: status 0x%08X",glo_status) ;
2881 LOG(NOTE,
"FEE SEND_CONFIG: END 0") ;
2885 LOG(NOTE,
"FEE Configuration: START") ;
2888 LOG(NOTE,
"FEE Configuration: END") ;
2892 LOG(NOTE,
"FEE Monitoring: START 0") ;
2895 LOG(NOTE,
"FEE Monitoring: END 0") ;
2898 LOG(NOTE,
"FEE Monitoring: START 1") ;
2901 LOG(NOTE,
"FEE Monitoring: END 1") ;
2910 l = (*data++) & 0xFFFF ;
2911 h = (*data++) & 0xFFFF ;
2913 glo_status = (h<<16) | l ;
2916 LOG(ERR,
"FEE SEND_CONFIG: START 1: status 0x%08X",glo_status) ;
2919 LOG(NOTE,
"FEE SEND_CONFIG: START 1: status 0x%08X",glo_status) ;
2925 LOG(NOTE,
"FEE SEND_CONFIG: END 1 (all)") ;
2930 LOG(NOTE,
"FEE Trigger: START: TRIGGERED") ;
2938 l = (*data++) & 0xFFFF ;
2939 h = (*data++) & 0xFFFF ;
2941 glo_status = (h<<16) | l ;
2944 l = (*data++) & 0xFFFF ;
2945 h = (*data++) & 0xFFFF ;
2947 rh_xing_start = (h<<16) | l ;
2950 l = (*data++) & 0xFFFF ;
2951 h = (*data++) & 0xFFFF ;
2953 bx_xing = (h<<16) | l ;
2956 l = (*data++) & 0xFFFF ;
2957 h = (*data++) & 0xFFFF ;
2959 type = (h<<16) | l ;
2961 l = (*data++) & 0xFFFF ;
2962 h = (*data++) & 0xFFFF ;
2964 fee_evt = (h<<16) | l ;
2967 int fee_id = (d>>16)&0x3F ;
2970 LOG(ERR,
"FEE %d(#%d) START Event %d: type 0x%08X, xing %u, 20bit %u, RHIC %u, glo 0x%08X",fee_id,fee_port,
2971 fee_evt,type,bx_xing,bx_xing&0xFFFFF,rh_xing_start,glo_status) ;
2974 LOG(TERR,
"FEE %d(#%d) START Event %d: type 0x%08X, xing %u, 20bit %u, RHIC %u, glo 0x%08X",fee_id,fee_port,
2975 fee_evt,type,bx_xing,bx_xing&0xFFFFF,rh_xing_start,glo_status) ;
2981 LOG(NOTE,
"FEE Trigger: END: hdr") ;
2991 a = (*data++) & 0xFFFF ;
2992 b = (*data++) & 0xFFFF ;
2994 glo_status = (b<<16) | a ;
2997 a = (*data++) & 0xFFFF ;
2998 b = (*data++) & 0xFFFF ;
3000 status = (b<<16) | a ;
3002 a = (*data++) & 0xFFFF ;
3003 b = (*data++) & 0xFFFF ;
3005 xing = (b<<16) | a ;
3007 a = (*data++) & 0xFFFF ;
3008 b = (*data++) & 0xFFFF ;
3010 fee_evt = (b<<16) | a ;
3012 if(glo_status || status) {
3013 LOG(ERR,
"FEE END Event %d: glo 0x%08X, status 0x%08X, xing %u, delta %u",
3014 fee_evt,glo_status,status, xing, xing-rh_xing_start) ;
3017 LOG(TERR,
"FEE END Event %d: glo 0x%08X, status 0x%08X, xing %u, delta %u",
3018 fee_evt,glo_status,status, xing, xing-rh_xing_start) ;
3023 LOG(WARN,
"FEE Event: END") ;
3027 if(words==(data-data_start)) {
3028 if((d & 0xFFFF0000)==0x005C0000) break ;
3039 if((d & 0xFFFF0000)==0x005C0000) ;
3041 if(words==(data-data_start)) ;
3064 if((flags != 0x1F)) {
3065 LOG(ERR,
"At end: %d, flags 0x%X",data_end-data,flags) ;
3066 for(
int i=0;i<32;i++) {
3067 LOG(WARN,
"... %2d = 0x%08X",i,data_end[16-i]) ;
3071 if((data[-1] & 0xFFFF0000)==0x005C0000) {
3076 else LOG(NOTE,
"%d: no end-comma %d %d = 0x%08X!",rdo_id,data_end-data,words,data[-1]) ;
3093 typedef unsigned char uint8_t ;
3095 static void hammingdecode(
unsigned int buffer[2],
bool& error,
bool& uncorrectable,
bool fix_data)
3099 bool parityreceived[6];
3103 for (
int i = 0; i < 6; i++)
3104 parityreceived[i] = (buffer[0] >> i) & 0x1;
3106 overallparity = (buffer[0] >> 6) & 0x1;
3111 for (
int i = 7; i < 30; i++)
3112 data_in[i-7] = (buffer[0] >> i) & 0x1;
3114 for (
int i = 30; i < 50; i++)
3115 data_in[i-7] = (buffer[1] >> (i - 30)) & 0x1;
3118 bool corrected_out[43];
3119 bool overallparitycalc = 0;
3120 bool overallparity_out = 0;
3122 bool paritycorreced_out[6];
3126 paritycalc[0] = data_in[0] ^ data_in[1] ^ data_in[3] ^ data_in[4] ^ data_in[6] ^
3127 data_in[8] ^ data_in[10] ^ data_in[11] ^ data_in[13] ^ data_in[15] ^
3128 data_in[17] ^ data_in[19] ^ data_in[21] ^ data_in[23] ^ data_in[25] ^
3129 data_in[26] ^ data_in[28] ^ data_in[30] ^ data_in[32] ^ data_in[34] ^
3130 data_in[36] ^ data_in[38] ^ data_in[40] ^ data_in[42];
3132 paritycalc[1] = data_in[0] ^ data_in[2] ^ data_in[3] ^ data_in[5] ^ data_in[6] ^
3133 data_in[9] ^ data_in[10] ^ data_in[12] ^ data_in[13] ^ data_in[16] ^
3134 data_in[17] ^ data_in[20] ^ data_in[21] ^ data_in[24] ^ data_in[25] ^
3135 data_in[27] ^ data_in[28] ^ data_in[31] ^ data_in[32] ^ data_in[35] ^
3136 data_in[36] ^ data_in[39] ^ data_in[40] ;
3138 paritycalc[2] = data_in[1] ^ data_in[2] ^ data_in[3] ^ data_in[7] ^ data_in[8] ^
3139 data_in[9] ^ data_in[10] ^ data_in[14] ^ data_in[15] ^ data_in[16] ^
3140 data_in[17] ^ data_in[22] ^ data_in[23] ^ data_in[24] ^ data_in[25] ^
3141 data_in[29] ^ data_in[30] ^ data_in[31] ^ data_in[32] ^ data_in[37] ^
3142 data_in[38] ^ data_in[39] ^ data_in[40] ;
3144 paritycalc[3] = data_in[4] ^ data_in[5] ^ data_in[6] ^ data_in[7] ^ data_in[8] ^
3145 data_in[9] ^ data_in[10] ^ data_in[18] ^ data_in[19] ^ data_in[20] ^
3146 data_in[21] ^ data_in[22] ^ data_in[23] ^ data_in[24] ^ data_in[25] ^
3147 data_in[33] ^ data_in[34] ^ data_in[35] ^ data_in[36] ^ data_in[37] ^
3148 data_in[38] ^ data_in[39] ^ data_in[40] ;
3150 paritycalc[4] = data_in[11] ^ data_in[12] ^ data_in[13] ^ data_in[14] ^ data_in[15] ^
3151 data_in[16] ^ data_in[17] ^ data_in[18] ^ data_in[19] ^ data_in[20] ^
3152 data_in[21] ^ data_in[22] ^ data_in[23] ^ data_in[24] ^ data_in[25] ^
3153 data_in[41] ^ data_in[42] ;
3155 paritycalc[5] = data_in[26] ^ data_in[27] ^ data_in[28] ^ data_in[29] ^ data_in[30] ^
3156 data_in[31] ^ data_in[32] ^ data_in[33] ^ data_in[34] ^ data_in[35] ^
3157 data_in[36] ^ data_in[37] ^ data_in[38] ^ data_in[39] ^ data_in[40] ^
3158 data_in[41] ^ data_in[42] ;
3161 uint8_t syndrome = 0;
3163 for (
int i = 0; i < 6; i++)
3164 syndrome |= (paritycalc[i]^parityreceived[i]) << i;
3166 bool data_parity_interleaved[64];
3170 data_parity_interleaved[1] = parityreceived[0];
3171 data_parity_interleaved[2] = parityreceived[1];
3172 data_parity_interleaved[3] = data_in[0];
3173 data_parity_interleaved[4] = parityreceived[2];
3174 for (
int i = 1; i <= 3; i++)
3175 data_parity_interleaved[i+5-1] = data_in[i];
3176 data_parity_interleaved[8] = parityreceived[3];
3177 for (
int i = 4; i <= 10; i++)
3178 data_parity_interleaved[i+9-4] = data_in[i];
3179 data_parity_interleaved[16] = parityreceived[4];
3180 for (
int i = 11; i <= 25; i++)
3181 data_parity_interleaved[i+17-11] = data_in[i];
3182 data_parity_interleaved[32] = parityreceived[5];
3183 for (
int i = 26; i <= 42; i++)
3184 data_parity_interleaved[i+33-26] = data_in[i];
3188 data_parity_interleaved[syndrome] = !data_parity_interleaved[syndrome];
3190 paritycorreced_out[0] = data_parity_interleaved[1];
3191 paritycorreced_out[1] = data_parity_interleaved[2];
3192 corrected_out[0] = data_parity_interleaved[3];
3193 paritycorreced_out[2] = data_parity_interleaved[4];
3194 for (
int i = 1; i <= 3; i++)
3195 corrected_out[i] = data_parity_interleaved[i+5-1];
3196 paritycorreced_out[3] = data_parity_interleaved[8];
3197 for (
int i = 4; i <= 10; i++)
3198 corrected_out[i] = data_parity_interleaved[i+9-4];
3199 paritycorreced_out[4] = data_parity_interleaved[16];
3200 for (
int i = 11; i <= 25; i++)
3201 corrected_out[i] = data_parity_interleaved[i+17-11];
3202 paritycorreced_out[5] = data_parity_interleaved[32];
3203 for (
int i = 26; i <= 42; i++)
3204 corrected_out[i] = data_parity_interleaved[i+33-26];
3209 for (
int i = 0; i < 43; i++)
3210 overallparitycalc ^=data_in[i];
3211 for (
int i = 0; i < 6; i++)
3212 overallparitycalc ^= parityreceived[i];
3213 syndromeerror = (syndrome > 0) ? 1 : 0;
3214 wrongparity = (overallparitycalc != overallparity);
3215 overallparity_out = !syndromeerror && wrongparity ? overallparitycalc : overallparity;
3216 error = syndromeerror | wrongparity;
3217 uncorrectable = (syndromeerror && (!wrongparity));
3228 for (
int i = 0; i < 6; i++)
3229 buffer[0] = (buffer[0] & ~(1 << i)) | (paritycorreced_out[i] << i);
3230 buffer[0] = (buffer[0] & ~(1 << 6)) | (overallparity_out << 6);
3231 for (
int i = 7; i < 30; i++)
3232 buffer[0] = (buffer[0] & ~(1 << i)) | (corrected_out[i - 7] << i);
3233 for (
int i = 30; i < 50; i++)
3234 buffer[1] = (buffer[1] & ~(1 << (i - 30))) | (corrected_out[i - 7] << (i - 30));