test_DuneTimeConverter.cxx
Go to the documentation of this file.
1 // test_DuneTimeConverter.cxx
2 
3 // David Adams
4 // September 2015
5 //
6 // This test demonstrates how to use art::Timestamp.
7 
8 #undef NDEBUG
9 
10 #include "../DuneTimeConverter.h"
11 #include <string>
12 #include <iostream>
13 #include <iomanip>
14 #include <cassert>
15 
16 using std::string;
17 using std::cout;
18 using std::endl;
19 using std::setw;
20 using std::uint32_t;
21 using std::uint64_t;
22 
23 //**********************************************************************
24 
26  const string myname = "test_DuneTimeConverter: ";
27  cout << myname << "Starting test" << endl;
28 #ifdef NDEBUG
29  cout << myname << "NDEBUG must be off." << endl;
30  abort();
31 #endif
32  string line = "-----------------------------";
33  string scfg;
34 
35  cout << myname << line << endl;
36  cout << myname << "Test data" << endl;
37  assert( DuneTimeConverter::novaT0Sec() > 0 );
39  assert( DuneTimeConverter::novaTicksPerSec() > 0 );
41 
42  cout << myname << line << endl;
43  cout << myname << "Create test time" << endl;
44  //uint32_t tsec = 2208988800; // 2040
45  uint32_t tsec = 1577836800; // 2020
46  //uint32_t tsec = 1483228800; // 2017
47  uint32_t trem = 123456789;
48 
49  cout << myname << line << endl;
50  cout << myname << "Create timestamp." << endl;
52  cout << myname << DuneTimeConverter::toString(ts1) << " sec " << endl;
53  assert( ts1.timeLow() == trem );
54  assert( ts1.timeHigh() == tsec );
55 
56  cout << myname << line << endl;
57  cout << myname << "Create nova time." << endl;
58  uint64_t tnova = DuneTimeConverter::toNova(ts1);
60  cout << myname << "Nova time: " <<tnova << endl;
61  cout << myname << "Timestamp: " << setw(9) << DuneTimeConverter::toString(ts2) << " sec" << endl;
62  assert( ts2.timeHigh() == tsec );
63  int64_t lodiff = ts2.timeLow();
64  lodiff -= trem;
65  int64_t tol = 1000/DuneTimeConverter::novaTicksPerUsec();;
66  cout << myname << "Low tolerance: " << tol << endl;
67  assert( abs(lodiff) < tol );
68 
69  cout << myname << line << endl;
70  cout << myname << "Test creation from string." << endl;
71  string stime = "1577836800.123456789";
73  cout << myname << " String: " << stime << endl;
74  cout << myname << "Timestamp: " << DuneTimeConverter::toString(ts5) << endl;
75  assert( ts5.timeLow() == ts1.timeLow() );
76  assert( ts5.timeHigh() == ts1.timeHigh() );
77  assert( DuneTimeConverter::toString(ts5) == stime );
78 
79  cout << myname << line << endl;
80  cout << myname << "Done." << endl;
81  return 0;
82 }
83 
84 //**********************************************************************
85 
86 int main() {
87  return test_DuneTimeConverter();
88 }
89 
90 //**********************************************************************
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
static art::Timestamp fromNova(uint64_t tnova)
static std::string toString(art::Timestamp tart)
std::string string
Definition: nybbler.cc:12
auto const tol
Definition: SurfXYZTest.cc:16
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
static art::Timestamp makeTimestamp(uint32_t tsec, uint32_t trem)
static uint64_t novaTicksPerSec()
static art::Timestamp fromString(std::string stime)
T abs(T value)
int test_DuneTimeConverter()
int main()
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
static uint64_t novaT0Sec()
void line(double t, double *p, double &x, double &y, double &z)
static uint64_t toNova(art::Timestamp tart)
QTextStream & endl(QTextStream &s)
static uint64_t novaTicksPerUsec()