Belle II Software development
Clock.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <gtest/gtest.h>
9
10#include <trg/trg/Clock.h>
11
12using namespace Belle2;
13
14namespace TRGTest {
16 TEST(TRGClockTest, TimeConversions)
17 {
18 double cycleBase = 8.; // cycle of base clock in ns
19 int multi = 4;
20 double cycle = cycleBase / multi;
21 TRGClock baseClock("8ns clock", 0., 1000. / cycleBase); // base clock
22 TRGClock syncClock("2ns clock (sync)", baseClock, multi); // synchronized to base clock
23 TRGClock testClock("2ns clock", 0., 1000. / cycle); // independent test clock, same as syncClock
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;
31 }
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;
36 }
37 }
38
39 TEST(TRGClockTest, ClockConversions)
40 {
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)",
45 _clock,
46 4);
47 const TRGClock _clockD("CDCTrigger data clock", _clock, 1, 4);
48
49 const double tfe0 = 0.;
50 const double tfe255 = 255;
51
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);
55
56 EXPECT_EQ(_clockFE.positionInSourceClock(tfe0),
57 _clockD.positionInSourceClock(tfe0));
58 }
59}
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
Abstract base class for different kinds of events.