8 #include "daqFormats.h"
9 #include "rtsSystems.h"
12 #include "evpSupport.h"
13 #include "ssdReader.h"
14 using namespace OLDEVP;
19 static int unpackRaw(
int rb,
int mz,
int what,
char *mem) ;
23 memset(
this,0,
sizeof(
ssd_t));
27 max_channels = 20*16*2*768 ;
55 int OLDEVP::ssdReader(
char *m)
83 if(m == NULL)
return EVP_DATA_ERR ;
85 datap = (
struct DATAP *)m ;
88 len = l2h32(datap->det[EXT_ID].len) ;
89 if(len == 0)
return EVP_NO_DET ;
90 assert(len>0&&len<99999);
92 off = l2h32(datap->det[EXT_ID].off) ;
93 if(off == 0)
return EVP_NO_DET ;
95 datapx = (
struct DATAPX *)((u_int *)m + off) ;
98 if(checkBank(datapx->bh.bank_type, CHAR_DATAPX) < 0) assert(0);
101 len = l2h32(datapx->det[SSD_ID-10].len) * 4 ;
102 if(len == 0)
return EVP_NO_DET ;
105 if(datapx->bh.byte_order==0x01020304) off = b2h32(datapx->det[SSD_ID-10].off) ;
106 else if(datapx->bh.byte_order==0x04030201) off = l2h32(datapx->det[SSD_ID-10].off) ;
108 if(off == 0)
return EVP_NO_DET ;
111 ssdp = (
struct TPCP *)((u_int *)datapx + off) ;
112 if(checkBank((
char *)ssdp,
"SSDP") < 0) assert(0);
123 memset(ssd.raw,0,
sizeof(ssd.raw)) ;
126 memset((
char *)ssd.counts,0,
sizeof(ssd.counts)) ;
132 for(sec=0;sec<1;sec++) {
136 if(ssdp->sb[sec].len == 0) continue ;
138 {
int herb=b2h32(ssdp->sb[sec].off); assert(herb>0&&herb<99999); }
139 secp = (
struct TPCSECP *) ((u_int *)ssdp + b2h32(ssdp->sb[sec].off)) ;
141 if(checkBank((
char *)secp,
"SSDSECP") < 0) assert(0);
145 for(rb=0;rb<last;rb++) {
148 if(secp->rb[rb].len == 0) continue ;
150 herb=b2h32(secp->rb[rb].off); assert(herb>0&&herb<999999);
151 rbp = (
struct TPCRBP *) ((u_int *)secp + herb ) ;
152 if(checkBank((
char *)rbp,
"SSDRBP") < 0) assert(0);
156 for(mz=0;mz<2;mz++) {
157 if(rbp->mz[mz].len == 0) continue ;
159 {
int herb=l2h32(rbp->mz[mz].off); assert(herb>0&&herb<99999); }
160 mzp = (
struct TPCMZP *)((u_int *)rbp + l2h32(rbp->mz[mz].off)) ;
161 if(checkBank((
char *)mzp,
"SSDMZP") < 0) assert(0);
164 if((mzp->banks[TPC_ADCD].len != 0) && (ssd.mode==0)) {
167 {
int herb=l2h32(mzp->banks[TPC_SEQD].off); assert(herb>0&&herb<99999); }
168 seqd = (
struct TPCSEQD *)((u_int *)mzp + l2h32(mzp->banks[TPC_SEQD].off)) ;
169 {
int herb=l2h32(mzp->banks[TPC_ADCD].off); assert(herb>0&&herb<99999); }
170 adcd = (
struct TPCADCD *)((u_int *)mzp + l2h32(mzp->banks[TPC_ADCD].off)) ;
172 if(checkBank((
char *)seqd,
"SSDSEQD") < 0) assert(0);
173 if(checkBank((
char *)adcd,
"SSDADCD") < 0) assert(0);
175 int len = l2h32(seqd->bh.length) - 10 ;
186 for(jj=0;jj<len;jj++) {
187 int start, last, length, stop ;
191 ss = l2h16(seqd->seq[jj]) ;
196 pp = (ss & 0x7FFF) % 256 ;
197 rr = (ss & 0x7FFF) / 256 ;
199 if(pp == 0xff) break ;
204 start = (ss & 0x7FC0) >> 6 ;
205 stop = start + length ;
207 for(tbin=start;tbin<stop;tbin++) {
211 val = adcd->adc[adccou++] ;
213 if(val==0) continue ;
215 counter = ssd.counts[rr-1][pp-1] ;
217 ssd.adc[rr-1][pp-1][counter] = val ;
218 ssd.strip[rr-1][pp-1][counter] = tbin ;
219 ssd.counts[rr-1][pp-1] += 1 ;
234 if(mzp->banks[TPC_PADK].len != 0) {
236 int herb= l2h32(mzp->banks[TPC_PADK].off);
238 assert(herb>0&&herb<99999);
240 padk = (
struct TPCPADK *)((u_int *)mzp + l2h32(mzp->banks[TPC_PADK].off)) ;
242 if(checkBank((
char *)padk,
"SSDPADK") < 0) assert(0);
247 if(mzp->banks[TPC_CPPR].len != 0) {
249 cppr = (
struct TPCCPPR_l *)((u_int *)mzp + l2h32(mzp->banks[TPC_CPPR].off)) ;
250 if(checkBank((
char *)cppr,
"SSDCPPR") < 0) assert(0);
253 if((mzp->banks[TPC_ADCR].len != 0) && (ssd.mode==0)) {
254 adcr = (
struct TPCADCR_l *)((u_int *)mzp + l2h32(mzp->banks[TPC_ADCR].off)) ;
256 if(checkBank((
char *)adcr,
"SSDADCR") < 0) assert(0);
258 if(unpackRaw(rb, mz, 0, (
char *)adcr) < 0) {
268 if(mzp->banks[TPC_PEDR].len != 0) {
269 pedr = (
struct TPCPEDR *)((u_int *)mzp + l2h32(mzp->banks[TPC_PEDR].off)) ;
271 if(checkBank((
char *)pedr,
"SSDPEDR") < 0) assert(0);
273 unpackRaw(rb, mz, 1,(
char *)pedr) ;
278 if(mzp->banks[TPC_RMSR].len != 0) {
279 rmsr = (
struct TPCRMSR *)((u_int *)mzp + l2h32(mzp->banks[TPC_RMSR].off)) ;
281 if(checkBank((
char *)rmsr,
"SSDRMSR") < 0) assert(0);
282 unpackRaw(rb, mz, 2, (
char *)rmsr) ;
304 static int unpackRaw(
int rb,
int mz,
int what,
char *mem)
308 int as, ch, strip, cou ;
325 adcdata = (u_char *) mem +
sizeof(
struct TPCADCR_l);
326 ssd.raw[rb][mz] = adcdata ;
330 adcdata = ((
struct TPCPEDR *)mem)->ped ;
331 ssd.raw[rb][mz] = adcdata ;
332 for(as=0;as<5;as++) {
333 row = rb*10+mz*5+as ;
334 for(ch=0;ch<64;ch++) {
335 dta = adcdata + (as*64*512) + (ch*512) ;
336 memcpy(ssd.adc[row][ch],dta,192) ;
339 ssd.channels += 5*64*192 ;
342 adcdata = ((
struct TPCRMSR *)mem)->rms ;
343 for(as=0;as<5;as++) {
344 row = rb*10+mz*5+as ;
345 for(ch=0;ch<64;ch++) {
346 dta = adcdata + (as*64*512) + (ch*512) ;
347 memcpy(ssd.strip[row][ch],dta,192) ;
351 default :printf(
"WARN,unknown case, do nothing \n");