7 #include <rtsSystems.h>
11 #include <SFS/sfs_index.h>
12 #include <DAQ_READER/daqReader.h>
13 #include <DAQ_READER/daq_dta.h>
19 const char *daq_fps::help_string =
"FPS\n\
20 raw returns raw data\n" ;
26 daq_det_factory::det_factories[FPS_ID] = this ;
40 name = rts2name(rts_id) ;
44 if(caller) caller->insert(
this, rts_id) ;
50 LOG(DBG,
"%s: constructor: caller %p",name,rts_caller) ;
56 LOG(DBG,
"%s: DEstructor",name) ;
67 daq_dta *daq_fps::get(
const char *bank,
int sec,
int rdo,
int pad,
void *p1,
void *p2)
71 if(present == 0)
return 0 ;
74 if(strcasecmp(bank,
"raw")==0) {
75 return handle_raw(sec) ;
77 else if(strcasecmp(bank,
"adc")==0) {
78 return handle_adc(sec) ;
80 else if(strcasecmp(bank,
"pedrms")==0) {
81 return handle_pedrms(sec) ;
85 LOG(ERR,
"%s: unknown bank type \"%s\"",name,bank) ;
92 daq_dta *daq_fps::handle_adc(
int sec)
103 s_start = s_stop = sec ;
106 adc->create(32,
"fps_adc",rts_id,DAQ_DTA_STRUCT(
fps_adc_t)) ;
108 for(
int s=s_start;s<=s_stop;s++) {
110 raw_d = handle_raw(s) ;
111 if(raw_d==0) continue ;
112 if(raw_d->iterate() == 0)
continue ;
116 u_int *d32 = (u_int *) raw_d->Void ;
120 int tb_cou = hdr->pre_post_cou ;
121 int qt_cou = hdr->qt_cou ;
128 memcpy(&meta_hdr,hdr,
sizeof(meta_hdr)) ;
129 adc->meta = (
void *) &meta_hdr ;
131 d32 += (hdr->ver & 0xFF) ;
135 for(
int tb=0;tb<tb_cou;tb++) {
136 int rel_xing = *d32++ ;
140 for(
int q=0;q<qt_cou;q++) {
146 if(chs==0) continue ;
152 for(
int c=0;c<chs;c++) {
153 u_int datum = *d32++ ;
155 int ch = datum >> 27 ;
156 int aadc = datum & 0x0FFF ;
157 int tdc = (datum >> 16) & 0x07FF ;
165 adc->finalize(chs,s,qt,rel_xing) ;
178 daq_dta *daq_fps::handle_raw(
int sec)
184 int s_start, s_stop ;
192 LOG(DBG,
"%s: present %d",name,present) ;
201 s_start = s_stop = sec ;
205 raw->create(1024,
"fps_raw",rts_id,DAQ_DTA_STRUCT(
char)) ;
208 for(
int s=s_start;s<=s_stop;s++) {
209 sprintf(str,
"%s/sec0%d/rb01/raw",sfs_name,s) ;
210 full_name = caller->get_sfs_name(str) ;
214 if(!full_name) continue ;
215 bytes = caller->sfs->fileSize(full_name) ;
217 st = (
char *) raw->request(bytes) ;
219 int ret = caller->sfs->read(str, st, bytes) ;
221 LOG(ERR,
"ret is %d") ;
226 raw->finalize(bytes,s,0,0) ; ;
237 daq_dta *daq_fps::handle_pedrms(
int sec)
242 int s_start, s_stop ;
249 s_start = s_stop = sec ;
252 for(
int s=s_start;s<=s_stop;s++) {
254 sprintf(str,
"%s/sec%02d/pedrms",sfs_name, s) ;
256 LOG(NOTE,
"Trying %s",str) ;
258 full_name = caller->get_sfs_name(str) ;
261 LOG(NOTE,
"full_name %s",full_name) ;
264 if(!full_name) continue ; ;
267 bytes = caller->sfs->fileSize(full_name) ;
269 LOG(NOTE,
"bytes %d",bytes) ;
275 LOG(ERR,
"Got %d, expect %d",bytes,
sizeof(
fps_pedrms_t)) ;
279 char *
data = (
char *)malloc(bytes) ;
281 int ret = caller->sfs->read(str, (
char *)data, bytes) ;
283 LOG(ERR,
"ret is %d") ;
286 pedrms->create(1,
"fps_pedrms",rts_id,DAQ_DTA_STRUCT(
fps_pedrms_t)) ;
288 for(
int i=0;i<nitems;i++) {
294 if(ped->version != FPS_PED_VERSION) {
295 LOG(ERR,
"Wrong version %d in file, expect %d",ped->version,FPS_PED_VERSION) ;
298 pedrms->finalize(1,s,ped->qt_ix,0) ;
313 int daq_fps::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo)
324 trg[t_cou].rhic = h->tick ;
325 trg[t_cou].rhic_delta = 0 ;
326 trg[t_cou].t = h->token;
334 LOG(ERR,
"%u: bad QT event 0x%08X 0x%08X 0x%08X [%d]",h->ev,h->stp_data[0],h->stp_data[1],h->stp_data[2],err) ;