Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Enumerations | Functions
JDiffAcousticsEvent.cc File Reference

Program to compare acoustics event data. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JSupport.hh"
#include "JSupport/JSingleFileScanner.hh"
#include "JLang/JException.hh"
#include "JLang/JComparator.hh"
#include "JLang/JComparison.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Enumerations

enum  JCompare_t
 
enum  JOption_t
 Options. More...
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to compare acoustics event data.

Author
mdejong

Definition in file JDiffAcousticsEvent.cc.

Enumeration Type Documentation

enum JCompare_t

Definition at line 27 of file JDiffAcousticsEvent.cc.

27  {
28  ToA_t = 1,
29  ToE_t = 2
30  };
enum JOption_t

Options.

Definition at line 227 of file JDiffAcousticsEvent.cc.

227  {
228  Null_t = 0,
229  Sort_t = 1
230  };

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 239 of file JDiffAcousticsEvent.cc.

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  if (cta == ToA_t) { sort(buffer[i].begin(), buffer[i].end(), toa); }
286  if (cta == ToE_t) { sort(buffer[i].begin(), buffer[i].end(), toe); }
287 
288  for (vector<JEvent>::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
289  sort(p->begin(), p->end(), compare);
290  }
291  }
292  }
293 
294  int count[] = { 0, 0 };
295 
297  p0 = buffer[0].begin(),
298  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
299 
300  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && ((cta == ToA_t && toa(*p0,*p1)) || (cta == ToE_t && toe(*p0,*p1))); ++p0, ++count[1]) {
301  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
302  }
303 
304  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && ((cta == ToA_t && toa(*p1,*p0)) || (cta == ToE_t && toe(*p1,*p0))); ++p1, ++count[1]) {
305  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
306  }
307 
308  if (p0 != buffer[0].end() && p1 != buffer[1].end()) {
309 
310  if (!compare(*p0,*p1) && !compare(*p1,*p0)) {
311 
312  ++count[0];
313 
314  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\");
315  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ ");
316 
317  } else {
318 
319  ++count[1];
320 
321  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "*");
322  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "*");
323 
324  if (p0->getOID() == p1->getOID() &&
325  p0->getCounter() == p1->getCounter() &&
326  p0->getID() == p1->getID()) {
327 
328  JEvent::const_iterator i0 = p0->begin();
329  JEvent::const_iterator i1 = p1->begin();
330 
331  while (i0 != p0->end() && i1 != p1->end()) {
332 
333  for ( ; i0 != p0->end() && i1 != p1->end() && compare(*i0,*i1); ++i0) {
334  print(cout, *i0, ">>", "");
335  }
336 
337  for ( ; i0 != p0->end() && i1 != p1->end() && compare(*i1,*i0); ++i1) {
338  print(cout, *i1, "<<", "");
339  }
340 
341  if (i0 != p0->end() && i1 != p1->end()) {
342  if (!compare(*i0, *i1) && !compare(*i1,*i0)) {
343  ++i0;
344  ++i1;
345  }
346  }
347  }
348 
349  for ( ; i0 != p0->end(); ++i0) {
350  print(cout, *i0, ">>", "");
351  }
352 
353  for ( ; i1 != p1->end(); ++i1) {
354  print(cout, *i1, "<<", "");
355  }
356 
357  } else {
358 
359  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
360  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
361  }
362  }
363 
364  if (toa(*p0,*p1) || toa(*p1,*p0)) {
365 
366  } else {
367 
368  ++p0;
369  ++p1;
370  }
371  }
372  }
373 
374  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
375 
376  if (buffer[0].size() != buffer[1].size()) {
377  FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl);
378  }
379 
380  if (count[1] != 0) {
381  FATAL("Number of differences " << count[1] << endl);
382  }
383 }
Utility class to parse command line options.
Definition: JParser.hh:1514
TPaveText * p1
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
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
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
Object reading from a list of files.
double u[N+1]
Definition: JPolint.hh:776
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