9 #include <rtsSystems.h>
11 #include <DAQ_READER/daq_dta.h>
13 #include <DAQ_ITPC/itpcCore.h>
14 #include <DAQ_ITPC/itpc_rowlen.h>
15 #include <DAQ_ITPC/itpcPed.h>
26 static const char *hwicap_version(u_int v) ;
27 static u_int get_ifee_mask(
int sec1,
int rdo1) ;
30 static inline u_int sw16(u_int d)
32 d = ((d>>16)&0xFFFF)|(d<<16) ;
37 inline u_int itpc23::set_rdo(
int sec,
int rdo)
44 fee_mask = get_ifee_mask(sector1,rdo1) ;
51 int itpc23::from22to23(
char *c_dta,
int words)
54 u_int *
data = (u_int *)c_dta ;
56 u_int *d_use = (u_int *)malloc(words*4+1024) ;
58 u_int *data_end = data + words ;
59 u_int *data_start = data ;
64 fee_mask = get_ifee_mask(sector1,rdo1) ;
68 int w_cou = (words<16)?words:16 ;
70 for(
int i=0;i<w_cou;i++) {
71 if((data[i]==0xCCCC001C)||(data[i]==0x001CCCCC)) {
77 w_cou = data_end - data ;
79 int need_swapping = 0 ;
80 if(data[0]==0xCCCC001C) {
83 for(
int i=0;i<w_cou;i++) {
84 data[i] = sw16(data[i]) ;
95 if((data[0]&0xFFFF000F) != 0x98000004) {
97 if(mode || (online && run_errors<10)) {
98 LOG(ERR,
"start 0 0x98 = 0x%08X",data[0]) ;
117 data_end = data_end - 1 - 2 - 1 - 6 - 1 ;
126 if((data_end[0]&0xFF000000) != 0x58000000) {
127 LOG(ERR,
"data_end 0 0x58 = 0x%08X",data_end[0]) ;
133 for(
int i=0;i<16;i++) {
136 if((data_end[-i]&0xFF000000)==0x58000000) {
137 data_end = data_end - i ;
146 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: can't find data_end!",rdo1) ;
154 while(data_end>data) {
155 if((*data_end & 0xFF000000)==0x98000000) {
167 if(mode || (online && (run_errors<10))) {
168 LOG(ERR,
"%d: data_end 0x98 not found = 0x%08X",rdo1,data_end[0]) ;
172 n_words = data_end - data ;
174 u_int *d = data + 2 ;
182 memset(fee_p,0,
sizeof(fee_p)) ;
187 if((d[0]&0xFF000000)==0x80000000) {
188 int port = d[4]&0xF ;
191 l_fee_mask |= (1<<port) ;
202 if(l_fee_mask != fee_mask) {
205 if(online && run_errors<10) LOG(ERR,
"%d: FEE mask 0x%X, expect 0x%X, words %d/%d",rdo1,l_fee_mask,fee_mask,words,n_words) ;
212 fee_mask = l_fee_mask ;
216 for(
int i=0;i<5;i++) d_use[i] = data_start[i] ;
218 d_use[5] = 0x20000000 ;
221 d_use[8] = fee_mask<<16 ;
224 d_use[11] = 0xF0000000 | fee_mask ;
226 u_int *d_fee = d_use + 12 ;
229 for(
int i=0;i<16;i++) {
230 u_int *p = fee_p[i] ;
234 d_fee[ix] = p[0] & 0xFFFF0000 ;
240 while((p[0]&0xF0000000)!=0xB0000000) {
249 while((p[0]&0xF0000000)!=0x40000000) {
250 if((p[0]&0xF0000000)==0xA0000000) {
261 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: words %d, ix %d",rdo1,n_words,ix) ;
275 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: words %d, ix %d",rdo1,n_words,ix) ;
284 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: n_words %d",rdo1,n_words) ;
291 d_use[n_words-1] = 0xDEADC0DE ;
292 d_use[n_words-2] = 0xFEEDC0FE ;
293 d_use[n_words-3] = 0x0 ;
294 d_use[n_words-4] = 0xFFFFFFFF ;
302 memcpy(c_dta,d_use,n_words*4) ;
314 int itpc23::init(
daq_dta *gain)
316 if(gain==0)
return -1 ;
318 while(gain->iterate()) {
324 for(u_int p=0;p<gain->ncontent;p++) {
328 LOG(TERR,
"gains: S%02d, rp %d:%d = %.1f",s,r,p,gp[p].gain) ;
337 u_int *itpc23::ch_scan(u_int *start)
347 w[0] = (d[0]>>20)&0x3FF ;
348 w[1] = (d[0]>>10)&0x3FF ;
349 w[2] = (d[0]>>00)&0x3FF ;
351 w[3] = (d[1]>>20)&0x3FF ;
352 w[4] = (d[1]>>10)&0x3FF ;
353 w[5] = (d[1]>>00)&0x3FF ;
355 int pkt = (w[0]>>7)&0x7 ;
356 int sampa_ch = (w[2]>>4)&0x1F ;
357 int sampa_id = w[2]&0xF ;
362 if(log_level>=1) LOG(TERR,
"%d: words10 %d:%d (SAMPA %d,%d): words10 %d",rdo1,fee_ix,ch_ix,sampa_id,sampa_ch,words10) ;
364 if(unlikely(words10==1023)) {
366 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: ch_scan %d:%d: SAMPA%d:%d -- prog-full",rdo1,fee_ix,ch_ix,sampa_id,sampa_ch) ;
372 if(unlikely(pkt!=4 || sampa_ch>31 || words10>512)) {
376 if(mode || (online && run_errors<20)) {
377 LOG(ERR,
"%d: T %d: ch_scan %d:%d:%d: pkt %d, sampa %d:%d, words10 %d [0x%08X: 0x%08X 0x%08X], err 0x%X",
378 rdo1,token,fee_ix,lane_ix,
380 pkt,sampa_id,sampa_ch,words10,
381 d[0],d[-1],d[1],err) ;
400 if(mode || online) LOG(ERR,
"Can't fix -- giving up") ;
405 if(mode || (online && run_errors<20)) LOG(WARN,
"Recovered %d:%d, words10 %d",sampa_id,sampa_ch,words10) ;
410 int bx = ((w[4]&0x1FF)<<17)|(w[3]<<1)|((w[2]>>9)&1) ;
412 if(unlikely(bx_count<0)) {
416 if(unlikely(bx != bx_count)) {
417 if(abs(bx-bx_count)>1) {
420 if(mode || (online && run_errors<10)) {
421 LOG(ERR,
"%d: T %d: ch_scan %d:%d:%d bx %d, expect %d",rdo1,token,fee_ix,lane_ix,ch_ix,bx,bx_count) ;
428 int words10_start = words10 ;
430 while(words10%3) words10++ ;
432 int words = words10/3 ;
443 u_short *d_start = s1_dta + last_ix ;
444 struct seq_t *seq = 0 ;
445 u_short *dd = s1_dta + last_ix ;
446 u_short *dd_save = dd ;
451 int id = (fee_pp<<1)|(sampa_id&1) ;
452 int flags = flags_row_pad(
id, sampa_ch, row, pad) ;
455 LOG(TERR,
"... %d: fee_ix %d, fee_pp %d: sampa_id %d, sampa_ch %d: row %d, pad %d, flags 0x%X",rdo1,fee_ix,fee_pp,
456 sampa_id,sampa_ch,row,pad,flags) ;
469 seq = s1[row][pad].seq ;
471 if(log_level>=2) LOG(TERR,
"Here %p, words %d, %p",seq,words,dd) ;
475 for(
int i=0;likely(i<words);i++) {
476 w[0] = (d[i]>>20)&0x3FF ;
477 w[1] = (d[i]>>10)&0x3FF ;
478 w[2] = (d[i]>>00)&0x3FF ;
483 if(unlikely(d[i]&0xC0000000)) {
485 if(mode || (online && run_errors<10)) {
486 LOG(ERR,
"%d: ch_scan %d:%d: SAMPA %d:%d: bad word 0x%08X",rdo1,fee_ix,ch_ix,
487 sampa_id,sampa_ch,d[i]) ;
491 if(log_level>=2) LOG(TERR,
"FEE %d:%d -- %d = 0x%08X",fee_ix,ch_ix,i,d[i]) ;
494 for(
int j=0;likely(j<3);j++) {
501 if(log_level>=100) LOG(TERR,
" tb_cou %d %p",tb_cou,dd) ;
505 if(log_level>=100) LOG(TERR,
" tb_cou %d",tb_cou) ;
507 if(unlikely(tb_cou>500)) {
509 if(mode || (online && run_errors<10)) {
510 LOG(ERR,
"%d: rp %d:%d: tb_cou %d [0x%08X,%d]",rdo1,row,pad,tb_cou,d[i],i) ;
519 if(seq_ix>=(SEQ_MAX-1)) {
520 if(mode || online) LOG(ERR,
"too many seqs %d",seq_ix) ;
529 seq[seq_ix].t_lo = tb_start ;
530 seq[seq_ix].t_hi = tb_start + tb_cou - 1 ;
531 seq[seq_ix].dta_p = (dd-d_start) ;
532 seq[seq_ix].blob_id = 0 ;
537 if(unlikely(log_level>=100)) LOG(TERR,
" tb_start %d",tb_start) ;
539 if(unlikely(tb_start<=tb_last)) {
541 if(mode || (online && run_errors<10))LOG(ERR,
"%d: rp %d:%d: tb_start %d, tb_last %d",rdo1,row,pad,tb_start,tb_last) ;
543 seq[seq_ix].t_lo = 400 ;
544 seq[seq_ix].t_hi = 401 ;
550 tb_last = tb_start + tb_cou ;
551 if(unlikely(tb_last>500)) {
553 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: rp %d:%d: tb_last %d [0x%08X,%d]",rdo1,row,pad,tb_last,d[i],i) ;
555 seq[seq_ix].t_lo = 400 ;
556 seq[seq_ix].t_hi = 401 ;
565 if(log_level>=100) LOG(TERR,
" adc %d, %d",w[j],a_ix) ;
572 if(unlikely(a_ix==tb_cou)) {
576 if(w10==words10_start)
goto done_ch ;
582 if(log_level>=2) LOG(TERR,
"Here %d",__LINE__) ;
591 sequence_cou += seq_ix ;
592 seq[seq_ix].t_hi = -1 ;
593 s1[row][pad].ix = last_ix ;
599 u_short *dd = dd_save ;
602 int ch = ii*32 + sampa_ch ;
605 LOG(TERR,
"fee_pp %d, fee_ix %d, lane_ix %d, sampa_ch %d, ch %d",
606 fee_pp,fee_ix,lane_ix,sampa_ch,ch) ;
611 data_c->sector = sector1 -1 ;
612 data_c->rdo = rdo1-1 ;
613 data_c->port = fee_ix ;
614 data_c->fee_id = fee_pp ;
616 data_c->ch_start(ch) ;
619 for(
int i=0;i<seq_ix;i++) {
621 int t_len = seq[i].t_hi - seq[i].t_lo + 1 ;
626 for(
int j=0;j<t_len;j++) {
628 int tb = seq[i].t_lo + ii ;
630 data_c->accum(sector1-1,rdo1-1,fee_ix,fee_pp,ch,tb,adc) ;
639 u_short *dd = dd_save ;
640 for(
int i=0;i<seq_ix;i++) {
642 int t_len = seq[i].t_hi - seq[i].t_lo + 1 ;
644 printf(
"RP %d:%d, seq %d: t_lo %d, t_hi %d\n",row,pad,i,seq[i].t_lo,seq[i].t_hi) ;
647 for(
int j=0;j<t_len;j++) {
649 int tb = seq[i].t_lo + ii ;
651 printf(
" tb %3d = %3d ADC\n",tb,adc);
661 last_ix += dd-d_start ;
670 u_int *itpc23::lane_scan(u_int *start)
676 if(log_level>=1) LOG(TERR,
"%d: lane scan %d: 0x%08X",rdo1,lane_ix,d[0]) ;
679 if((d[0]&0xF0000000)!=0xB0000000) {
680 if((online && run_errors<10) || mode) {
681 LOG(ERR,
"%d: T %d: lane_scan %d:%d: unknown start 0x%08X [0x%08X 0x%08X]",rdo1,token,fee_ix,lane_ix,d[0],d[-1],d[1]) ;
685 if(mode || (online && run_errors<10)) {
686 LOG(WARN,
"%d: lane_scan %d:%d: retrying fix",rdo1,fee_ix,lane_ix) ;
696 else if((d[0]>>26)&0x3) {
698 if(online || mode) LOG(ERR,
"%d: lane_scan %d:%d: SAMPA FIFO overwritten 0x%08X",rdo1,fee_ix,lane_ix,d[0]) ;
703 if(log_level>=1) LOG(TERR,
"%d: lane scan %d: 0x%08X",rdo1,lane_ix,d[0]) ;
705 for(
int i=0;i<16;i++) {
711 if((d[0]&0xF0000000)!=0x70000000) {
714 if((online && run_errors<20)|| mode) LOG(ERR,
"%d: T %d: lane_scan %d:%d: unknown end 0x%08X",rdo1,token,fee_ix,lane_ix,d[0]) ;
722 u_int *itpc23::fee_non_trgd(u_int *start)
728 if(fee_evt_type != 0x02) {
729 if(online || mode) LOG(ERR,
"%d: T %d: fee_non_trgd %d: evt_type 0x%02X",rdo1,token,fee_ix,fee_evt_type) ;
733 if((d[0]&0xF0000000)==0x40000000) {
741 LOG(NOTE,
"fee_scan %d: evt_type 0x%02X, words %d",fee_ix,fee_evt_type,fee_words) ;
744 for(
int i=0;i<16;i++) {
745 LOG(NOTE,
"%d = 0x%08X",i,d[i]) ;
757 int rdo_port = d[1]&0xFFFF ;
758 int fee_id = d[2]&0xFFFF ;
762 u_short sampa_stat[2] ;
764 sampa_stat[0] = d[0]&0xFFFF ;
765 sampa_stat[1] = d[1]&0xFFFF ;
773 u_int v_all = d[0]&0xFFFF ;
774 v_all |= (d[1]&0xFFFF)<<16 ;
776 u_int v_bit = d[2]&0xFFFF ;
777 v_bit |= (d[3]&0xFFFF)<<16 ;
779 unsigned long wire1 = d[4]&0xFFFF ;
780 wire1 |= (long)(d[5]&0xFFFF)<<16 ;
781 wire1 |= (long)(d[6]&0xFFFF)<<32 ;
782 wire1 |= (long)(d[7]&0xFFFF)<<48 ;
785 wire1 &= 0xFFFFFFFF ;
787 u_int temp = d[8]&0xFFFF ;
788 temp |= (d[9]&0xFFFF)<<16 ;
792 reg[0] = d[10]&0xFFFF ;
793 reg[0] |= (d[11]&0xFFFF)<<16 ;
794 reg[1] = d[12]&0xFFFF ;
795 reg[1] |= (d[13]&0xFFFF)<<16 ;
798 strcpy(s_all,hwicap_version(v_all)) ;
800 LOG(INFO,
"%d: FEE %2d[%02d,%d]: v_all 0x%08X[%s], v_bit 0x%08X[%s], wire1 0x%08llX, padplane %02d",rdo1,fee_ix,rdo_port,fee_id,
801 v_all,s_all,v_bit,hwicap_version(v_bit),wire1,fee_pp) ;
804 if(fee_ix!=rdo_port || fee_pp!=fee_id) {
805 LOG(ERR,
"%d: fee_ix %d but read %d (fee_pp expect %d, read %d)",rdo1,fee_ix,rdo_port,fee_pp,fee_id) ;
808 LOG(NOTE,
" regs 0x%08X 0x%08X",reg[0],reg[1]) ;
810 if(sampa_stat[0]||sampa_stat[1]) {
811 LOG(ERR,
" SAMPA stat: 0x%04X 0x%04X",sampa_stat[0],sampa_stat[1]) ;
816 if((d[0]&0xF0000000)==0x40000000) break ;
826 u_int *itpc23::fee_scan(u_int *start)
829 u_int *d_save = start ;
836 if(d_save>=trl)
return start ;
839 if((d[0]&0xF0000000)!=0x80000000) {
841 if(online || mode) LOG(ERR,
"%d: T %d: fee_scan %d: not start-of-FEE 0x%08X",rdo1,token,fee_ix,d[0]) ;
844 if(d[0]&0x00800000) {
846 if(online || mode) LOG(ERR,
"%d: fee_scan %d: SAMPA overrun 0x%08X",rdo1,fee_ix,d[0]) ;
848 if(d[0]&0x00400000) {
853 fee_evt_type = d[0] & 0xFF ;
854 fee_pp = (d[0]>>16)&0xFF ;
856 LOG(DBG,
"FEE %d = 0x%08X",fee_ix,d[0]) ;
858 if(log_level>=2) LOG(TERR,
"%d: FEE %d (0x%08X) fee_padplane %d, fee_evt_type 0x%02X",rdo1,fee_ix,d[0],fee_pp,fee_evt_type) ;
863 if(fee_evt_type==0xF0) {
864 for(
int i=0;i<4;i++) {
870 LOG(WARN,
"%d: T %d: non-physics fee_ix %d, padplane %d",rdo1,token,fee_ix,fee_pp) ;
871 d = fee_non_trgd(d) ;
875 if((d[0]&0xF0000000)!=0x40000000) {
877 if(online || mode) LOG(ERR,
"%d: T %d: fee_scan %d: not end-of-FEE 0x%08X",rdo1,token,fee_ix,d[0]) ;
880 if(d[0]&0x00800000) {
882 if(online || mode) LOG(ERR,
"fee_scan %d: SAMPA overrun 0x%08X",fee_ix,d[0]) ;
884 if(d[0]&0x00400000) {
893 for(
int i=0;i<(d-d_save);i++) {
894 printf(
"fee_ix %2d: %d = 0x%08X\n",fee_ix,i,d_save[i]) ;
902 int itpc23::rdo_scan(
char *c_addr,
int iwords)
908 u_int *d = (u_int *)c_addr ;
925 if(d[0]==0xCCCC001C || d[0]==0x001CCCCC) ;
927 LOG(ERR,
"%d: evt %d: bad header 0x%08X, words %d",rdo1,evt,d[0],words) ;
928 for(
int i=-4;i<=2;i++) {
929 LOG(ERR,
" %d = 0x%08X",i,d[i]) ;
942 trg_cmd = (d[2]>>0)&0xF ;
943 daq_cmd = (d[2]>>4)&0xF ;
948 u_short t_hi = (d[2]>>8)&0xF ;
949 u_short t_mid = (d[2]>>12)&0xF ;
950 u_short t_lo = (d[2]>>16)&0xF ;
952 token = (t_hi<<8)|(t_mid<<4)|t_lo ;
956 if(log_level>=1) LOG(TERR,
"%d: T %d(%d,%d)",rdo1,token,trg_cmd,daq_cmd) ;
959 for(
int i=0;i<8;i++) {
960 LOG(TERR,
"rdo_scan %d/%d = 0x%08X",i,words,d[i]) ;
964 u_int mhz_start = d[3] ;
965 u_int fee_synced = d[4]>>16 ;
966 u_int fee_overrun = d[4]&0xFFFF ;
967 u_int fee_xoff = d[5]>>16 ;
968 u_int rdo_stuff = d[5]&0xFFFF ;
969 u_int fee_empty = d[6]&0xFFFF ;
973 for(
int i=7;i<15;i++) {
974 if((d[i]&0xFFFF0000)==0xF0000000) {
975 l_fee_mask = d[i]&0xFFFF ;
981 LOG(ERR,
"%d: no local FEE mask, expecting 0x%04X",rdo1,fee_mask) ;
992 fee_mask = l_fee_mask ;
998 if((fee_synced&fee_mask)!=fee_mask) {
999 if(mode || (online)) LOG(ERR,
"%d: evt %d: fee sync error 0x%04X, expect 0x%04X",rdo1,evt,fee_synced,fee_mask) ;
1004 if(fee_overrun&fee_mask) {
1005 if(mode || online) {
1006 LOG(ERR,
"%d: %d: RDOs fee FIFO overrun 0x%04X: words %d: 0x%04X 0x%04X 0x%04X 0x%04X",
1007 rdo1,evt,fee_overrun&fee_mask,words,
1008 fee_mask,l_fee_mask,fee_xoff,fee_empty) ;
1014 if((fee_xoff&fee_mask) != 0) {
1019 if(rdo_stuff & 0xF000) {
1020 LOG(NOTE,
"%d: rdo_stuff 0x%04X",rdo1,rdo_stuff) ;
1025 if((fee_empty&fee_mask)==fee_mask) ;
1033 for(
int i=0;i>-35;i--) {
1036 if(trl[i]==0xDEADC0DE) got_it |=1 ;
1037 else if(got_it && (trl[i]==0xFEEDC0FE)) {
1045 if(mode || online) {
1046 LOG(ERR,
"%d: evt %d: no trailer (0x%08X), %d, words %d",rdo1,evt,trl[0],got_it,words) ;
1058 u_int evt_status = trl[0] ;
1059 u_int mhz_end = trl[1] ;
1063 if(evt_status==0x0EEDC0DE) {
1064 for(
int i=-8;i<=8;i++) {
1065 if(online || mode) LOG(ERR,
"%d: %d = 0x%08X",rdo1,i,trl[i]) ;
1071 u_int evt_type = (d[1]>>28)&0xF ;
1075 int loc_err_cou = 0 ;
1088 LOG(ERR,
"%d: %d: unknown event type %d: 0x%08X",rdo1,evt,evt_type,d[1]) ;
1096 for(
int i=0;i<16;i++) {
1097 if(fee_mask & (1<<i)) ;
1100 u_int st = (evt_status>>(i*2)) & 0x3 ;
1104 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: %d: FEE %2d: timeout 0x%X [0x%08X]",rdo1,evt,i,st,evt_status) ;
1110 while((*d>>28)==0x4) {
1116 LOG(WARN,
"Lots of triggers %d",trg_cou) ;
1119 if(log_level>=1) LOG(TERR,
"%d: evt %d: fee_mask expected 0x%04X",rdo1,evt,fee_mask) ;
1124 if(((*d>>28)!=0xF)||((*d&0xFFFF)!=fee_mask)) {
1125 if(mode || (online && run_errors<10)) LOG(ERR,
"%d: evt %d: Bad FEE_START 0x%08X, expect 0x%08X",rdo1,evt,*d,0xF0000000|fee_mask) ;
1134 if(fee_words)
goto done ;
1137 printf(
"==== trg_evts %d\n",trgd_evt) ;
1138 for(
int i=0;i<(trl-d);i++) {
1139 printf(
"%d = 0x%08X\n",i,d[i]) ;
1148 if(log_level>=2) LOG(TERR,
"here") ;
1154 if(mode || online) {
1155 LOG(ERR,
"%d: T %d: error 0x%X before fee_scan??",rdo1,token,err) ;
1161 for(
int i=0;i<16;i++) {
1162 if(fee_mask & (1<<i)) ;
1169 if(loc_err_cou==0) {
1170 if(mode || online) {
1171 LOG(ERR,
"%d: T %d: error at FEE #%d (0x%X)",rdo1,token,i+1,err) ;
1179 if(log_level>=2) LOG(TERR,
"here2") ;
1191 if(err||prog_fulls) {
1192 if(online || mode) LOG(ERR,
"%d: evt %d/%d: T %d,%d,%d: error 0x%08X, prog_fulls %d: words %d, %d us",rdo1,evt_trgd,evt,
1193 token,trg_cmd,daq_cmd,
1196 words,mhz_end-mhz_start) ;
1198 else if(token==4096) {
1199 LOG(DBG,
"%d/%d: T %d,%d,%d: error 0x%06X, prog_fulls %d, rdo_stuff 0x%04X: words %d, %d us",evt_trgd,evt,
1200 token,trg_cmd,daq_cmd,
1202 prog_fulls,rdo_stuff,
1203 words,mhz_end-mhz_start) ;
1205 else if((evt_trgd%1000)==1) {
1207 LOG(TERR,
"%d/%d: T %d,%d,%d: error 0x%06X, prog_fulls %d, rdo_stuff 0x%04X: words %d, %d us",evt_trgd,evt,
1208 token,trg_cmd,daq_cmd,
1210 prog_fulls,rdo_stuff,
1211 words,mhz_end-mhz_start) ;
1216 LOG(NOTE,
"%d/%d: T %d,%d,%d: error 0x%06X, prog_fulls %d, rdo_stuff 0x%04X: words %d, %d us",evt_trgd,evt,
1217 token,trg_cmd,daq_cmd,
1219 prog_fulls,rdo_stuff,
1220 words,mhz_end-mhz_start) ;
1230 u_int itpc23::get_token_s(
char *c_addr,
int words)
1232 u_int *d = (u_int *)c_addr ;
1244 u_int sig, trg_w,sub ;
1247 if(d[4]==0xCCCC001C && fmt<23) {
1249 trg_w = sw16(d[6]) ;
1260 if((sig&0xFF000000)==0x98000000) {
1273 u_short t_hi = (trg_w>>8)&0xF ;
1274 u_short t_mid = (trg_w>>12)&0xF ;
1275 u_short t_lo = (trg_w>>16)&0xF ;
1277 t = (t_hi<<8)|(t_mid<<4)|t_lo ;
1280 trg = (trg_w>>0)&0xF ;
1281 daq = (trg_w>>4)&0xF ;
1283 evt_type = (sig>>28)&0xF ;
1298 for(
int i=0;i<16;i++) {
1299 if(d[i] == 0xCCCC001C || d[i]==0x001CCCCC) {
1313 int rdo_version = 0 ;
1315 if(sig==0x98000004) rdo_version = 0 ;
1316 else if((sig&0xFF00000F)==0x98000004) rdo_version = (sig>>4)&0xFF ;
1318 LOG(WARN,
"%d: fmt 22: not triggered: ds 0x%08X, words",rdo1,sig,words) ;
1335 t = ((trg_w>>8)&0xF)<<8 ;
1336 t |= ((trg_w>>12)&0xF) << 4 ;
1337 t |= ((trg_w>>16)&0xF) ;
1340 daq = (trg_w>>4) & 0xF ;
1360 return (trg<<16)|(daq<<12)|t ;
1370 if(rp_gain_itpc==0) {
1371 rp_gain_itpc = (row_pad_t (*)[ROW_MAX+1][PAD_MAX+1]) malloc(
sizeof(row_pad_t)*24*(ROW_MAX+1)*(PAD_MAX+1)) ;
1375 for(
int s=0;s<24;s++) {
1376 for(
int r=0;r<=ROW_MAX;r++) {
1377 for(
int p=0;p<=PAD_MAX;p++) {
1378 rp_gain_itpc[s][r][p].gain = 1.0 ;
1379 rp_gain_itpc[s][r][p].t0 = 0.0 ;
1380 rp_gain_itpc[s][r][p].flags = 0 ;
1386 rp_gain = rp_gain_itpc ;
1395 for(
int row=1;row<=40;row++) rowlen[row] = itpc_rowlen[row] ;
1413 u_char itpc23::flags_row_pad(
int asic,
int channel,
int &row,
int &pad)
1420 itpc_sampa_to_rowpad(
id,sampa,channel,row,pad) ;
1421 if(row==0 || row==255)
return 0xFF ;
1422 if(pad==0 || pad==255)
return 0xFF ;
1425 return rp_gain[sector1-1][row][pad].flags ;
1429 static const char *hwicap_version(u_int v)
1431 static char ascii[64] ;
1434 int m = (v>>6)&0x3F ;
1435 int h = (v>>12)&0x1F ;
1436 int y = ((v>>17)&0x3F) ;
1437 int mo = (v>>23)&0xF ;
1438 int d = (v>>27)&0x1F ;
1441 sprintf(ascii,
"%02d-%02d-%02d %02d:%02d:%02d",
1449 static int itpc_fee_map[24][4][16] = {
1451 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1452 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1453 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1454 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1457 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1458 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1461 { 7, 1, 0,12,24,17,13, 8,28, 2,19,20,29,25,21, 3},
1462 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1465 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1466 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1467 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1468 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1472 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1473 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1474 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1475 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1479 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1480 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1481 { 7, 1,17,12,24,19,13, 8,28, 2, 3,20,29,25,21, 0},
1482 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1486 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1487 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1488 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1489 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1493 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1494 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1495 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1496 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1500 {49,52,46, 0, 0, 54,0,47, 0,50,48,55, 0, 0,51,53},
1501 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1502 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1503 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1507 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1508 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1509 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1510 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1514 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1515 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1516 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1517 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1522 {49,52,46,47, 0, 54,0, 0, 0,50, 0,55,48, 0,51,53},
1523 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1524 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1525 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1529 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1530 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1531 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1532 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1536 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1537 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1538 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1539 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1542 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1543 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1544 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1545 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1548 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1549 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1550 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1551 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1554 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1555 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1556 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1557 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1561 {49,52, 0, 0,46, 54,0,47, 0,50, 0,55,48, 0,51,53},
1562 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1563 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1564 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1567 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1568 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1569 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1570 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1573 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1574 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1575 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1576 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1579 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1580 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1581 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1582 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1586 {49,52,46, 0, 0,54,47, 0, 0,50, 0,55,48, 0,51,53},
1587 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1588 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1589 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1592 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1593 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1594 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1595 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1598 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1599 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1600 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1601 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1604 {49,52,46, 0, 0, 54,0,47, 0,50, 0,55,48, 0,51,53},
1605 {36,32,40,43,37,33, 0,41, 0,44,38,34,42,45,39,35},
1606 { 7, 1,17,12,24,19,13, 8,28, 2, 0,20,29,25,21, 3},
1607 { 9, 4,26,14,15,10,30,22,27, 5,31,23,18,16,11, 6}
1613 static u_int get_ifee_mask(
int sec1,
int rdo1)
1617 for(
int i=0;i<16;i++) {
1618 if(itpc_fee_map[sec1-1][rdo1-1][i]) mask |= (1<<i) ;
1624 void itpc23::itpc_fee_kill(
int s0,
int r0,
int p0)
1626 itpc_fee_map[s0][r0][p0] = 0 ;