6 #include <rtsSystems.h>
9 #include <SFS/sfs_index.h>
10 #include <DAQ_READER/daqReader.h>
11 #include <DAQ_READER/daq_dta.h>
15 #include <DAQ_EMC/daq_emc.h>
21 const int etow_crate_map[] = {
22 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
26 const char *daq_etow::help_string =
"ETOW tst\n" ;
32 daq_det_factory::det_factories[ETOW_ID] = this ;
47 LOG(DBG,
"ETOW: rts_id %d, name %s",rts_id,name) ;
51 name = rts2name(rts_id) ;
54 if(caller) caller->insert(
this, rts_id) ;
59 LOG(DBG,
"%s: constructor: caller %p",name,caller) ;
64 LOG(DBG,
"%s: destructor",name) ;
82 LOG(DBG,
"%s: Make()",name) ;
85 present |= DET_PRESENT_SFS ;
87 else if(legacyDetp(rts_id, caller->mem)) {
88 present |= DET_PRESENT_DATAP ;
90 else if(getEmcTrgData(caller->mem,2,&dummy)) {
91 present |= DET_PRESENT_TRG ;
95 case DET_PRESENT_DATAP :
96 LOG(NOTE,
"%s: %d: has DATAP",name,evt_num) ;
98 case DET_PRESENT_SFS :
99 LOG(NOTE,
"%s: %d: has SFS(%s)",name,evt_num,sfs_name) ;
101 case DET_PRESENT_TRG :
102 LOG(NOTE,
"%s: %d: has DATAP within Trigger",name,evt_num) ;
110 daq_dta *daq_etow::get(
const char *bank,
int c1,
int c2,
int c3,
void *p1,
void *p2)
113 if(!present)
return 0 ;
116 if(strcasecmp(bank,
"raw") == 0) {
117 return handle_raw() ;
119 else if(strcasecmp(bank,
"adc") == 0) {
120 return handle_adc() ;
123 LOG(ERR,
"%s: unknown bank \"%s\"",name,bank) ;
130 daq_dta *daq_etow::handle_raw()
139 if(present & DET_PRESENT_DATAP) {
140 char *mem = (
char *)legacyDetp(rts_id, caller->mem) ;
141 from = emc_single_reader(mem, &bytes, rts_id) ;
142 if(from == 0)
return 0 ;
145 else if(present & DET_PRESENT_TRG) {
146 from = getEmcTrgData(caller->mem,2,&bytes) ;
147 if(from == 0)
return 0 ;
153 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name,1,1) ;
156 full_name = caller->get_sfs_name(str) ;
158 LOG(DBG,
"%s: %s: %p",name,str,full_name) ;
160 if(!full_name)
return 0 ;
162 bytes = caller->sfs->fileSize(full_name) ;
164 LOG(DBG,
"ETOW sfs bytes %d",bytes) ;
166 raw->create(bytes,
"raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
168 st = (
char *) raw->request(bytes) ;
170 int ret = caller->sfs->read(str, st, bytes) ;
172 LOG(ERR,
"ret is %d") ;
177 raw->create(bytes,
"raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
178 st = (
char *)raw->request(bytes) ;
179 memcpy(st, from, bytes) ;
183 raw->finalize(bytes,1,1,0) ;
186 LOG(DBG,
"Returning raw bank...") ;
191 daq_dta *daq_etow::handle_adc()
195 LOG(DBG,
"Entering adc") ;
199 LOG(DBG,
"raw bank %p",dd) ;
201 if(dd && dd->iterate()) {
202 raw_dta = (u_short *) dd->Byte ;
209 LOG(DBG,
"Got raw bank, on to adc...") ;
211 adc->create(1,
"adc", rts_id, DAQ_DTA_STRUCT(
etow_t)) ;
217 u_short *
data = (u_short *)((
char *)raw_dta + 4 + 128) ;
219 for(
int j=0;j<ETOW_PRESIZE;j++) {
220 for(
int i=0;i<ETOW_MAXFEE;i++) {
221 etow_p->preamble[i][j] = l2h16(*data++) ;
225 for(
int j=0;j<ETOW_DATSIZE;j++) {
226 for(
int i=0;i<ETOW_MAXFEE;i++) {
227 etow_p->adc[i][j] = l2h16(*data++) ;
232 adc->finalize(1,1,1,0) ;
238 int daq_etow::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo1)
240 const int ETOW_DDL_BYTES = 2100 ;
241 int buff_bytes = words * 4 ;
243 u_short *us = (u_short *)addr ;
245 u_short t_hi = l2h16(us[2]) ;
246 u_short t_lo = l2h16(us[3]) ;
250 if(buff_bytes != ETOW_DDL_BYTES) {
252 LOG(ERR,
"Received %d bytes, expect %d!?",buff_bytes,ETOW_DDL_BYTES) ;
255 if((t_lo & 0xFF00) || (t_hi & 0xFFF0)) {
257 LOG(ERR,
"Corrupt token: t_hi 0x%04X, t_lo 0x%04X",t_hi,t_lo) ;
272 trg[0].t = t_hi*256 + t_lo ;
275 trg[0].rhic = l2h16(us[4]) ;
281 LOG(ERR,
"token 0!") ;
285 LOG(WARN,
"RDO %d: 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X",rdo1, us[0],us[1],us[2],us[3],us[4]) ;