8#include <gtest/gtest.h>
10#include <trg/trg/Clock.h>
16 TEST(TRGClockTest, TimeConversions)
18 double cycleBase = 8.;
20 double cycle = cycleBase / multi;
21 TRGClock baseClock(
"8ns clock", 0., 1000. / cycleBase);
22 TRGClock syncClock(
"2ns clock (sync)", baseClock, multi);
23 TRGClock testClock(
"2ns clock", 0., 1000. / cycle);
24 for (
double time = -2 * cycle; time <= 2 * cycle; time += cycle / 2.) {
25 EXPECT_EQ(1, testClock.position(time + cycle) - testClock.position(time)) <<
"time " << time <<
" cycle " << cycle;
26 EXPECT_EQ(testClock.overShoot(time), time - testClock.absoluteTime(testClock.position(time))) <<
"time " << time;
27 EXPECT_LT(testClock.overShoot(time), cycle) <<
"time " << time;
28 EXPECT_GE(testClock.overShoot(time), 0) <<
"time " << time;
29 EXPECT_EQ(testClock.position(time), syncClock.position(time)) <<
"time " << time;
30 EXPECT_EQ(testClock.overShoot(time), syncClock.overShoot(time)) <<
"time " << time;
32 for (
int clock = -2; clock <= 2; ++clock) {
33 EXPECT_EQ(cycle, testClock.absoluteTime(clock + 1) - testClock.absoluteTime(clock)) <<
"clock " << clock;
34 EXPECT_EQ(clock, testClock.position(testClock.absoluteTime(clock))) <<
"clock " << clock;
35 EXPECT_EQ(testClock.absoluteTime(clock), syncClock.absoluteTime(clock)) <<
"clock " << clock;
39 TEST(TRGClockTest, ClockConversions)
41 const double tdcBinWidth = 1.0;
42 const TRGClock _clock(
"CDCTrigger system clock", 0, 125. / tdcBinWidth);
43 const TRGClock _clockFE(
"CDCFE TDC clock", _clock, 8);
44 const TRGClock _clockTDC(
"CDCTrigger TDC clock (after mergers)",
47 const TRGClock _clockD(
"CDCTrigger data clock", _clock, 1, 4);
49 const double tfe0 = 0.;
50 const double tfe255 = 255;
52 EXPECT_EQ(_clockFE.position(tfe0), _clockD.position(tfe0));
53 EXPECT_EQ(_clockFE.position(tfe255) / 8, _clock.position(tfe255));
54 EXPECT_EQ(_clockD.position(tfe255), _clockFE.position(tfe255) / 32);
56 EXPECT_EQ(_clockFE.positionInSourceClock(tfe0),
57 _clockD.positionInSourceClock(tfe0));
A class to represent a digitized signal. Unit is nano second.
Abstract base class for different kinds of events.