DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
messenger.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
6/*
7 * messenger.cpp
8 *
9 * Created on: Nov 3, 2015
10 * Author: Leonidas Georgopoulos
11 */
12
13#include "logging/Logging.hpp"
14
15#include "dbe/messenger.hpp"
17
18#include <cassert>
19#include <map>
20
21namespace dbe {
22namespace interface {
23namespace messenger {
24
25//------------------------------------------------------------------------------------------
32
33msglevels::t_levels const msglevels::all_levels = { debug, info, note, warn, error, fail };
34// provides codes from message level type ( level -> code )
39
40// provides level types from code ( code->level)
45
46// provides titles from level types
47static std::map<qt::t_str const, qt::t_str const> titles = {
48 { msglevels::debug, "Debug info" }, { msglevels::info, "Information" }, { msglevels::note, "Notice" },
49 { msglevels::warn, "Warning" }, { msglevels::error, "Error" }, { msglevels::fail, "Failure" }
50};
51
52std::mutex qt::m_block;
53std::atomic<bool> qt::m_batch_mode(false);
55//------------------------------------------------------------------------------------------
56
57//------------------------------------------------------------------------------------------
58qt::post_ret_type
59qt::post(t_str const& m, t_str const& l)
60{
61 std::lock_guard<std::mutex> lock(m_block);
62
63 if (m_batch_mode) {
64 merge_post(m, l);
65 } else {
66 direct_post(m, l);
67 }
68}
69//------------------------------------------------------------------------------------------
70
71//------------------------------------------------------------------------------------------
72qt::post_ret_type
73qt::direct_post(t_str const& m, t_str const& l)
74{
75 if (warn == l) {
76 TLOG_DEBUG(0) << static_cast<int>(messages::WARN) << m;
78 } else if (error == l) {
79 TLOG_DEBUG(0) << static_cast<int>(messages::ERROR) << m;
81 } else if (info == l) {
82 TLOG_DEBUG(0) << static_cast<int>(messages::INFO) << m;
84 } else if (fail == l) {
85 TLOG_DEBUG(0) << static_cast<int>(messages::FAIL) << m;
87 } else if (note == l) {
88 TLOG_DEBUG(0) << static_cast<int>(messages::NOTE) << m;
90 } else if (debug == l) {
91 TLOG_DEBUG(0) << static_cast<int>(messages::DEBUG) << m;
93 }
94}
95//------------------------------------------------------------------------------------------
96
97//------------------------------------------------------------------------------------------
98qt::post_ret_type
99qt::merge_post(t_str const& m, t_str const& l)
100{
101 auto codeit = codes.find(l);
102 assert(codeit != codes.end());
103 m_batches[static_cast<int>(codeit->second)].insert(m);
104}
105//------------------------------------------------------------------------------------------
106
107//------------------------------------------------------------------------------------------
108void
110{
111 for (auto clevel = m_batches.begin(); clevel != m_batches.end(); ++clevel) {
112 if (not clevel->empty()) {
113 t_str merged("Summary of messages during batch mode");
114
115 for (auto it = clevel->begin(); it != clevel->end();) {
116 auto cnt = clevel->count(*it);
117
118 t_str cmessage = *it;
119 merged += t_str("\n\n") + cmessage + t_str("\n\n #Occurances=") + std::to_string(cnt);
120
121 std::advance(it, cnt);
122 }
123
124 direct_post(merged, levels[static_cast<messages>(clevel - m_batches.begin())]);
125 clevel->clear();
126 }
127 }
128}
129//------------------------------------------------------------------------------------------
130
131//------------------------------------------------------------------------------------------
132std::unique_ptr<batch_guard>
134{
135 return std::unique_ptr<batch_guard>(new batch_guard());
136}
137//------------------------------------------------------------------------------------------
138
139//------------------------------------------------------------------------------------------
145//------------------------------------------------------------------------------------------
146
147//------------------------------------------------------------------------------------------
152//------------------------------------------------------------------------------------------
153
154} // namespace messenger
155} /* namespace interface */
156} /* namespace dbe */
static std::atomic< bool > m_batch_mode
static std::unique_ptr< batch_guard > batchmode()
static post_ret_type merge_post(t_str const &m, t_str const &l)
Definition messenger.cpp:99
std::array< t_message_bucket, static_cast< int >(messages::sizeme)> t_batches
static post_ret_type direct_post(t_str const &m, t_str const &l)
Definition messenger.cpp:73
static HAS_POST post_ret_type post(t_str const &, t_str const &)
Definition messenger.cpp:59
void fail(t_extstr const &, t_extstr const &)
static messenger_proxy & ref()
void info(t_extstr const &, t_extstr const &)
void warn(t_extstr const &, t_extstr const &)
void error(t_extstr const &, t_extstr const &)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
static std::map< qt::t_str const, qt::t_str const > titles
Definition messenger.cpp:47
static std::map< qt::t_str const, messages const > codes
Definition messenger.cpp:35
static std::map< messages const, qt::t_str const > levels
Definition messenger.cpp:41
Include QT Headers.
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34