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 btow_crate_map[] = {
22 0x12, 0x11, 0x10, 0x1e,
23 0x1d, 0x1c, 0x1b, 0x1a,
24 0x19, 0x18, 0x17, 0x16,
25 0x15, 0x14, 0x13, 0x01,
26 0x0f, 0x0e, 0x0d, 0x0c,
27 0x0b, 0x0a, 0x09, 0x08,
28 0x07, 0x06, 0x05, 0x04,
36 daq_det_factory::det_factories[BTOW_ID] = this ;
47 const char *daq_btow::help_string =
"BTOW tst\n" ;
54 LOG(DBG,
"BTOW: rts_id %d, name %s",rts_id,name) ;
57 name = rts2name(rts_id) ;
60 if(caller) caller->insert(
this, rts_id) ;
65 LOG(DBG,
"%s: constructor: caller %p",name,caller) ;
70 LOG(DBG,
"%s: destructor",name) ;
90 LOG(DBG,
"%s: Make()",name) ;
93 present |= DET_PRESENT_SFS;
94 LOG(NOTE,
"%s: %d: has SFS(%s)",name,evt_num,sfs_name) ;
96 else if(legacyDetp(rts_id, caller->mem)) {
97 present |= DET_PRESENT_DATAP ;
98 LOG(NOTE,
"%s: %d: has DATAP",name,evt_num) ;
100 else if(getEmcTrgData(caller->mem,1,&dummy)) {
101 present |= DET_PRESENT_TRG ;
102 LOG(NOTE,
"%s: %d: has DATAP within Trigger",name,present) ;
105 LOG(DBG,
"%s: not present",name) ;
114 daq_dta *daq_btow::get(
const char *bank,
int c1,
int c2,
int c3,
void *p1,
void *p2)
117 if(!present)
return 0 ;
120 if(strcasecmp(bank,
"raw") == 0) {
121 return handle_raw() ;
123 else if(strcasecmp(bank,
"adc") == 0) {
124 return handle_adc() ;
127 LOG(ERR,
"%s: unknown bank \"%s\"",name,bank) ;
134 daq_dta *daq_btow::handle_raw()
139 const char *full_name =
"?" ;
147 if(present & DET_PRESENT_DATAP) {
148 char *mem = (
char *) legacyDetp(rts_id, caller->mem) ;
149 from = emc_single_reader(mem, &bytes, rts_id) ;
150 if(from == 0)
return 0 ;
153 else if(present & DET_PRESENT_TRG) {
154 from = getEmcTrgData(caller->mem,1,&bytes) ;
155 if(from == 0)
return 0 ;
159 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name,1,1) ;
160 full_name = caller->get_sfs_name(str) ;
161 if(!full_name)
return 0 ;
163 bytes = caller->sfs->fileSize(full_name) ;
167 raw->create(bytes,
"btow_raw",rts_id,DAQ_DTA_STRUCT(
char)) ;
168 st = (
char *) raw->request(bytes) ;
170 if(present & DET_PRESENT_SFS) {
171 int ret = caller->sfs->read(full_name, st, bytes) ;
173 LOG(ERR,
"ret is %d") ;
178 memcpy(st, from, bytes) ;
181 raw->finalize(bytes,1,1,0) ;
184 LOG(DBG,
"Returning raw bank...") ;
189 daq_dta *daq_btow::handle_adc()
193 LOG(DBG,
"Entering adc") ;
197 LOG(DBG,
"raw bank %p",dd) ;
199 if(dd && dd->iterate()) {
200 raw_dta = (u_short *) dd->Byte ;
207 LOG(DBG,
"Got raw bank, on to adc...") ;
209 adc->create(1,
"adc", rts_id, DAQ_DTA_STRUCT(
btow_t)) ;
219 u_short *
data = (u_short *)((
char *)raw_dta + 4 + 128) ;
224 u_short *ppp = (u_short *) raw_dta ;
225 for(
int i=0;i<10;i++) {
226 LOG(TERR,
"%d: 0x%04X",i,ppp[i]) ;
230 for(
int j=0;j<BTOW_PRESIZE;j++) {
231 for(
int i=0;i<BTOW_MAXFEE;i++) {
232 btow_p->preamble[i][j] = l2h16(*data++) ;
236 for(
int j=0;j<BTOW_DATSIZE;j++) {
237 for(
int i=0;i<BTOW_MAXFEE;i++) {
238 btow_p->adc[i][j] = l2h16(*data++) ;
243 adc->finalize(1,1,1,0) ;
250 int daq_btow::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo)
252 const int BTOW_DDL_BYTES = 9972 ;
253 int buff_bytes = words * 4 ;
257 u_short *us = (u_short *)addr ;
259 u_short t_hi = l2h16(us[2]) ;
260 u_short t_lo = l2h16(us[3]) ;
264 if(buff_bytes != BTOW_DDL_BYTES) {
266 LOG(ERR,
"Received %d bytes, expect %d!?",buff_bytes,BTOW_DDL_BYTES) ;
269 if((t_lo & 0xFF00) || (t_hi & 0xFFF0)) {
271 LOG(ERR,
"Corrupt token: t_hi 0x%04X, t_lo 0x%04X",t_hi,t_lo) ;
286 trg[tcou].t = t_hi*256 + t_lo ;
287 trg[tcou].daq = us[1] ;
288 trg[tcou].trg = us[0] ;
289 trg[tcou].rhic = l2h16(us[4]) ;
296 LOG(ERR,
"token 0!") ;
300 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]) ;