DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
messenger.cpp
Go to the documentation of this file.
1/*
2 * messenger.cpp
3 *
4 * Created on: Nov 3, 2015
5 * Author: Leonidas Georgopoulos
6 */
7
8#include "logging/Logging.hpp"
9
10#include "dbe/messenger.hpp"
12
13#include <map>
14#include <cassert>
15
16namespace dbe
17{
18namespace interface
19{
20namespace messenger
21{
22
23//------------------------------------------------------------------------------------------
30
31msglevels::t_levels const msglevels::all_levels = {debug, info, note, warn, error, fail};
32// provides codes from message level type ( level -> code )
33static std::map<qt::t_str const, messages const> codes =
34{
41};
42
43// provides level types from code ( code->level)
44static std::map<messages const, qt::t_str const> levels =
45{
52};
53
54// provides titles from level types
55static std::map<qt::t_str const, qt::t_str const> titles =
56{
57 { msglevels::debug, "Debug info" },
58 { msglevels::info, "Information" },
59 { msglevels::note, "Notice" },
60 { msglevels::warn, "Warning" },
61 { msglevels::error, "Error" },
62 { msglevels::fail, "Failure" }
63};
64
65std::mutex qt::m_block;
66std::atomic<bool> qt::m_batch_mode ( false );
68//------------------------------------------------------------------------------------------
69
70//------------------------------------------------------------------------------------------
71qt::post_ret_type qt::post ( t_str const & m, t_str const & l )
72{
73 std::lock_guard<std::mutex> lock ( m_block );
74
75 if ( m_batch_mode )
76 {
77 merge_post ( m, l );
78 }
79 else
80 {
81 direct_post ( m, l );
82 }
83}
84//------------------------------------------------------------------------------------------
85
86//------------------------------------------------------------------------------------------
87qt::post_ret_type qt::direct_post ( t_str const & m, t_str const & l )
88{
89 if ( warn == l )
90 {
91 TLOG_DEBUG(0) << static_cast<int> ( messages::WARN ) << m ;
93 }
94 else if ( error == l )
95 {
96 TLOG_DEBUG(0) << static_cast<int> ( messages::ERROR ) << m ;
98 }
99 else if ( info == l )
100 {
101 TLOG_DEBUG(0) << static_cast<int> ( messages::INFO ) << m ;
103 }
104 else if ( fail == l )
105 {
106 TLOG_DEBUG(0) << static_cast<int> ( messages::FAIL ) << m ;
108 }
109 else if ( note == l )
110 {
111 TLOG_DEBUG(0) << static_cast<int> ( messages::NOTE ) << m ;
113 }
114 else if ( debug == l )
115 {
116 TLOG_DEBUG(0) << static_cast<int> ( messages::DEBUG ) << m ;
118 }
119}
120//------------------------------------------------------------------------------------------
121
122//------------------------------------------------------------------------------------------
123qt::post_ret_type qt::merge_post ( t_str const & m, t_str const & l )
124{
125 auto codeit = codes.find ( l );
126 assert ( codeit != codes.end() );
127 m_batches[static_cast<int const> ( codeit->second )].insert ( m );
128}
129//------------------------------------------------------------------------------------------
130
131//------------------------------------------------------------------------------------------
133{
134 for ( auto clevel = m_batches.begin(); clevel != m_batches.end(); ++clevel )
135 {
136 if ( not clevel->empty() )
137 {
138 t_str merged ( "Summary of messages during batch mode" );
139
140 for(auto it = clevel->begin(); it != clevel->end(); ) {
141 auto cnt = clevel->count(*it);
142
143 t_str cmessage = *it;
144 merged += t_str ( "\n\n" ) + cmessage + t_str ( "\n\n #Occurances=" ) + std::to_string(cnt);
145
146 std::advance(it, cnt);
147 }
148
149 direct_post ( merged, levels[static_cast<messages> ( clevel - m_batches.begin() )] );
150 clevel->clear();
151 }
152 }
153}
154//------------------------------------------------------------------------------------------
155
156//------------------------------------------------------------------------------------------
157std::unique_ptr<batch_guard> qt::batchmode()
158{
159 return std::unique_ptr<batch_guard> ( new batch_guard() );
160}
161//------------------------------------------------------------------------------------------
162
163//------------------------------------------------------------------------------------------
169//------------------------------------------------------------------------------------------
170
171//------------------------------------------------------------------------------------------
176//------------------------------------------------------------------------------------------
177
178}// namespace messenger
179} /* namespace interface */
180} /* 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)
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:87
static HAS_POST post_ret_type post(t_str const &, t_str const &)
Definition messenger.cpp:71
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:112
static std::map< qt::t_str const, qt::t_str const > titles
Definition messenger.cpp:55
static std::map< qt::t_str const, messages const > codes
Definition messenger.cpp:33
static std::map< messages const, qt::t_str const > levels
Definition messenger.cpp:44
Include QT Headers.
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34