Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 }
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
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
#define STATUS(A)
Definition: JMessage.hh:63
Recording of objects on file according a format that follows from the file name extension.
string outputFile
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Type list.
Definition: JTypeList.hh:22
Scanning of objects from a single file according a format that follows from the extension of each fil...
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
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
ROOT I/O of application specific meta data.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
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:48
Utility class to parse command line options.
Object reading from a list of files.
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20