Jpp  18.0.0-rc.3
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);
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  for (size_t i = 0; i != N; ++i) {
191 
193 
194  io >> outputFile;
195  }
196 
197  outputFile.close();
198 
199  return 0;
200 }
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:1514
#define STATUS(A)
Definition: JMessage.hh:63
Long64_t counter_type
Type definition for counter.
string outputFile
Type list.
Definition: JTypeList.hh:22
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:36
Object reading from a list of files.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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:46
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62