16 unsigned int MAX = 100 * 1000 * 1000;
30 int main(
int argc,
char* argv[]) {
37 while ((c = getopt(argc,argv,
"ho:i:ars:M:dR:")) != -1) {
47 std::cout <<
"infile name: " <<
INFILENAME << std::endl;
51 std::cout <<
"outfile name: " <<
OUTFILENAME << std::endl;
58 if (
OUTFILENAME.find(
".hddm") != std::string::npos) {
71 std::cout <<
"event selection type: " <<
selectType << std::endl;
75 std::cout <<
"maximum number of events: " <<
MAX << std::endl;
79 std::cout <<
"debug mode" << std::endl;
83 std::cout <<
"Random seed is only needed for select type 4"
88 std::cout <<
"random seed: " <<
seed << std::endl;
112 hddm_s::istream *istr_s;
113 hddm_s::ostream *ostr_s;
114 hddm_s::ostream *ostr_s_remainder;
116 hddm_r::istream *istr_r;
117 hddm_r::ostream *ostr_r;
118 hddm_r::ostream *ostr_r_remainder;
122 ofstream ofs_remainder;
126 if (! ifs.is_open()) {
127 std::cout <<
" Error opening input file \"" <<
INFILENAME
128 <<
"\"!" << std::endl;
131 istr_s =
new hddm_s::istream(ifs);
134 if (! ofs.is_open()) {
135 std::cout <<
" Error opening output file \"" <<
OUTFILENAME
136 <<
"\"!" << std::endl;
139 ostr_s =
new hddm_s::ostream(ofs);
141 ostr_s->setCompression(hddm_r::k_bz2_compression);
144 ostr_s->setIntegrityChecks(hddm_r::k_crc32_integrity);
149 if (! ofs_remainder.is_open()) {
151 <<
"\"!" << std::endl;
154 ostr_s_remainder =
new hddm_s::ostream(ofs_remainder);
156 ostr_s_remainder->setCompression(hddm_r::k_bz2_compression);
159 ostr_s_remainder->setIntegrityChecks(hddm_r::k_crc32_integrity);
163 ostr_s_remainder = NULL;
169 ostr_r_remainder = NULL;
174 if (! ifs.is_open()) {
175 std::cout <<
" Error opening input file \"" <<
INFILENAME
176 <<
"\"!" << std::endl;
179 istr_r =
new hddm_r::istream(ifs);
182 if (! ofs.is_open()) {
183 std::cout <<
" Error opening output file \"" <<
OUTFILENAME
184 <<
"\"!" << std::endl;
187 ostr_r =
new hddm_r::ostream(ofs);
189 ostr_r->setCompression(hddm_r::k_bz2_compression);
192 ostr_r->setIntegrityChecks(hddm_r::k_crc32_integrity);
196 if (! ofs_remainder.is_open()) {
198 <<
"\"!" << std::endl;
201 ostr_r_remainder =
new hddm_r::ostream(ofs_remainder);
203 ostr_r_remainder->setCompression(hddm_r::k_bz2_compression);
206 ostr_r_remainder->setIntegrityChecks(hddm_r::k_crc32_integrity);
210 ostr_r_remainder = NULL;
215 ostr_s_remainder = NULL;
219 unsigned int NEvents = 0;
220 unsigned int NEvents_read = 0;
221 time_t last_time = time(NULL);
224 while (
true && NEvents_read <
MAX) {
241 std::cout << NEvents_read << std::endl;
248 *ostr_s_remainder << record;
257 std::cout << NEvents_read << std::endl;
258 hddm_r::ReconstructedPhysicsEvent &re =
259 record.getReconstructedPhysicsEvent();
260 int runno = re.getRunNo();
261 int eventno = re.getEventNo();
263 std::cout << runno <<
"\t" << eventno << std::endl;
270 *ostr_r_remainder << record;
274 time_t now = time(NULL);
275 if (now != last_time) {
276 std::cout <<
" " << NEvents_read <<
" events read ("
277 << NEvents <<
" event written) \r";
294 if (ofs_remainder.is_open()) {
295 delete ostr_s_remainder;
296 ofs_remainder.close();
304 if (ofs_remainder.is_open()) {
305 delete ostr_r_remainder;
306 ofs_remainder.close();
310 std::cout << std::endl;
311 std::cout <<
" " << NEvents_read <<
" events read, "
312 << NEvents <<
" events written" << std::endl;
322 std::cout << std::endl <<
"Usage:" << std::endl;
323 std::cout <<
" hddm_select_events [-i Inputfile] [-o Outputfile]"
324 " [-r REST format] [-a save remainder events too]"
325 " [-s selection type] [-M maximum number of events]"
327 std::cout << std::endl;
328 std::cout <<
"options:" << std::endl;
329 std::cout <<
" -i Inputfile Set input filename" << std::endl;
330 std::cout <<
" -o Outputfile Set output filename" << std::endl;
331 std::cout <<
" -r Input is REST format" << std::endl;
332 std::cout <<
" -a Save remainder events in a file too"
334 std::cout <<
" -s selectType Set which type of cut to do"
336 std::cout <<
" -M MAX Set maximum number of events"
338 std::cout <<
" -C Enable compression in the output"
339 " hddm streams" << std::endl;
340 std::cout <<
" -I Enable data integrity checks in the"
341 " output hddm streams" << std::endl;
342 std::cout << std::endl;
353 std::cerr << std::endl <<
"SIGINT received (" <<
QUIT <<
")....."
bool selectEvent_r(int select_type, hddm_r::HDDM &record, int nevents, bool debug)
string OUTFILENAME_REMAINDER
bool selectEvent_s(int select_type, hddm_s::HDDM &record, int nevents, bool debug)
bool HDDM_USE_COMPRESSION
bool HDDM_USE_INTEGRITY_CHECKS
void Usage(JApplication &app)
int main(int argc, char *argv[])