16 #include <sys/types.h>
24 #include <rtsSystems.h>
27 #include <DAQ_READER/daqReader.h>
28 #include <DAQ_READER/daq_dta.h>
32 LOG(ERR,
"Usage: daqFileChopper filename <filterlist>");
33 LOG(ERR,
" filterlist --> -trg xxx yyy zzz... // list of offline trigger bits");
34 LOG(ERR,
" -dtrg xxx yyy zzz... // list of daq trigger bits");
35 LOG(ERR,
" -ndtrg xxx yyy zzz // not list of daq trigger bits");
36 LOG(ERR,
" -eventnum xxx yyy... // list of event numbers");
37 LOG(ERR,
" -chop xxx // chop into files of xxx events");
44 int FilterEvent(
daqReader *rdr,
int nargs,
char *argv[])
46 int eventNumber = rdr->seq;
48 if(strcmp(argv[0],
"-trg")==0) {
49 unsigned int bits = rdr->daqbits;
50 for(
int i=0;i<32;i++) {
52 int trgSat = rdr->getOfflineId(i);
54 for(
int j=1;j<nargs;j++) {
55 if(trgSat == atoi(argv[j])) {
62 else if(strcmp(argv[0],
"-dtrg")==0) {
63 UINT64 bits = rdr->daqbits64;
64 for(
int i=1;i<nargs;i++) {
65 int trg = atoi(argv[i]);
66 if(bits & (1ll<<trg))
return 1;
70 else if (strcmp(argv[0],
"-ndtrg")==0) {
71 UINT64 bits = rdr->daqbits64;
72 for(
int i=1;i<nargs;i++) {
73 int trg = atoi(argv[i]);
74 if((bits & (1ll<<trg)) == 0)
return 1;
78 else if(strcmp(argv[0],
"-eventnum")==0) {
79 for(
int i=1;i<nargs;i++) {
80 if(eventNumber == atoi(argv[i])) {
92 void doChopInstead(
int argc,
char *argv[]);
95 int main(
int argc,
char *argv[])
97 rtsLogOutput(RTS_LOG_STDERR) ;
98 rtsLogLevel((
char *)WARN) ;
106 int filterArgc = argc-2;
107 char **filterArgv = &argv[2];
114 if(strcmp(argv[2],
"-chop") == 0) {
115 doChopInstead(argc, argv);
128 char *ret = evp->get(0,EVP_TYPE_ANY);
132 LOG(ERR,
"evp status is non-null [0x08X, %d dec]",evp->status,evp->status) ;
138 switch(evp->status) {
142 LOG(OPER,
"Done after scanning %d events (%d bad)",good,bad);
146 LOG(WARN,
"Problem getting event - skipping [good %d, bad %d]",good,bad);
149 LOG(CRIT,
"evp->status CRITICAL (?)") ;
154 if(evp->status == EVP_STAT_EOR) {
155 LOG(INFO,
"Done after scanning %d events (%d bad)",good,bad) ;
159 if(FilterEvent(evp, filterArgc, filterArgv) == 0) {
162 LOG(INFO,
"Keep event #%d (ptr=0x%x sz=%d)",evp->seq,evp->memmap->mem,evp->event_size);
164 write(STDOUT_FILENO, evp->memmap->mem, evp->event_size);
173 void doChopInstead(
int argc,
char *argv[]) {
175 printf(
"-chop argument requires number of events per file...\n");
179 int nevts_perfile = atoi(argv[3]);
181 int nevts_thisfile = 0;
188 if(argv[1][i] ==
'\0')
break;
189 if(argv[1][i] ==
'.')
break;
191 basename[i] = argv[1][i];
205 char *ret = evp->get(0,EVP_TYPE_ANY);
209 LOG(ERR,
"evp status is non-null [0x08X, %d dec]",evp->status,evp->status) ;
215 switch(evp->status) {
219 LOG(OPER,
"Done after scanning %d events (%d bad)",good,bad);
223 LOG(WARN,
"Problem getting event - skipping [good %d, bad %d]",good,bad);
226 LOG(CRIT,
"evp->status CRITICAL (?)") ;
231 if(evp->status == EVP_STAT_EOR) {
233 LOG(INFO,
"Wrote %d evts to file: %s", nevts_thisfile, currname);
237 LOG(INFO,
"Done after scanning %d events (%d bad)",good,bad) ;
247 sprintf(currname,
"%s-%d.daq", basename, fidx);
248 fd = open(currname, O_WRONLY | O_CREAT, 0666);
250 LOG(INFO,
"Error opening file %s: (%s)", currname, strerror(errno));
255 LOG(DBG,
"Writing event #%d (ptr=0x%x sz=%d) [%d in file %s]",evp->seq,evp->memmap->mem,evp->event_size, nevts_thisfile, currname);
257 write(fd, evp->memmap->mem, evp->event_size);
259 if(nevts_thisfile >= nevts_perfile) {
260 LOG(INFO,
"Wrote %d evts to file: %s", nevts_thisfile, currname);