Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hddm_merge_files/Process_r.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_r.hpp>
8 using namespace hddm_r;
9 
10 
11 //-----------
12 // Process_r -- HDDM REST format
13 //-----------
14 void Process_r(unsigned int &NEvents, unsigned int &NEvents_read)
15 {
16  // Output file
17  std::cout << " output file: " << OUTFILENAME << std::endl;
18  std::ofstream ofs(OUTFILENAME);
19  if (! ofs.is_open()) {
20  std::cout << " Error opening output file \"" << OUTFILENAME
21  << "\"!" << std::endl;
22  exit(-1);
23  }
24  hddm_r::ostream *ostr = new hddm_r::ostream(ofs);
26  std::cout << " Enabling bz2 compression of output HDDM file stream"
27  << std::endl;
28  ostr->setCompression(hddm_r::k_bz2_compression);
29  }
30  else {
31  std::cout << " HDDM compression disabled" << std::endl;
32  }
34  std::cout << " Enabling CRC data integrity check in output HDDM"
35  " file stream" << std::endl;
36  ostr->setIntegrityChecks(hddm_r::k_crc32_integrity);
37  }
38  else {
39  std::cout << " HDDM integrity checks disabled" << std::endl;
40  }
41 
42  // Loop over input files
43  time_t last_time = time(NULL);
44  for (unsigned int i=0; i<INFILENAMES.size(); i++) {
45  std::cout << " input file: " << INFILENAMES[i] << std::endl;
46 
47  // Open hddm file for reading
48  std::ifstream ifs(INFILENAMES[i]);
49 
50  // Associate input file stream with HDDM record
51  hddm_r::istream *istr = new hddm_r::istream(ifs);
52 
53  // Loop over events
54  while (ifs.good()) {
55  HDDM xrec;
56  *istr >> xrec;
57  NEvents_read++;
58 
59  *ostr << xrec;
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  if (QUIT)
71  break;
72  }
73  delete istr;
74  }
75  delete ostr;
76 }
void Process_r(unsigned int &NEvents, unsigned int &NEvents_read)
char * OUTFILENAME
int QUIT
bool HDDM_USE_COMPRESSION
bool HDDM_USE_INTEGRITY_CHECKS
vector< char * > INFILENAMES