Skip to content

Commit

Permalink
updates to reader --- mainly to fix iTPC fee_words=0 problem (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
jml985 committed Jun 28, 2024
1 parent 9811528 commit e23deba
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 17 deletions.
51 changes: 40 additions & 11 deletions StRoot/RTS/src/DAQ_TPC23/itpc23.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ u_int *itpc23::ch_scan(u_int *start)
is_error = 1 ;
run_errors++ ;
if(mode || (online && run_errors<20)) {
LOG(ERR,"%d: ch_scan %d:%d:%d: pkt %d, sampa %d:%d, words10 %d [0x%08X: 0x%08X 0x%08X], err 0x%X",rdo1,fee_ix,lane_ix,
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",
rdo1,token,fee_ix,lane_ix,
ch_ix,
pkt,sampa_id,sampa_ch,words10,
d[0],d[-1],d[1],err) ;
Expand Down Expand Up @@ -417,7 +418,7 @@ u_int *itpc23::ch_scan(u_int *start)
err |= 0x2000000 ;
run_errors++ ;
if(mode || (online && run_errors<10)) {
LOG(ERR,"%d: ch_scan %d:%d: bx %d, expect %d",rdo1,fee_ix,ch_ix,bx,bx_count) ;
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) ;
}
}
}
Expand Down Expand Up @@ -529,7 +530,7 @@ u_int *itpc23::ch_scan(u_int *start)
seq[seq_ix].t_hi = tb_start + tb_cou - 1 ;
seq[seq_ix].dta_p = (dd-d_start) ; // where is this sequence...
seq[seq_ix].blob_id = 0 ;
seq_ix++ ;
//seq_ix++ ;

//dd += tb_cou ; // this doesn't sound correct!!!

Expand All @@ -538,6 +539,10 @@ u_int *itpc23::ch_scan(u_int *start)
if(unlikely(tb_start<=tb_last)) {
run_errors++ ;
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) ;

seq[seq_ix].t_lo = 400 ;
seq[seq_ix].t_hi = 401 ;

}


Expand All @@ -546,9 +551,12 @@ u_int *itpc23::ch_scan(u_int *start)
if(unlikely(tb_last>500)) {
run_errors++ ;
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) ;
}

seq[seq_ix].t_lo = 400 ;
seq[seq_ix].t_hi = 401 ;
}

seq_ix++ ;

ix = 2 ;
break ;
Expand Down Expand Up @@ -670,7 +678,7 @@ u_int *itpc23::lane_scan(u_int *start)
// should be at start of lane 0xB....
if((d[0]&0xF0000000)!=0xB0000000) { // start of lane
if((online && run_errors<10) || mode) {
LOG(ERR,"%d: lane_scan %d:%d: unknown start 0x%08X [0x%08X 0x%08X]",rdo1,fee_ix,lane_ix,d[0],d[-1],d[1]) ;
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]) ;
}

if(d[0]==d[-1]) {
Expand Down Expand Up @@ -703,7 +711,7 @@ u_int *itpc23::lane_scan(u_int *start)
if((d[0]&0xF0000000)!=0x70000000) { // end of lane
err |= 0x400000 ;
run_errors++ ;
if((online && run_errors<20)|| mode) LOG(ERR,"%d: lane_scan %d:%d: unknown end 0x%08X",rdo1,fee_ix,lane_ix,d[0]) ;
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]) ;
}

d++ ; // skip 0x7...
Expand All @@ -718,7 +726,7 @@ u_int *itpc23::fee_non_trgd(u_int *start)
int fee_words = 0 ;

if(fee_evt_type != 0x02) { // no clue
if(online || mode) LOG(ERR,"%d: fee_non_trgd %d: evt_type 0x%02X",rdo1,fee_ix,fee_evt_type) ;
if(online || mode) LOG(ERR,"%d: T %d: fee_non_trgd %d: evt_type 0x%02X",rdo1,token,fee_ix,fee_evt_type) ;


while(d<trl) {
Expand Down Expand Up @@ -830,7 +838,7 @@ u_int *itpc23::fee_scan(u_int *start)
// we must be at 0x8....
if((d[0]&0xF0000000)!=0x80000000) { // start of fee
err |= 0x10000 ; // oopsy -- what now!?
if(online || mode) LOG(ERR,"%d: fee_scan %d: not start-of-FEE 0x%08X",rdo1,fee_ix,d[0]) ;
if(online || mode) LOG(ERR,"%d: T %d: fee_scan %d: not start-of-FEE 0x%08X",rdo1,token,fee_ix,d[0]) ;
}
else {
if(d[0]&0x00800000) { // from real FEE
Expand Down Expand Up @@ -859,14 +867,14 @@ u_int *itpc23::fee_scan(u_int *start)
}
}
else { // non-physics trigger... typically send_config stuff
LOG(WARN,"%d: non-physics fee_ix %d, padplane %d",rdo1,fee_ix,fee_pp) ;
LOG(WARN,"%d: T %d: non-physics fee_ix %d, padplane %d",rdo1,token,fee_ix,fee_pp) ;
d = fee_non_trgd(d) ;
}


if((d[0]&0xF0000000)!=0x40000000) {
err |= 0x40000 ; // oopsy -- what now!?
if(online || mode) LOG(ERR,"%d: fee_scan %d: not end-of-FEE 0x%08X",rdo1,fee_ix,d[0]) ;
if(online || mode) LOG(ERR,"%d: T %d: fee_scan %d: not end-of-FEE 0x%08X",rdo1,token,fee_ix,d[0]) ;
}
else {
if(d[0]&0x00800000) {
Expand Down Expand Up @@ -1064,7 +1072,7 @@ int itpc23::rdo_scan(char *c_addr, int iwords)


int trg_cou = 0 ;

int loc_err_cou = 0 ;

switch(evt_type) {
case 1 : // timer
Expand All @@ -1074,6 +1082,7 @@ int itpc23::rdo_scan(char *c_addr, int iwords)
goto done ;
case 2 : // trigger!
evt_trgd++ ;
f_stat.evt_cou++ ;
break ;
default :
LOG(ERR,"%d: %d: unknown event type %d: 0x%08X",rdo1,evt,evt_type,d[1]) ;
Expand Down Expand Up @@ -1140,12 +1149,30 @@ int itpc23::rdo_scan(char *c_addr, int iwords)

// LOG(TERR,"%d: fee_mask 0x%08X",rdo1,fee_mask) ;


if(err) {
if(mode || online) {
LOG(ERR,"%d: T %d: error 0x%X before fee_scan??",rdo1,token,err) ;
}
}



for(int i=0;i<16;i++) {
if(fee_mask & (1<<i)) ;
else continue ;

fee_ix = i ;
d = fee_scan(d) ;
if(err) {
// LOG first FEE which failed
if(loc_err_cou==0) {
if(mode || online) {
LOG(ERR,"%d: T %d: error at FEE #%d (0x%X)",rdo1,token,i+1,err) ;
}
}
loc_err_cou++ ;
}
if(d>=trl) break ;
}

Expand Down Expand Up @@ -1371,6 +1398,8 @@ itpc23::itpc23()

fmt = 0 ;

fee_words = 0 ;

}


Expand Down
14 changes: 14 additions & 0 deletions StRoot/RTS/src/DAQ_TPC23/tpc23_base.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,8 @@ int tpc23_base::run_start()
run_errors = 0 ;
// fee_errs = 0 ;

memset(&f_stat,0,sizeof(f_stat)) ;

return 0 ;

}
Expand All @@ -1364,6 +1366,16 @@ int tpc23_base::run_start()
int tpc23_base::run_stop()
{
// LOG(TERR,"%d: run_stop: %d/%d events, run_errors %d",id,evt_trgd,evt,run_errors) ;

if(online || mode) {
for(int i=0;i<10;i++) {
f_stat.tm[i] /= f_stat.evt_cou ;
}

LOG(NOTE,"id %d: evts %d, means %f %f %f %f %f %f",id,f_stat.evt_cou,
f_stat.tm[0],f_stat.tm[1],f_stat.tm[2],f_stat.tm[3],f_stat.tm[4],
f_stat.tm[5]) ;
}

return 0 ;
}
Expand Down Expand Up @@ -1414,6 +1426,8 @@ tpc23_base::tpc23_base()

data_c = 0 ;

store_track_id = 0 ;

token = 1 ; // for ease of simulation
}

Expand Down
5 changes: 5 additions & 0 deletions StRoot/RTS/src/DAQ_TPC23/tpc23_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class tpc23_base {
// called from daq_itpc
int init(daq_dta *gain) ;

struct f_stat_t {
int evt_cou ;
double tm[10] ;
} f_stat ;

//private:


Expand Down
70 changes: 69 additions & 1 deletion StRoot/RTS/src/DAQ_TPC23/tpx23.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <pthread.h>
#include <sys/time.h>

#include <rtsLog.h>

Expand Down Expand Up @@ -35,6 +36,21 @@
#include "tpx23.h"


static double mark(void)
{
struct timeval tmval ;

gettimeofday(&tmval,0) ;

return ((double)tmval.tv_sec*1000000.0 + (double)tmval.tv_usec) ;
}

static double delta(double v)
{
return mark() - v ;
}


tpxPed *tpx23::peds ;
tpc23_base::row_pad_t (*tpx23::rp_gain_tpx)[ROW_MAX+1][PAD_MAX+1] ;

Expand Down Expand Up @@ -62,6 +78,7 @@ int tpx23::fee_scan()
int ch_pre = -1 ;
int s_cou ;
char retry ;
// double s_tmx = mark() ;

get_token((char *)d_start,words) ;

Expand Down Expand Up @@ -93,10 +110,16 @@ int tpx23::fee_scan()
u_int *h_to_continue ;
retry = 0 ;


f_stat.evt_cou++ ;

// NOTE: ALTRO scans from the end!!!
while(h>(d_start+2)) {
u_int hi, lo ;

// double tmx ;
// tmx=mark() ;

lo = *h-- ;
hi = *h-- ;

Expand Down Expand Up @@ -225,6 +248,9 @@ int tpx23::fee_scan()

while(wc%4) wc++ ;


// f_stat.tm[0] += delta(tmx) ;

// if this is a physics run: skip pads which have flags
// hmm... is this right?
if(flags && run_type==3) {
Expand Down Expand Up @@ -261,6 +287,8 @@ int tpx23::fee_scan()
//TLOGX(row) ;


// tmx = mark() ;

for(int i=0;i<wc;) { // NOTE: no increment!
lo = *h-- ;
hi = *h-- ;
Expand Down Expand Up @@ -315,6 +343,10 @@ int tpx23::fee_scan()
u_short d[512] ;
} sseq[SEQ_MAX] ;

// f_stat.tm[1] += delta(tmx) ;

// tmx = mark() ;

while(dd<(d+ix)) {
u_short t_lo ;

Expand Down Expand Up @@ -404,14 +436,39 @@ int tpx23::fee_scan()
}

}
else if(altro) {
altro[altro_cou].row = row ;
altro[altro_cou].pad = pad ;
altro[altro_cou].ch = ch ;
altro[altro_cou].id = id ;
altro[altro_cou].count = 0 ;

int aix = 0 ;

for(int i=(seq_ix-1);i>=0;i--) {
int t_len = sseq[i].t_hi - sseq[i].t_lo + 1 ;

int ii = 0 ;
for(int j=(t_len-1);j>=0;j--) {
int adc = sseq[i].d[j] ;
altro[altro_cou].adc[aix] = adc ;
altro[altro_cou].tb[aix] = sseq[i].t_lo + ii ;
altro[altro_cou].count++ ;
ii++ ;
aix++ ;
}
}

altro_cou++ ;
}
else if(tpx_d) {
tpx_d->sector = sector1 ;
tpx_d->rdo = rdo1 ;
tpx_d->row = row ;
tpx_d->pad = pad ;
tpx_d->altro = id ;

//LOG(TERR,"%d:%d %d:%d %d:%d",sector1,rdo1,row,pad,id,ch) ;
LOG(NOTE,"%d:%d %d:%d %d:%d",sector1,rdo1,row,pad,id,ch) ;

tpx_d->ch_start(ch) ; // sets tpx_d->ch within

Expand Down Expand Up @@ -441,6 +498,7 @@ int tpx23::fee_scan()



// f_stat.tm[2] += delta(tmx) ;


//LOG(TERR,"Here 2") ;
Expand All @@ -450,6 +508,9 @@ int tpx23::fee_scan()

// printf("row %d, pad %d: seq_ix %d\n",row,pad,seq_ix) ;


// tmx = mark() ;

for(int i=(seq_ix-1);i>=0;i--) {
seq[s_cou].t_lo = sseq[i].t_lo;
seq[s_cou].t_hi = sseq[i].t_hi ;
Expand Down Expand Up @@ -499,13 +560,18 @@ int tpx23::fee_scan()
id_pre = id ;
ch_pre = ch ;


// f_stat.tm[3] += delta(tmx) ;

end_loop:;
}



done:;

// f_stat.tm[4] += delta(s_tmx) ;

TLOG() ;

return err ;
Expand Down Expand Up @@ -1113,6 +1179,8 @@ tpx23::tpx23()

memset(fpga_usercode,0,sizeof(fpga_usercode)) ;

altro = 0 ;

tpx_d = 0 ;
}

Expand Down
Loading

0 comments on commit e23deba

Please sign in to comment.