Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JEvtMerge.cc File Reference

Auxiliary program for time sorting of Monte-Carlo events. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/MultiHead.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JLang/JException.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JSingleFileScanner.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program for time sorting of Monte-Carlo events.

Author
mdejong

Definition in file JEvtMerge.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 57 of file JEvtMerge.cc.

58 {
59  using namespace std;
60  using namespace JPP;
61 
62  typedef typename JTYPELIST<Head, MultiHead, Evt, JMeta>::typelist typelist;
63 
64  vector<string> inputFile;
66  int debug;
67 
68  try {
69 
70  JParser<> zap("Auxiliary program for time sorting of Monte-Carlo events.");
71 
72  zap['f'] = make_field(inputFile, "Input file (produced with JEvtSplit)");
73  zap['o'] = make_field(outputFile);
74  zap['d'] = make_field(debug) = 2;
75 
76  zap(argc, argv);
77  }
78  catch(const exception& error) {
79  FATAL(error.what() << endl);
80  }
81 
82 
83  outputFile.open();
84 
85  outputFile.put(JMeta(argc, argv));
86 
87  const size_t N = inputFile.size();
88 
89  typedef JTreeScanner <Evt> JScanner_t;
90  //typedef JSingleFileScanner<Evt> JScanner_t;
91 
92  counter_type number_of_events = JTreeScanner<Evt>(inputFile).getEntries();
93 
95 
96  for (size_t i = 0; i != N; ++i) {
97 
98  in[i].configure(inputFile[i]);
99 
100  STATUS("Processing " << inputFile[i] << endl);
101  }
102 
103 #ifdef PRIORITY_QUEUE
104 
105  priority_queue<entry_type, deque<entry_type> > buffer; // multiplex
106 
107  for (size_t i = 0; i != N; ++i) {
108 
109  if (in[i].hasNext()) {
110 
111  buffer.push({i, *in[i].next()});
112 
113  --number_of_events;
114  }
115  }
116 
117  while (number_of_events != 0) { // process
118 
119  STATUS("event: " << setw(10) << number_of_events << '\r'); DEBUG(endl);
120 
121  const entry_type& top = buffer.top();
122 
123  outputFile.put(top.evt);
124 
125  if (in[top.index].hasNext()) {
126 
127  buffer.push({top.index, *in[top.index].next()});
128 
129  --number_of_events;
130  }
131 
132  buffer.pop();
133  }
134 
135  while (!buffer.empty()) { // flush
136 
137  const entry_type& top = buffer.top();
138 
139  outputFile.put(top.evt);
140 
141  buffer.pop();
142  }
143 
144 #else
145 
146  vector<entry_type> buffer; // multiplex
147 
148  for (size_t i = 0; i != N; ++i) {
149 
150  if (in[i].hasNext()) {
151 
152  buffer.push_back({i, *in[i].next()});
153 
154  --number_of_events;
155  }
156  }
157 
158  make_heap(buffer.begin(), buffer.end());
159 
160  while (number_of_events != 0) { // process
161 
162  STATUS("event: " << setw(10) << number_of_events << '\r'); DEBUG(endl);
163 
164  const size_t index = buffer[0].index;
165 
166  outputFile.put(buffer[0].evt);
167 
168  pop_heap(buffer.begin(), buffer.end());
169 
170  buffer.pop_back();
171 
172  if (in[index].hasNext()) {
173 
174  buffer.push_back({index, *in[index].next()});
175 
176  push_heap(buffer.begin(), buffer.end());
177 
178  --number_of_events;
179  }
180  }
181 
182  sort_heap(buffer.begin(), buffer.end()); // flush
183 
184  for (vector<entry_type>::const_reverse_iterator top = buffer.rbegin(); top != buffer.rend(); ++top) {
185  outputFile.put(top->evt);
186  }
187 #endif
188  STATUS(endl);
189 
190  int counter = 0;
191 
192  Head h0;
193  MultiHead m0;
194 
195  for (size_t i = 0; i != N; ++i) {
196 
197  try {
198 
199  const Head h1 = getHeader (inputFile[i]);
200  const MultiHead m1 = getMultiHeader(inputFile[i]);
201 
202  if (counter == 0) {
203 
204  outputFile.put(h1);
205  outputFile.put(m1);
206 
207  } else {
208 
209  if (h0 != h1) { FATAL("Inconsistent header " << endl << h1 << endl << "!=" << endl << h0 << endl); }
210  if (m0 != m1) { FATAL("Inconsistent multi header " << endl << m1 << endl << "!=" << endl << m0 << endl); }
211  }
212 
213  counter += 1;
214 
215  h0 = h1;
216  m0 = m1;
217  }
218  catch (const exception&) {}
219  }
220 
221  if (counter == 0) {
222  FATAL("Missing header." << endl);
223  }
224 
225  for (size_t i = 0; i != N; ++i) {
226 
227  JSingleFileScanner<JMeta> io(inputFile[i]);
228 
229  io >> outputFile;
230  }
231 
232  outputFile.close();
233 
234  return 0;
235 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1711
#define STATUS(A)
Definition: JMessage.hh:63
Long64_t counter_type
Type definition for counter.
string outputFile
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Type list.
Definition: JTypeList.hh:22
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
JMultiHead getMultiHeader(const JMultipleFileScanner_t &file_list)
Get multi-header corresponding to a given file list.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Object reading from a list of files.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62