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 <map>
19#include <cassert>
20
21namespace dbe
22{
23namespace interface
24{
25namespace messenger
26{
27
28//------------------------------------------------------------------------------------------
35
36msglevels::t_levels const msglevels::all_levels = {debug, info, note, warn, error, fail};
37// provides codes from message level type ( level -> code )
38static std::map<qt::t_str const, messages const> codes =
39{
46};
47
48// provides level types from code ( code->level)
49static std::map<messages const, qt::t_str const> levels =
50{
57};
58
59// provides titles from level types
60static std::map<qt::t_str const, qt::t_str const> titles =
61{
62 { msglevels::debug, "Debug info" },
63 { msglevels::info, "Information" },
64 { msglevels::note, "Notice" },
65 { msglevels::warn, "Warning" },
66 { msglevels::error, "Error" },
67 { msglevels::fail, "Failure" }
68};
69
70std::mutex qt::m_block;
71std::atomic<bool> qt::m_batch_mode ( false );
73//------------------------------------------------------------------------------------------
74
75//------------------------------------------------------------------------------------------
76qt::post_ret_type qt::post ( t_str const & m, t_str const & l )
77{
78 std::lock_guard<std::mutex> lock ( m_block );
79
80 if ( m_batch_mode )
81 {
82 merge_post ( m, l );
83 }
84 else
85 {
86 direct_post ( m, l );
87 }
88}
89//------------------------------------------------------------------------------------------
90
91//------------------------------------------------------------------------------------------
92qt::post_ret_type qt::direct_post ( t_str const & m, t_str const & l )
93{
94 if ( warn == l )
95 {
96 TLOG_DEBUG(0) << static_cast<int> ( messages::WARN ) << m ;
98 }
99 else if ( error == l )
100 {
101 TLOG_DEBUG(0) << static_cast<int> ( messages::ERROR ) << m ;
103 }
104 else if ( info == l )
105 {
106 TLOG_DEBUG(0) << static_cast<int> ( messages::INFO ) << m ;
108 }
109 else if ( fail == l )
110 {
111 TLOG_DEBUG(0) << static_cast<int> ( messages::FAIL ) << m ;
113 }
114 else if ( note == l )
115 {
116 TLOG_DEBUG(0) << static_cast<int> ( messages::NOTE ) << m ;
118 }
119 else if ( debug == l )
120 {
121 TLOG_DEBUG(0) << static_cast<int> ( messages::DEBUG ) << m ;
123 }
124}
125//------------------------------------------------------------------------------------------
126
127//------------------------------------------------------------------------------------------
128qt::post_ret_type qt::merge_post ( t_str const & m, t_str const & l )
129{
130 auto codeit = codes.find ( l );
131 assert ( codeit != codes.end() );
132 m_batches[static_cast<int> ( codeit->second )].insert ( m );
133}
134//------------------------------------------------------------------------------------------
135
136//------------------------------------------------------------------------------------------
138{
139 for ( auto clevel = m_batches.begin(); clevel != m_batches.end(); ++clevel )
140 {
141 if ( not clevel->empty() )
142 {
143 t_str merged ( "Summary of messages during batch mode" );
144
145 for(auto it = clevel->begin(); it != clevel->end(); ) {
146 auto cnt = clevel->count(*it);
147
148 t_str cmessage = *it;
149 merged += t_str ( "\n\n" ) + cmessage + t_str ( "\n\n #Occurances=" ) + std::to_string(cnt);
150
151 std::advance(it, cnt);
152 }
153
154 direct_post ( merged, levels[static_cast<messages> ( clevel - m_batches.begin() )] );
155 clevel->clear();
156 }
157 }
158}
159//------------------------------------------------------------------------------------------
160
161//------------------------------------------------------------------------------------------
162std::unique_ptr<batch_guard> qt::batchmode()
163{
164 return std::unique_ptr<batch_guard> ( new batch_guard() );
165}
166//------------------------------------------------------------------------------------------
167
168//------------------------------------------------------------------------------------------
174//------------------------------------------------------------------------------------------
175
176//------------------------------------------------------------------------------------------
181//------------------------------------------------------------------------------------------
182
183}// namespace messenger
184} /* namespace interface */
185} /* 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)
static post_ret_type direct_post(t_str const &m, t_str const &l)
Definition messenger.cpp:92
static HAS_POST post_ret_type post(t_str const &, t_str const &)
Definition messenger.cpp:76
std::array< t_message_bucket, static_cast< int >(messages::sizeme) > t_batches
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:60
static std::map< qt::t_str const, messages const > codes
Definition messenger.cpp:38
static std::map< messages const, qt::t_str const > levels
Definition messenger.cpp:49
Include QT Headers.
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34