00001 #include <sys/types.h>
00002 #include <string.h>
00003
00004 #include <rtsLog.h>
00005 #include <rtsSystems.h>
00006
00007 #include <SFS/sfs_index.h>
00008 #include <DAQ_READER/daqReader.h>
00009 #include <DAQ_READER/daq_dta.h>
00010
00011 #include "daq_l3.h"
00012
00013 extern int l3_reader(char *m, struct l3_t *l3, u_int driver) ;
00014
00015 const char *daq_l3::help_string = "L3 tst\n" ;
00016
00017 class daq_det_l3_factory : public daq_det_factory
00018 {
00019 public:
00020 daq_det_l3_factory() {
00021 daq_det_factory::det_factories[L3_ID] = this ;
00022 }
00023
00024 daq_det *create() {
00025 return new daq_l3 ;
00026 }
00027 } ;
00028
00029 static daq_det_l3_factory l3_factory ;
00030
00031
00032
00033 daq_l3::daq_l3(daqReader *rts_caller)
00034 {
00035 LOG(DBG,"L3: rts_id %d, name %s",rts_id,name) ;
00036
00037
00038 rts_id = L3_ID ;
00039 name = rts2name(rts_id) ;
00040 sfs_name = "l3" ;
00041 caller = rts_caller ;
00042 if(caller) caller->insert(this, rts_id) ;
00043
00044 legacy = new daq_dta ;
00045
00046 LOG(DBG,"%s: constructor: caller %p",name,caller) ;
00047 }
00048
00049 daq_l3::~daq_l3()
00050 {
00051 LOG(DBG,"%s: destructor",name) ;
00052 if(caller) caller->de_insert(rts_id) ;
00053
00054 delete legacy ;
00055
00056 return ;
00057 }
00058
00059
00060 daq_dta *daq_l3::get(const char *bank, int c1, int c2, int c3, void *p1, void *p2)
00061 {
00062 Make() ;
00063 if(!present) return 0 ;
00064
00065 if(strcmp(bank,"*")==0) bank = "legacy" ;
00066
00067 if(strcasecmp(bank,"legacy") != 0) {
00068 LOG(ERR,"%s: unknown bank %s",name,bank) ;
00069 return 0 ;
00070 }
00071
00072 return handle_legacy() ;
00073
00074 }
00075
00076
00077 daq_dta *daq_l3::handle_legacy()
00078 {
00079
00080
00081 legacy->create(1,"l3_t",rts_id,DAQ_DTA_STRUCT(l3_t)) ;
00082
00083
00084 l3_t *l3_p = (l3_t *) legacy->request(1) ;
00085
00086 if(present & DET_PRESENT_DATAP) {
00087 l3_reader(caller->mem, l3_p, 0) ;
00088 }
00089 else {
00090 char str[256] ;
00091 char *full_name ;
00092
00093 sprintf(str,"gl3/l3_gtd") ;
00094 full_name = caller->get_sfs_name(str) ;
00095
00096 LOG(DBG,"full_name %s",full_name) ;
00097
00098 if(!full_name) {
00099 sprintf(str,"l3/l3_gtd") ;
00100 full_name = caller->get_sfs_name(str) ;
00101
00102 LOG(DBG,"full_name %s",full_name) ;
00103
00104
00105 if(!full_name) return 0 ;
00106 }
00107
00108 int bytes = caller->sfs->fileSize(full_name) ;
00109
00110 LOG(DBG,"bytes %d",bytes) ;
00111
00112 char *mem = (char *)valloc(bytes) ;
00113
00114
00115 int ret = caller->sfs->read(str, mem, bytes) ;
00116
00117 LOG(DBG,"ret %d",ret) ;
00118
00119 l3_reader(mem, l3_p, 1) ;
00120
00121 free(mem) ;
00122 }
00123
00124 legacy->finalize(1,0,0,0) ;
00125 legacy->rewind() ;
00126
00127 return legacy ;
00128 }