Jpp  19.1.0
the software that should make you happy
JGizmo/JEvt.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <string>
4 #include <vector>
5 #include <algorithm>
6 
10 
11 #include "JSupport/JMeta.hh"
12 #include "JSupport/JSupport.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 
21 namespace {
22 
23  /**
24  * Auxiliary data structure for sorting of Monte Carlo events.
25  */
26  static const struct {
27  /**
28  * Compare two events.
29  *
30  * \param first first event
31  * \param second second event
32  * \return true if first event earlier than second; else false
33  */
34  inline double operator()(const Evt& first, const Evt& second) const
35  {
36  if (first.mc_event_time != second.mc_event_time)
37  return first.mc_event_time.AsDouble() < second.mc_event_time.AsDouble();
38  else
39  return first.mc_id < second.mc_id;
40 
41  }
42  } compare;
43 }
44 
45 
46 /**
47  * \file
48  * Auxiliary program for time sorting of Monte-Carlo events.
49  *
50  * \author mdejong
51  */
52 int main(int argc, char **argv)
53 {
54  using namespace std;
55  using namespace JPP;
56 
57  typedef typename JTYPELIST<Head, MultiHead, Evt, JMeta>::typelist typelist;
58 
59  string inputFile;
60  JLimit_t numberOfEvents;
62  int debug;
63 
64  try {
65 
66  JParser<> zap("Auxiliary program for time sorting of Monte-Carlo events.");
67 
68  zap['f'] = make_field(inputFile);
69  zap['n'] = make_field(numberOfEvents) = JLimit::max();
70  zap['o'] = make_field(outputFile);
71  zap['d'] = make_field(debug) = 1;
72 
73  zap(argc, argv);
74  }
75  catch(const exception& error) {
76  FATAL(error.what() << endl);
77  }
78 
79 
80  STATUS("Processing " << inputFile << "." << flush);
81 
82  vector<Evt> buffer;
83 
84  for (JSingleFileScanner<Evt> in(inputFile, numberOfEvents); in.hasNext(); ) {
85  buffer.push_back(*in.next());
86  }
87 
88  STATUS("." << flush);
89 
90  sort(buffer.begin(), buffer.end(), compare);
91 
92  STATUS("OK" << endl);
93 
94  outputFile.open();
95 
96  outputFile.put(JMeta(argc, argv));
97 
98  for (vector<Evt>::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
99  outputFile.put(*i);
100  }
101 
103 
104  io >> outputFile;
105 
106  outputFile.close();
107 }
string outputFile
Recording of objects on file according a format that follows from the file name extension.
int main(int argc, char **argv)
Definition: JGizmo/JEvt.cc:52
General purpose messaging.
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Scanning of objects from a single file according a format that follows from the extension of each fil...
ROOT TTree parameter settings of various packages.
Utility class to parse command line options.
Definition: JParser.hh:1698
Object writing to file.
Object reading from a list of files.
virtual bool hasNext() override
Check availability of next element.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:24
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
Definition: Evt.hh:46
Type list.
Definition: JTypeList.hh:23
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72