6 #include <rtsSystems.h>
7 #include <daqFormats.h>
9 #include <SFS/sfs_index.h>
11 #include <DAQ_READER/daqReader.h>
12 #include <DAQ_READER/daq_dta.h>
15 #include "daq_rhicf.h"
17 extern int rhicf_reader(
char *mem,
struct rhicf_t *rhicf, u_int driver) ;
22 const char *daq_rhicf::help_string =
"\
26 raw returns=ptr of start of DDL data; c1=sector[1..1]; c2=rdo[1..4]; \n\
35 daq_det_factory::det_factories[RHICF_ID] = this ;
47 daq_rhicf::daq_rhicf(
daqReader *rts_caller)
50 name = rts2name(rts_id) ;
53 if(caller) caller->insert(
this, rts_id) ;
59 LOG(DBG,
"%s: constructor: caller %p",name,rts_caller) ;
63 daq_rhicf::~daq_rhicf()
65 LOG(DBG,
"%s: DEstructor",name) ;
75 daq_dta *daq_rhicf::get(
const char *bank,
int sec,
int row,
int pad,
void *p1,
void *p2)
79 if(present==0)
return 0 ;
81 LOG(DBG,
"%s: looking for bank %s",name,bank) ;
83 if(strcmp(bank,
"*")==0) bank =
"raw" ;
87 if(strcasecmp(bank,
"raw")==0) {
88 if((present & DET_PRESENT_SFS)==0)
return 0 ;
89 return handle_raw(sec,row) ;
92 LOG(ERR,
"%s: unknown bank type \"%s\"",name,bank) ;
98 daq_dta *daq_rhicf::handle_raw(
int sec,
int rdo)
106 sprintf(str,
"%s/sec01/rb01/raw",sfs_name) ;
107 char *full_name = caller->get_sfs_name(str) ;
109 LOG(DBG,
"%s: trying sfs on \"%s\"",name,str) ;
110 if(full_name == 0)
return 0 ;
112 int size = caller->sfs->fileSize(full_name) ;
114 LOG(DBG,
"Got size %d",size) ;
116 LOG(DBG,
"%s: %s: not found in this event",name,str) ;
120 char *ptr = (
char *) malloc(size) ;
121 LOG(DBG,
"Malloc at %p",ptr) ;
123 caller->sfs->read(full_name, ptr, size) ;
125 LOG(DBG,
"sfs read succeeded") ;
130 int ret = get_l2(ptr,size*4,&trg,1) ;
131 LOG(NOTE,
"get_l2 returns %d: %d %d %d",ret,trg.trg,trg.daq,trg.t) ;
135 raw->create(size,
"rhicf_raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
137 char *st = (
char *) raw->request(size) ;
139 memcpy(st,ptr+40,size) ;
143 raw->finalize(size,1,1,0) ;
152 int daq_rhicf::get_token(
char *addr,
int words)
154 LOG(ERR,
"get_token") ;
159 cou = get_l2(addr,words,trg,1) ;
161 if(cou==0)
return -1000 ;
162 if(trg[0].t==0)
return -ENOSYS ;
182 int daq_rhicf::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo)
185 int in_words = words ;
194 LOG(NOTE,
"Token %d, CRC word 0x%08X, format number 0x%08X",bh->token,bh->crc,bh->format_number) ;
196 trg[0].t = bh->crc & 0xFFF ;
197 trg[0].trg = (bh->crc>>16)&0xF ;
198 trg[0].daq = (bh->crc>>12)&0xF ;
203 LOG(ERR,
"[%d] Bad Event: T %4d: words %d",
204 rdo,trg[0].t,in_words) ;