DuneTimeConverter.cxx
Go to the documentation of this file.
1 // DuneTimeConverter.cxx
2 
3 #include "DuneTimeConverter.h"
4 #include <sstream>
5 #include <iomanip>
6 
7 using std::string;
8 using std::ostringstream;
9 using std::istringstream;
10 using std::setw;
11 using std::setfill;
12 
13 //**********************************************************************
14 
16  const uint64_t nsecPerUsec = 1000;
17  uint64_t secSinceNovaT0 = novaTime/novaTicksPerSec();
18  uint64_t ticksRem = novaTime - novaTicksPerSec()*secSinceNovaT0;
19  uint64_t sec = secSinceNovaT0 + novaT0Sec();
20  uint64_t nsec = (ticksRem*nsecPerUsec)/novaTicksPerUsec();
21  uint64_t tart = (sec << 32) + nsec;
22  art::Timestamp ts(tart);
23  return ts;
24 }
25 
26 //**********************************************************************
27 
29  uint64_t thi = tart.timeHigh();
30  uint64_t tlo = tart.timeLow();
31  uint64_t tnova = novaTicksPerSec()*(thi - novaT0Sec()) + (tlo*novaTicksPerUsec())/1000;
32  return tnova;
33 }
34 
35 //**********************************************************************
36 
37 art::Timestamp DuneTimeConverter::makeTimestamp(uint32_t tsec, uint32_t tns) {
38  uint64_t tthi = tsec;
39  uint64_t thilo = (tthi << 32) + tns;
40  return art::Timestamp(thilo);
41 }
42 
43 //**********************************************************************
44 
46  ostringstream sstime;
47  sstime << tart.timeHigh();
48  sstime << ".";
49  sstime << setw(9) << setfill('0') << tart.timeLow();
50  return sstime.str();
51 }
52 
53 //**********************************************************************
54 
56  string::size_type ipos = stime.find(".");
57  if ( ipos != string::npos ) ++ipos;
58  while ( ipos < stime.size() && stime[ipos] == '0' ) ++ipos;
59  bool hasns = ipos < stime.size();
60  uint32_t tsec;
61  istringstream sssec(stime.substr(0,ipos));
62  sssec >> tsec;
63  uint32_t tns = 0;
64  if ( hasns ) {
65  istringstream ssns(stime.substr(ipos));
66  ssns >> tns;
67  }
68  return makeTimestamp(tsec, tns);
69 }
70 
71 //**********************************************************************
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
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)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
static uint64_t novaT0Sec()
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
static uint64_t toNova(art::Timestamp tart)
static uint64_t novaTicksPerUsec()