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 kLive, // Live to triggers
23 kDead, // Dead to triggers due to a problem
24 kPaused // Triggers paused (so we are dead to triggers, but intentionally)
25 };
26
30 using state_time_t = uint64_t;
31
32
39
41
42
48 void set_state(State state);
49
53 std::map<State, state_time_t> get_time_map();
54
59
63 std::string get_report_string();
64
65 std::string get_state_name(State state) const;
66
67private:
68 state_time_t now() const;
69 // Precondition: m_mutex is locked by caller
70 void update_map();
71
72 std::mutex m_mutex;
74 std::map<State, state_time_t> m_state_times;
76
77};
78} // namespace dunedaq::trigger
79
80#endif // TRIGGER_PLUGINS_LIVETIMECOUNTER_HPP_
LivetimeCounter counts the total time in milliseconds spent in each of the available states.
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.