Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hddm_merge_files/Process_s.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // Created Oct 25, 2013 Kei Moriya
4 
5 #include "hddm_merge_files.h"
6 
7 #include <HDDM/hddm_s.hpp>
8 
9 //-----------
10 // Process_s -- HDDM simulation format
11 //-----------
12 void Process_s(unsigned int &NEvents, unsigned int &NEvents_read)
13 {
14  // Output file
15  std::cout << " output file: " << OUTFILENAME << std::endl;
16  std::ofstream ofs(OUTFILENAME);
17  if (! ofs.is_open()) {
18  std::cout << " Error opening output file \"" << OUTFILENAME
19  << "\"!" << std::endl;
20  exit(-1);
21  }
22  hddm_s::ostream *fout = new hddm_s::ostream(ofs);
24  std::cout << " Enabling bz2 compression of output HDDM file stream"
25  << std::endl;
26  fout->setCompression(hddm_s::k_bz2_compression);
27  }
28  else {
29  std::cout << " HDDM compression disabled" << std::endl;
30  }
32  std::cout << " Enabling CRC data integrity check in output HDDM"
33  " file stream" << std::endl;
34  fout->setIntegrityChecks(hddm_s::k_crc32_integrity);
35  }
36  else {
37  std::cout << " HDDM integrity checks disabled" << std::endl;
38  }
39 
40  // Loop over input files
41  time_t last_time = time(NULL);
42  for (unsigned int i=0; i<INFILENAMES.size(); i++) {
43  std::cout << " input file: " << INFILENAMES[i] << std::endl;
44  std::ifstream ifs(INFILENAMES[i]);
45  if (! ifs.is_open()) {
46  std::cout << " Error opening input file \"" << INFILENAMES[i]
47  << "\"!" << std::endl;
48  exit(-1);
49  }
50  hddm_s::istream *fin = new hddm_s::istream(ifs);
51 
52  // Loop over all events in input
53  while (ifs.good()) {
54  hddm_s::HDDM record;
55  *fin >> record;
56  NEvents_read++;
57 
58  // Write this output event to file
59  *fout << record;
60  NEvents++;
61 
62  // Update ticker
63  time_t now = time(NULL);
64  if (now != last_time) {
65  std::cout << " " << NEvents_read << " events read ("
66  << NEvents << " event written) \r";
67  std::cout.flush();
68  last_time = now;
69  }
70 
71  if (QUIT)
72  break;
73  }
74 
75  // Close input file
76  ifs.close();
77  delete fin;
78  }
79 
80  // Close output file
81  ofs.close();
82  delete fout;
83 }
void Process_s(unsigned int &NEvents, unsigned int &NEvents_read)
char * OUTFILENAME
int QUIT
bool HDDM_USE_COMPRESSION
bool HDDM_USE_INTEGRITY_CHECKS
vector< char * > INFILENAMES