Belle II Software development
hardwareClockSettings.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 <framework/dbobjects/HardwareClockSettings.h>
9#include <framework/gearbox/Const.h>
10#include <gtest/gtest.h>
11#include <framework/utilities/TestHelpers.h>
12
13using namespace Belle2;
14
15namespace {
16
18 TEST(HardwareClockSettings, getClock)
19 {
20
21 Int_t topPrescaleTest = 6;
22 Int_t eclPrescaleTest = 3 * 24;
23 Float_t RF = 508.887;
24 Float_t dummyFrequency = 999.99;
25
26 HardwareClockSettings testClock;
27
28 testClock.setAcceleratorRF(RF);
29
30 testClock.setClockPrescale(Const::EDetector::TOP, "sampling", topPrescaleTest);
31 testClock.setClockPrescale(Const::EDetector::ECL, "sampling", eclPrescaleTest);
32 testClock.setClockFrequency(Const::EDetector::ECL, "dummy", dummyFrequency);
33 testClock.setClockFrequency(Const::EDetector::ARICH, "dummy", dummyFrequency);
34
35 EXPECT_EQ(testClock.getAcceleratorRF(), RF);
36
37 EXPECT_EQ(testClock.getClockPrescale(Const::EDetector::TOP, "sampling"), topPrescaleTest);
38 EXPECT_EQ(testClock.getClockPrescale(Const::EDetector::ECL, "sampling"), eclPrescaleTest);
39
40 EXPECT_EQ(testClock.getClockFrequency(Const::EDetector::ECL, "sampling"), RF / 4. / eclPrescaleTest);
41 EXPECT_EQ(testClock.getClockFrequency(Const::EDetector::ECL, "dummy"), dummyFrequency);
42 EXPECT_EQ(testClock.getClockFrequency(Const::EDetector::ARICH, "dummy"), dummyFrequency);
43
44 EXPECT_EQ(testClock.isPrescaleAvailable(Const::EDetector::TOP, "sampling"), true);
45 EXPECT_EQ(testClock.isPrescaleAvailable(Const::EDetector::TOP, "wrongname"), false);
46 EXPECT_EQ(testClock.isPrescaleAvailable(Const::EDetector::SVD, "wrongname"), false);
47
48 EXPECT_EQ(testClock.isFrequencyAvailable(Const::EDetector::TOP, "sampling"), true);
49 EXPECT_EQ(testClock.isFrequencyAvailable(Const::EDetector::ECL, "dummy"), true);
50 EXPECT_EQ(testClock.isFrequencyAvailable(Const::EDetector::ARICH, "wrongname"), false);
51 EXPECT_EQ(testClock.isFrequencyAvailable(Const::EDetector::SVD, "wrongname"), false);
52
53
54 //Try to get prescale from detector not present in the prescale map
55 EXPECT_B2ERROR(testClock.getClockPrescale(Const::EDetector::SVD, "sampling"));
56
57 //Try to get prescale from label not present in the prescale map
58 EXPECT_B2ERROR(testClock.getClockPrescale(Const::EDetector::ECL, "wrongname"));
59
60 //Try to get clock from detector not present in both prescale and frequency map
61 EXPECT_B2ERROR(testClock.getClockFrequency(Const::EDetector::KLM, "wrongname"));
62
63 //Try to get clock from label not present in the maps and detector present in both prescale and frequency map
64 EXPECT_B2ERROR(testClock.getClockFrequency(Const::EDetector::ECL, "wrongname"));
65
66 //Try to get clock from label not present in the maps and detector present only in frequency map
67 EXPECT_B2ERROR(testClock.getClockFrequency(Const::EDetector::ARICH, "wrongname"));
68
69 //Try to get clock from label not present in the maps and detector present only in prescale map
70 EXPECT_B2ERROR(testClock.getClockFrequency(Const::EDetector::TOP, "wrongname"));
71 }
72} // namespace
Database object containing the nominal accelerator RF value and the prescales to derive the clock fre...
void setClockFrequency(const Const::EDetector detector, std::string label, double frequency)
Set the frequency value of detector clock not derived from the global clock.
double getClockPrescale(Const::EDetector detector, std::string label) const
Get the prescale factor used to derive a detector clock from the global clock frequency.
bool isPrescaleAvailable(Const::EDetector detector, std::string label) const
Check if the prescale of a clock is available.
double getClockFrequency(Const::EDetector detector, std::string label) const
Get the frequency of a detector clock.
double getAcceleratorRF() const
Get the accelerator RF value.
bool isFrequencyAvailable(Const::EDetector detector, std::string label) const
Check if the frequency of a detector clock is available.
void setClockPrescale(const Const::EDetector detector, std::string label, double prescale)
Set the prescale value used to derive a detector clock from the global clock frequency.
void setAcceleratorRF(double acceleratorRF)
Set the accelerator RF value.
Abstract base class for different kinds of events.