Skip to content

Commit a1b8fe0

Browse files
committed
documented Variant Visitor rate class
1 parent e8acba6 commit a1b8fe0

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

examples/4-RateDerivedMetric.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
1616
Monitoring::Get().addDerivedMetric("myMetric", AliceO2::Monitoring::DerivedMetricMode::RATE);
1717

1818
// now send at least two metrics to see the result
19-
for (int i = 0; i < 101; i+=10) {
19+
for (int i = 0; i < 101; i += 10) {
2020
Monitoring::Get().send(i, "myMetric");
2121
std::this_thread::sleep_for(std::chrono::milliseconds(250));
2222
}

src/Backends/InfluxDB.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void InfluxDB::send(const Metric& metric)
7171

7272
std::stringstream convert;
7373
convert << name << "," << tagSet << metricTags << " value=" << value << " " << convertTimestamp(metric.getTimestamp());
74-
74+
7575
try {
7676
transport->send(convert.str());
7777
} catch (MonitoringInternalException&) {

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

src/VariantVisitorRate.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,38 @@ namespace AliceO2
44
namespace Monitoring
55
{
66

7-
class VariantVisitor : public boost::static_visitor<boost::variant<int, std::string, double, int64_t>>
7+
class VariantVisitorRate : public boost::static_visitor<boost::variant<int, std::string, double, int64_t>>
88
{
99
private:
10+
/// Timestamp difference in milliseconds
1011
int timestampCount;
12+
1113
public:
12-
VariantVisitor(int count) {
13-
timestampCount = count;
14+
/// Creates variant visitor functor
15+
/// \param count timestamp difference in milliseconds
16+
VariantVisitorRate(int count) : timestampCount(count) {
1417
}
1518

19+
/// Overloads operator() to avoid operating on strings
20+
/// \throws MonitoringInternalException
1621
boost::variant<int, std::string, double, int64_t> operator()(const std::string& a, const std::string& b) const {
17-
std::cout << "skipping string" << std::endl;
22+
throw MonitoringInternalException("DerivedMetrics/VariantRateVisitor", "Cannot operate on string values");
1823
}
1924

25+
/// Calculates rate only when two arguments of the same type are passed
26+
/// \return calculated rate in Hz
2027
template<typename T>
2128
boost::variant<int, std::string, double, int64_t> operator()(const T& a, const T& b) const {
2229
return (1000*(a - b)) / timestampCount;
2330
}
2431

32+
/// If arguments have different type an exception is raised
33+
/// \throws MonitoringInternalException
2534
template<typename T, typename U>
2635
boost::variant<int, std::string, double, int64_t> operator()(const T& a, const U& b) const {
27-
throw std::invalid_argument("can't operate on different types");
36+
throw MonitoringInternalException("DerivedMetrics/VariantRateVisitor", "Cannot operate on different types");
2837
}
2938
};
3039

31-
}
32-
}
40+
} // namespace Monitoring
41+
} // namespace AliceO2

0 commit comments

Comments
 (0)