Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDiffToAshort.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 "JDB/JToAshort.hh"
10 #include "JDB/JSupport.hh"
11 
13 
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 namespace {
18 
20 
21  /**
22  * Compare measured times of arrival.
23  *
24  * \param first first time-of-arrival
25  * \param second second time-of-arrival
26  * \return true if first time-of-arrival less than second; else false
27  */
28  inline bool compare(const JToAshort& first, const JToAshort& second)
29  {
30  if (first.DETID == second.DETID) {
31 
32  if (first.RUN == second.RUN) {
33 
34  if (first.DOMID == second.DOMID) {
35 
36  if (first.EMITTERID == second.EMITTERID) {
37 
38  if (first.UNIXTIMEBASE == second.UNIXTIMEBASE) {
39 
40  if (first.TOA_S == second.TOA_S) {
41 
42  return first.QUALITYFACTOR < second.QUALITYFACTOR;
43 
44  } else {
45 
46  return first.TOA_S < second.TOA_S;
47  }
48 
49  } else {
50 
51  return first.UNIXTIMEBASE < second.UNIXTIMEBASE;
52  }
53 
54  } else {
55 
56  return first.EMITTERID < second.EMITTERID;
57  }
58 
59  } else {
60 
61  return first.DOMID < second.DOMID;
62  }
63 
64  } else {
65 
66  return first.RUN < second.RUN;
67  }
68 
69  } else {
70 
71  return first.DETID < second.DETID;
72  }
73  }
74 
75  /**
76  * Write time-of-arrival to outout stream.
77  *
78  * \param out output stream
79  * \param object time-of-arrival
80  * \return output stream
81  */
82  std::ostream& operator<<(std::ostream& out, const JToAshort& object)
83  {
84  using namespace std;
85  using namespace JPP;
86 
87  out << setw(8) << object.RUN << ' '
88  << setw(8) << object.DOMID << ' '
89  << setw(2) << object.EMITTERID << ' '
90  << FIXED(15,1) << object.UNIXTIMEBASE << ' '
91  << FIXED( 9,6) << object.TOA_S << ' '
92  << FIXED( 9,3) << object.QUALITYFACTOR;
93 
94  return out;
95  }
96 }
97 
98 /**
99  * \file
100  *
101  * Program to compare toashort data.
102  * \author mdejong
103  */
104 int main(int argc, char **argv)
105 {
106  using namespace std;
107  using namespace JPP;
108 
109  vector<string> inputFile;
110  JLimit numberOfEvents;
111  int debug;
112 
113  try {
114 
115  JParser<> zap("Program to compare toashort data.");
116 
117  zap['f'] = make_field(inputFile, "two outputs of JConvertDB -q toashort");
118  zap['n'] = make_field(numberOfEvents) = JLimit::max();
119  zap['d'] = make_field(debug) = 2;
120 
121  zap(argc, argv);
122  }
123  catch(const exception &error) {
124  FATAL(error.what() << endl);
125  }
126 
127  if (inputFile.size() != 2u) {
128  FATAL("Wrong number of input files " << inputFile.size() << endl);
129  }
130 
131  const size_t width = max(inputFile[0].size(), inputFile[1].size());
132 
133  vector<JToAshort> buffer[2];
134 
135  for (int i = 0; i != 2; ++i) {
136 
137  for (JSingleFileScanner<JToAshort> in(inputFile[i], numberOfEvents); in.hasNext(); ) {
138  buffer[i].push_back(*in.next());
139  }
140 
141  sort(buffer[i].begin(), buffer[i].end(), compare);
142  }
143 
144  int count[] = { 0, 0 };
145 
147  p0 = buffer[0].begin(),
148  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
149 
150  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p0,*p1); ++p0, ++count[1]) {
151  DEBUG(">> " << setw(width) << left << inputFile[0] << right << ' ' << *p0 << endl);
152  }
153 
154  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p1,*p0); ++p1, ++count[1]) {
155  DEBUG("<< " << setw(width) << left << inputFile[1] << right << ' ' << *p1 << endl);
156  }
157 
158  if (p0 != buffer[0].end() && p1 != buffer[1].end() && !compare(*p0,*p1) && !compare(*p1,*p0)) {
159 
160  ++count[0];
161 
162  DEBUG(setw(width) << left << inputFile[0] << right << ' ' << *p0 << " \\" << endl);
163  DEBUG(setw(width) << left << inputFile[1] << right << ' ' << *p1 << " / " << endl);
164 
165  ++p0;
166  ++p1;
167  }
168  }
169 
170  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
171 
172  if (buffer[0].size() != buffer[1].size()) {
173  FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl);
174  }
175 
176  if (count[1] != 0) {
177  FATAL("Number of differences " << count[1] << endl);
178  }
179 }
double UNIXTIMEBASE
[s]
Definition: JToAshort.hh:25
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
TPaveText * p1
#define STATUS(A)
Definition: JMessage.hh:63
std::string DETID
constraint
Definition: JToAshort.hh:22
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...
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
ROOT TTree parameter settings.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
double TOA_S
[s]
Definition: JToAshort.hh:28
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
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 EMITTERID
waveform identifier
Definition: JToAshort.hh:27
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62