6 #include <rtsSystems.h>
10 #include <SFS/sfs_index.h>
11 #include <DAQ_READER/daqReader.h>
12 #include <DAQ_READER/daq_dta.h>
17 int esmd_crate_map[] = {
18 0x40, 0x41, 0x42, 0x43,
19 0x44, 0x45, 0x46, 0x47,
20 0x48, 0x49, 0x4a, 0x4b,
21 0x4c, 0x4d, 0x4e, 0x4f,
22 0x50, 0x51, 0x52, 0x53,
23 0x54, 0x55, 0x56, 0x57,
24 0x58, 0x59, 0x5a, 0x5b,
25 0x5c, 0x5d, 0x5e, 0x5f,
26 0x60, 0x61, 0x62, 0x63,
27 0x64, 0x65, 0x66, 0x67,
28 0x68, 0x69, 0x6a, 0x6b,
29 0x6c, 0x6d, 0x6e, 0x6f
32 const char *daq_esmd::help_string =
"ESMD\n\
33 adc returns esmd_t;\n\
34 raw returns raw data\n" ;
40 daq_det_factory::det_factories[ESMD_ID] = this ;
54 name = rts2name(rts_id) ;
58 if(caller) caller->insert(
this, rts_id) ;
63 LOG(DBG,
"%s: constructor: caller %p",name,rts_caller) ;
69 LOG(DBG,
"%s: DEstructor",name) ;
79 daq_dta *daq_esmd::get(
const char *bank,
int sec,
int row,
int pad,
void *p1,
void *p2)
82 if(present == 0)
return 0 ;
85 if(strcasecmp(bank,
"raw")==0) {
88 else if(strcasecmp(bank,
"adc")==0) {
93 LOG(ERR,
"%s: unknown bank type \"%s\"",name,bank) ;
109 LOG(ERR,
"%s: not present?",name) ;
113 LOG(DBG,
"%s: present %d",name,present) ;
116 if(present & DET_PRESENT_DATAP) {
117 char *mem = (
char *)legacyDetp(rts_id, caller->mem) ;
118 from = emc_single_reader(mem, &bytes, rts_id) ;
119 if(from == 0)
return 0 ;
122 raw->create(bytes,
"esmd_raw",rts_id,DAQ_DTA_STRUCT(
char)) ;
123 st = (
char *) raw->request(bytes) ;
127 memcpy(st, from, bytes) ;
134 sprintf(str,
"%s/sec%02d/rb%02d/raw",sfs_name, 1, 1) ;
135 full_name = caller->get_sfs_name(str) ;
137 if(!full_name)
return 0 ;
139 bytes = caller->sfs->fileSize(full_name) ;
141 raw->create(bytes,
"esmd_raw",rts_id,DAQ_DTA_STRUCT(
char)) ;
142 st = (
char *) raw->request(bytes) ;
144 int ret = caller->sfs->read(str, st, bytes) ;
146 LOG(ERR,
"ret is %d") ;
151 raw->finalize(bytes,1,1,0) ;
160 daq_dta *daq_esmd::handle_adc()
166 LOG(DBG,
"%s: got raw %p",name,dd) ;
168 if(dd && dd->iterate()) {
169 raw_dta = (u_short *) dd->Byte ;
175 adc->create(1,
"esmd_adc", rts_id, DAQ_DTA_STRUCT(
esmd_t)) ;
181 u_short *
data = (u_short *)((
char *)raw_dta + 128) ;
183 if(present & DET_PRESENT_DATAP) {
188 memset(esmd_p,0,
sizeof(
esmd_t)) ;
193 if(raw->ncontent < (48*192)) {
203 for(
int j=0;j<ESMD_PRESIZE;j++) {
204 for(
int i=0;i<max_fee;i++) {
205 esmd_p->preamble[i][j] = l2h16(*data++) ;
209 for(
int j=0;j<ESMD_DATSIZE;j++) {
210 for(
int i=0;i<max_fee;i++) {
211 esmd_p->adc[i][j] = l2h16(*data++) ;
217 adc->finalize(1,1,1,0) ;
225 int daq_esmd::get_l2(
char *buff,
int buff_words,
struct daq_trg_word *trg,
int rdo1)
227 const int ESMD_DDL_BYTES = 18948 ;
228 int buff_bytes = buff_words * 4 ;
230 u_short *us = (u_short *)buff ;
232 u_short t_hi = l2h16(us[2]) ;
233 u_short t_lo = l2h16(us[3]) ;
237 if(buff_bytes != ESMD_DDL_BYTES) {
239 LOG(ERR,
"Received %d bytes, expect %d!?",buff_bytes,ESMD_DDL_BYTES) ;
242 if((t_lo & 0xFF00) || (t_hi & 0xFFF0)) {
244 LOG(ERR,
"Corrupt token: t_hi 0x%04X, t_lo 0x%04X",t_hi,t_lo) ;
259 trg[0].t = t_hi*256 + t_lo ;
262 trg[0].rhic = l2h16(us[4]) ;
272 LOG(ERR,
"token 0!") ;
276 LOG(WARN,
"RDO %d error: 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X",rdo1, us[0],us[1],us[2],us[3],us[4]) ;