6 #include <rtsSystems.h>
8 #include <SFS/sfs_index.h>
10 #include <DAQ_READER/daqReader.h>
11 #include <DAQ_READER/daq_dta.h>
15 extern int tof_reader(
char *mem,
struct tof_t *
tof, u_int driver) ;
20 const char *daq_tof::help_string =
"\
24 raw returns=ptr of start of DDL data; c1=sector[1..1]; c2=rdo[1..4]; \n\
25 legacy returns=ptr to struct tof_t; \n\
34 daq_det_factory::det_factories[TOF_ID] = this ;
49 name = rts2name(rts_id) ;
52 if(caller) caller->insert(
this, rts_id) ;
59 LOG(DBG,
"%s: constructor: caller %p",name,rts_caller) ;
65 LOG(DBG,
"%s: DEstructor",name) ;
75 daq_dta *daq_tof::get(
const char *bank,
int sec,
int row,
int pad,
void *p1,
void *p2)
79 if(present==0)
return 0 ;
81 LOG(DBG,
"%s: looking for bank %s",name,bank) ;
83 if(strcmp(bank,
"*")==0) bank =
"legacy" ;
87 if(strcasecmp(bank,
"raw")==0) {
88 if((present & DET_PRESENT_SFS)==0)
return 0 ;
89 return handle_raw(sec,row) ;
91 else if(strcasecmp(bank,
"legacy")==0) {
93 return handle_legacy() ;
96 LOG(ERR,
"%s: unknown bank type \"%s\"",name,bank) ;
103 daq_dta *daq_tof::handle_legacy()
107 legacy->create(1,
"tof_t",rts_id,DAQ_DTA_STRUCT(
tof_t)) ;
113 memset(tof_p->ddl_words,0,
sizeof(tof_p->ddl_words)) ;
115 if(present & DET_PRESENT_DATAP) {
116 tof_reader(caller->mem, tof_p, m_Debug) ;
120 tof_p->channels = 0 ;
121 tof_p->max_channels = 48+48+32+12 ;
124 for(
int r=1;r<=4;r++) {
125 daq_dta *dd = handle_raw(0,r) ;
126 if(dd && dd->iterate()) {
127 u_int *tmp = (u_int *)dd->Void ;
129 u_int words = dd->ncontent/4 ;
131 LOG(DBG,
"TOF: RDO %d: bytes %d (max %d)",r,dd->ncontent,
sizeof(tof_p->ddl[0])) ;
133 if(words > (
sizeof(tof_p->ddl[0])/4)) {
134 LOG(ERR,
"TOF: Huge event in RDO %d: %d words -- clipping to %d words",
135 r,words,
sizeof(tof_p->ddl[0])/4) ;
137 words =
sizeof(tof_p->ddl[0])/4 ;
141 tof_p->ddl_words[r-1] = words ;
144 for(u_int i=0;i<words;i++) {
145 tof_p->ddl[r-1][i] = l2h32(*tmp) ;
154 legacy->finalize(1,1,0,0) ;
161 daq_dta *daq_tof::handle_raw(
int sec,
int rdo)
165 int min_rdo, max_rdo ;
166 int min_sec, max_sec ;
171 } obj[MAX_SEC*MAX_RDO] ;
175 min_sec = max_sec = sec ;
181 else if((rdo<1) || (rdo>MAX_RDO))
return 0 ;
183 min_rdo = max_rdo = rdo ;
192 for(
int s=min_sec;s<=max_sec;s++) {
193 for(
int r=min_rdo;r<=max_rdo;r++) {
195 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name, s, r) ;
196 char *full_name = caller->get_sfs_name(str) ;
198 LOG(DBG,
"%s: trying sfs on \"%s\"",name,str) ;
199 if(full_name == 0) continue ;
201 int size = caller->sfs->fileSize(full_name) ;
203 LOG(DBG,
"Got %d",size) ;
206 LOG(DBG,
"%s: %s: not found in this event",name,str) ;
212 obj[o_cou].bytes = size ;
217 LOG(DBG,
"%s: %s: reading in \"%s\": bytes %d",name,str,
"raw", size) ;
222 raw->create(tot_bytes,
"tof_raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
224 for(
int i=0;i<o_cou;i++) {
226 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name, obj[i].sec, obj[i].
rb) ;
227 char *full_name = caller->get_sfs_name(str) ;
228 if(full_name == 0) continue ;
230 char *st = (
char *) raw->request(obj[i].bytes) ;
232 int ret = caller->sfs->read(full_name, st, obj[i].bytes) ;
234 if(ret != (
int)obj[i].bytes) {
235 LOG(ERR,
"%s: %s: read failed, expect %d, got %d [%s]",name,str,
236 obj[i].bytes,ret,strerror(errno)) ;
240 LOG(NOTE,
"%s: %s read %d bytes",name,str,ret) ;
244 raw->finalize(obj[i].bytes,obj[i].sec,obj[i].
rb,0) ;
254 int daq_tof::get_token(
char *addr,
int words)
259 cou = get_l2(addr,words,trg,1) ;
261 if(cou==0)
return -1000 ;
262 if(trg[0].t==0)
return -ENOSYS ;
268 int daq_tof::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo)
273 int in_words = words ;
282 LOG(DBG,
"First words 0x%08X 0x%08X 0x%08X, last words 0x%08X 0x%08X 0x%08X [+0x%08X], %u",
283 w[0],w[1],w[2],w[words-2],w[words-1],w[words],w[words+1],words+1) ;
290 trg[t_cou].t = w[0] & 0xFFF ;
291 trg[t_cou].daq = (w[0]>>12) & 0xF ;
292 trg[t_cou].trg = (w[0]>>16) & 0xF ;
293 trg[t_cou].rhic = 0 ;
294 trg[t_cou].rhic_delta = 0 ;
298 LOG(NOTE,
"prompt: T %4d, trg %d, daq %d [0x%08X]: words %d",trg[0].t,trg[0].trg,trg[0].daq,w[0],in_words) ;
302 LOG(ERR,
"[%d] bad word count %d < 2",rdo,in_words);
306 if(w[0] == 0xA0000000) {
312 LOG(ERR,
"[%d] bad word count %d <= 3",rdo,in_words);
317 LOG(ERR,
"[%d] token 0",rdo);
321 if(trg[0].trg != 4) {
323 LOG(ERR,
"[%d] bad trg_cmd %d != 4",rdo,trg[0].trg);
326 if(w[1] != 0xDEADFACE) {
328 LOG(ERR,
"[%d] bad DEADCODE 0x%08X",rdo,w[1]);
334 if((w[0] >> 20) != 0xA00) {
336 LOG(ERR,
"[%d] bad first word 0x%08X doesn't start with 0xA00",rdo,w[0]);
344 if((w[words] >> 28)==0xA) {
355 LOG(ERR,
"[%d] No Trigger FIFO contribution??",rdo);
363 for(
int i=0;i<cou;i++) {
366 trg[t_cou].t = w[words+i] & 0xFFF ;
367 trg[t_cou].daq = (w[words+i]>>12) & 0xF ;
368 trg[t_cou].trg = (w[words+i]>>16) & 0xF ;
369 trg[t_cou].rhic = i+1 ;
370 trg[t_cou].rhic_delta = i+1 ;
372 if(trg[t_cou].t == 0) l_err = 1 ;
375 switch(trg[t_cou].trg) {
387 LOG(ERR,
"[%d] bad FIFO trg (%d.): T %4d, trg %d, daq %d [0x%08X]",rdo,words+i,trg[t_cou].t,trg[t_cou].trg,trg[t_cou].daq,w[words+i]);
396 LOG(ERR,
"[%d] Too many trigger contributions %d >= 120",rdo,t_cou) ;
404 if((t_cou==1) && (trg[0].t > 0) && (trg[0].t<=4095)) {
405 trg[t_cou].t = trg[0].t ;
407 trg[t_cou].trg = 15 ;
408 trg[t_cou].rhic = trg[0].rhic + 1 ;
409 trg[t_cou].rhic_delta = 1 ;
414 LOG(WARN,
"%d %d %d???",t_cou,trg[0].t,trg[0].trg) ;
419 LOG(ERR,
"[%d] Bad Event: T %4d: words %d, trg_words %d (start at %d) : 0x%08X 0x%08X 0x%08X",
420 rdo,trg[0].t,in_words,cou,trg_start,w[0],w[1],w[2]) ;