17 #include <sys/types.h>
25 #include <rtsSystems.h>
28 #include <DAQ_READER/daqReader.h>
29 #include <DAQ_READER/daq_dta.h>
33 printf(
"Usage: daqFileMerger [-omit n] -o outputfile.daq source1.daq source2.daq ...\n");
34 printf(
" The files will be merged such that:\n");
35 printf(
" a) The events from each file will be in the same order as in the original files\n");
36 printf(
" b) The events' source files will be randomly distributed throughout the run.\n");
37 printf(
" c) The optional omit parameter will omit n%% of the events randomly\n");
44 void parseArgs(
int argc,
char *argv[])
48 for(arg=1;arg<argc;arg++) {
49 if(strcmp(argv[arg],
"-omit") == 0) {
51 omit = atoi(argv[arg]);
53 else if(strcmp(argv[arg],
"-o") == 0) {
55 outputfile = argv[arg];
56 firstSourceFile = arg+1;
58 printf(
"output file: %s, omit = %d%%\n", outputfile, omit);
69 char *ret = rdr->get(0, EVP_TYPE_ANY);
72 if(rdr->status)
continue;
76 if(rdr->status == EVP_STAT_OK)
continue;
77 if(rdr->status == EVP_STAT_EOR)
return 1;
80 LOG(ERR,
"Error reading!");
91 int main(
int argc,
char *argv[])
93 srand((
unsigned int)time(NULL));
95 rtsLogOutput(RTS_LOG_STDERR) ;
96 rtsLogLevel((
char *)WARN) ;
98 parseArgs(argc, argv);
100 int fd = open(outputfile, O_CREAT | O_WRONLY, 0666);
102 printf(
"Error opening output file: %s", outputfile);
105 int n_sourcefiles = argc - firstSourceFile;
107 int *n_evts = (
int *)malloc(
sizeof(
int) * n_sourcefiles);
112 for(
int i=0;i<n_sourcefiles;i++) {
116 rdrs[i] =
new daqReader(argv[firstSourceFile + i]);
118 while((ret = getGoodEvent(rdrs[i])) == 0) {
122 tot_evts += n_evts[i];
123 printf(
"File #%02d: %s (%d events)\n",i, argv[firstSourceFile + i], n_evts[i]);
126 rdrs[i] =
new daqReader(argv[firstSourceFile + i]);
133 for(
int i=0;i<n_sourcefiles;i++) {
134 for(
int j=0;j<n_evts[i];j++) {
136 specs[idx].random = rand();
142 for(
int i=0;i<tot_evts;i++) {
143 for(
int j=i+1;j<tot_evts;j++) {
144 if(specs[i].random > specs[j].random) {
145 int t = specs[i].file;
146 specs[i].file = specs[j].file;
149 specs[i].random = specs[j].random;
157 for(
int i=0;i<tot_evts;i++) {
159 int file = specs[i].file;
161 int ret = getGoodEvent(rdrs[file]);
163 printf(
"Error reading from %d: ret = %d", file, ret);
170 zz /= (double)RAND_MAX;
173 printf(
"[%07d] File: #%02d Evt: #%07d Seq: #%07d\n", k, file, rdrs[file]->event_number, rdrs[file]->seq);
175 ret = write(fd, rdrs[file]->memmap->mem, rdrs[file]->event_size);
177 printf(
"Error writing to file %s\n", outputfile);
188 for(
int i=0;i<n_sourcefiles; i++) {
189 int ret = getGoodEvent(rdrs[i]);
192 printf(
"Error reading EOF from %d: ret = %d\n", file, ret);