Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hddm_merge_files.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // Created Dec 22, 2007 David Lawrence
4 
5 #include "hddm_merge_files.h"
6 
7 void ParseCommandLineArguments(int narg, char* argv[]);
8 void Usage(void);
9 void ctrlCHandle(int x);
10 
11 string HDDM_CLASS = "s";
12 vector<char*> INFILENAMES;
13 char *OUTFILENAME = NULL;
14 int QUIT = 0;
15 bool HDDM_USE_COMPRESSION = false;
17 
18 
19 //-----------
20 // main
21 //-----------
22 int main(int narg,char* argv[])
23 {
24  // Set up to catch SIGINTs for graceful exits
25  signal(SIGINT, ctrlCHandle);
26 
27  ParseCommandLineArguments(narg, argv);
28 
29  unsigned int NEvents = 0;
30  unsigned int NEvents_read = 0;
31 
32  // Each HDDM class must have it's own cull routine
33  if (HDDM_CLASS == "s")
34  Process_s(NEvents, NEvents_read);
35  else if (HDDM_CLASS == "r")
36  Process_r(NEvents, NEvents_read);
37  else {
38  std::cout << "Don't know how to process HDDM class \"" << HDDM_CLASS
39  << "\"!" << std::endl;
40  return -1;
41  }
42 
43  std::cout << std::endl;
44  std::cout << " " << NEvents_read << " events read, "
45  << NEvents << " events written" << std::endl;
46  return 0;
47 }
48 
49 //-----------
50 // ParseCommandLineArguments
51 //-----------
52 void ParseCommandLineArguments(int narg, char* argv[])
53 {
54  INFILENAMES.clear();
55 
56  for (int i=1; i<narg; i++) {
57  char *ptr = argv[i];
58 
59  if (ptr[0] == '-') {
60  switch(ptr[1]) {
61  case 'h':
62  Usage();
63  break;
64  case 'o':
65  OUTFILENAME=&ptr[2];
66  break;
67  case 'r':
68  HDDM_CLASS = "r";
69  break;
70  case 'C':
71  HDDM_USE_COMPRESSION = true;
72  break;
73  case 'I':
75  break;
76  }
77  }
78  else {
79  INFILENAMES.push_back(argv[i]);
80  }
81  }
82 
83  if (INFILENAMES.size() == 0) {
84  std::cout << std::endl << "You must enter a filename!"
85  << std::endl << std::endl;
86  Usage();
87  }
88 
89  if (OUTFILENAME == NULL) {
90  OUTFILENAME = new char[256];
91  sprintf(OUTFILENAME,"merged_files.hddm");
92  }
93 }
94 
95 
96 //-----------
97 // Usage
98 //-----------
99 void Usage(void)
100 {
101  std::cout << std::endl << "Usage:" << std::endl;
102  std::cout << " hddm_merge_files [options] "
103  "file1.hddm file2.hddm ..." << std::endl;
104  std::cout << std::endl;
105  std::cout << "options:" << std::endl;
106  std::cout << " -oOutputfile Set output filename "
107  << "(def. merged_files.hddm)" << std::endl;
108  std::cout << " -I Enable data integrity checks on"
109  " the output hddm stream" << std::endl;
110  std::cout << " -C Enable data compression on"
111  " the output hddm stream" << std::endl;
112  std::cout << " -r Input file is in REST format" << std::endl;
113  std::cout << std::endl;
114  std::cout << " This will merge 1 or more HDDM files "
115  "into a single HDDM file." << std::endl;
116  std::cout << " " << std::endl;
117  std::cout << " " << std::endl;
118  std::cout << std::endl;
119 
120  exit(0);
121 }
122 
123 //-----------------------------------------------------------------
124 // ctrlCHandle
125 //-----------------------------------------------------------------
126 void ctrlCHandle(int x)
127 {
128  QUIT++;
129  std::cerr << std::endl << "SIGINT received (" << QUIT << ")....."
130  << std::endl;
131 }
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
void Process_s(unsigned int &NEvents, unsigned int &NEvents_read)
sprintf(text,"Post KinFit Cut")
void Process_r(unsigned int &NEvents, unsigned int &NEvents_read)
string HDDM_CLASS
Definition: hddm2root.cc:18
char * OUTFILENAME
void ParseCommandLineArguments(int &narg, char *argv[])
Definition: hd_dump.cc:124
int QUIT
bool HDDM_USE_COMPRESSION
bool HDDM_USE_INTEGRITY_CHECKS
vector< char * > INFILENAMES
void ctrlCHandle(int x)
void Usage(JApplication &app)
Definition: hd_ana.cc:33
int main(int argc, char *argv[])
Definition: gendoc.cc:6