22 #define DDEVENTITERATOR 1
23 #define FILEEVENTITERATOR 2
24 #define TESTEVENTITERATOR 3
29 #if defined(SunOS) || defined(Linux) || defined(OSF1)
37 #include <sys/types.h>
43 #if defined(SunOS) || defined(Linux) || defined(OSF1)
52 COUT <<
"** usage: eventcombiner outputfile inputfile1 inputfile2 ..." << std::endl;
53 COUT <<
" eventcombiner -h for more help" << std::endl;
60 COUT <<
" Syntax:"<< std::endl;
62 COUT <<
" eventcombiner [-v] [-i] [-n number] [-u] [-p] [-h] inputfile1 inputfile2 ..."<< std::endl;
63 COUT <<
" e.g eventcombiner -v /export/rcfdata/dcm_data/built_evt/rc_3612.prdfz /export/rcfdata/dcm_data/rc/*3612*" << std::endl;
64 COUT <<
" will combine all the *3612* (from one run number) together in the file. "<< std::endl;
65 COUT <<
" Options:" << std::endl;
66 COUT <<
" -v verbose, without that it does its work silently" << std::endl;
67 COUT <<
" -i identify the events as they are processed, good for debugging" << std::endl;
68 COUT <<
" -e <event number> start with event number (number in evt. header)" << std::endl;
69 COUT <<
" -c <event number> start with nth event" << std::endl;
70 COUT <<
" -n <number> stop after so many events" << std::endl;
71 COUT <<
" -p read and write legacy PHENIX format data, default is sPHENIX "<< std::endl;
73 COUT <<
" -f force output file overwrite, normally you cannot overwrite an existing file (safety belt)"<< std::endl;
74 COUT <<
" -x ignore event numbers (allow non-matching evt nrs to be combined, DANGEROUS)"<< std::endl;
75 COUT <<
" -h this message" << std::endl;
81 COUT <<
"** cannot specify both -e and -c!" << std::endl;
82 COUT <<
" type eventcombiner -h for more help" << std::endl;
91 main(
int argc,
char *argv[])
103 int ignoreeventnr = 0;
105 int legacyphenix = 0;
121 while ((c = getopt(argc, argv,
"n:c:e:vipfhx")) != EOF)
152 if ( !sscanf(optarg,
"%d", &eventnumber) )
exitmsg();
156 if ( !sscanf(optarg,
"%d", &countnumber) )
exitmsg();
160 if ( !sscanf(optarg,
"%d", &maxevents) )
exitmsg();
177 vector<Eventiterator *>
it;
184 filename =argv[optind];
188 fd =
open(filename.c_str(), O_RDONLY | O_LARGEFILE);
193 COUT <<
"file " << filename <<
" exists - I won't override it" << std::endl;
194 COUT <<
" use -f to force" << std::endl;
199 for ( index = optind+1; index < argc; index++ )
201 COUT <<
"reading from file " << argv[
index] << std::endl;
205 COUT <<
"could not open " << argv[
index] << std::endl;
217 unlink (filename.c_str());
219 fd =
open(filename.c_str(),
220 O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE ,
221 S_IRWXU | S_IROTH | S_IRGRP );
226 COUT <<
"Could not open file: " << filename << std::endl;
229 if (verbose)
COUT <<
"Opened file: " << filename << std::endl;
242 while ( ( maxevents == 0 || eventnr < maxevents) && go_on)
244 int total_length = 0;
247 vector<Eventiterator *>::iterator it_itr;
250 for (it_itr = it.begin(); it_itr != it.end(); ++it_itr)
252 e = (*it_itr)->getNextEvent();
265 int *
out =
new int[total_length];
271 if ( eventnumber && e != 0 && e->
getEvtSequence() < eventnumber) take_this = 0;
273 if ( countnumber && count+1 < countnumber) take_this = 0;
275 vector<Event *>::iterator evt_itr;
276 for (evt_itr = evt.begin(); evt_itr != evt.end(); ++evt_itr)
278 if (evt_itr == evt.begin() )
280 enr = (*evt_itr)->getEvtSequence();
281 (*evt_itr)->Copy ( out , total_length , &nwout);
287 if (take_this ==0 || (ignoreeventnr ==0 && (*evt_itr)->getEvtSequence() != enr ))
293 (*evt_itr)->Copy ( &out[current] , total_length-current , &nwout,
"DATA");
315 vector<Eventiterator *>::iterator it_itr;
316 for (it_itr = it.begin(); it_itr != it.end(); ++it_itr)
318 delete ( (*it_itr) ) ;