Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hddm_cull_events.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // Created Dec 22, 2007 David Lawrence
4 
5 #include "hddm_cull_events.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 unsigned int EVENTS_TO_SKIP = 0;
16 unsigned int EVENTS_TO_KEEP = 1;
17 unsigned int SPECIFIC_OFFSET_TO_KEEP = 0;
18 unsigned int SPECIFIC_EVENT_TO_KEEP = 0;
19 bool EVENT_TO_KEEP_MODE = false;
20 bool HDDM_USE_COMPRESSION = false;
22 
23 
24 //-----------
25 // main
26 //-----------
27 int main(int narg,char* argv[])
28 {
29  // Set up to catch SIGINTs for graceful exits
30  signal(SIGINT,ctrlCHandle);
31 
32  ParseCommandLineArguments(narg, argv);
33 
34  std::cout << "Skipping " << EVENTS_TO_SKIP << std::endl;
35  std::cout << "Keeping " << EVENTS_TO_KEEP << std::endl;
36  unsigned int NEvents = 0;
37  unsigned int NEvents_read = 0;
38 
39  // Each HDDM class must have it's own cull routine
40  if (HDDM_CLASS == "s") {
41  Process_s(NEvents, NEvents_read);
42  }
43  else if (HDDM_CLASS == "r") {
44  Process_r(NEvents, NEvents_read);
45  }
46  else {
47  std::cout << "Don't know how to process HDDM class \"" << HDDM_CLASS << "\"!" << std::endl;
48  return -1;
49  }
50 
51  std::cout << std::endl;
52  std::cout << " " << NEvents_read << " events read, " << NEvents << " events written" << std::endl;
53 
54  return 0;
55 }
56 
57 //-----------
58 // ParseCommandLineArguments
59 //-----------
60 void ParseCommandLineArguments(int narg, char* argv[])
61 {
62  INFILENAMES.clear();
63 
64  for (int i=1; i < narg; i++) {
65  char *ptr = argv[i];
66 
67  if (ptr[0] == '-') {
68  switch(ptr[1]) {
69  case 'h':
70  Usage();
71  break;
72  case 'o':
73  OUTFILENAME=&ptr[2];
74  break;
75  case 's':
76  EVENTS_TO_SKIP=atoi(&ptr[2]);
77  break;
78  case 'k':
79  EVENTS_TO_KEEP=atoi(&ptr[2]);
80  break;
81  case 'e':
82  SPECIFIC_OFFSET_TO_KEEP=atoi(&ptr[2]);
83  break;
84  case 'E':
85  SPECIFIC_EVENT_TO_KEEP=atoi(&ptr[2]);
86  EVENT_TO_KEEP_MODE=true;
87  break;
88  case 'r':
89  HDDM_CLASS = "r";
90  break;
91  case 'I':
93  break;
94  case 'C':
96  break;
97  }
98  }
99  else {
100  INFILENAMES.push_back(argv[i]);
101  }
102  }
103 
104  if (INFILENAMES.size() == 0) {
105  std::cout << std::endl << "You must enter a filename!"
106  << std::endl << std::endl;
107  Usage();
108  }
109 
110  if (SPECIFIC_OFFSET_TO_KEEP>0) {
111  EVENTS_TO_KEEP=1;
113  }
114 
115  if (SPECIFIC_EVENT_TO_KEEP>0) {
116  EVENTS_TO_KEEP=1;
117  EVENTS_TO_SKIP=1000000000; // Large number of events to read in while looking for the specified event
118  }
119 
120  if (OUTFILENAME == NULL) {
121  if (SPECIFIC_OFFSET_TO_KEEP>0) {
122  OUTFILENAME = new char[256];
124  }
125  else {
126  OUTFILENAME = (char*)"culled.hddm";
127  }
128  }
129 }
130 
131 //-----------
132 // Usage
133 //-----------
134 void Usage(void)
135 {
136  std::cout << std::endl << "Usage:" << std::endl;
137  std::cout << " hddm_cull_events [-oOutputfile] [-sNeventsToSkip] [-kNeventsToKeep] file1.hddm file2.hddm ..." << std::endl;
138  std::cout << std::endl;
139  std::cout << "options:" << std::endl;
140  std::cout << " -oOutputfile Set output filename (def. culled.hddm)" << std::endl;
141  std::cout << " -sNeventsToSkip Set number of events to skip (def. 0)" << std::endl;
142  std::cout << " -kNeventsToKeep Set number of events to keep (def. 1)" << std::endl;
143  std::cout << " -eSingleEvent Keep only the single, specified event (file pos.)" << std::endl;
144  std::cout << " -ESingleEvent Keep only the single, specified event (event number)" << std::endl;
145  std::cout << " -r Input file is in REST format (def. hdgeant format)" << std::endl;
146  std::cout << " -I Enable data integrity checks on output HDDM stream" << std::endl;
147  std::cout << " -C Enable compression on output HDDM stream" << std::endl;
148  std::cout << std::endl;
149  std::cout << " This will copy a continguous set of events from the combined event streams" << std::endl;
150  std::cout << " into a seperate output file. The primary use for this would be to copy" << std::endl;
151  std::cout << " a single, problematic event into a seperate file for easier debugging." << std::endl;
152  std::cout << std::endl;
153  std::cout << " If the -eNNN option is used then only a single event is extracted" << std::endl;
154  std::cout << " (the NNN-th event) and written to a file with the name evtNNN.hddm." << std::endl;
155  std::cout << " Note that the event is counted from the begining of the file, starting" << std::endl;
156  std::cout << " with \"1\". This does NOT look at the event number stored in the event itself." << std::endl;
157  std::cout << " " << std::endl;
158  std::cout << " If the -ENNN option is used then only a single event is extracted" << std::endl;
159  std::cout << " (the specified event number) and written to a file with the name evtNNN.hddm." << std::endl;
160  std::cout << " " << std::endl;
161  std::cout << std::endl;
162 
163  exit(0);
164 }
165 
166 //-----------------------------------------------------------------
167 // ctrlCHandle
168 //-----------------------------------------------------------------
169 void ctrlCHandle(int x)
170 {
171  QUIT++;
172  std::cerr << std::endl << "SIGINT received (" << QUIT << ")....."
173  << std::endl;
174 }
unsigned int EVENTS_TO_KEEP
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
void Process_s(unsigned int &NEvents, unsigned int &NEvents_read)
unsigned int SPECIFIC_EVENT_TO_KEEP
sprintf(text,"Post KinFit Cut")
void Process_r(unsigned int &NEvents, unsigned int &NEvents_read)
string HDDM_CLASS
Definition: hddm2root.cc:18
char * OUTFILENAME
bool EVENT_TO_KEEP_MODE
void ParseCommandLineArguments(int &narg, char *argv[])
Definition: hd_dump.cc:124
int QUIT
bool HDDM_USE_COMPRESSION
unsigned int SPECIFIC_OFFSET_TO_KEEP
bool HDDM_USE_INTEGRITY_CHECKS
vector< char * > INFILENAMES
void ctrlCHandle(int x)
unsigned int EVENTS_TO_SKIP
void Usage(JApplication &app)
Definition: hd_ana.cc:33
int main(int argc, char *argv[])
Definition: gendoc.cc:6