Jpp  17.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDiffAcousticsEvent.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <algorithm>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 
9 #include "JAcoustics/JEvent.hh"
10 #include "JAcoustics/JSupport.hh"
11 
13 
14 #include "JLang/JComparator.hh"
15 #include "JLang/JComparison.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 namespace {
21 
23  using JACOUSTICS::JEvent;
24 
25  const struct {
26 
27  /**
28  * Compare transmissions.
29  *
30  * \param first first transmission
31  * \param second second transmission
32  * \return true if first transmission less than second; else false
33  */
34  inline bool operator()(const JTransmission& first, const JTransmission& second) const
35  {
36  if (first.getRunNumber() == second.getRunNumber()) {
37 
38  if (first.getID() == second.getID()) {
39 
40  if (first.getToA() == second.getToA()) {
41 
42  return first.getQ() < second.getQ();
43 
44  } else {
45 
46  return first.getToA() < second.getToA();
47  }
48 
49  } else {
50 
51  return first.getID() < second.getID();
52  }
53 
54  } else {
55 
56  return first.getRunNumber() < second.getRunNumber();
57  }
58  }
59 
60 
61  /**
62  * Compare events.
63  *
64  * \param first first event
65  * \param second second event
66  * \return true if first event less than second; else false
67  */
68  inline bool operator()(const JEvent& first, const JEvent& second) const
69  {
70  if (first.getOID() == second.getOID()) {
71 
72  if (first.getCounter() == second.getCounter()) {
73 
74  if (first.getID() == second.getID()) {
75 
76  if (first.size() == second.size()) {
77 
78  for (JEvent::const_iterator
79  p0 = first .begin(),
80  p1 = second.begin(); p0 != first.end() && p1 != second.end(); ++p0, ++p1) {
81 
82  if ((*this)(*p0, *p1)) {
83  return true;
84  }
85  }
86 
87  return false;
88 
89  } else {
90 
91  return first.size() < second.size();
92  }
93 
94  } else {
95 
96  return first.getID() < second.getID();
97  }
98 
99  } else {
100 
101  return first.getCounter() < second.getCounter();
102  }
103 
104  } else {
105 
106  return first.getOID() < second.getOID();
107  }
108  }
109  } compare;
110 
111 
112  /**
113  * Printer.
114  */
115  struct printer {
116 
117  int debug;
118  size_t width;
119 
120  /**
121  * Print data.
122  *
123  * \param out output stream
124  * \param filename file name
125  * \param index index
126  * \param evt event
127  * \param prefix prefix
128  * \param postfix postfix
129  * \return output stream
130  */
131  std::ostream& operator()(std::ostream& out, const std::string& filename, const int index, const JEvent& evt, const std::string& prefix, const std::string& postfix) const
132  {
133  using namespace std;
134  using namespace JPP;
135 
136  if (debug >= debug_t) {
137  out << prefix << (prefix == "" ? "" : " ")
138  << setw(width) << left << filename << right << ' '
139  << "[" << FILL(6,'0') << index << "]" << FILL() << ' '
140  << evt.getOID() << ' '
141  << setw(6) << evt.getCounter() << ' '
142  << setw(2) << evt.getID() << ' '
143  << FIXED(12,6) << evt.begin()->getToE()
144  << (postfix == "" ? "" : " ") << postfix << endl;
145  }
146 
147  return out;
148  }
149 
150 
151  /**
152  * Write transmission to output stream.
153  *
154  * \param out output stream
155  * \param object transmission
156  * \param prefix prefix
157  * \param postfix postfix
158  * \return output stream
159  */
160  std::ostream& operator()(std::ostream& out, const JTransmission& object, const std::string& prefix, const std::string& postfix) const
161  {
162  using namespace std;
163  using namespace JPP;
164 
165  if (debug >= debug_t) {
166  out << prefix << (prefix == "" ? "" : " ")
167  << setw(8) << object.getID() << ' '
168  << setw(8) << object.getRunNumber() << ' '
169  << FIXED(13,7) << object.getToA() << ' '
170  //<< "(" << FIXED(13,7) << object.getToE() << ")" << ' '
171  << FIXED(8,0) << object.getQ()
172  << (postfix == "" ? "" : " ") << postfix << endl;
173  }
174 
175  return out;
176  }
177  };
178 }
179 
180 /**
181  * \file
182  *
183  * Program to compare acoustics event data.
184  * \author mdejong
185  */
186 int main(int argc, char **argv)
187 {
188  using namespace std;
189  using namespace JPP;
190 
191  vector<string> inputFile;
192  JLimit numberOfEvents;
193  int debug;
194 
195  try {
196 
197  JParser<> zap("Program to compare acoustics event data.");
198 
199  zap['f'] = make_field(inputFile, "two outputs of JAcousticsEventBuilder[.sh]");
200  zap['n'] = make_field(numberOfEvents) = JLimit::max();
201  zap['d'] = make_field(debug) = 2;
202 
203  zap(argc, argv);
204  }
205  catch(const exception &error) {
206  FATAL(error.what() << endl);
207  }
208 
209  if (inputFile.size() != 2u) {
210  FATAL("Wrong number of input files " << inputFile.size() << endl);
211  }
212 
213  const size_t width = max(inputFile[0].size(), inputFile[1].size());
214  const printer print = { debug, width };
215 
216  vector<JEvent> buffer[2];
217 
218  for (int i = 0; i != 2; ++i) {
219 
220  for (JSingleFileScanner<JEvent> in(inputFile[i], numberOfEvents); in.hasNext(); ) {
221  buffer[i].push_back(*in.next());
222  }
223  }
224 
225  if (false) {
226 
227  for (int i = 0; i != 2; ++i) {
228 
229  sort(buffer[i].begin(), buffer[i].end());
230 
231  for (vector<JEvent>::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
232  sort(p->begin(), p->end(), make_comparator(&JTransmission::getToA, JComparison::lt()));
233  }
234  }
235  }
236 
237  int count[] = { 0, 0 };
238 
240  p0 = buffer[0].begin(),
241  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
242 
243  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && *p0 < *p1; ++p0, ++count[1]) {
244  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
245  }
246 
247  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && *p1 < *p0; ++p1, ++count[1]) {
248  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
249  }
250 
251  if (p0 != buffer[0].end() && p1 != buffer[1].end()) {
252 
253  if (!compare(*p0,*p1) && !compare(*p1,*p0)) {
254 
255  ++count[0];
256 
257  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\");
258  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ ");
259 
260  } else {
261 
262  ++count[1];
263 
264  if (p0->getOID() == p1->getOID() &&
265  p0->getCounter() == p1->getCounter() &&
266  p0->getID() == p1->getID()) {
267 
268  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "");
269  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "");
270 
271  JEvent::const_iterator i0 = p0->begin();
272  JEvent::const_iterator i1 = p1->begin();
273 
274  for ( ; i0 != p0->end() && i1 != p1->end(); ++i0, ++i1) {
275  if (compare(*i0, *i1) || compare(*i1,*i0)) {
276  print(cout, *i0, ">>", "");
277  print(cout, *i1, "<<", "");
278  }
279  }
280 
281  for ( ; i0 != p0->end(); ++i0) {
282  print(cout, *i0, ">>", "");
283  }
284 
285  for ( ; i1 != p1->end(); ++i1) {
286  print(cout, *i1, "<<", "");
287  }
288 
289  } else {
290 
291  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
292  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
293  }
294  }
295 
296  if (*p0 < *p1 || *p1 < *p0) {
297 
298  } else {
299 
300  ++p0;
301  ++p1;
302  }
303  }
304  }
305 
306  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
307 
308  if (buffer[0].size() != buffer[1].size()) {
309  FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl);
310  }
311 
312  if (count[1] != 0) {
313  FATAL("Number of differences " << count[1] << endl);
314  }
315 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
double getQ() const
Get quality.
TPaveText * p1
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
int getRunNumber() const
Get run number.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
Acoustic event.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Scanning of objects from a single file according a format that follows from the extension of each fil...
JFIT::JEvent JEvent
Definition: JHistory.hh:328
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Acoustic transmission.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
const std::string & getOID() const
Get detector identifier.
int debug
debug level
Definition: JSirene.cc:66
print
Definition: JConvertDusj.sh:44
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
std::vector< int > count
Definition: JAlgorithm.hh:180
Utility class to parse command line options.
int getCounter() const
Get counter.
double getToA() const
Get calibrated time of arrival.
int getID() const
Get identifier.
Acoustic event.
Object reading from a list of files.
int getID() const
Get identifier.
double u[N+1]
Definition: JPolint.hh:755
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