4 #include <daqFormats.h>
5 #include <rtsSystems.h>
12 static int unpackRaw(
int rb,
int mz,
int what,
char *mem,
ssd_t *ssd) ;
27 int ssd_reader(
char *m,
struct ssd_t *ssd, u_int driver)
55 ssd->max_channels = 20*16*2*768 ;
58 if(m == NULL)
return 0 ;
60 datap = (
struct DATAP *)m ;
63 if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatap = 1;
65 len = qswap32(swapdatap, datap->det[EXT_ID].len) ;
66 if(len == 0)
return 0 ;
67 off = qswap32(swapdatap, datap->det[EXT_ID].off) ;
68 if(off == 0)
return 0 ;
70 datapx = (
struct DATAPX *)((u_int *)m + off) ;
73 if(datapx->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatapx = 1;
76 if(checkBank(datapx->bh.bank_type, CHAR_DATAPX) < 0) {
81 len = qswap32(swapdatapx, datapx->det[SSD_ID-10].len) * 4 ;
82 if(len == 0)
return 0 ;
85 off = qswap32(swapdatapx, datapx->det[SSD_ID-10].off) ;
86 if(off == 0)
return 0 ;
88 ssdp = (
struct TPCP *)((u_int *)datapx + off) ;
89 if(checkBank((
char *)ssdp,
"SSDP") < 0)
return 0 ;
101 memset(ssd->raw,0,
sizeof(ssd->raw)) ;
104 memset((
char *)ssd->counts,0,
sizeof(ssd->counts)) ;
110 memset(occup,0,
sizeof(occup)) ;
112 for(sec=0;sec<1;sec++) {
116 if(ssdp->sb[sec].len == 0) continue ;
118 secp = (
struct TPCSECP *) ((u_int *)ssdp + b2h32(ssdp->sb[sec].off)) ;
119 if(checkBank((
char *)secp,
"SSDSECP") < 0)
return 0 ;
123 for(rb=0;rb<last;rb++) {
126 if(secp->rb[rb].len == 0) continue ;
128 rbp = (
struct TPCRBP *) ((u_int *)secp + b2h32(secp->rb[rb].off)) ;
129 if(checkBank((
char *)rbp,
"SSDRBP") < 0) {
135 for(mz=0;mz<2;mz++) {
136 if(rbp->mz[mz].len == 0) continue ;
138 mzp = (
struct TPCMZP *)((u_int *)rbp + l2h32(rbp->mz[mz].off)) ;
139 if(checkBank((
char *)mzp,
"SSDMZP") < 0) {
144 if((mzp->banks[TPC_ADCD].len != 0) && (ssd->mode==0)) {
147 seqd = (
struct TPCSEQD *)((u_int *)mzp + l2h32(mzp->banks[TPC_SEQD].off)) ;
148 adcd = (
struct TPCADCD *)((u_int *)mzp + l2h32(mzp->banks[TPC_ADCD].off)) ;
150 if(checkBank((
char *)seqd,
"SSDSEQD") < 0)
continue ;
151 if(checkBank((
char *)adcd,
"SSDADCD") < 0)
continue ;
153 int len = l2h32(seqd->bh.length) - 10 ;
163 for(jj=0;jj<len;jj++) {
164 int start, last, length, stop ;
168 ss = l2h16(seqd->seq[jj]) ;
173 pp = (ss & 0x7FFF) % 256 ;
174 rr = (ss & 0x7FFF) / 256 ;
177 if(pp == 0xff) break ;
182 start = (ss & 0x7FC0) >> 6 ;
183 stop = start + length ;
187 for(tbin=start;tbin<stop;tbin++) {
191 val = adcd->adc[adccou++] ;
197 if(val==0) continue ;
199 counter = ssd->counts[rr-1][pp-1] ;
201 ssd->adc[rr-1][pp-1][counter] = val ;
202 ssd->strip[rr-1][pp-1][counter] = tbin ;
203 ssd->counts[rr-1][pp-1] += 1 ;
214 LOG(NOTE,
"SSD: RB %d, MZ %d: counts %d",rb,mz,occup[rb][mz]) ;
222 if(mzp->banks[TPC_PADK].len != 0) {
223 padk = (
struct TPCPADK *)((u_int *)mzp + l2h32(mzp->banks[TPC_PADK].off)) ;
225 if(checkBank((
char *)padk,
"SSDPADK") < 0)
return 0 ;
230 if(mzp->banks[TPC_CPPR].len != 0) {
232 cppr = (
struct TPCCPPR_l *)((u_int *)mzp + l2h32(mzp->banks[TPC_CPPR].off)) ;
233 if(checkBank((
char *)cppr,
"SSDCPPR") < 0)
return 0 ;
236 if((mzp->banks[TPC_ADCR].len != 0) && (ssd->mode==0)) {
237 adcr = (
struct TPCADCR_l *)((u_int *)mzp + l2h32(mzp->banks[TPC_ADCR].off)) ;
239 if(checkBank((
char *)adcr,
"SSDADCR") < 0)
return 0 ;
241 if(unpackRaw(rb, mz, 0, (
char *)adcr, ssd) < 0) {
242 LOG(ERR,
"Problems in RAW data in sector %d, RB %d, MZ %d - skipping...",
243 sec+1,rb+1,mz+1,0,0) ;
246 LOG(DBG,
"SSD Raw data bank in sector %d, RB %d, MZ %d!",
247 sec+1,rb+1,mz+1,0,0) ;
251 if(mzp->banks[TPC_PEDR].len != 0) {
252 pedr = (
struct TPCPEDR *)((u_int *)mzp + l2h32(mzp->banks[TPC_PEDR].off)) ;
254 if(checkBank((
char *)pedr,
"SSDPEDR") < 0)
return 0 ;
256 unpackRaw(rb, mz, 1,(
char *)pedr,ssd) ;
261 if(mzp->banks[TPC_RMSR].len != 0) {
262 rmsr = (
struct TPCRMSR *)((u_int *)mzp + l2h32(mzp->banks[TPC_RMSR].off)) ;
264 if(checkBank((
char *)rmsr,
"SSDRMSR") < 0)
return 0 ;
266 unpackRaw(rb, mz, 2, (
char *)rmsr, ssd) ;
290 static int unpackRaw(
int rb,
int mz,
int what,
char *mem,
ssd_t *ssd)
294 int as, ch, strip, cou ;
299 LOG(WARN,
"No DATA? - skipping...",0,0,0,0,0) ;
304 LOG(WARN,
"MZ3 should not exist in SSD's RB %d - skipping...",rb+1,0,0,0,0) ;
311 adcdata = (u_char *) mem +
sizeof(
struct TPCADCR_l);
312 ssd->raw[rb][mz] = adcdata ;
313 LOG(NOTE,
"SSD rb %d, mz %d: raw...",rb,mz) ;
316 adcdata = ((
struct TPCPEDR *)mem)->ped ;
317 ssd->raw[rb][mz] = adcdata ;
318 for(as=0;as<5;as++) {
319 row = rb*10+mz*5+as ;
323 for(ch=0;ch<64;ch++) {
324 dta = adcdata + (as*64*512) + (ch*512) ;
325 memcpy(ssd->adc[row][ch],dta,192) ;
329 ssd->channels += 5*64*192 ;
332 adcdata = ((
struct TPCRMSR *)mem)->rms ;
333 for(as=0;as<5;as++) {
334 row = rb*10+mz*5+as ;
335 for(ch=0;ch<64;ch++) {
336 dta = adcdata + (as*64*512) + (ch*512) ;
337 memcpy(ssd->strip[row][ch],dta,192) ;
348 for(as=0;as<5;as++) {
349 row = rb*10+mz*5+as ;
351 for(ch=0;ch<64;ch++) {
353 dta = adcdata + (as*64*512) + ch*512 ;
356 for(strip=0;strip<192;strip++) {
361 ssd->strip[row][ch][cou] = strip ;
362 ssd->adc[row][ch][cou] = *dta ;
369 ssd->counts[row][ch] += cou ;