5 #include <daqFormats.h>
6 #include <rtsSystems.h>
12 static int unpackRaw(
int sec,
int what,
struct TPCPADK *padk,
struct TPCCPPR_l *cppr,
char *mem,
ftp_t *ftp) ;
14 int ftp_reader(
char *m,
struct ftp_t *ftp, u_int driver)
42 ftp->max_channels = 2*10*960*256 ;
44 if(m == NULL)
return 0 ;
45 datap = (
struct DATAP *)m ;
47 len = ntohl(datap->det[FTP_ID].len) ;
48 if(len == 0)
return 0 ;
51 off = ntohl(datap->det[FTP_ID].off) ;
52 if(off == 0)
return 0 ;
54 ftpp = (
struct TPCP *)((u_int *)m + off) ;
55 if(checkBank((
char *)ftpp,
"FTPP") < 0)
return -1 ;
58 memset((
char *)ftp->counts,0,
sizeof(ftp->counts)) ;
61 for(sec=0;sec<2;sec++) {
65 if(ftpp->sb[sec].len == 0) continue ;
67 secp = (
struct TPCSECP *) ((
char *)ftpp + b2h32(ftpp->sb[sec].off)*4) ;
68 if(checkBank((
char *)secp,
"FTPSECP") < 0)
return -1 ;
72 for(rb=0;rb<last;rb++) {
75 if(secp->rb[rb].len == 0) continue ;
77 rbp = (
struct TPCRBP *) ((
char *)secp + b2h32(secp->rb[rb].off)*4) ;
78 if(checkBank((
char *)rbp,
"FTPRBP") < 0) {
86 if(rbp->mz[mz].len == 0) continue ;
88 mzp = (
struct TPCMZP *)((
char *)rbp + l2h32(rbp->mz[mz].off)*4) ;
89 if(checkBank((
char *)mzp,
"FTPMZP") < 0) {
97 if((mzp->banks[TPC_ADCD].len != 0) && (ftp->mode==0)) {
100 seqd = (
struct TPCSEQD *)((
char *)mzp + l2h32(mzp->banks[TPC_SEQD].off)*4) ;
101 adcd = (
struct TPCADCD *)((
char *)mzp + l2h32(mzp->banks[TPC_ADCD].off)*4) ;
103 if(checkBank((
char *)seqd,
"FTPSEQD") < 0)
return -1 ;
104 if(checkBank((
char *)adcd,
"FTPADCD") < 0)
return -1 ;
106 int len = l2h32(seqd->bh.length) - 10 ;
114 for(jj=0;jj<len;jj++) {
115 int start, last, length, stop ;
121 ss = l2h16(seqd->seq[jj]) ;
122 f8 = (ss & 0x8000) ? 1 : 0 ;
126 fpad = ((rr-1)%6)*160 + (pp-1) ;
131 pp = (ss & 0x7FFF) % 256 ;
132 rr = (ss & 0x7FFF) / 256 ;
139 LOG(DBG,
"Dummy row %d...",jj,0,0,0,0) ;
147 last = (ss & 0x0020) ? 1 : 0 ;
148 start = (ss & 0x7FC0) >> 6 ;
152 stop = start + length ;
156 for(tbin=start;tbin<stop;tbin++) {
159 val = adcd->adc[adccou++] ;
161 if(tbin > 255) continue ;
164 counter = ftp->counts[sec][frow][fpad] ;
166 ftp->adc[sec][frow][fpad][counter] = val ;
167 ftp->timebin[sec][frow][fpad][counter] = tbin ;
168 if(ftp->counts[sec][frow][fpad] != 255) {
169 (ftp->counts[sec][frow][fpad])++ ;
180 LOG(DBG,
"FTP: Setor %d, RB %d, MZ %d: ticks %u, pix %u",sec+1,rb+1,mz+1,l2h32(mzp->bh.w9),mz_pix) ;
188 if(mzp->banks[TPC_PADK].len != 0) {
189 padk = (
struct TPCPADK *)((
char *)mzp + l2h32(mzp->banks[TPC_PADK].off)*4) ;
191 if(checkBank((
char *)padk,
"FTPPADK") < 0)
return -1 ;
196 if(mzp->banks[TPC_CPPR].len != 0) {
198 cppr = (
struct TPCCPPR_l *)((
char *)mzp + l2h32(mzp->banks[TPC_CPPR].off)*4) ;
199 if(checkBank((
char *)cppr,
"FTPCPPR") < 0)
return -1 ;
202 if((mzp->banks[TPC_ADCR].len != 0) && (ftp->mode==0)) {
203 adcr = (
struct TPCADCR_l *)((
char *)mzp + l2h32(mzp->banks[TPC_ADCR].off)*4) ;
205 if(checkBank((
char *)adcr,
"FTPADCR") < 0)
return -1 ;
207 if(unpackRaw(sec, 0, padk, cppr, (
char *)adcr, ftp) < 0) {
208 LOG(ERR,
"Problems in RAW data in sector %d, RB %d, MZ %d - skipping...",
209 sec+1,rb+1,mz+1,0,0) ;
212 LOG(DBG,
"FTP Raw data bank in sector %d, RB %d, MZ %d!",
213 sec+1,rb+1,mz+1,0,0) ;
217 if(mzp->banks[TPC_PEDR].len != 0) {
218 pedr = (
struct TPCPEDR *)((
char *)mzp + l2h32(mzp->banks[TPC_PEDR].off)*4) ;
220 if(checkBank((
char *)pedr,
"FTPPEDR") < 0)
return -1 ;
222 unpackRaw(sec, 1, padk, cppr, (
char *)pedr, ftp) ;
227 if(mzp->banks[TPC_RMSR].len != 0) {
228 rmsr = (
struct TPCRMSR *)((
char *)mzp + l2h32(mzp->banks[TPC_RMSR].off)*4) ;
230 if(checkBank((
char *)rmsr,
"FTPRMSR") < 0)
return -1 ;
232 unpackRaw(sec, 2, padk, cppr, (
char *)rmsr, ftp) ;
255 static int unpackRaw(
int sec,
int what,
struct TPCPADK *padk,
struct TPCCPPR_l *cppr,
char *mem,
ftp_t *ftp)
272 LOG(WARN,
"No PADK? - skipping...",0,0,0,0,0) ;
276 LOG(WARN,
"No DATA? - skipping...",0,0,0,0,0) ;
285 adcdata = (u_char *) mem +
sizeof(
struct TPCADCR_l);
288 LOG(WARN,
"No CPPR? - skipping...",0,0,0,0,0) ;
292 cppdata = (u_short *)((
char *)cppr +
sizeof(
struct TPCCPPR_l)) ;
295 adcdata = ((
struct TPCPEDR *)mem)->ped ;
298 adcdata = ((
struct TPCRMSR *)mem)->rms ;
304 row = padk->rp[i].row ;
305 pad = padk->rp[i].pad ;
307 if((row==0xFF) || (pad==0xFF)) continue ;
316 fpad = (row%6)*160 + pad ;
318 adcseq = (u_char *) adcdata + timebins*i ;
322 cppseq = (u_short *)((
char *) cppdata + 2*2*32*i) ;
323 for(j=0;j<cpps;j++) {
324 u_short start, stop ;
330 start = l2h16(*cppseq++) ;
331 stop = l2h16(*cppseq++) ;
334 if(start & 0xFE00) break ;
335 if(start >= 256) break ;
338 if(start == 511) stop = 511 ;
340 if((stop < start) || (stop >= timebins)) {
341 LOG(WARN,
"Bad data stop<start %d<%d - skipping",stop,start,0,0,0) ;
346 if(stop >= 256) stop = 255 ;
348 for(t=start;t<=stop;t++) {
350 val = *(adcseq + t) ;
356 counter = ftp->counts[sec][frow][fpad] ;
359 ftp->adc[sec][frow][fpad][counter] = val ;
360 ftp->timebin[sec][frow][fpad][counter] = t ;
361 if(ftp->counts[sec][frow][fpad] != 255) {
362 ftp->counts[sec][frow][fpad]++ ;
374 ftp->adc[sec][frow][fpad][j] = val ;
384 ftp->timebin[sec][frow][fpad][j] = val ;