main(int argc, char **argv) { int nr,sec,layer,strip,wire,nl,ncol,nrow,i,j,l,l1,l2,ichan,nn,iev,ii; int ind,ind1,ind2,status,status1,handle,handle1,k,m,rocid; int scal,nw,scaler,scaler_old; unsigned int hel,str,strob,helicity,strob_old,helicity_old, tgbi1; int tmp1 = 1, tmp2 = 2, iret, bit1, bit2, leading[2000], trailing[2000], nleading, ntrailing; float *bcsfl, rndm_(); char strr[1000], bankname[5], histname[128]; static int syn[32], id; MTDCHead *mtdchead; MTDC *mtdc; char *HBOOKfile = "schist.his"; int nwpawc,lun,lrec,istat,icycle,idn,nbins,nbins1,igood,offset; float x1,x2,y1,y2,ww,tmpx,tmpy,ttt,ref; unsigned short *tlv1, *tlv2, *buf16; printf(" dchist reached !\n"); if(argc != 2) { printf("Usage: dchist <fpack_filename>\n"); exit(1); } bcsfl = (float*)bcs_.iw; bosInit(bcs_.iw,NBCS); nwpawc = NWPAWC; hlimit_(&nwpawc); lun = 11; lrec = LREC; hropen_(&lun,"NTUPEL",HBOOKfile,"N",&lrec,&istat, strlen("NTUPEL"),strlen(HBOOKfile),1); if(istat) { printf("\aError: cannot open RZ file %s for writing.\n", HBOOKfile); exit(0); } else { printf("RZ file >%s< opened for writing, istat = %d\n\n", HBOOKfile, istat); } nbins=200; x1 = 0.; x2 = 2000.; ww = 0.; for(k=1; k<=6; k++) { for(j=1; j<=2; j++) { for(i=1; i<=57; i++) { if(j==1) sprintf(histname,"ADC: sec %1d slab %2d left",k,i); else sprintf(histname,"ADC: sec %1d slab %2d right",k,i); idn = k*1000+j*100+i; hbook1_(&idn,histname,&nbins,&x1,&x2,&ww,strlen(histname)); } } } /* nbins=100; x1 = 0.; x2 = 10000.; nbins1=100; y1 = 0.; y2 = 10000.; ww = 0.; idn=3; sprintf(histname,"Reference: channel1 vs channel2",idn); hbook2_(&idn,histname,&nbins,&x1,&x2,&nbins1,&y1,&y2,&ww,strlen(histname)); idn=4; sprintf(histname,"Reference: channel1 vs channel2 (sync)",idn); hbook2_(&idn,histname,&nbins,&x1,&x2,&nbins1,&y1,&y2,&ww,strlen(histname)); */ sprintf(strr,"OPEN INPUT UNIT=1 FILE='%s' ",argv[1]); printf("fparm string: >%s<\n",strr); status = fparm_(strr,strlen(strr)); for(iev=0; iev<1000000; iev++) { frbos_(bcs_.iw,&tmp1,"E",&iret,1); if(!(iev%10000)) printf("===== Event no. %d\n",iev); for(k=1; k<=6; k++) { if((ind1=bosNlink(bcs_.iw,"SC ",k)) > 0) { unsigned int *fb, *fbend; unsigned short *fb16; int crate,slot,channel,edge,data,ncol1,nrow1,adc1,adc2; ncol1 = bcs_.iw[ind1-6]; nrow1 = bcs_.iw[ind1-5]; nw = nrow1; offset = 0; /* printf("ncol=%d nrow=%d nw=%d\n",ncol1,nrow1,nw); */ ww = 1.0; /*printf("\n");*/ fb16 = (unsigned short *)&bcs_.iw[ind1]; for(ii=0; ii<nrow1; ii++) { wire = (fb16[0])&0xFF; adc1 = fb16[2]; adc2 = fb16[4]; /*if(k==1) printf("sec=%d wire=%d adc1=%d adc2=%d (0x%08x)\n", k,wire,adc1,adc2,fb16);*/ if(wire>0&&wire<58) { tmpx = adc1; layer = 1; idn=k*1000+layer*100+wire; if(tmpx>0.) { /*if(k==1) printf("wire=%d idn=%d,tmpx=%f\n",wire,idn,tmpx);*/ hf1_(&idn,&tmpx,&ww); } tmpx = adc2; layer = 2; idn=k*1000+layer*100+wire; if(tmpx>0.) hf1_(&idn,&tmpx,&ww); } else { printf("ERROR: sec=%d layer=%d wire=%d (0x%08x)\n",k,layer,wire,*fb); } fb16 += 5; } } } /* */ if(iret == -1 || iret > 0) { printf(" End-of-File flag, iret =%d\n",iret); goto a111111; } else if(iret < 0) { printf(" Error1, iret =%d\n",iret); goto a111111; } if(iret != 0) { printf(" Error2, iret =%d\n",iret); } bdrop_(bcs_.iw,"E",1); bgarb_(bcs_.iw); } a111111: fparm_("CLOSE",5); /* closing HBOOK file */ idn = 0; hrout_(&idn,&icycle," ",1); /*hprint_(&idn);*/ hrend_("NTUPEL", 6); exit(0); /* end of v1190 test */ }
int bos2et(int *jw, char *list, int *ev, int et_size, int *size, int control[4]) { BOSptr b; int *w, *buf, *fmtbuf, nbanks; int i,j,ind,error,nami; int start,id,nch,ndim,nf,ird,ntot,nama,nw; char *fmt, *ch; b = (BOSptr)jw; w = jw-1; error = start = 0; ndim = et_size / sizeof(int); /* write record header to ET buffer */ if(ndim < RECHEADLEN) return(-1); /* not enough space for record header */ ev[irPTRN] = SWAP; /* Pattern to recognize byte swapping */ ev[irFORG] = LOCAL*16; /* (format code: 1-IEEE,2-IBM,3-VAX,4-DEC)*16 + origin code */ ev[irNRSG] = 0; /* #logrec*100 + #segment */ ev[irNAME1] = *((unsigned long *)"RUNE"); /* event name - part 1 (Hollerith) */ ev[irNAME2] = *((unsigned long *)"VENT"); /* event name - part 2 (Hollerith) */ ev[irNPHYS] = 0; /* # of several phys. records in one logical */ ev[irCODE] = 0; /* segment code: 0-complete, 1-first, 2-middle, 3-last */ ev[irNWRD] = 0; /* the number of words in this record segment */ if(ind = bosNlink(jw,"HEAD",0)) { ev[irNRUN] = w[ind+2]; /* run number */ ev[irNEVNT] = w[ind+3]; /* event number */ ev[irTRIG] = w[ind+5]; /* Trig pattern */ } start += RECHEADLEN; control[0] = ev[irNRUN]; control[1] = 0; control[2] = 0; control[3] = ev[irTRIG]; /* get a list of BOS bank indexes */ nbanks = bosLdump(jw,list,&buf,&fmtbuf); /* extract bank by bank from BOS array and fill ET buffer */ for(i=0; i<nbanks; i++) { ind = buf[i]; nami = fmtbuf[i]; ev[start+idNHEAD] = 9; ev[start+idNAME1] = w[ind-INAM]; /* the name of bank */ ev[start+idNAME1] = *((unsigned long *)" "); /* blank */ ev[start+idNSGM] = w[ind-INR]; /* the number of bank */ ev[start+idNCOL] = w[ind-ICOL]; /* the number of columns */ ev[start+idNROW] = w[ind-IROW]; /* the number of rows */ ev[start+idCODE] = 0; ev[start+idNPREV] = 0; ev[start+idDATA] = w[ind]; /* the number of data words */ /* printf(" ind %7d name >%4.4s< len %7d fmt >",ind,&w[ind-INAM],w[ind]); */ /* bank format (the same piece in bosWrite.c - make macros ? ) */ if((id = w[b->idfmt + nami - b->s->nsyst]) == 0) { ev[start+idNHEAD] += 1; ev[start+idFRMT] = *((unsigned long *)" "); } else { if(w[id+3] != 0) { ev[start+idNHEAD] += 1; if(w[id+3] == 1) ev[start+idFRMT] = *((unsigned long *)"B32 "); else if(w[id+3] == 2) ev[start+idFRMT] = *((unsigned long *)"B16 "); else if(w[id+3] == 3) ev[start+idFRMT] = *((unsigned long *)"B08 "); else {printf("bos2et: error : unknown format\n"); error = -2; goto exit;} } else { ch = (char *)&w[id+4]; nch = strlen(ch); fmt = (char *)&ev[start+idFRMT]; bcopy((char *)ch, (char *)fmt, nch); fmt[nch++] = ' '; fmt[nch++] = ' '; fmt[nch] = ' '; nch = ((nch + 1)/4) * 4; ev[start+idNHEAD] += nch / 4; } } /* !!! do we have space enough in ET buffer ? - check it before puting next bank !!! */ if((start + ev[start+idNHEAD] + w[ind]) > ndim) { printf("bos2et: ERROR - ET buffer too small (%d < %d)\n",ndim,start + ev[start+idNHEAD] + w[ind]); error = EBIO_NOETSPACE; goto exit; } /* ch = (char *)&ev[start+idFRMT]; for(j=0; j<(ev[start+idNHEAD]-9)*4; j++) printf("%c",ch[j]); printf("<\n"); */ start += ev[start+idNHEAD]; /* copy data */ bcopy((char *)&w[ind+1], (char *)&ev[start], w[ind]<<2); start += w[ind]; } /* printf("\n"); */ exit: ev[irNWRD] = start - RECHEADLEN; /* the number of words in this record segment */ *size = start * sizeof(int); return(error); }
main(int argc, char **argv) { int nr,sec,layer,strip,wire,nl,ncol,nrow,i,j,l,l1,l2,ichan,nn,iev; int iev_START, iev_STOP, done=0; BOSIO *descriptor; int nevent=0; int crate,slot,connector, tdc_width; int ind,ind1,ind2,status,status1,handle,handle1,k,m,rocid; int scal,nw,scaler,scaler_old, counter,dccount[7],rccount[7]; unsigned int hel,str,strob,helicity,strob_old,helicity_old, tgbi1; int tmp1 = 1, tmp2 = 2, iret, bit1, bit2, nleading, ntrailing; float *bcsfl, rndm_(); char strr[1000], bankname[5], histname[128]; static int syn[32], id; MTDCHead *mtdchead; MTDC *mtdc; unsigned int leading[20000], trailing[20000]; char *HBOOKfile = "dsc2hist.his"; int nwpawc,lun,lrec,istat,icycle,idn,nbins,nbins1,igood,offset; float x1,x2,y1,y2,ww,tmpx,tmpy,ttt,ref; unsigned short *tlv1, *tlv2, *buf16; printf("\n dsc2hist reached !\n"); /* leading = (int *)malloc(80000); trailing = (int *)malloc(80000); */ if(argc != 4) { printf("\n Usage: dsc2hist data_file iev_START iev_STOP \n\n"); exit(1); } else { iev_START = atoi(argv[2]); iev_STOP = atoi(argv[3]); } printf("===============\n"); printf("argv0: >%s<\n",argv[0]); printf("argv1: >%s<\n",argv[1]); printf("argv2: >%s< iev_START = %d \n",argv[2],iev_START); printf("argv3: >%s< iev_STOP = %d \n",argv[3],iev_STOP); printf("TDC_slot: >%d<\n",TDC_SLOT); printf("---------------\n"); bcsfl = (float*)bcs_.iw; bosInit(bcs_.iw,NBCS); nwpawc = NWPAWC; hlimit_(&nwpawc); lun = 11; lrec = LREC; hropen_(&lun,"NTUPEL",HBOOKfile,"N",&lrec,&istat, strlen("NTUPEL"),strlen(HBOOKfile),1); if(istat) { printf("\aError: cannot open RZ file %s for writing.\n", HBOOKfile); exit(0); } else { printf("RZ file >%s< opened for writing, istat = %d\n\n", HBOOKfile, istat); chmod(HBOOKfile,0666); } /* nbins=200; x1 = 400.; x2 = 600.; */ nbins=8000; x1 = 0.; x2 = 8000.; ww = 0.; for(idn=1; idn<=16; idn++) { sprintf(histname,"TDC%02d",idn-1); hbook1_(&idn,histname,&nbins,&x1,&x2,&ww,strlen(histname)); } /* nbins=1000; x1 = 5500.; x2 = 6500.; */ nbins=8000; x1 = 0.; x2 = 8000.; ww = 0.; for(idn=17; idn<=32; idn++) { sprintf(histname,"TRG%02d",idn-17); hbook1_(&idn,histname,&nbins,&x1,&x2,&ww,strlen(histname)); } /* nbins=250; x1 = 0.; x2 = 250.; nbins1=500; y1 = 0.; y2 = 500.; ww = 0.; for(idn=201; idn<=206; idn++) { sprintf(histname,"DC load REG1 SEC%1d",idn-200); hbook2_(&idn,histname,&nbins,&x1,&x2,&nbins1,&y1,&y2,&ww,strlen(histname)); } */ sprintf(strr,"OPEN INPUT UNIT=1 FILE='%s' ",argv[1]); printf("fparm string: >%s<\n",strr); status = fparm_(strr,strlen(strr)); while(done==0) /* skip loop */ { nevent++; if(nevent>iev_START) { done = 1; } else { frbos_(bcs_.iw,&tmp1,"E",&iret,1); bdrop_(bcs_.iw,"E",1); bgarb_(bcs_.iw); if(iret == -1 || iret > 0) { printf(" End-of-File flag, iret =%d\n",iret); goto a111111; } else if(iret < 0) { printf(" Error1, iret =%d\n",iret); goto a111111; } } } /* for(iev=0; iev<100000; iev++) */ for(iev=iev_START; iev<iev_STOP; iev++) { frbos_(bcs_.iw,&tmp1,"E",&iret,1); if(!(iev%5000)) printf("===== Event no. %d\n",iev); if((ind1=bosNlink(bcs_.iw,"RC00",0)) > 0) { unsigned int *fb, *fbend; int crate,slot,channel,edge,data,count,ncol1,nrow1; int ndata0[22], data0[21][8]; int baseline, ii; int ref; ncol1 = bcs_.iw[ind1-6]; nrow1 = bcs_.iw[ind1-5]; nw = nrow1; offset = 0; /* printf("ind1=%d ncol=%d nrow=%d nw=%d\n",ind1,ncol1,nrow1,nw); */ ww = 1.0; /* printf("\n"); */ /* pass 0: find reference */ fb = (unsigned int *)&bcs_.iw[ind1]; fbend = fb + nrow1; /*fb += 6;*/ ii=0; ref=0; tdc_width=*(fbend-1); printf("tdc_width=%d\n",tdc_width); while(fb<fbend /*&& ii<32*/) { slot=((*fb)>>27)&0x1f; edge=((*fb)>>26)&0x1; channel=((*fb)>>21)&0x1f; data=(*fb)&0xfffff; if(slot==0) { printf("\n[%3d] board header: slot=%d len=%d\n",ii,(*fb)&0x1F,((*fb)>>5)&0x3FFF); } else { printf("[%3d] slot %d chan %d -> data %d (%d)\n",ii,slot,channel,data,data+2000-ref); if((ref == 0) && (channel == 0) && (slot == TDC_SLOT)) { ref = data; /* printf("ref=%d\n",ref); */ } } ii ++; fb ++; }
int et2bos(int *ev, int *jw, char *list) { BOSptr b; int *w; int i,ii,ind,error,nami,lrlen; int start,nf,ird,ndata,ntot,nama,nw; char *fmt; b = (BOSptr)jw; w = jw - 1; /* ET2ET should take care about that !!!!!!!!!!!! following call will swap input buffer if necessary etfswap((unsigned int *)ev); */ error = bosWgarbage(jw); error = start = 0; lrlen = ev[irNWRD]+RECHEADLEN; bosNdrop(jw,"+REC",RECNUM); /* extract nesessary info from record header here (do we need it ?) */ /* printf("ev[irPTRN]=0x%08x\n",ev[irPTRN]); */ /* ev[irPTRN ] == SWAP; ev[irFORG ] == LOCAL*16; ev[irNRSG ] == 100*BIOS_NPHYSREC+(BIOS_NSEGM-1); */ ind = RECHEADLEN; /*printf("lrlen=%d\n",lrlen);*/ while(ind < lrlen) { /* printf("ind=%d headlen=%d name>%4.4s< code=%d size=%d\n", ind,ev[ind+idNHEAD],&ev[ind+1],ev[ind+idCODE],ev[ind+idDATA]); */ /* open temporary BOS bank +REC */ fmt = (char *)&ev[ind+idFRMT]; nf = 0; while(fmt[nf] != ' ' && fmt[nf] != '\0' && nf < (ev[ind+idNHEAD]-idFRMT)*4) nf++; fmt[nf] = '\0'; if(nf > 0 && ev[ind+idNCOL] > 0 && *fmt != ' ') bosNformat(jw,&ev[ind+idNAME1],fmt); if(start == 0) { if((ird = bosNcreate(jw,"+REC",RECNUM,0,1)) <= 0) return(-55); start = b->igp; } w[start+(NHW-1)-ICOL] = ev[ind+idNCOL]; w[start+(NHW-1)-IROW] = ev[ind+idNROW]; w[start+(NHW-1)-INAM] = ev[ind+idNAME1]; w[start+(NHW-1)-INR ] = ev[ind+idNSGM]; w[start+(NHW-1)-INXT] = 0; /* how much space left */ ndata = ev[ind+idDATA]; if((b->iwk - start - NHW) < ndata) { printf("et2bos: NOBOSSPACE %d %d %d %d %d %d\n", b->iwk,start,ndata,ind,idDATA,NHW); error = EBIO_NOBOSSPACE; goto error_exit; } /* get data */ bcopy((char *)&ev[ind+ev[ind+idNHEAD]],(char *)&w[start+NHW],ndata<<2); w[start + (NHW-1)] = ndata; start = start + ndata + NHW; ind = ind+ev[ind+idNHEAD]+ev[ind+idDATA]; } b->s->jw1 = 1; /* the total number of words = last index - first index */ if((ird = bosNcreate(jw,"+REC",RECNUM,(start - b->igp),1)) == 0) { bosNdrop(jw,"+REC",RECNUM); return(-4); } if((ird = bosNlink(jw,"+REC",RECNUM)) == 0) return(-5); ntot = w[ird]; ind = ird + NHW; nama = w[ind-INAM] + 1; do { nw = w[ind] + NHW; ii = (ntot < nw) ? ntot : nw; if(ii < NHW || nw > ntot) { bosNdrop(jw,"+REC",RECNUM); return(-6); } if(w[ind-INAM] != nama) { nama = w[ind-INAM]; nami = namez(jw,nama); if(nami == 0) nami = mamind(jw,nama); } w[ind-INXT] = nami; ind = ind + nw; } while((ntot = ntot - nw) != 0); error = bosins(RECNUM,jw,list); return(error); error_exit: bosNdrop(jw,"+REC",RECNUM); return(error); }