Belle II Software light-2406-ragdoll
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/logging/Logger.h>
10#include <framework/gearbox/Unit.h>
11#include <iostream>
12
13using namespace Belle2;
14
16
17
18bool HardwareClockSettings::isPrescaleAvailable(Const::EDetector detector, std::string label) const
19{
20 if ((m_prescaleMap.find(detector) == m_prescaleMap.end())
21 or (m_prescaleMap.at(detector).find(label) == m_prescaleMap.at(detector).end())) return false;
22 else return true;
23}
24
26{
27 if (((m_prescaleMap.find(detector) == m_prescaleMap.end()) or
28 (m_prescaleMap.at(detector).find(label) == m_prescaleMap.at(detector).end()))
29 and ((m_clocksMap.find(detector) == m_clocksMap.end()) or
30 (m_clocksMap.at(detector).find(label) == m_clocksMap.at(detector).end()))) return false;
31 else return true;
32}
33
34double HardwareClockSettings::getClockFrequency(Const::EDetector detector, std::string label) const
35{
36 bool isDetectorInPrescaleMap = true;
37
38 if (m_prescaleMap.find(detector) == m_prescaleMap.end()) isDetectorInPrescaleMap = false;
39 else if (m_prescaleMap.at(detector).find(label) != m_prescaleMap.at(detector).end())
40 return m_acceleratorRF / 4. / m_prescaleMap.at(detector).at(label);
41
42 if (m_clocksMap.find(detector) == m_clocksMap.end()) {
43 if (!isDetectorInPrescaleMap) B2ERROR("No clocks available for " << Const::parseDetectors(detector));
44 else B2ERROR("Clock named " << label << " not available for " << Const::parseDetectors(detector));
45 } else if (m_clocksMap.at(detector).find(label) != m_clocksMap.at(detector).end())
46 return m_clocksMap.at(detector).at(label);
47 else B2ERROR("Clock named " << label << " not available for " << Const::parseDetectors(detector));
48
49 return std::numeric_limits<double>::quiet_NaN();
50}
51
53{
54 return m_acceleratorRF / 4.;
55}
56
58{
59 return m_acceleratorRF;
60}
61
62double HardwareClockSettings::getClockPrescale(Const::EDetector detector, std::string label) const
63{
64 if (m_prescaleMap.find(detector) == m_prescaleMap.end()) B2ERROR("No clocks available for " << Const::parseDetectors(detector));
65 else if (m_prescaleMap.at(detector).find(label) != m_prescaleMap.at(detector).end())
66 return m_prescaleMap.at(detector).at(label);
67 else B2ERROR("Clock named " << label << " not available for " << Const::parseDetectors(detector));
68
69 return std::numeric_limits<double>::quiet_NaN();
70}
71
72void HardwareClockSettings::setClockPrescale(const Const::EDetector detector, std::string label, double prescale)
73{
74 m_prescaleMap[detector][label] = prescale;
75}
76
77
78void HardwareClockSettings::setClockFrequency(const Const::EDetector detector, std::string label, double frequency)
79{
80 m_clocksMap[detector][label] = frequency;
81}
82
84{
85 m_acceleratorRF = acceleratorRF;
86}
87
89{
90 std::cout << std::endl;
91 std::cout << "Accelerator RF: " << m_acceleratorRF / Unit::MHz << " MHz" << std::endl;
92 std::cout << "Clock prescale factors:" << std::endl;
93 std::cout << "===================================" << std::endl;
94
95 for (const auto& det : m_prescaleMap) {
96 std::cout << Const::parseDetectors(det.first) << ":" << std::endl;
97 for (const auto& clock : det.second) std::cout << " " << clock.first << " " << clock.second << std::endl;
98 }
99 std::cout << "===================================" << std::endl;
100
101 std::cout << "Clock frequencies:" << std::endl;
102 std::cout << "===================================" << std::endl;
103 for (const auto& det : m_clocksMap) {
104 std::cout << Const::parseDetectors(det.first) << ":" << std::endl;
105 for (const auto& clock : det.second) {
106 std::cout << " " << clock.first << " " << clock.second / Unit::MHz << " MHz" << std::endl;
107 }
108 }
109 std::cout << "===================================" << std::endl;
110}
111
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
static std::string parseDetectors(EDetector det)
Converts Const::EDetector object to string.
Definition: UnitConst.cc:162
void setClockFrequency(const Const::EDetector detector, std::string label, double frequency)
Set the frequency value of detector clock not derived from the global clock.
std::map< Const::EDetector, std::map< std::string, double > > m_prescaleMap
Map of prescale factors used to derive the clock frequencies from the global clock frequency.
double getGlobalClockFrequency() const
Get the global clock (system clock) frequency.
double getClockPrescale(Const::EDetector detector, std::string label) const
Get the prescale factor used to derive a detector clock from the global clock frequency.
std::map< Const::EDetector, std::map< std::string, double > > m_clocksMap
Map of clock frequencies not derived from the global clock frequency.
double m_acceleratorRF
Accelerator radio frequency [GHz].
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 print() const
Print the content of the class.
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.
static const double MHz
[Megahertz]
Definition: Unit.h:104
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24