DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
LivetimeCounter.hpp
Go to the documentation of this file.
1#ifndef TRIGGER_PLUGINS_LIVETIMECOUNTER_HPP_
2#define TRIGGER_PLUGINS_LIVETIMECOUNTER_HPP_
3#include <chrono>
4#include <map>
5#include <mutex>
6#include <string>
7
8namespace dunedaq::trigger {
9
19{
20public:
21 enum class State
22 {
23 kLive, // Live to triggers
24 kDead, // Dead to triggers due to a problem
25 kPaused // Triggers paused (so we are dead to triggers, but intentionally)
26 };
27
31 using state_time_t = uint64_t;
32
39
41
47 void set_state(State state);
48
52 std::map<State, state_time_t> get_time_map();
53
58
62 std::string get_report_string();
63
64 std::string get_state_name(State state) const;
65
66private:
67 state_time_t now() const;
68 // Precondition: m_mutex is locked by caller
69 void update_map();
70
71 std::mutex m_mutex;
73 std::map<State, state_time_t> m_state_times;
75};
76} // namespace dunedaq::trigger
77
78#endif // TRIGGER_PLUGINS_LIVETIMECOUNTER_HPP_
uint64_t state_time_t
A type to store a time duration in milliseconds.
std::map< State, state_time_t > m_state_times
LivetimeCounter(State state)
Construct a LivetimeCounter in the given state.
std::string get_state_name(State state) const
std::string get_report_string()
Get a nicely-formatted string of the time spent in each state.
std::map< State, state_time_t > get_time_map()
Get a map of accumulated time in milliseconds in each state.
void set_state(State state)
Set the current state to state.
state_time_t get_time(State state)
Get the accumulated time in milliseconds spent in a particular state.