10 #include <rtsSystems.h>
11 #include <daqFormats.h>
13 #include <SFS/sfs_index.h>
15 #include "daqReader.h"
26 daq_det *daq_det_factory::make_det(
int wh)
36 sprintf(libname,
"libdaq_emc.so") ;
39 sprintf(libname,
"libdaqhlt.so") ;
42 sprintf(libname,
"libitpc.so") ;
50 sprintf(libname,
"libdaq_%s.so",rts2name(wh)) ;
54 for(u_int i=0;i<strlen(libname);i++) {
55 libname[i] = tolower(libname[i]) ;
58 LOG(NOTE,
"factory for det %d, lib %s",wh,libname) ;
62 use_factory = pseudo_factories[wh] ;
65 use_factory = det_factories[wh] ;
70 if(use_factory == 0) {
71 #if 0 // this was never completed...
73 gSomething->Loadsomething(libname) ;
78 void *handle = dlopen(
"../DAQ_SC/libdaq_sc.so", RTLD_LAZY | RTLD_GLOBAL) ;
80 LOG(ERR,
"dlopen failed for %s [%s]",libname,dlerror()) ;
83 LOG(NOTE,
"dlopen OK for det %d, lib %s",wh,libname) ;
90 if(use_factory == 0) {
91 LOG(ERR,
"Can't load or find detector %d,libname %s",wh,libname) ;
96 LOG(NOTE,
"factory for %d: calling create",wh) ;
98 return use_factory->create() ;
102 int daq_det::endianess = 0 ;
107 name = sfs_name =
"(generic)" ;
109 caller = rts_caller ;
115 def_sector = def_rdo = -1 ;
122 if(htonl(0x12345678) != 0x12345678) {
130 LOG(DBG,
"daq_det: %s [%d], caller %p: endianess %c",name,rts_id,caller,endianess?
'B':
'L') ;
138 LOG(DBG,
"~daq_det: %s [%d]",name,rts_id) ;
142 LOG(DBG,
"Before de_insert(%d)",rts_id) ;
143 caller->de_insert(rts_id) ;
144 LOG(DBG,
"After de_insert(%d)",rts_id) ;
151 unsigned int daq_det::get_global_event_num()
153 if(caller)
return caller->seq ;
158 void daq_det::managed_by(
class daqReader *c)
164 caller->insert(
this, rts_id) ;
174 present |= DET_PRESENT_SFS ;
175 LOG(NOTE,
"%s(SFS %s): present via SFS",name,sfs_name) ;
177 else if(legacyDetp(rts_id, caller->mem)) {
178 present |= DET_PRESENT_DATAP ;
179 LOG(NOTE,
"%s(SFS %s): present via DATAP",name,sfs_name) ;
186 LOG(DBG,
"%s: not found",name) ;
198 LOG(DBG,
"Init: %s[%d], sfs_name %s",name,rts_id,sfs_name) ;
203 int daq_det::InitRun(
int run_number)
205 run_num = run_number ;
209 LOG(DBG,
"InitRun: %s [%d]: run %09u",name,rts_id,run_number) ;
214 int daq_det::FinishRun(
int old_run_number)
217 LOG(DBG,
"FinishRun: %s [%d]: run %09u",name,rts_id,old_run_number) ;
222 void daq_det::help()
const
224 printf(
"***************** %s: %s ******************\n",name,GetCVS()) ;
231 int daq_det::presence()
237 LOG(NOTE,
"no caller? %s",name) ;
246 if(caller->sfs == 0)
goto ret_here ;
248 if(caller->sfs->opendirent((
char *)sfs_name)) {
257 LOG(DBG,
"sfs presence(%s): %d",sfs_name,pres) ;
265 int daq_det::get_token(
char *addr,
int words)
269 int ret = get_l2(addr, words, trgs, 1) ;
271 LOG(ERR,
"No triggers?") ;
277 LOG(ERR,
"Token 0 not allowed but I will try to use the other triggers...") ;
287 int daq_det::get_l2(
char *buff,
int buff_bytes,
daq_trg_word *trg,
int prompt)
290 LOG(ERR,
"%s: get_l2() not written!",name) ;
294 int daq_det::bad_sanity()
299 daq_dta *daq_det::get(
const char *bank,
int c1,
int c2,
int c3,
void *p1,
void *p2)
301 LOG(ERR,
"%s [%d]: get() not written!",name,rts_id) ;
307 daq_dta *daq_det::put(
const char *bank,
int c1,
int c2,
int c3,
void *p1,
void *p2)
309 LOG(ERR,
"%s: put() not written!",name) ;
317 int checkBank(
const char *in,
const char *expect)
329 if(strcmp(buff,
"DATAP")==0) {
330 memcpy(buff,CHAR_DATAP,8) ;
333 if(memcmp(buff,expect,strlen(expect))) {
334 LOG(ERR,
"Read \"%s\", expect \"%s\"",buff,expect) ;
338 LOG(DBG,
"Found \"%s\", as expected...",expect) ;
348 int *legacyDetp(
int rts_id,
char *m)
359 LOG(DBG,
"No DATAP: I would need it for %s [%d]",rts2name(rts_id),rts_id) ;
367 LOG(DBG,
"Checking for %s",rts2name(rts_id)) ;
370 if(checkBank(datap->bh.bank_type, CHAR_DATAP) < 0) {
376 if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatap = 1;
378 for(
int i=0;i<10;i++) {
379 if(datap->det[i].len) {
380 LOG(DBG,
"Found DATAP ix %d: [%s]",i,rts2name(i)) ;
401 len = qswap32(swapdatap, datap->det[
id].len) ;
402 off = qswap32(swapdatap, datap->det[
id].off) ;
404 LOG(DBG,
"Checking for datap: len=%d off=%d",len,off);
406 if((len == 0) || (off == 0)) {
411 LOG(DBG,
"%s [%d] found in this event",rts2name(rts_id),rts_id) ;
412 ret_p = ((
int *)datap + off) ;
416 len = qswap32(swapdatap, datap->det[EXT_ID].len) ;
417 off = qswap32(swapdatap, datap->det[EXT_ID].off) ;
419 LOG(DBG,
"Checking for datapx: len=%d off=%d",len,off);
421 if((len == 0) || (off == 0)) {
426 datapx = (
struct DATAPX *)((
int *)datap + off) ;
429 if(checkBank(datapx->bh.bank_type, CHAR_DATAPX) < 0) {
433 if(datapx->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatapx = 1;
435 for(
int i=0;i<22;i++) {
436 if(datapx->det[i].len) {
437 LOG(DBG,
"Found DATAPX ix %d: ID %d [%s]",i,i+10,rts2name(i+10)) ;
442 len = qswap32(swapdatapx, datapx->det[
id-10].len) ;
443 off = qswap32(swapdatapx, datapx->det[
id-10].off) ;
446 if((len == 0) || (off == 0)) {
451 LOG(DBG,
"%s [%d] found in this event",rts2name(rts_id),rts_id) ;
452 ret_p = ((
int *)datapx + off) ;
457 if(ret_p == 0)
return 0 ;
466 LOG(DBG,
"[BE]TOW: %p: %d, %d",emcp,emcp->sec[0].len, emcp->sec[1].len) ;
467 if(emcp->sec[0].len) ;
472 LOG(DBG,
"[BE]SMD: %p: %d, %d",emcp,emcp->sec[0].len, emcp->sec[1].len) ;
473 if(emcp->sec[1].len) ;
478 if(ret_p) LOG(DBG,
"%s [%d] found in this event",rts2name(rts_id),rts_id) ;