Skip to content

Commit e6b35a1

Browse files
committed
rate value returned as double
1 parent 3480eae commit e6b35a1

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/DerivedMetrics.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Metric DerivedMetrics::calculateRate(std::string name)
6161
throw MonitoringInternalException("DerivedMetrics/Calculate rate", "Division by 0");
6262
}
6363

64-
boost::variant< int, std::string, double, int64_t > rate = boost::apply_visitor(VariantVisitorRate(timestampCount), current, previous);
64+
auto rate = boost::apply_visitor(VariantVisitorRate(timestampCount), current, previous);
6565
return Metric{rate, name + "Rate"};
6666
}
6767

src/VariantVisitorRate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ class VariantVisitorRate : public boost::static_visitor<boost::variant<int, std:
1818

1919
/// Overloads operator() to avoid operating on strings
2020
/// \throws MonitoringInternalException
21-
boost::variant<int, std::string, double, int64_t> operator()(const std::string& a, const std::string& b) const {
21+
double operator()(const std::string& a, const std::string& b) const {
2222
throw MonitoringInternalException("DerivedMetrics/VariantRateVisitor", "Cannot operate on string values");
2323
}
2424

2525
/// Calculates rate only when two arguments of the same type are passed
2626
/// \return calculated rate in Hz
2727
template<typename T>
28-
boost::variant<int, std::string, double, int64_t> operator()(const T& a, const T& b) const {
29-
return (1000*(a - b)) / timestampCount;
28+
double operator()(const T& a, const T& b) const {
29+
return static_cast<double>((1000*(a - b)) / timestampCount);
3030
}
3131

3232
/// If arguments have different type an exception is raised
3333
/// \throws MonitoringInternalException
3434
template<typename T, typename U>
35-
boost::variant<int, std::string, double, int64_t> operator()(const T& a, const U& b) const {
35+
double operator()(const T& a, const U& b) const {
3636
throw MonitoringInternalException("DerivedMetrics/VariantRateVisitor", "Cannot operate on different types");
3737
}
3838
};

test/testDerived.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(derivedRateInt)
4949
AliceO2::Monitoring::Metric metric(result.value, name);
5050
AliceO2::Monitoring::Metric derived = derivedHandler.processMetric(metric);
5151
BOOST_CHECK_EQUAL(derived.getName(), "metricIntRate");
52-
BOOST_CHECK_EQUAL(boost::get<int>(derived.getValue()), result.rate);
52+
BOOST_CHECK_EQUAL(boost::get<double>(derived.getValue()), result.rate);
5353
} catch(MonitoringInternalException &e) {
5454
BOOST_TEST(e.what() == std::string("Not enough values"));
5555
}
@@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(derivedRateInt64_t) {
9595
AliceO2::Monitoring::Metric metric(result.value, name);
9696
AliceO2::Monitoring::Metric derived = derivedHandler.processMetric(metric);
9797
BOOST_CHECK_EQUAL(derived.getName(), "metricInt64_tRate");
98-
BOOST_CHECK_EQUAL(boost::get<int64_t>(derived.getValue()), result.rate);
98+
BOOST_CHECK_EQUAL(boost::get<double>(derived.getValue()), result.rate);
9999
} catch(MonitoringInternalException &e) {
100100
BOOST_TEST(e.what() == std::string("Not enough values"));
101101
}

0 commit comments

Comments
 (0)