Jpp  17.3.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  if (first.getQ() == second.getQ()) {
43 
44  return first.getW() < second.getW();
45 
46  } else {
47 
48  return first.getQ() < second.getQ();
49  }
50 
51  } else {
52 
53  return first.getToA() < second.getToA();
54  }
55 
56  } else {
57 
58  return first.getID() < second.getID();
59  }
60 
61  } else {
62 
63  return first.getRunNumber() < second.getRunNumber();
64  }
65  }
66 
67 
68  /**
69  * Compare events.
70  *
71  * \param first first event
72  * \param second second event
73  * \return true if first event less than second; else false
74  */
75  inline bool operator()(const JEvent& first, const JEvent& second) const
76  {
77  if (first.getOID() == second.getOID()) {
78 
79  if (first.getCounter() == second.getCounter()) {
80 
81  if (first.getID() == second.getID()) {
82 
83  if (first.size() == second.size()) {
84 
85  for (JEvent::const_iterator
86  p0 = first .begin(),
87  p1 = second.begin(); p0 != first.end() && p1 != second.end(); ++p0, ++p1) {
88 
89  if ((*this)(*p0, *p1)) {
90  return true;
91  }
92  }
93 
94  return false;
95 
96  } else {
97 
98  return first.size() < second.size();
99  }
100 
101  } else {
102 
103  return first.getID() < second.getID();
104  }
105 
106  } else {
107 
108  return first.getCounter() < second.getCounter();
109  }
110 
111  } else {
112 
113  return first.getOID() < second.getOID();
114  }
115  }
116  } compare;
117 
118 
119  /**
120  * Printer.
121  */
122  struct printer {
123 
124  int debug;
125  size_t width;
126 
127  /**
128  * Print data.
129  *
130  * \param out output stream
131  * \param filename file name
132  * \param index index
133  * \param evt event
134  * \param prefix prefix
135  * \param postfix postfix
136  * \return output stream
137  */
138  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
139  {
140  using namespace std;
141  using namespace JPP;
142 
143  if (debug >= debug_t) {
144  out << prefix << (prefix == "" ? "" : " ")
145  << setw(width) << left << filename << right << ' '
146  << "[" << FILL(6,'0') << index << "]" << FILL() << ' '
147  << evt.getOID() << ' '
148  << setw(6) << evt.getCounter() << ' '
149  << setw(2) << evt.getID() << ' '
150  << FIXED(12,6) << evt.begin()->getToE()
151  << (postfix == "" ? "" : " ") << postfix << endl;
152  }
153 
154  return out;
155  }
156 
157 
158  /**
159  * Write transmission to output stream.
160  *
161  * \param out output stream
162  * \param object transmission
163  * \param prefix prefix
164  * \param postfix postfix
165  * \return output stream
166  */
167  std::ostream& operator()(std::ostream& out, const JTransmission& object, const std::string& prefix, const std::string& postfix) const
168  {
169  using namespace std;
170  using namespace JPP;
171 
172  if (debug >= debug_t) {
173  out << prefix << (prefix == "" ? "" : " ")
174  << setw(8) << object.getID() << ' '
175  << setw(8) << object.getRunNumber() << ' '
176  << FIXED(13,7) << object.getToA() << ' '
177  //<< "(" << FIXED(13,7) << object.getToE() << ")" << ' '
178  << FIXED(8,0) << object.getQ()
179  << (postfix == "" ? "" : " ") << postfix << endl;
180  }
181 
182  return out;
183  }
184  };
185 }
186 
187 /**
188  * \file
189  *
190  * Program to compare acoustics event data.
191  * \author mdejong
192  */
193 int main(int argc, char **argv)
194 {
195  using namespace std;
196  using namespace JPP;
197 
198  vector<string> inputFile;
199  JLimit numberOfEvents;
200  int debug;
201 
202  try {
203 
204  JParser<> zap("Program to compare acoustics event data.");
205 
206  zap['f'] = make_field(inputFile, "two outputs of JAcousticsEventBuilder[.sh]");
207  zap['n'] = make_field(numberOfEvents) = JLimit::max();
208  zap['d'] = make_field(debug) = 2;
209 
210  zap(argc, argv);
211  }
212  catch(const exception &error) {
213  FATAL(error.what() << endl);
214  }
215 
216  if (inputFile.size() != 2u) {
217  FATAL("Wrong number of input files " << inputFile.size() << endl);
218  }
219 
220  const size_t width = max(inputFile[0].size(), inputFile[1].size());
221  const printer print = { debug, width };
222 
223  vector<JEvent> buffer[2];
224 
225  for (int i = 0; i != 2; ++i) {
226 
227  for (JSingleFileScanner<JEvent> in(inputFile[i], numberOfEvents); in.hasNext(); ) {
228  buffer[i].push_back(*in.next());
229  }
230  }
231 
232  if (false) {
233 
234  for (int i = 0; i != 2; ++i) {
235 
236  sort(buffer[i].begin(), buffer[i].end());
237 
238  for (vector<JEvent>::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
239  sort(p->begin(), p->end(), make_comparator(&JTransmission::getToA, JComparison::lt()));
240  }
241  }
242  }
243 
244  int count[] = { 0, 0 };
245 
247  p0 = buffer[0].begin(),
248  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
249 
250  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && *p0 < *p1; ++p0, ++count[1]) {
251  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
252  }
253 
254  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && *p1 < *p0; ++p1, ++count[1]) {
255  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
256  }
257 
258  if (p0 != buffer[0].end() && p1 != buffer[1].end()) {
259 
260  if (!compare(*p0,*p1) && !compare(*p1,*p0)) {
261 
262  ++count[0];
263 
264  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\");
265  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ ");
266 
267  } else {
268 
269  ++count[1];
270 
271  if (p0->getOID() == p1->getOID() &&
272  p0->getCounter() == p1->getCounter() &&
273  p0->getID() == p1->getID()) {
274 
275  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "");
276  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "");
277 
278  JEvent::const_iterator i0 = p0->begin();
279  JEvent::const_iterator i1 = p1->begin();
280 
281  for ( ; i0 != p0->end() && i1 != p1->end(); ++i0, ++i1) {
282  if (compare(*i0, *i1) || compare(*i1,*i0)) {
283  print(cout, *i0, ">>", "");
284  print(cout, *i1, "<<", "");
285  }
286  }
287 
288  for ( ; i0 != p0->end(); ++i0) {
289  print(cout, *i0, ">>", "");
290  }
291 
292  for ( ; i1 != p1->end(); ++i1) {
293  print(cout, *i1, "<<", "");
294  }
295 
296  } else {
297 
298  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
299  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
300  }
301  }
302 
303  if (*p0 < *p1 || *p1 < *p0) {
304 
305  } else {
306 
307  ++p0;
308  ++p1;
309  }
310  }
311  }
312 
313  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
314 
315  if (buffer[0].size() != buffer[1].size()) {
316  FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl);
317  }
318 
319  if (count[1] != 0) {
320  FATAL("Number of differences " << count[1] << endl);
321  }
322 }
Utility class to parse command line options.
Definition: JParser.hh:1517
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.
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: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:1993
const std::string & getOID() const
Get detector identifier.
then awk string
static struct JACOUSTICS::@4 compare
Auxiliary data structure to sort transmissions.
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
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: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