artdaq_core  v3_01_04
StatisticsCollection.hh
1 #ifndef artdaq_core_Core_StatisticsCollection_hh
2 #define artdaq_core_Core_StatisticsCollection_hh
3 
4 #include "artdaq-core/Core/MonitoredQuantity.hh"
5 #include <map>
6 #include <memory>
7 #include <mutex>
8 #include <boost/thread.hpp>
9 
10 namespace artdaq
11 {
15  typedef std::shared_ptr<MonitoredQuantity> MonitoredQuantityPtr;
16 
24  {
25  public:
26 
32 
36  virtual ~StatisticsCollection() noexcept;
37 
43  void addMonitoredQuantity(const std::string& name,
44  MonitoredQuantityPtr mqPtr);
45 
51  MonitoredQuantityPtr getMonitoredQuantity(const std::string& name) const;
52 
56  void reset();
57 
61  void requestStop();
62 
66  void run();
67 
68  private:
69 
73  explicit StatisticsCollection();
74 
75  // disallow any copying
79  StatisticsCollection(StatisticsCollection const&) = delete; // not implemented
83  void operator=(StatisticsCollection const&) = delete; // not implemented
84 
88  double calculationInterval_;
92  std::map<std::string, MonitoredQuantityPtr> monitoredQuantityMap_;
93 
97  bool thread_stop_requested_;
101  std::unique_ptr<boost::thread> calculation_thread_;
102 
106  mutable std::mutex map_mutex_;
107  };
108 }
109 
110 #endif /* artdaq_core_Core_StatisticsCollection_hh */
void addMonitoredQuantity(const std::string &name, MonitoredQuantityPtr mqPtr)
Registers a new MonitoredQuantity to be tracked by the StatisticsCollection.
static StatisticsCollection & getInstance()
Returns the singleton instance of the StatisticsCollection.
void reset()
Reset all MonitoredQuantity object in this StatisticsCollection.
void requestStop()
Stops the statistics calculation thread.
virtual ~StatisticsCollection() noexcept
StatisticsCollection Destructor.
A collection of MonitoredQuantity instances describing low-level statistics of the artdaq system...
MonitoredQuantityPtr getMonitoredQuantity(const std::string &name) const
Lookup and return a MonitoredQuantity from the StatisticsCollection.
void run()
Start the background thread that performs MonitoredQuantity statistics calculation.
std::shared_ptr< MonitoredQuantity > MonitoredQuantityPtr
A shared_ptr to a MonitoredQuantity instance.