Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
dunetpc
dune
Protodune
singlephase
CRT
alg
util
Timer.cpp
Go to the documentation of this file.
1
//File: Timer.cpp
2
//Brief: A CRT::Timer approximates the time represented by a CRT timestamp and the elapsed time since an initial time it was given.
3
//Author: Andrew Olivier aolivier@ur.rochester.edu
4
5
//Include header
6
#include "
Timer.h
"
7
8
//Include definition of CRT::Trigger for interface
9
#include "
dunetpc/dune/Protodune/singlephase/CRT/data/CRTTrigger.h
"
10
11
namespace
CRT
12
{
13
Timer::Timer
(
const
CRT::Trigger
&
trigger
):
Timer
(trigger.
Timestamp
())
14
{
15
}
16
17
//TODO: Fill in constructor
18
Timer::Timer
(
const
uint64_t
timestamp):
fLastUNIXSecond
(
Timestamp
(timestamp).upper),
fNsOfLastUNIXSecond
(
Timestamp
(timestamp).lower),
19
fNsOfLastSync
(0),
fPrevNs
(
Timestamp
(timestamp).lower),
fFirstTime
(
GetSeconds
(timestamp))
20
{
21
}
22
23
double
Timer::seconds
(
const
CRT::Trigger
&
trigger
)
24
{
25
return
seconds
(trigger.
Timestamp
());
26
}
27
28
double
Timer::seconds
(
const
uint64_t
timestamp)
29
{
30
return
GetSeconds
(timestamp);
31
}
32
33
double
Timer::elapsed
(
const
CRT::Trigger
&
trigger
)
34
{
35
return
elapsed
(trigger.
Timestamp
());
36
}
37
38
double
Timer::elapsed
(
const
uint64_t
timestamp)
39
{
40
return
GetSeconds
(timestamp) -
fFirstTime
;
41
}
42
43
double
Timer::GetSeconds
(
const
uint64_t
timestamp)
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
)*1
e
-9;
54
}
55
56
//If the UNIX timestamp has moved to a new value
57
if
(time.
upper
>
fLastUNIXSecond
)
58
{
59
fLastUNIXSecond
= time.
upper
;
60
fNsOfLastUNIXSecond
= time.
lower
+
fNsOfLastSync
;
61
}
62
63
return
time.
upper
+(time.
lower
-
fNsOfLastUNIXSecond
)*1
e
-9;
64
}
65
66
double
Timer::elapsed
()
67
{
68
const
uint64_t
lastTimestamp = ((
uint64_t
)
fLastUNIXSecond
<< 32) |
fPrevNs
;
69
return
elapsed
(lastTimestamp);
70
}
71
}
Timer.h
CRT::Timer::fPrevNs
uint32_t fPrevNs
Definition:
Timer.h:60
CRT::Timer::fFirstTime
const double fFirstTime
Definition:
Timer.h:61
CRT::Timer::Timer
Timer(const CRT::Trigger &trigger)
Definition:
Timer.cpp:13
CRT::Timestamp::lower
uint32_t lower
Definition:
Timer.h:31
CRT::Timer::GetSeconds
double GetSeconds(const uint64_t timestamp)
Definition:
Timer.cpp:43
CRT::Timestamp
Definition:
Timer.h:20
CRT::Timer::seconds
double seconds(const CRT::Trigger &trigger)
Definition:
Timer.cpp:23
CRT::Trigger::Timestamp
unsigned long long Timestamp() const
Definition:
CRTTrigger.h:96
CRT
Definition:
DQMPlotter.cpp:23
CRTTrigger.h
CRT::Timer::fNsOfLastSync
uint32_t fNsOfLastSync
Definition:
Timer.h:58
e
const double e
Definition:
gUpMuFluxGen.cxx:165
time
uint64_t
unsigned __int64 uint64_t
Definition:
stdint.h:136
CRT::Trigger
Definition:
CRTTrigger.h:80
CRT::Timer::fLastUNIXSecond
uint32_t fLastUNIXSecond
Definition:
Timer.h:56
CRT::Timer
Definition:
Timer.h:35
CRT::Timestamp::upper
uint32_t upper
Definition:
Timer.h:32
trigger
Definition:
TriggerAlgoBase.h:27
CRT::Timer::fNsOfLastUNIXSecond
uint32_t fNsOfLastUNIXSecond
Definition:
Timer.h:57
CRT::Timer::elapsed
double elapsed()
Definition:
Timer.cpp:66
Generated by
1.8.11