Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JToAImp.cc
Go to the documentation of this file.
1#include <chrono>
2#include "JAcoustics/JToA.hh"
3
4// FIXME: to be replaced by std::chrono::round once we move to C++17
5namespace {
6 template<class To, class Duration>
7 To round(const Duration& d)
8 {
9 To t0 = std::chrono::duration_cast<To>(d);
10 To t1 = t0 + To{1};
11 auto diff0 = d - t0;
12 auto diff1 = t1 - d;
13 if (diff0 == diff1) {
14 if (t0.count() & 1) {
15 return t1;
16 }
17 return t0;
18 } else if (diff0 < diff1) {
19 return t0;
20 }
21 return t1;
22 }
23}
24
25namespace JACOUSTICS {
26
27 constexpr double ONE_TICK_IN_NS = 16E-9; // one tick of the 62.5 MHz clock = 16 nanoseconds
28 constexpr double SECOND_IN_NANOSECOND = 1E-9;
29 constexpr double SECOND_IN_MICROSECOND = 1E-6;
30 constexpr int64_t NANOSECONDS_IN_ONE_SECOND = 1000000000LL;
31 constexpr int64_t NANOSECONDS_IN_ONE_TICK = 16LL;
32
33 JToA::JToA() = default;
34
36 {
37 return (static_cast<double>(SECONDS) + static_cast<double>(TICKS) * ONE_TICK_IN_NS);
38 }
39
40 double JToA::TOA_S() const
41 {
43 }
44
45 int64_t JToA::relativeToA_ns() const
46 {
48 }
49
50 double JToA::relativeToA_s() const
51 {
52 // to mimic what's done in the streamds retrieval, we truncate
53 // to microseconds first, then go to seconds.
54 std::chrono::microseconds mus = round<std::chrono::microseconds>(std::chrono::nanoseconds{relativeToA_ns()});
55 return static_cast<double>(mus.count()) * SECOND_IN_MICROSECOND;
56 }
57
62
63} // namespace JACOUSTICS
Acoustic event.
Auxiliary classes and methods for acoustic position calibration.
constexpr double SECOND_IN_NANOSECOND
Definition JToAImp.cc:28
constexpr int64_t NANOSECONDS_IN_ONE_SECOND
Definition JToAImp.cc:30
constexpr double SECOND_IN_MICROSECOND
Definition JToAImp.cc:29
constexpr int64_t NANOSECONDS_IN_ONE_TICK
Definition JToAImp.cc:31
constexpr double ONE_TICK_IN_NS
Definition JToAImp.cc:27
double daqFrameTimeStart_s() const
Time stamp of the DAQ frame start, in seconds since the Unix epoch (1 January 1970 00:00:00 UTC)
Definition JToAImp.cc:35
int64_t daqFrameTimeStart_ns() const
Normalization for the quality factor.
Definition JToAImp.cc:58
uint32_t SECONDS
Time of Arrival, in ns (relative to Unix epoch, 1 January 1970 00:00:00 UTC)
Definition JToA.hh:37
int64_t TOA_NS
Unique ID of the waveform that best described the signal around TOA_NS.
Definition JToA.hh:36
int64_t relativeToA_ns() const
Time of Arrival, expressed in nanoseconds relative to the DAQ frame start.
Definition JToAImp.cc:45
double relativeToA_s() const
Time of Arrival, expressed in seconds relative to the DAQ frame start.
Definition JToAImp.cc:50
double TOA_S() const
Time of Arrival, expressed in seconds relative to Unix epoch (1 January 1970 00:00:00 UTC)
Definition JToAImp.cc:40
uint32_t TICKS
The seconds part of the DAQ frame timestamp.
Definition JToA.hh:38