Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTransmission.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JTRANSMISSION__
2 #define __JACOUSTICS__JTRANSMISSION__
3 
4 #include <cmath>
5 
6 #include <TROOT.h>
7 #include <TObject.h>
8 
9 #include "JIO/JSerialisable.hh"
10 
11 
12 /**
13  * \file
14  *
15  * Acoustic transmission.
16  * \author mdejong
17  */
18 namespace JACOUSTICS {}
19 namespace JPP { using namespace JACOUSTICS; }
20 
21 namespace JACOUSTICS {
22 
23  using JIO::JReader;
24  using JIO::JWriter;
25 
26  /**
27  * Acoustic transmission.
28  */
29  struct JTransmission :
30  public TObject
31  {
32  /**
33  * Default constructor.
34  */
36  run(-1),
37  id (-1),
38  q (0.0),
39  w (0.0),
40  toa(0.0),
41  toe(0.0)
42  {}
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param run run number
49  * \param id identifier
50  * \param Q quality
51  * \param W normalisation
52  * \param toa_s time-of-arrival [s]
53  * \param toe_s time-of-emission [s]
54  */
55  JTransmission(const int run,
56  const int id,
57  const double Q,
58  const double W,
59  const double toa_s,
60  const double toe_s) :
61  run(run),
62  id (id),
63  q (Q),
64  w (W),
65  toa(toa_s),
66  toe(toe_s)
67  {}
68 
69 
70  /**
71  * Virtual destructor.
72  */
73  virtual ~JTransmission()
74  {}
75 
76 
77  /**
78  * Get run number.
79  *
80  * \return run number
81  */
82  int getRunNumber() const
83  {
84  return run;
85  }
86 
87 
88  /**
89  * Get identifier.
90  *
91  * \return identifier
92  */
93  int getID() const
94  {
95  return id;
96  }
97 
98 
99  /**
100  * Get quality.
101  *
102  * \return quality
103  */
104  double getQ() const
105  {
106  return q;
107  }
108 
109 
110  /**
111  * Get normalisation.
112  *
113  * \return normalisation
114  */
115  double getW() const
116  {
117  return w;
118  }
119 
120 
121  /**
122  * Get calibrated time of arrival.
123  *
124  * \return time [s]
125  */
126  double getToA() const
127  {
128  return toa;
129  }
130 
131 
132  /**
133  * Get estimated time of emission.
134  *
135  * \return time [s]
136  */
137  double getToE() const
138  {
139  return toe;
140  }
141 
142 
143  /**
144  * Set estimated time of emission.
145  *
146  * \param toe time [s]
147  */
148  void setToE(const double toe)
149  {
150  this->toe = toe;
151  }
152 
153 
154  /**
155  * Read transmission from input.
156  *
157  * \param in reader
158  * \param object transmission
159  * \return reader
160  */
161  friend inline JReader& operator>>(JReader& in, JTransmission& object)
162  {
163  in >> object.run;
164  in >> object.id;
165  in >> object.q;
166  in >> object.w;
167  in >> object.toa;
168  in >> object.toe;
169 
170  return in;
171  }
172 
173 
174  /**
175  * Write transmission to output.
176  *
177  * \param out writer
178  * \param object transmission
179  * \return writer
180  */
181  friend inline JWriter& operator<<(JWriter& out, const JTransmission& object)
182  {
183  out << object.run;
184  out << object.id;
185  out << object.q;
186  out << object.w;
187  out << object.toa;
188  out << object.toe;
189 
190  return out;
191  }
192 
194 
195  /**
196  * Auxiliary class to compare transmissions.
197  */
198  struct equals {
199  /**
200  * Constructor.
201  *
202  * \param precision time-of-arrival precision [s]
203  */
204  equals(const double precision) :
205  precision(precision)
206  {}
207 
208 
209  /**
210  * Compare two transmissions.
211  *
212  * \param first first transmission
213  * \param second second transmission
214  * \return true if times-of-arrival are similar; else false
215  */
216  bool operator()(const JTransmission& first, const JTransmission& second) const
217  {
218  return fabs(first.getToA() - second.getToA()) <= precision;
219  }
220 
221  const double precision;
222  };
223 
224 
225  /**
226  * Auxiliary class to compare transmissions.
227  */
228  struct compare :
229  public equals
230  {
231  /**
232  * Constructor.
233  *
234  * \param precision time-of-arrival precision [s]
235  */
236  compare(const double precision) :
237  equals(precision)
238  {}
239 
240 
241  /**
242  * Compare two transmissions.
243  *
244  * The transmission wih the earliest time-of-arrival comes first.\n
245  * If the two transmissions are equal within the specified precision,
246  * the transmission with the highest quality comes first.\n
247  * If also the qualities are the same, the time-of-arrival is again used.
248  *
249  * \param first first transmission
250  * \param second second transmission
251  * \return true if time-of-arrival of first transmission earlier than that of second; else false
252  */
253  bool operator()(const JTransmission& first, const JTransmission& second) const
254  {
255  if (static_cast<const equals&>(*this)(first, second)) {
256 
257  if (first.getQ() == second.getQ())
258  return first.getToA() < second.getToA();
259  else
260  return first.getQ() > second.getQ();
261 
262  } else {
263 
264  return first.getToA() < second.getToA();
265  }
266  }
267  };
268 
269  protected:
270  int run;
271  int id;
272  double q;
273  double w;
274  double toa;
275  double toe;
276  };
277 
278 
279  /**
280  * Less-than operator for two transmissions.
281  *
282  * The less-than operator is first applied to the time-of-emission and then to the identifier.
283  *
284  * \param first first transmission
285  * \param second second transmission
286  * \return true if first transmission earlier than second; else false
287  */
288  static inline bool operator<(const JTransmission& first, const JTransmission& second)
289  {
290  if (first.getToE() == second.getToE())
291  return first.getID() < second.getID();
292  else
293  return first.getToE() < second.getToE();
294  }
295 
296 
297  /**
298  * Equals operator for two transmissions.
299  *
300  * The equal operator is applied to the time-of-emission and the identifier.
301  *
302  * \param first first transmission
303  * \param second second transmission
304  * \return true if first transmission equal to second; else false
305  */
306  static inline bool operator==(const JTransmission& first, const JTransmission& second)
307  {
308  return (first.getID() == second.getID() &&
309  first.getToE() == second.getToE());
310  }
311 }
312 
313 #endif
Interface for binary output.
Q(UTCMax_s-UTCMin_s)-livetime_s
friend JWriter & operator<<(JWriter &out, const JTransmission &object)
Write transmission to output.
double getQ() const
Get quality.
int getRunNumber() const
Get run number.
equals(const double precision)
Constructor.
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1814
Definition: JRoot.hh:19
double getToE() const
Get estimated time of emission.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double getW() const
Get normalisation.
Acoustic transmission.
bool operator==(Packet const &p, ID const &id)
friend JReader & operator>>(JReader &in, JTransmission &object)
Read transmission from input.
ClassDef(JTransmission, 3)
JTransmission(const int run, const int id, const double Q, const double W, const double toa_s, const double toe_s)
Constructor.
Interface for binary input.
void setToE(const double toe)
Set estimated time of emission.
Auxiliary class to compare transmissions.
JTransmission()
Default constructor.
virtual ~JTransmission()
Virtual destructor.
double getToA() const
Get calibrated time of arrival.
int getID() const
Get identifier.
Auxiliary class to compare transmissions.
bool operator()(const JTransmission &first, const JTransmission &second) const
Compare two transmissions.
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:48
bool operator()(const JTransmission &first, const JTransmission &second) const
Compare two transmissions.
compare(const double precision)
Constructor.