6 #include <rtsSystems.h>
8 #include <SFS/sfs_index.h>
10 #include <DAQ_READER/daqReader.h>
11 #include <DAQ_READER/daq_dta.h>
20 const char *daq_mtd::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 mtd_t; \n\
34 daq_det_factory::det_factories[MTD_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_mtd::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) {
92 if((present & DET_PRESENT_SFS)==0)
return 0 ;
93 return handle_legacy() ;
96 LOG(ERR,
"%s: unknown bank type \"%s\"",name,bank) ;
103 daq_dta *daq_mtd::handle_legacy()
107 legacy->create(1,
"mtd_t",rts_id,DAQ_DTA_STRUCT(
mtd_t)) ;
113 memset(mtd_p->ddl_words,0,
sizeof(mtd_p->ddl_words)) ;
116 mtd_p->channels = 0 ;
117 mtd_p->max_channels = 0 ;
120 for(
int r=1;r<=MAX_RDO;r++) {
121 daq_dta *dd = handle_raw(0,r) ;
122 if(dd && dd->iterate()) {
123 u_int *tmp = (u_int *)dd->Void ;
125 u_int words = dd->ncontent/4 ;
127 LOG(DBG,
"MTD: RDO %d: bytes %d (max %d)",r,dd->ncontent,
sizeof(mtd_p->ddl[0])) ;
129 if(words > (
sizeof(mtd_p->ddl[0])/4)) {
130 LOG(ERR,
"MTD: Huge event in RDO %d: %d words -- clipping to %d words",
131 r,words,
sizeof(mtd_p->ddl[0])/4) ;
133 words =
sizeof(mtd_p->ddl[0])/4 ;
137 mtd_p->ddl_words[r-1] = words ;
140 for(u_int i=0;i<words;i++) {
141 mtd_p->ddl[r-1][i] = l2h32(*tmp) ;
150 legacy->finalize(1,1,0,0) ;
157 daq_dta *daq_mtd::handle_raw(
int sec,
int rdo)
161 int min_rdo, max_rdo ;
162 int min_sec, max_sec ;
167 } obj[MAX_SEC*MAX_RDO] ;
171 min_sec = max_sec = sec ;
177 else if((rdo<1) || (rdo>MAX_RDO))
return 0 ;
179 min_rdo = max_rdo = rdo ;
188 for(
int s=min_sec;s<=max_sec;s++) {
189 for(
int r=min_rdo;r<=max_rdo;r++) {
191 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name, s, r) ;
192 char *full_name = caller->get_sfs_name(str) ;
194 LOG(DBG,
"%s: trying sfs on \"%s\"",name,str) ;
195 if(full_name == 0) continue ;
197 int size = caller->sfs->fileSize(full_name) ;
199 LOG(DBG,
"Got %d",size) ;
202 LOG(DBG,
"%s: %s: not found in this event",name,str) ;
208 obj[o_cou].bytes = size ;
213 LOG(DBG,
"%s: %s: reading in \"%s\": bytes %d",name,str,
"raw", size) ;
218 raw->create(tot_bytes,
"mtd_raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
220 for(
int i=0;i<o_cou;i++) {
222 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name, obj[i].sec, obj[i].
rb) ;
223 char *full_name = caller->get_sfs_name(str) ;
224 if(full_name == 0) continue ;
226 char *st = (
char *) raw->request(obj[i].bytes) ;
228 int ret = caller->sfs->read(full_name, st, obj[i].bytes) ;
230 if(ret != (
int)obj[i].bytes) {
231 LOG(ERR,
"%s: %s: read failed, expect %d, got %d [%s]",name,str,
232 obj[i].bytes,ret,strerror(errno)) ;
236 LOG(NOTE,
"%s: %s read %d bytes",name,str,ret) ;
240 raw->finalize(obj[i].bytes,obj[i].sec,obj[i].
rb,0) ;
250 int daq_mtd::get_token(
char *addr,
int words)
255 cou = get_l2(addr,words,trg,1) ;
257 if(cou==0)
return -1000 ;
258 if(trg[0].t==0)
return -ENOSYS ;
264 int daq_mtd::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo)
269 int in_words = words ;
278 LOG(DBG,
"First words 0x%08X 0x%08X 0x%08X, last words 0x%08X 0x%08X 0x%08X [+0x%08X], %u",
279 w[0],w[1],w[2],w[words-2],w[words-1],w[words],w[words+1],words+1) ;
286 trg[t_cou].t = w[0] & 0xFFF ;
287 trg[t_cou].daq = (w[0]>>12) & 0xF ;
288 trg[t_cou].trg = (w[0]>>16) & 0xF ;
289 trg[t_cou].rhic = 0 ;
290 trg[t_cou].rhic_delta = 0 ;
297 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) ;
301 LOG(ERR,
"[%d] bad word count %d < 2",rdo,in_words);
305 if(w[0] == 0xA0000000) {
311 LOG(ERR,
"[%d] bad word count %d <= 3",rdo,in_words);
316 LOG(ERR,
"[%d] token 0",rdo);
320 if(trg[0].trg != 4) {
322 LOG(ERR,
"[%d] bad trg_cmd %d != 4",rdo,trg[0].trg);
325 if(w[1] != 0xDEADFACE) {
327 LOG(ERR,
"[%d] bad DEADFACE 0x%08X",rdo,w[1]);
333 if((w[0] >> 20) != 0xA00) {
335 LOG(ERR,
"[%d] bad first word 0x%08X doesn't start with 0xA00",rdo,w[0]);
342 if((w[words] >> 28)==0xA) {
353 LOG(ERR,
"[%d] No Trigger FIFO contribution??",rdo);
361 for(
int i=0;i<cou;i++) {
364 trg[t_cou].t = w[words+i] & 0xFFF ;
365 trg[t_cou].daq = (w[words+i]>>12) & 0xF ;
366 trg[t_cou].trg = (w[words+i]>>16) & 0xF ;
367 trg[t_cou].rhic = i+1 ;
368 trg[t_cou].rhic_delta = i+1 ;
370 if(trg[t_cou].t == 0) l_err = 1 ;
373 switch(trg[t_cou].trg) {
385 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]);
394 LOG(ERR,
"[%d] Too many trigger contributions %d >= 120",rdo,t_cou) ;
401 LOG(ERR,
"[%d] Bad Event: T %4d: words %d, trg_words %d (start at %d) : 0x%08X 0x%08X 0x%08X",
402 rdo,trg[0].t,in_words,cou,trg_start,w[0],w[1],w[2]) ;