00001 #ifndef artdaq_core_Core_StatisticsCollection_hh 00002 #define artdaq_core_Core_StatisticsCollection_hh 00003 00004 #include "artdaq-core/Core/MonitoredQuantity.hh" 00005 #include <map> 00006 #include <memory> 00007 #include <mutex> 00008 #include <thread> 00009 00010 namespace artdaq 00011 { 00015 typedef std::shared_ptr<MonitoredQuantity> MonitoredQuantityPtr; 00016 00023 class StatisticsCollection 00024 { 00025 public: 00026 00031 static StatisticsCollection& getInstance(); 00032 00036 virtual ~StatisticsCollection() noexcept; 00037 00043 void addMonitoredQuantity(const std::string& name, 00044 MonitoredQuantityPtr mqPtr); 00045 00051 MonitoredQuantityPtr getMonitoredQuantity(const std::string& name) const; 00052 00056 void reset(); 00057 00061 void requestStop(); 00062 00066 void run(); 00067 00068 private: 00069 00073 explicit StatisticsCollection(); 00074 00075 // disallow any copying 00079 StatisticsCollection(StatisticsCollection const&) = delete; // not implemented 00083 void operator=(StatisticsCollection const&) = delete; // not implemented 00084 00088 double calculationInterval_; 00092 std::map<std::string, MonitoredQuantityPtr> monitoredQuantityMap_; 00093 00097 bool thread_stop_requested_; 00101 std::unique_ptr<std::thread> calculation_thread_; 00102 00106 mutable std::mutex map_mutex_; 00107 }; 00108 } 00109 00110 #endif /* artdaq_core_Core_StatisticsCollection_hh */