Public Member Functions | Private Member Functions | Private Attributes | List of all members
CRT::Timer Class Reference

#include <Timer.h>

Public Member Functions

 Timer (const CRT::Trigger &trigger)
 
 Timer (const uint64_t timestamp)
 
double seconds (const CRT::Trigger &trigger)
 
double seconds (const uint64_t timestamp)
 
double elapsed (const CRT::Trigger &trigger)
 
double elapsed (const uint64_t timestamp)
 
double elapsed ()
 

Private Member Functions

double GetSeconds (const uint64_t timestamp)
 

Private Attributes

uint32_t fLastUNIXSecond
 
uint32_t fNsOfLastUNIXSecond
 
uint32_t fNsOfLastSync
 
uint32_t fPrevNs
 
const double fFirstTime
 

Detailed Description

Definition at line 35 of file Timer.h.

Constructor & Destructor Documentation

Timer::Timer ( const CRT::Trigger trigger)

Definition at line 13 of file Timer.cpp.

13  : Timer(trigger.Timestamp())
14  {
15  }
Timer(const CRT::Trigger &trigger)
Definition: Timer.cpp:13
unsigned long long Timestamp() const
Definition: CRTTrigger.h:96
Timer::Timer ( const uint64_t  timestamp)

Definition at line 18 of file Timer.cpp.

18  : fLastUNIXSecond(Timestamp(timestamp).upper), fNsOfLastUNIXSecond(Timestamp(timestamp).lower),
19  fNsOfLastSync(0), fPrevNs(Timestamp(timestamp).lower), fFirstTime(GetSeconds(timestamp))
20  {
21  }
uint32_t fPrevNs
Definition: Timer.h:60
const double fFirstTime
Definition: Timer.h:61
double GetSeconds(const uint64_t timestamp)
Definition: Timer.cpp:43
uint32_t fNsOfLastSync
Definition: Timer.h:58
uint32_t fLastUNIXSecond
Definition: Timer.h:56
uint32_t fNsOfLastUNIXSecond
Definition: Timer.h:57

Member Function Documentation

double Timer::elapsed ( const CRT::Trigger trigger)

Definition at line 33 of file Timer.cpp.

34  {
35  return elapsed(trigger.Timestamp());
36  }
unsigned long long Timestamp() const
Definition: CRTTrigger.h:96
double elapsed()
Definition: Timer.cpp:66
double Timer::elapsed ( const uint64_t  timestamp)

Definition at line 38 of file Timer.cpp.

39  {
40  return GetSeconds(timestamp) - fFirstTime;
41  }
const double fFirstTime
Definition: Timer.h:61
double GetSeconds(const uint64_t timestamp)
Definition: Timer.cpp:43
double Timer::elapsed ( )

Definition at line 66 of file Timer.cpp.

67  {
68  const uint64_t lastTimestamp = ((uint64_t)fLastUNIXSecond << 32) | fPrevNs;
69  return elapsed(lastTimestamp);
70  }
uint32_t fPrevNs
Definition: Timer.h:60
unsigned __int64 uint64_t
Definition: stdint.h:136
uint32_t fLastUNIXSecond
Definition: Timer.h:56
double elapsed()
Definition: Timer.cpp:66
double Timer::GetSeconds ( const uint64_t  timestamp)
private

Definition at line 43 of file Timer.cpp.

44  {
45  //Extract upper and lower parts of timestamp
46  Timestamp time(timestamp);
47 
48  //If a sync pulse arrived between this timestamp and the previous one seen. This could skip Sync pulses entirely.
49  if(time.lower < fPrevNs)
50  {
51  fNsOfLastSync = fPrevNs; //Estimate time in ns of previous Sync as previous timestamp seen
52  fPrevNs = time.lower;
53  return time.upper+(time.lower+fNsOfLastSync)*1e-9;
54  }
55 
56  //If the UNIX timestamp has moved to a new value
57  if(time.upper > fLastUNIXSecond)
58  {
59  fLastUNIXSecond = time.upper;
61  }
62 
63  return time.upper+(time.lower-fNsOfLastUNIXSecond)*1e-9;
64  }
uint32_t fPrevNs
Definition: Timer.h:60
uint32_t fNsOfLastSync
Definition: Timer.h:58
const double e
uint32_t fLastUNIXSecond
Definition: Timer.h:56
uint32_t fNsOfLastUNIXSecond
Definition: Timer.h:57
double Timer::seconds ( const CRT::Trigger trigger)

Definition at line 23 of file Timer.cpp.

24  {
25  return seconds(trigger.Timestamp());
26  }
double seconds(const CRT::Trigger &trigger)
Definition: Timer.cpp:23
unsigned long long Timestamp() const
Definition: CRTTrigger.h:96
double Timer::seconds ( const uint64_t  timestamp)

Definition at line 28 of file Timer.cpp.

29  {
30  return GetSeconds(timestamp);
31  }
double GetSeconds(const uint64_t timestamp)
Definition: Timer.cpp:43

Member Data Documentation

const double CRT::Timer::fFirstTime
private

Definition at line 61 of file Timer.h.

uint32_t CRT::Timer::fLastUNIXSecond
private

Definition at line 56 of file Timer.h.

uint32_t CRT::Timer::fNsOfLastSync
private

Definition at line 58 of file Timer.h.

uint32_t CRT::Timer::fNsOfLastUNIXSecond
private

Definition at line 57 of file Timer.h.

uint32_t CRT::Timer::fPrevNs
private

Definition at line 60 of file Timer.h.


The documentation for this class was generated from the following files: