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 
17 
18 #include "Jeep/JPrint.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 namespace {
24 
25  using namespace JPP;
26 
27  /**
28  * Auxiliary class to extend JDATABASE::JToAshort.
29  */
30  struct JToAshort_t :
31  public JToAshort
32  {
33  /**
34  * Constructor.
35  *
36  * \param data data
37  * \param counter counter
38  */
39  JToAshort_t( const JToAshort& data, const int counter) :
40  JToAshort(data),
41  counter(counter)
42  {}
43 
44 
45  /**
46  * Write data to output stream.
47  *
48  * \param out output stream
49  * \param object object
50  * \return output stream
51  */
52  friend inline std::ostream& operator<<(std::ostream& out, const JToAshort_t& object)
53  {
54  using namespace std;
55  using namespace JPP;
56 
57  out << setw(6) << object.RUN << ' '
58  << setw(8) << object.counter << ' '
59  << FIXED(20,5) << object.UNIXTIMEBASE << ' '
60  << setw(10) << object.DOMID << ' '
61  << FIXED(9,6) << object.TOA_S << ' '
62  << FIXED(5,0) << object.QUALITYFACTOR;
63 
64  return out;
65  }
66 
67  int counter;
68  };
69 }
70 
71 
72 /**
73  * \file
74  *
75  * Example program to test acoustic data.
76  * \author mdejong
77  */
78 int main(int argc, char **argv)
79 {
80  using namespace std;
81  using namespace JPP;
82 
84  JLimit_t& numberOfEvents = inputFile.getLimit();
85  double precision;
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['p'] = make_field(precision) = 1.0e-7;
95  zap['d'] = make_field(debug) = 2;
96 
97  zap(argc, argv);
98  }
99  catch(const exception &error) {
100  FATAL(error.what() << endl);
101  }
102 
103 
104  typedef vector<JToAshort_t> buffer_type; // acoustic data type
105 
106  map<int, map< int, buffer_type > > data; // emitter -> receiver -> data
107 
108  for (int counter = 0; inputFile.hasNext(); ++counter) {
109 
110  STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
111 
112  const JToAshort* parameters = inputFile.next();
113 
114  data[parameters->EMITTERID][parameters->DOMID].push_back(JToAshort_t(*parameters, counter));
115  }
116  STATUS(endl);
117 
118 
119  for (map<int, map< int, buffer_type> >::const_iterator i = data.begin(); i != data.end(); ++i) {
120 
121  for (map< int, buffer_type>::const_iterator module = i->second.begin(); module != i->second.end(); ++module) {
122 
123  const buffer_type& buffer = module->second;
124 
125  for (buffer_type::const_iterator p = buffer.begin(); p != buffer.end(); ++p) {
126  for (buffer_type::const_iterator q = buffer.begin(); q != p; ++q) {
127 
128  if (labs(p->DOMID - q->DOMID) == 0 &&
129  fabs(p->QUALITYFACTOR - q->QUALITYFACTOR) <= precision &&
130  fabs((p->UNIXTIMEBASE + p->TOA_S) -
131  (q->UNIXTIMEBASE + q->TOA_S)) <= precision) {
132 
133  cout << *p << endl;
134  cout << *q << endl;
135 
136  cout << "Difference between absolute times "
137  << SCIENTIFIC(12,3) << ((p->UNIXTIMEBASE + p->TOA_S) -
138  (q->UNIXTIMEBASE + q->TOA_S)) << endl;
139  }
140  }
141  }
142  }
143  }
144 }
Utility class to parse command line options.
Definition: JParser.hh:1493
Sound velocity.
#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: JPrint.hh:481
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
ROOT TTree parameter settings.
int debug
debug level
Definition: JSirene.cc:61
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.
Acoustic transmission.
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: JPrint.hh:518
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15