Jpp  15.0.1-rc.2-highQE
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 
11 #include "JDAQ/JDAQEventIO.hh"
12 #include "JDAQ/JDAQTimesliceIO.hh"
14 #include "JDAQ/JDAQEvaluator.hh"
16 
18 #include "JSupport/JTreeScanner.hh"
20 #include "JSupport/JSupport.hh"
21 #include "JSupport/JMeta.hh"
22 
23 #include "JReconstruction/JEvt.hh"
24 
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 namespace {
30 
33  using JFIT::JEvt;
35 
36  /**
37  * Auxiliary class for TTree routing.
38  */
39  struct JTreeRouter_t {
40  /**
41  * Default constructor.
42  */
43  JTreeRouter_t()
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param file_name file name
51  */
52  JTreeRouter_t(const std::string& input_file) :
53  indexer(input_file),
54  scanner(input_file)
55  {}
56 
57 
58  /**
59  * Get reconstructed event corresponding to given DAQ event.
60  *
61  * \param evt DAQ event
62  * \return reconstructed event
63  */
64  const JEvt* get(const JDAQEvent& evt)
65  {
66  const Long64_t i = indexer.find(evt);
67  const JDAQEvent* p = indexer.getEntry(i);
68 
69  if (p != NULL && evt.getDAQEventHeader().is_same(p->getDAQEventHeader()))
70  return scanner.getEntry(i);
71  else
72  return NULL;
73  }
74 
76  JTreeScanner<JEvt> scanner;
77  };
78 }
79 
80 
81 /**
82  * \file
83  *
84  * Program to merge different files with JFIT::JEvt data.
85  * \author mdejong
86  */
87 int main(int argc, char **argv)
88 {
89  using namespace std;
90  using namespace JPP;
91  using namespace KM3NETDAQ;
92 
93  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
94  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
96 
97  vector<std::string> inputFile;
99  int debug;
100 
101  try {
102 
103  JParser<> zap("Program to merge different files with JFIT::JEvt data.");
104 
105  zap['f'] = make_field(inputFile, "list of JEvt compatible files");
106  zap['o'] = make_field(outputFile, "single file with merged JEvt data");
107  zap['d'] = make_field(debug) = 1;
108 
109  zap(argc, argv);
110  }
111  catch(const exception& error) {
112  FATAL(error.what() << endl);
113  }
114 
115  cout.tie(&cerr);
116 
117  if (inputFile.empty()) {
118  FATAL("No input files." << endl);
119  }
120 
121  outputFile.open();
122 
123  outputFile.put(JMeta(argc, argv));
124 
125 
126  JParallelFileScanner_t in(inputFile[0]);
127 
128  vector<JTreeRouter_t> buffer(1); // skip one entry
129 
130  for (size_t i = 1; i != inputFile.size(); ++i) {
131  buffer.push_back(JTreeRouter_t(inputFile[i]));
132  }
133 
134  while (in.hasNext()) {
135 
136  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
137 
138  multi_pointer_type ps = in.next();
139 
140  const JDAQEvent* tev = ps;
141  const JEvt* evt = ps;
142 
143  JEvt out(*evt);
144 
145  for (size_t i = 1; i != inputFile.size(); ++i) {
146 
147  const JEvt* p = buffer[i].get(*tev);
148 
149  if (p != NULL) {
150 
151  copy(p->begin(), p->end(), back_inserter(out));
152 
153  } else {
154 
155  FATAL("Inconsistent data at " << in.getFilename() << ":" << in.getCounter() << endl);
156  }
157  }
158 
159  outputFile.put(out);
160  }
161  STATUS(endl);
162 
164 
165  io >> outputFile;
166 
167  outputFile.close();
168 }
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...
string outputFile
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
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:63
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
const JDAQEventHeader & getDAQEventHeader() const
Get DAQ event header.