Project
Loading...
Searching...
No Matches
testDCSAliases.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test MCHConditions DCSNamer
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include <boost/test/unit_test.hpp>
19#include <algorithm>
20#include <fmt/format.h>
21#include <map>
22#include <string>
23
24using namespace o2::mch::dcs;
25
26namespace
27{
28struct ID {
31 int number;
34 ID(Chamber ch, MeasurementType m, int n, Plane p, Side s) : chamber{ch},
35 measurement{m},
36 number{n},
37 side{s},
38 plane{p}
39 {
40 }
41};
42
43bool operator==(const ID& i1, const ID& i2)
44{
45 return i1.side == i2.side &&
46 i1.chamber == i2.chamber &&
47 i1.number == i2.number &&
48 i1.measurement == i2.measurement &&
49 i1.plane == i2.plane;
50}
51
52bool operator<(const ID& i1, const ID& i2)
53{
54 if (i1.plane == i2.plane) {
55 if (i1.measurement == i2.measurement) {
56 int s1 = i1.side == Side::Left ? 0 : 1;
57 int s2 = i2.side == Side::Left ? 0 : 1;
58 if (s1 == s2) {
59 if (i1.chamber == i2.chamber) {
60 return i1.number < i2.number;
61 } else {
62 return toInt(i1.chamber) < toInt(i2.chamber);
63 }
64 } else {
65 return s1 < s2;
66 }
67 } else {
68 return (int)i1.measurement < (int)i2.measurement;
69 }
70 } else {
71 return (int)i1.plane < (int)i2.plane;
72 }
73}
74
75} // namespace
76
77namespace o2::mch::dcs
78{
79
80extern std::vector<std::string> expectedHVAliasesVoltages;
81extern std::vector<std::string> expectedHVAliasesCurrents;
82extern std::vector<std::string> expectedLVAliasesFeeAnalog;
83extern std::vector<std::string> expectedLVAliasesFeeDigital;
84extern std::vector<std::string> expectedLVAliasesSolar;
85} // namespace o2::mch::dcs
86
87BOOST_AUTO_TEST_SUITE(o2_mch_conditions)
88
89BOOST_AUTO_TEST_SUITE(dcsnamer)
90
91BOOST_AUTO_TEST_CASE(NumberOfHVAliasesVoltagesIs188)
92{
93 auto result = aliases({MeasurementType::HV_V});
96 bool permutation = std::is_permutation(begin(result), end(result), begin(expectedHVAliasesVoltages));
97 BOOST_CHECK_EQUAL(permutation, true);
98}
99
100BOOST_AUTO_TEST_CASE(NumberOfHVAliasesCurrentsIs188)
101{
102 auto result = aliases({MeasurementType::HV_I});
105 bool permutation = std::is_permutation(begin(result), end(result), begin(expectedHVAliasesCurrents));
106 BOOST_CHECK_EQUAL(permutation, true);
107}
108
109BOOST_AUTO_TEST_CASE(NumberOfLVAliasesFeeAnalogIs108)
110{
111 auto result = aliases({MeasurementType::LV_V_FEE_ANALOG});
114 bool permutation = std::is_permutation(begin(result), end(result), begin(expectedLVAliasesFeeAnalog));
115 BOOST_CHECK_EQUAL(permutation, true);
116}
117
118BOOST_AUTO_TEST_CASE(NumberOfLVAliasesFeeDigitalIs108)
119{
120 auto result = aliases({MeasurementType::LV_V_FEE_DIGITAL});
123 bool permutation = std::is_permutation(begin(result), end(result), begin(expectedLVAliasesFeeDigital));
124 BOOST_CHECK_EQUAL(permutation, true);
125}
126
127BOOST_AUTO_TEST_CASE(NumberOfLVAliasesSolarIs112)
128{
129 auto result = aliases({MeasurementType::LV_V_SOLAR});
132 bool permutation = std::is_permutation(begin(result), end(result), begin(expectedLVAliasesSolar));
133 BOOST_CHECK_EQUAL(permutation, true);
134}
135
136BOOST_AUTO_TEST_CASE(AliasNameIsShortEnough)
137{
138 auto result = aliases();
139 std::map<size_t, int> sizes;
140 constexpr size_t maxLen{62};
141 for (auto& a : result) {
142 sizes[a.size()]++;
143 if (a.size() > maxLen) {
144 std::cout << fmt::format("Alias is too long : {:2d} characters, while {:2d} max are allowed : {}\n",
145 a.size(), maxLen, a);
146 }
147 }
148 size_t len{0};
149
150 for (auto p : sizes) {
151 std::cout << fmt::format("{:3d} aliases of size {:2d}\n",
152 p.second, p.first);
153 len = std::max(len, p.first);
154 }
155 BOOST_CHECK(len <= 62);
156}
157
158BOOST_AUTO_TEST_CASE(AllAliasesShouldBeValid)
159{
160 auto all = aliases();
161 for (auto a : all) {
163 }
164}
165
166std::map<std::string, ID> expected = {
167 {"MchHvLvRight/Chamber06Right/Slat08.actual.vMon", {Chamber::Ch06, MeasurementType::HV_V, 8, Plane::Both, Side::Right}},
168
169 {"MchHvLvLeft/Chamber06Left/Group02an.SenseVoltage", {Chamber::Ch06, MeasurementType::LV_V_FEE_ANALOG, 2, Plane::Both, Side::Left}},
170
171 {"MchHvLvRight/Chamber01Right/Quad3Sect2.actual.iMon", {Chamber::Ch01, MeasurementType::HV_I, 32, Plane::Both, Side::Right}},
172
173 {"MchHvLvRight/Chamber01Right/Group04an", {Chamber::Ch01, MeasurementType::LV_V_FEE_ANALOG, 4, Plane::NonBending, Side::Right}},
174
175 {"MchHvLvLeft/Chamber00Left/SolCh00LCr01.SenseVoltage", {Chamber::Ch00, MeasurementType::LV_V_SOLAR, 1, Plane::Both, Side::Left}}
176
177};
178
180{
181 for (const auto e : expected) {
182 const auto alias = e.first;
183 const auto c = aliasToChamber(alias);
184 const auto m = aliasToMeasurementType(alias);
185 const auto n = aliasToNumber(alias);
186 const auto p = aliasToPlane(alias);
187 const auto s = aliasToSide(alias);
188 BOOST_CHECK_EQUAL(c, e.second.chamber);
189 BOOST_CHECK_EQUAL(m, e.second.measurement);
190 BOOST_CHECK_EQUAL(n, e.second.number);
191 BOOST_CHECK_EQUAL(p, e.second.plane);
192 BOOST_CHECK_EQUAL(s, e.second.side);
193 }
194}
195
196BOOST_AUTO_TEST_SUITE_END()
197BOOST_AUTO_TEST_SUITE_END()
uint32_t side
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
GLdouble n
Definition glcorearb.h:1982
const GLfloat * m
Definition glcorearb.h:4066
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint GLuint end
Definition glcorearb.h:469
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition glcorearb.h:2595
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition glcorearb.h:5034
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
MeasurementType aliasToMeasurementType(std::string_view alias)
std::vector< std::string > expectedHVAliasesVoltages
Definition HVAliases.cxx:16
int toInt(Chamber chamber)
Definition Chamber.cxx:68
Side aliasToSide(std::string_view alias)
Definition Side.cxx:22
Chamber aliasToChamber(std::string_view alias)
Definition Chamber.cxx:100
std::optional< Chamber > chamber(int chamberId)
Definition Chamber.cxx:17
int aliasToNumber(std::string_view dcsAlias)
Definition Number.cxx:30
std::vector< std::string > expectedLVAliasesSolar
std::vector< std::string > aliases(std::vector< MeasurementType > types={ MeasurementType::HV_V, MeasurementType::HV_I, MeasurementType::LV_V_FEE_ANALOG, MeasurementType::LV_V_FEE_DIGITAL, MeasurementType::LV_V_SOLAR})
bool isValid(std::string_view dcsAlias)
Plane aliasToPlane(std::string_view alias)
Definition Plane.cxx:25
std::vector< std::string > expectedHVAliasesCurrents
std::vector< std::string > expectedLVAliasesFeeAnalog
bool operator<(const Cathode &c1, const Cathode &c2)
Definition Cathode.cxx:16
std::vector< std::string > expectedLVAliasesFeeDigital
Definition LVAliases.cxx:16
BOOST_AUTO_TEST_CASE(NumberOfHVAliasesVoltagesIs188)
std::map< std::string, ID > expected
bool operator==(const CoarseLocation &a, const CoarseLocation &b)
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())