artdaq_utilities  v1_03_00
 All Classes Namespaces Functions Variables Typedefs
MetricData.hh
1 #ifndef ARTDAQ_UTILITIES_PLUGINS_METRICDATA_HH
2 #define ARTDAQ_UTILITIES_PLUGINS_METRICDATA_HH
3 
4 // MetricManager class definition file
5 // Author: Eric Flumerfelt
6 // Last Modified: 11/14/2014
7 //
8 // MetricManager loads a user-specified set of plugins, sends them their configuration,
9 // and sends them data as it is recieved. It also maintains the state of the plugins
10 // relative to the application state.
11 
12 #include "artdaq-utilities/Plugins/MetricPlugin.hh"
13 #include "fhiclcpp/fwd.h"
14 #include "messagefacility/MessageLogger/MessageLogger.h"
15 
16 #include <sstream>
17 #include <list>
18 #include <thread>
19 #include <condition_variable>
20 #include <atomic>
21 
22 namespace artdaq
23 {
24  enum class MetricType
25  {
26  InvalidMetric,
27  StringMetric,
28  IntMetric,
29  DoubleMetric,
30  FloatMetric,
31  UnsignedMetric
32  };
33 
34  enum class MetricMode
35  {
36  LastPoint,
37  Accumulate,
38  Average
39  };
40 
41  struct MetricData
42  {
43  MetricData(const MetricData&) = default;
44 
45  MetricData(MetricData&&) noexcept = default;
46 
47  MetricData& operator=(const MetricData&) = default;
48 
49  MetricData& operator=(MetricData&&) noexcept = default;
50 
51  std::string Name;
52  std::string StringValue;
53 
54  union
55  {
56  int IntValue;
57  double DoubleValue;
58  float FloatValue;
59  long unsigned int UnsignedValue;
60  };
61 
62 
63  MetricType Type;
64  std::string Unit;
65  int Level;
66  MetricMode Mode;
67  std::string MetricPrefix;
68  bool UseNameOverride;
69 
70  MetricData(std::string const& name, std::string const& value, std::string const& unit, int level, MetricMode mode, std::string const& metricPrefix, bool useNameOverride)
71  : Name(name)
72  , StringValue(value)
73  , Type(MetricType::StringMetric)
74  , Unit(unit)
75  , Level(level)
76  , Mode(mode)
77  , MetricPrefix(metricPrefix)
78  , UseNameOverride(useNameOverride) {}
79 
80  MetricData(std::string const& name, int const& value, std::string const& unit, int level, MetricMode mode, std::string const& metricPrefix, bool useNameOverride)
81  : Name(name)
82  , IntValue(value)
83  , Type(MetricType::IntMetric)
84  , Unit(unit)
85  , Level(level)
86  , Mode(mode)
87  , MetricPrefix(metricPrefix)
88  , UseNameOverride(useNameOverride)
89  {}
90 
91  MetricData(std::string const& name, double const& value, std::string const& unit, int level, MetricMode mode, std::string const& metricPrefix, bool useNameOverride)
92  : Name(name)
93  , DoubleValue(value)
94  , Type(MetricType::DoubleMetric)
95  , Unit(unit)
96  , Level(level)
97  , Mode(mode)
98  , MetricPrefix(metricPrefix)
99  , UseNameOverride(useNameOverride)
100  {}
101 
102  MetricData(std::string const& name, float const& value, std::string const& unit, int level, MetricMode mode, std::string const& metricPrefix, bool useNameOverride)
103  : Name(name)
104  , FloatValue(value)
105  , Type(MetricType::FloatMetric)
106  , Unit(unit)
107  , Level(level)
108  , Mode(mode)
109  , MetricPrefix(metricPrefix)
110  , UseNameOverride(useNameOverride)
111  {}
112 
113  MetricData(std::string const& name, long unsigned int const& value, std::string const& unit, int level, MetricMode mode, std::string const& metricPrefix, bool useNameOverride)
114  : Name(name)
115  , UnsignedValue(value)
116  , Type(MetricType::UnsignedMetric)
117  , Unit(unit)
118  , Level(level)
119  , Mode(mode)
120  , MetricPrefix(metricPrefix)
121  , UseNameOverride(useNameOverride)
122  {}
123 
124  MetricData() : Name("")
125  , Type(MetricType::InvalidMetric) {}
126  };
127 }
128 
129 #endif /* ARTDAQ_UTILITIES_PLUGINS_METRICDATA_HH */