artdaq_core  v3_05_07
StatisticsCollection.hh
1 #ifndef artdaq_core_Core_StatisticsCollection_hh
2 #define artdaq_core_Core_StatisticsCollection_hh
3 
4 #include <boost/thread.hpp>
5 #include <map>
6 #include <memory>
7 #include <mutex>
8 #include "artdaq-core/Core/MonitoredQuantity.hh"
9 
10 namespace artdaq {
14 typedef std::shared_ptr<MonitoredQuantity> MonitoredQuantityPtr;
15 
23 {
24 public:
30 
34  virtual ~StatisticsCollection() noexcept;
35 
41  void addMonitoredQuantity(const std::string& name,
42  MonitoredQuantityPtr mqPtr);
43 
49  MonitoredQuantityPtr getMonitoredQuantity(const std::string& name) const;
50 
54  void reset();
55 
59  void requestStop();
60 
64  void run();
65 
66 private:
70  explicit StatisticsCollection();
71 
72  // disallow any copying
76  StatisticsCollection(StatisticsCollection const&) = delete; // not implemented
80  void operator=(StatisticsCollection const&) = delete; // not implemented
81 
85  double calculationInterval_;
89  std::map<std::string, MonitoredQuantityPtr> monitoredQuantityMap_;
90 
94  bool thread_stop_requested_;
98  std::unique_ptr<boost::thread> calculation_thread_;
99 
103  mutable std::mutex map_mutex_;
104 };
105 } // namespace artdaq
106 
107 #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.