DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FrameErrorRegistry.hpp
Go to the documentation of this file.
1
8#ifndef DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_FRAMEERRORREGISTRY_HPP_
9#define DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_FRAMEERRORREGISTRY_HPP_
10
12
13#include <cstdint> // uint_t types
14#include <map>
15#include <mutex>
16#include <string>
17#include <utility>
18
19namespace dunedaq {
20namespace datahandlinglibs {
21
23{
24public:
26 {
27 public:
28 ErrorInterval(uint64_t start_ts, uint64_t end_ts) // NOLINT(build/unsigned)
30 , end_ts(end_ts)
31 {
32 }
33
34 uint64_t start_ts; // NOLINT(build/unsigned)
35 uint64_t end_ts; // NOLINT(build/unsigned)
36
37 bool operator<(const ErrorInterval& other) const { return end_ts < other.end_ts; }
38
39 bool operator>(const ErrorInterval& other) const { return end_ts > other.end_ts; }
40 };
41
43 : m_errors()
44 {
45 }
46
47 void set_ers_metadata(const std::string& ers_metadata) { m_ers_metadata = ers_metadata; }
48
49 void add_error(std::string error_name, ErrorInterval error)
50 {
51 std::lock_guard<std::mutex> guard(m_error_map_mutex);
52 m_errors.erase(error_name);
53 m_errors.insert(std::make_pair(error_name, error));
54 }
55
56 void remove_errors_until(uint64_t ts) // NOLINT(build/unsigned)
57 {
58 std::lock_guard<std::mutex> guard(m_error_map_mutex);
59 for (auto it = m_errors.begin(); it != m_errors.end();) {
60 if (ts > it->second.end_ts) {
61 std::string error_name = it->first;
62 it = m_errors.erase(it);
63 ers::info(ClearedError(ERS_HERE, m_ers_metadata.value_or(""), error_name));
64 } else {
65 it++;
66 }
67 }
68 }
69
71 {
72 std::lock_guard<std::mutex> guard(m_error_map_mutex);
73 for (const auto& [error_name, _] : m_errors) {
74 ers::warning(NewErrorRegistered(ERS_HERE, m_ers_metadata.value_or(""), error_name));
75 }
76 }
77
78 bool has_error(std::string error_name) { return m_errors.find(error_name) != m_errors.end(); }
79
80 bool has_error() { return !m_errors.empty(); }
81
82private:
83 std::map<std::string, ErrorInterval> m_errors;
85 std::optional<std::string> m_ers_metadata;
86};
87
88} // namespace datahandlinglibs
89} // namespace dunedaq
90
91#endif // DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_FRAMEERRORREGISTRY_HPP_
#define ERS_HERE
void set_ers_metadata(const std::string &ers_metadata)
void add_error(std::string error_name, ErrorInterval error)
std::map< std::string, ErrorInterval > m_errors
The DUNE-DAQ namespace.
CIB Buffer std::string descriptor Message from std::string descriptor CIB process error
void warning(const Issue &issue)
Definition ers.hpp:150
void info(const Issue &issue)
Definition ers.hpp:121