/* Program to read a CODA file, filter out an event type = FILTERTYPE to a new CODA file. Compile on HP-UX with as "make -f make_rwcoda" Usage: "rwcoda Nevents file-in file-out", where Nevents = number of events to filter out, and file-in = input file, and file-out = output file CANNOT RUN THIS FROM ADAQ ACCOUNT */ /* Other inputs or flags -- Filtering occurs in this order and is logically inclusive: FILTERTYPE -- if nonzero, only filter this event type eventlist.dat -- if this file exists and contains events, then only these events are filtered (if pass above) EVENTS_SKIP -- if nonzero, skip this many events before writing out (if pass above) */ #include #define FILTERTYPE 0 #define MAXEVLEN 819200 #define MAXFILT 2000 #define S_SUCCESS 0 #define S_EVFILE_TRUNC 0x40730001 /* Event truncated on read */ #define EVENTS_SKIP 0 /* number of events to skip */ main (int argc, char *argv[]) { int handle1,handle2; int evbuffer[MAXEVLEN]; int ev_size,status,ev_type,nevent,ntofilter,nfilter,go_on,j,iok; char inputfile[80],outputfile[80]; char whoami[80]; char evlist[]="eventlist.dat"; FILE *fp; FILE *fpev; char *strin; int nevlist,evnum,event_number[MAXFILT]; int found; if(argc<4) { printf("You made a mistake... \n"); printf("Usage: rwcoda nevents file-in file-out \n\n"); exit(1); } ntofilter = atoi(argv[1]); strcpy(inputfile,argv[2]); strcpy(outputfile,argv[3]); printf("num to filter %d\n",ntofilter); printf("input file: %s output : %s\n",inputfile,outputfile); if(evOpen(inputfile,"r",&handle1)!=0) { printf("File '%s' not found. Quitting.\n",inputfile); exit(1); } /* The following is to protect you from overwriting your data */ strcpy(whoami,(char *)getenv("USER")); if(strcmp(whoami,"adaq")==0) { printf("Error -- you cannot run this as user ADAQ !\n"); exit(1); } if(strcmp(inputfile,outputfile)==0) { printf("Error -- input file cannot be same as output \n"); exit(1); } if((fp = fopen(outputfile,"r"))==NULL) { fclose(fp); } else { printf("Error -- output file already exists !\n"); exit(1); } if(evOpen(outputfile,"w",&handle2)!=0) { printf("Error opening file %s. Quitting.\n",outputfile); exit(1); } /* Read in list of events to filter */ if((fpev = fopen(evlist,"r"))==NULL) { printf("Will not filter from an event list -- none found\n"); nevlist=0; } else { strin = (char *)malloc(100*sizeof(char)); nevlist=0; while (fgets(strin,100,fpev)!=NULL) { sscanf(strin,"%d",&evnum); if(nevlist>2; status=evRead(handle1,&evbuffer,ev_size); if(status!=S_SUCCESS) { if(status==S_EVFILE_TRUNC) { printf("ERROR: Event %d truncated\n",nevent); printf("Probably evbuffer too small\n"); } else { printf("\n evRead status 0x%x - ENDING\n",status); go_on=0; } } ev_type = evbuffer[1]>>16; evnum = evbuffer[4]; iok = -1; /* To turn OFF filtering by FILTERTYPE, make FILTERTYPE = 0 */ if(FILTERTYPE!=0) { if(ev_type==FILTERTYPE) { iok=1; } else { iok=0; /* not right event type */ } } /* Filter if event is in list, unless not right event type */ found=0; if(nevlist>0) { for (j=0;jEVENTS_SKIP) { if(iok==-1&&nevlist==0) iok=1; } else { iok=0; } if(iok==1) { evWrite(handle2,&evbuffer); nfilter++; } if(nevent>ntofilter) go_on=0; } printf("\n\n All done - number of events read = %d\n",nevent); printf(" Number filtered out = %d\n",nfilter); evClose(handle1); evClose(handle2); }