Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMergeFit.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <algorithm>
7 #include <iterator>
8 
12 
13 #include "JDAQ/JDAQEventIO.hh"
14 #include "JDAQ/JDAQTimesliceIO.hh"
16 #include "JDAQ/JDAQEvaluator.hh"
18 
20 #include "JSupport/JTreeScanner.hh"
22 #include "JSupport/JSupport.hh"
23 #include "JSupport/JMeta.hh"
24 
25 #include "JReconstruction/JEvt.hh"
26 
27 #include "Jeep/JParser.hh"
28 #include "Jeep/JMessage.hh"
29 
30 
31 namespace {
32 
35  using JFIT::JEvt;
37 
38  /**
39  * Auxiliary class for TTree routing.
40  */
41  struct JTreeRouter_t {
42  /**
43  * Default constructor.
44  */
45  JTreeRouter_t()
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param file_name file name
53  */
54  JTreeRouter_t(const std::string& input_file) :
55  indexer(input_file),
56  scanner(input_file)
57  {}
58 
59 
60  /**
61  * Get reconstructed event corresponding to given DAQ event.
62  *
63  * \param evt DAQ event
64  * \return reconstructed event
65  */
66  const JEvt* get(const JDAQEvent& evt)
67  {
68  const Long64_t i = indexer.find(evt);
69  const JDAQEvent* p = indexer.getEntry(i);
70 
71  if (p != NULL && evt.getDAQEventHeader().is_same(p->getDAQEventHeader()))
72  return scanner.getEntry(i);
73  else
74  return NULL;
75  }
76 
78  JTreeScanner<JEvt> scanner;
79  };
80 }
81 
82 
83 /**
84  * \file
85  *
86  * Program to merge different files with JFIT::JEvt data.
87  * \author mdejong
88  */
89 int main(int argc, char **argv)
90 {
91  using namespace std;
92  using namespace JPP;
93  using namespace KM3NETDAQ;
94 
95  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
96  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
97 
99  typedef JRemove<typelist1, JEvt>::typelist typelist2;
101 
102  vector<std::string> inputFile;
104  int debug;
105 
106  try {
107 
108  JParser<> zap("Program to merge different files with JFIT::JEvt data " \
109  "(e.g. from JMuonXXX[.sh] and JShowerXXX[.sh] applied to the same input data)." \
110  "\nThe input files should be event-by-event synchronised.");
111 
112  zap['f'] = make_field(inputFile, "list of JEvt compatible files");
113  zap['o'] = make_field(outputFile, "single file with merged JEvt data");
114  zap['d'] = make_field(debug) = 1;
115 
116  zap(argc, argv);
117  }
118  catch(const exception& error) {
119  FATAL(error.what() << endl);
120  }
121 
122  cout.tie(&cerr);
123 
124  if (inputFile.empty()) {
125  FATAL("No input files." << endl);
126  }
127 
128  outputFile.open();
129 
130  outputFile.put(JMeta(argc, argv));
131 
132  JParallelFileScanner_t in(inputFile[0]);
133 
134  vector<JTreeRouter_t> buffer(1); // skip one entry
135 
136  for (size_t i = 1; i != inputFile.size(); ++i) {
137  buffer.push_back(JTreeRouter_t(inputFile[i]));
138  }
139 
140  while (in.hasNext()) {
141 
142  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
143 
144  multi_pointer_type ps = in.next();
145 
146  const JDAQEvent* tev = ps;
147  const JEvt* evt = ps;
148 
149  JEvt out(*evt);
150 
151  for (size_t i = 1; i != inputFile.size(); ++i) {
152 
153  const JEvt* p = buffer[i].get(*tev);
154 
155  if (p != NULL) {
156 
157  copy(p->begin(), p->end(), back_inserter(out));
158 
159  } else {
160 
161  FATAL("Inconsistent data at " << in.getFilename() << ":" << in.getCounter() << endl);
162  }
163  }
164 
165  outputFile.put(out);
166  }
167  STATUS(endl);
168 
169  JMultipleFileScanner<typelist3> io(inputFile[0]);
170 
171  io >> outputFile;
172 
173  JMultipleFileScanner<JMetaTypes_t> meta(inputFile);
174 
175  meta >> outputFile;
176 
177  outputFile.close();
178 }
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:1500
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.
General purpose class for parallel reading of objects from a single file or multiple files...
Removal of data type from type list.
Definition: JTypeList.hh:114
string outputFile
Template definition for direct access of elements in ROOT TChain.
Type list.
Definition: JTypeList.hh:22
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
ROOT I/O of application specific meta data.
int debug
debug level
Definition: JSirene.cc:67
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
bool is_same(const JDAQEventHeader &header) const
Check if header is same.
Auxiliary class to determine value of DAQ objects.
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
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62