Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JToAshort.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <map>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 
9 #include "JDB/JToAshort.hh"
10 #include "JDB/JSupport.hh"
11 
12 #include "JLang/JPredicate.hh"
14 
16 
17 #include "Jeep/JPrint.hh"
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 namespace {
23 
24  using namespace JPP;
25 
26  /**
27  * Auxiliary class to extend JDATABASE::JToAshort.
28  */
29  struct JToAshort_t :
30  public JToAshort
31  {
32  /**
33  * Constructor.
34  *
35  * \param data data
36  * \param counter counter
37  */
38  JToAshort_t( const JToAshort& data, const int counter) :
39  JToAshort(data),
40  counter(counter)
41  {}
42 
43 
44  /**
45  * Write data to output stream.
46  *
47  * \param out output stream
48  * \param object object
49  * \return output stream
50  */
51  friend inline std::ostream& operator<<(std::ostream& out, const JToAshort_t& object)
52  {
53  using namespace std;
54  using namespace JPP;
55 
56  out << setw(6) << object.RUN << ' '
57  << setw(8) << object.counter << ' '
58  << FIXED(20,5) << object.UNIXTIMEBASE << ' '
59  << setw(10) << object.DOMID << ' '
60  << FIXED(9,6) << object.TOA_S << ' '
61  << FIXED(5,0) << object.QUALITYFACTOR;
62 
63  return out;
64  }
65 
66  int counter;
67  };
68 }
69 
70 
71 /**
72  * \file
73  *
74  * Example program to test acoustic data.
75  * \author mdejong
76  */
77 int main(int argc, char **argv)
78 {
79  using namespace std;
80  using namespace JPP;
81 
83  JLimit_t& numberOfEvents = inputFile.getLimit();
84  double precision;
85  bool allowed;
86  int debug;
87 
88  try {
89 
90  JParser<> zap("Example program to test acoustic data.");
91 
92  zap['f'] = make_field(inputFile);
93  zap['n'] = make_field(numberOfEvents) = JLimit::max();
94  zap['A'] = make_field(allowed);
95  zap['e'] = make_field(precision) = 1.0e-7;
96  zap['d'] = make_field(debug) = 2;
97 
98  zap(argc, argv);
99  }
100  catch(const exception &error) {
101  FATAL(error.what() << endl);
102  }
103 
104 
105  typedef vector<JToAshort_t> buffer_type; // acoustic data type
106 
107  map<int, map< int, buffer_type > > data; // emitter -> receiver -> data
108 
109  for (int counter = 0; inputFile.hasNext(); ++counter) {
110 
111  STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
112 
113  const JToAshort* parameters = inputFile.next();
114 
115  data[parameters->EMITTERID][parameters->DOMID].push_back(JToAshort_t(*parameters, counter));
116  }
117  STATUS(endl);
118 
119 
120  for (map<int, map< int, buffer_type> >::const_iterator i = data.begin(); i != data.end(); ++i) {
121 
122  for (map< int, buffer_type>::const_iterator module = i->second.begin(); module != i->second.end(); ++module) {
123 
124  const buffer_type& buffer = module->second;
125 
126  for (buffer_type::const_iterator p = buffer.begin(); p != buffer.end(); ++p) {
127  for (buffer_type::const_iterator q = buffer.begin(); q != p; ++q) {
128 
129  if (labs(p->DOMID - q->DOMID) == 0 &&
130  fabs(p->QUALITYFACTOR - q->QUALITYFACTOR) <= precision &&
131  fabs((p->UNIXTIMEBASE + p->TOA_S) -
132  (q->UNIXTIMEBASE + q->TOA_S)) <= precision) {
133 
134  if (!allowed || (p->TOA_S < TOAMAX_S &&
135  q->TOA_S < TOAMAX_S)) {
136 
137  cout << *p << endl;
138  cout << *q << endl;
139 
140  cout << "Difference between absolute times "
141  << SCIENTIFIC(12,3) << ((p->UNIXTIMEBASE + p->TOA_S) -
142  (q->UNIXTIMEBASE + q->TOA_S)) << endl;
143  }
144  }
145  }
146  }
147  }
148  }
149 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define STATUS(A)
Definition: JMessage.hh:63
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
static counter_type max()
Get maximum counter value.
Definition: JLimit.hh:117
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const double TOAMAX_S
Maximal allowed time-of-arrival [s].
I/O formatting auxiliaries.
Acoustics toolkit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT TTree parameter settings.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:483
int EMITTERID
waveform identifier
Definition: JToAshort.hh:27
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15