Jpp  18.2.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/JException.hh"
15 #include "JLang/JComparator.hh"
16 #include "JLang/JComparison.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 namespace {
22 
25  using JACOUSTICS::JEvent;
26 
27  enum JCompare_t {
28  ToA_t = 1,
29  ToE_t = 2
30  };
31 
32  int cta = 0; // time selection
33 
34  const struct {
35 
36  /**
37  * Compare transmissions.
38  *
39  * \param first first transmission
40  * \param second second transmission
41  * \return true if first transmission less than second; else false
42  */
43  inline bool operator()(const JTransmission& first, const JTransmission& second) const
44  {
45  if (cta != ToA_t && cta != ToE_t) {
46  THROW(JValueOutOfRange, "Invalid time selection " << cta);
47  }
48 
49  if (first.getRunNumber() == second.getRunNumber()) {
50 
51  if (first.getID() == second.getID()) {
52 
53  if ((cta == ToA_t && first.getToA() == second.getToA()) ||
54  (cta == ToE_t && first.getToE() == second.getToE())) {
55 
56  if (first.getQ() == second.getQ()) {
57 
58  return first.getW() < second.getW();
59 
60  } else {
61 
62  return first.getQ() < second.getQ();
63  }
64 
65  } else {
66 
67  if (cta == ToA_t) { return first.getToA() < second.getToA(); }
68  if (cta == ToE_t) { return first.getToE() < second.getToE(); }
69 
70  THROW(JValueOutOfRange, "Invalid time selection " << cta);
71  }
72 
73  } else {
74 
75  return first.getID() < second.getID();
76  }
77 
78  } else {
79 
80  return first.getRunNumber() < second.getRunNumber();
81  }
82  }
83 
84 
85  /**
86  * Compare events.
87  *
88  * \param first first event
89  * \param second second event
90  * \return true if first event less than second; else false
91  */
92  inline bool operator()(const JEvent& first, const JEvent& second) const
93  {
94  if (first.getOID() == second.getOID()) {
95 
96  if (first.getID() == second.getID()) {
97 
98  if (first.size() == second.size()) {
99 
100  for (JEvent::const_iterator
101  p0 = first .begin(),
102  p1 = second.begin(); p0 != first.end() && p1 != second.end(); ++p0, ++p1) {
103 
104  if ((*this)(*p0, *p1)) {
105  return true;
106  }
107  }
108 
109  return false;
110 
111  } else {
112 
113  return first.size() < second.size();
114  }
115 
116  } else {
117 
118  return first.getID() < second.getID();
119  }
120 
121  } else {
122 
123  return first.getOID() < second.getOID();
124  }
125  }
126  } compare;
127 
128 
129  /**
130  * Printer.
131  */
132  struct printer {
133 
134  int debug;
135  size_t width;
136 
137  /**
138  * Print data.
139  *
140  * \param out output stream
141  * \param filename file name
142  * \param index index
143  * \param evt event
144  * \param prefix prefix
145  * \param postfix postfix
146  * \return output stream
147  */
148  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
149  {
150  using namespace std;
151  using namespace JPP;
152 
153  if (debug >= debug_t) {
154  out << prefix << (prefix == "" ? "" : " ")
155  << setw(width) << left << filename << right << ' '
156  << "[" << FILL(6,'0') << index << "]" << FILL() << ' '
157  << evt.getOID() << ' '
158  << setw(6) << evt.getCounter() << ' '
159  << setw(2) << evt.getID() << ' '
160  << FIXED(12,6) << evt. begin()->getToA() << ' '
161  << FIXED(12,6) << evt.rbegin()->getToA()
162  << (postfix == "" ? "" : " ") << postfix << endl;
163  }
164 
165  return out;
166  }
167 
168 
169  /**
170  * Write transmission to output stream.
171  *
172  * \param out output stream
173  * \param object transmission
174  * \param prefix prefix
175  * \param postfix postfix
176  * \return output stream
177  */
178  std::ostream& operator()(std::ostream& out, const JTransmission& object, const std::string& prefix, const std::string& postfix) const
179  {
180  using namespace std;
181  using namespace JPP;
182 
183  if (debug >= debug_t) {
184  out << prefix << (prefix == "" ? "" : " ")
185  << setw(8) << object.getID() << ' '
186  << setw(8) << object.getRunNumber() << ' '
187  << FIXED(13,7) << object.getToA() << ' '
188  << FIXED(13,7) << object.getToE() << ' '
189  << FIXED(8,0) << object.getQ()
190  << (postfix == "" ? "" : " ") << postfix << endl;
191  }
192 
193  return out;
194  }
195  };
196 
197 
198  /**
199  * Compare acoustics events by time of arrival of first hit.
200  *
201  * \param first first event
202  * \param second second event
203  * \return true if first event earliear than second; else false
204  */
205  static inline bool toa(const JEvent& first, const JEvent& second)
206  {
207  return first.begin()->getToA() < second.begin()->getToA();
208  }
209 
210 
211  /**
212  * Compare acoustics events by time of emission of first hit.
213  *
214  * \param first first event
215  * \param second second event
216  * \return true if first event earliear than second; else false
217  */
218  static inline bool toe(const JEvent& first, const JEvent& second)
219  {
220  return first.begin()->getToE() < second.begin()->getToE();
221  }
222 
223 
224  /**
225  * Options.
226  */
227  enum JOption_t {
228  Null_t = 0,
229  Sort_t = 1
230  };
231 }
232 
233 /**
234  * \file
235  *
236  * Program to compare acoustics event data.
237  * \author mdejong
238  */
239 int main(int argc, char **argv)
240 {
241  using namespace std;
242  using namespace JPP;
243 
244  vector<string> inputFile;
245  JLimit numberOfEvents;
246  int option;
247  int debug;
248 
249  try {
250 
251  JParser<> zap("Program to compare acoustics event data.");
252 
253  zap['f'] = make_field(inputFile, "two outputs of JAcousticsEventBuilder[.sh]");
254  zap['n'] = make_field(numberOfEvents) = JLimit::max();
255  zap['O'] = make_field(option, Null_t << " -> nothing " << Sort_t << " -> sort") = Null_t, Sort_t;
256  zap['C'] = make_field(cta, ToA_t << " -> ToA " << ToE_t << " -> ToE") = ToA_t, ToE_t;
257  zap['d'] = make_field(debug) = 2;
258 
259  zap(argc, argv);
260  }
261  catch(const exception &error) {
262  FATAL(error.what() << endl);
263  }
264 
265  if (inputFile.size() != 2u) {
266  FATAL("Wrong number of input files " << inputFile.size() << endl);
267  }
268 
269  const size_t width = max(inputFile[0].size(), inputFile[1].size());
270  const printer print = { debug, width };
271 
272  vector<JEvent> buffer[2];
273 
274  for (int i = 0; i != 2; ++i) {
275 
276  for (JSingleFileScanner<JEvent> in(inputFile[i], numberOfEvents); in.hasNext(); ) {
277  buffer[i].push_back(*in.next());
278  }
279  }
280 
281  if (option == Sort_t) {
282 
283  for (int i = 0; i != 2; ++i) {
284 
285  for (JEvent& evt : buffer[i]) {
286  sort(evt.begin(), evt.end(), compare);
287  }
288 
289  if (cta == ToA_t) { sort(buffer[i].begin(), buffer[i].end(), toa); }
290  if (cta == ToE_t) { sort(buffer[i].begin(), buffer[i].end(), toe); }
291 
292  for (vector<JEvent>::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
293  sort(p->begin(), p->end(), compare);
294  }
295  }
296  }
297 
298  int count[] = { 0, 0 };
299 
301  p0 = buffer[0].begin(),
302  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
303 
304  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && ((cta == ToA_t && toa(*p0,*p1)) || (cta == ToE_t && toe(*p0,*p1))); ++p0, ++count[1]) {
305  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
306  }
307 
308  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && ((cta == ToA_t && toa(*p1,*p0)) || (cta == ToE_t && toe(*p1,*p0))); ++p1, ++count[1]) {
309  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
310  }
311 
312  if (p0 != buffer[0].end() && p1 != buffer[1].end()) {
313 
314  if (!compare(*p0,*p1) && !compare(*p1,*p0)) {
315 
316  ++count[0];
317 
318  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\");
319  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ ");
320 
321  } else {
322 
323  ++count[1];
324 
325  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "*");
326  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "*");
327 
328  if (p0->getOID() == p1->getOID() &&
329  p0->getCounter() == p1->getCounter() &&
330  p0->getID() == p1->getID()) {
331 
332  JEvent::const_iterator i0 = p0->begin();
333  JEvent::const_iterator i1 = p1->begin();
334 
335  while (i0 != p0->end() && i1 != p1->end()) {
336 
337  for ( ; i0 != p0->end() && i1 != p1->end() && compare(*i0,*i1); ++i0) {
338  print(cout, *i0, ">>", "");
339  }
340 
341  for ( ; i0 != p0->end() && i1 != p1->end() && compare(*i1,*i0); ++i1) {
342  print(cout, *i1, "<<", "");
343  }
344 
345  if (i0 != p0->end() && i1 != p1->end()) {
346  if (!compare(*i0, *i1) && !compare(*i1,*i0)) {
347  ++i0;
348  ++i1;
349  }
350  }
351  }
352 
353  for ( ; i0 != p0->end(); ++i0) {
354  print(cout, *i0, ">>", "");
355  }
356 
357  for ( ; i1 != p1->end(); ++i1) {
358  print(cout, *i1, "<<", "");
359  }
360 
361  } else {
362 
363  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
364  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
365  }
366  }
367 
368  if (toa(*p0,*p1) || toa(*p1,*p0)) {
369 
370  } else {
371 
372  ++p0;
373  ++p1;
374  }
375  }
376  }
377 
378  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
379 
380  if (buffer[0].size() != buffer[1].size()) {
381  FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl);
382  }
383 
384  if (count[1] != 0) {
385  FATAL("Number of differences " << count[1] << endl);
386  }
387 }
Utility class to parse command line options.
Definition: JParser.hh:1514
Exceptions.
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
double getQ() const
Get quality.
TPaveText * p1
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.
int getCounter() const
Get counter.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Acoustic event.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double getToE() const
Get estimated time of emission.
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:353
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
double getW() const
Get normalisation.
Acoustic transmission.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
const std::string & getOID() const
Get detector identifier.
then awk string
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
JOption_t
Options.
Utility class to parse command line options.
double getToA() const
Get calibrated time of arrival.
int getID() const
Get identifier.
Acoustic event.
Object reading from a list of files.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
int getID() const
Get emitter identifier.
double u[N+1]
Definition: JPolint.hh:865
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
int debug
debug level