ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMessageSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef TRIGSERVICES_TRIGMESSAGESVC_H
5#define TRIGSERVICES_TRIGMESSAGESVC_H
6
7
8#include "tbb/concurrent_queue.h"
9
10#include <TH1I.h>
11#include <TH2I.h>
12
14#include "GaudiKernel/IIncidentListener.h"
15#include "GaudiKernel/IMessageSvc.h"
16#include "GaudiKernel/Message.h"
17#include "Gaudi/Property.h"
18#include "GaudiKernel/Service.h"
19#include "GaudiKernel/StatusCode.h"
20
21// Include files
22#include <iosfwd>
23#include <map>
24#include <memory>
25#include <mutex>
26#include <set>
27#include <string>
28#include <thread>
29#include <vector>
30
31// Helper to mark some virtual methods as not supported
32#define NOTSUPPORTED \
33 throw std::logic_error(std::string(__func__) + " is not supported by TrigMessageSvc")
34
35// Forward declarations
36class ISvcLocator;
37class TH1I;
38class TH2I;
39
57class TrigMessageSvc : public extends<Service, IMessageSvc, IIncidentListener> {
58public:
59 typedef std::map<std::string, int, std::less<> > ThresholdMap;
60
61 TrigMessageSvc(const std::string& name, ISvcLocator* svcloc);
62
63 virtual StatusCode reinitialize() override;
64 virtual StatusCode initialize() override;
65 virtual StatusCode start() override;
66 virtual StatusCode stop() override;
67 virtual StatusCode finalize() override;
68 virtual void handle( const Incident& incident ) override;
69
70 virtual void reportMessage(const Message& message) override;
71 virtual void reportMessage(const Message& msg, int outputLevel) override;
72 virtual void reportMessage(std::string source, int type, std::string message) override;
73 virtual std::ostream* defaultStream ATLAS_NOT_CONST_THREAD_SAFE() const override
74 {
75 return m_defaultStream;
76 }
77
78 virtual void setDefaultStream(std::ostream* stream) override
79 {
80 m_defaultStream = stream;
81 }
82
83 virtual int outputLevel() const override;
84 virtual int outputLevel(std::string_view source) const override;
85 virtual void setOutputLevel(int new_level) override;
86 virtual void setOutputLevel(std::string_view source, int new_level) override;
87 virtual int messageCount(MSG::Level logLevel) const override;
88
89 virtual bool useColor() const override { return m_color; }
90 virtual std::string getLogColor(int) const override { return ""; }
91
93 virtual void reportMessage(const StatusCode&, std::string_view) override { NOTSUPPORTED; }
94 //coverity[PASS_BY_VALUE]
95 virtual void insertMessage(const StatusCode&, Message) override { NOTSUPPORTED; }
96 virtual void eraseMessage() override { NOTSUPPORTED; }
97 virtual void eraseMessage(const StatusCode&) override { NOTSUPPORTED; }
98 virtual void eraseMessage(const StatusCode&, const Message&) override { NOTSUPPORTED; }
99 virtual void insertStream(int, std::string, std::ostream*) override { NOTSUPPORTED; }
100 virtual void eraseStream() override { NOTSUPPORTED; }
101 virtual void eraseStream(int) override { NOTSUPPORTED; }
102 virtual void eraseStream(int, std::ostream*) override { NOTSUPPORTED; }
103 virtual void eraseStream(std::ostream*) override { NOTSUPPORTED; }
105
106private:
108 // Properties
110 Gaudi::Property<std::string> m_defaultFormat{this, "Format", Message::getDefaultFormat(),
111 "Default message format"};
112 Gaudi::Property<std::string> m_ersFormat{this, "ErsFormat", Message::getDefaultFormat(),
113 "ERS message format"};
114 Gaudi::Property<std::string> m_defaultTimeFormat{
115 this, "timeFormat", Message::getDefaultTimeFormat(), "Message time format"};
116 Gaudi::Property<bool> m_stats{this, "showStats", false, "Show message statistics"};
117 Gaudi::Property<unsigned int> m_statLevel{this, "statLevel", 0,
118 "Show total message statistics for >= level"};
119 Gaudi::Property<unsigned int> m_publishLevel{this, "publishLevel", MSG::INFO,
120 "Publish message statistics for this and higher message levels"};
121 Gaudi::Property<unsigned int> m_eventIDLevel{this, "printEventIDLevel", MSG::NIL,
122 "Print event ID for this and higher message levels"};
123 Gaudi::Property<bool> m_color{this, "useColors", false,
124 "Colors are not supported by TrigMessageSvc"};
125 Gaudi::Property<bool> m_suppress{this, "enableSuppression", false, "Enable message suppression"};
126 Gaudi::Property<bool> m_suppressRunningOnly{this, "suppressRunningOnly", true,
127 "Use message suppression only during RUNNING state"};
128
129 std::array<Gaudi::Property<std::vector<std::string>>, MSG::NUM_LEVELS> m_thresholdProp{
130 {{/*ignored*/},
131 {this, "setVerbose"},
132 {this, "setDebug"},
133 {this, "setInfo"},
134 {this, "setWarning"},
135 {this, "setError"},
136 {this, "setFatal"},
137 {this, "setAlways"}}};
138
139 std::array<Gaudi::Property<int>, MSG::NUM_LEVELS> m_msgLimit{{{this, "defaultLimit", 500},
140 {this, "verboseLimit", 500},
141 {this, "debugLimit", 500},
142 {this, "infoLimit", 500},
143 {this, "warningLimit", 500},
144 {this, "errorLimit", 500},
145 {this, "fatalLimit", 500},
146 {this, "alwaysLimit", 0}}};
147
157 std::array<Gaudi::Property<std::vector<std::string>>, MSG::NUM_LEVELS> m_useERS{
158 {{/*ignored*/},
159 {this, "useErsVerbose", {}},
160 {this, "useErsDebug", {}},
161 {this, "useErsInfo", {}},
162 {this, "useErsWarning", {}},
163 {this, "useErsError", {}},
164 {this, "useErsFatal", {}},
165 {this, "useErsAlways", {}}}};
166
167 Gaudi::Property<int> m_ersEventLimit{this, "ersPerEventLimit", -1,
168 "Maximum number of messages (per event and level) that are forwarded to ERS (-1: disabled)"};
169
171 // Private members
173 std::ostream* m_defaultStream = &std::cout;
175
177 struct MsgAry final {
179 std::array<int, MSG::NUM_LEVELS> msg = {{0}};
181 MsgAry() = default;
182 };
183
184 std::map<std::string, MsgAry> m_sourceMap;
185 std::array<int, MSG::NUM_LEVELS> m_msgCount{};
186 std::map<size_t, unsigned int> m_msgHashCount;
187 std::unordered_map<EventContext::ContextID_t,
188 std::pair<EventContext::ContextEvt_t, MsgAry>> m_slotMsgCount;
189
190 bool m_doPublish{false};
191 bool m_doSuppress{false};
192
193 TH1I* m_msgCountHist{nullptr};
194 TH2I* m_msgCountSrcHist{nullptr};
195
196 mutable std::recursive_mutex m_thresholdMapMutex;
197
198 bool m_asyncReporting{false};
199 std::thread m_thread;
200 tbb::concurrent_bounded_queue<std::function<void()>> m_messageActionsQueue;
201
202 void setupLimits(Gaudi::Details::PropertyBase& prop);
203 void setupThreshold(Gaudi::Details::PropertyBase& prop);
204 bool passErsFilter(const std::string& source, const std::vector<std::string>& filter) const;
205 bool passErsLimit(const Message& msg);
206 void i_reportMessage(const Message& msg, int outputLevel);
207 void i_reportERS(const Message& msg) const;
208 void asyncReporting();
209 void bookHistograms();
210};
211
212#endif
#define NOTSUPPORTED
Define macros for attributes used to control the static checker.
virtual void eraseMessage(const StatusCode &) override
bool passErsFilter(const std::string &source, const std::vector< std::string > &filter) const
virtual std::string getLogColor(int) const override
Gaudi::Property< std::string > m_ersFormat
virtual void eraseStream(int, std::ostream *) override
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
virtual void eraseStream(std::ostream *) override
void setupLimits(Gaudi::Details::PropertyBase &prop)
virtual int outputLevel() const override
virtual StatusCode finalize() override
void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
bool passErsLimit(const Message &msg)
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
virtual StatusCode start() override
Gaudi::Property< std::string > m_defaultTimeFormat
std::map< std::string, MsgAry > m_sourceMap
counts per source
std::map< size_t, unsigned int > m_msgHashCount
counts per message hash
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
std::unordered_map< EventContext::ContextID_t, std::pair< EventContext::ContextEvt_t, MsgAry > > m_slotMsgCount
counts per slot and level
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_useERS
Special properties to control output to ERS of individual sources.
Gaudi::Property< bool > m_color
std::recursive_mutex m_thresholdMapMutex
virtual void reportMessage(const Message &message) override
TH1I * m_msgCountHist
Message counting per level histogram.
void i_reportERS(const Message &msg) const
Report message to online messaging system (ERS).
bool m_doPublish
are we publishing message statistics?
virtual void insertMessage(const StatusCode &, Message) override
Gaudi::Property< std::string > m_defaultFormat
std::map< std::string, int, std::less<> > ThresholdMap
virtual void eraseMessage(const StatusCode &, const Message &) override
ThresholdMap m_thresholdMap
Output level threshold map.
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Gaudi::Property< bool > m_stats
virtual StatusCode stop() override
virtual void eraseStream() override
Gaudi::Property< bool > m_suppressRunningOnly
virtual int messageCount(MSG::Level logLevel) const override
bool m_doSuppress
is suppression currently enabled?
virtual bool useColor() const override
TH2I * m_msgCountSrcHist
Message counting per message source.
Gaudi::Property< int > m_ersEventLimit
virtual void eraseMessage() override
Gaudi::Property< unsigned int > m_statLevel
virtual void setOutputLevel(int new_level) override
std::array< int, MSG::NUM_LEVELS > m_msgCount
counts per level
virtual StatusCode reinitialize() override
virtual void handle(const Incident &incident) override
Gaudi::Property< unsigned int > m_eventIDLevel
virtual void insertStream(int, std::string, std::ostream *) override
Gaudi::Property< bool > m_suppress
std::thread m_thread
Thread for asynchronous reporting.
virtual void reportMessage(const StatusCode &, std::string_view) override
Not supported by this implementation.
Gaudi::Property< unsigned int > m_publishLevel
virtual StatusCode initialize() override
TrigMessageSvc(const std::string &name, ISvcLocator *svcloc)
std::ostream * m_defaultStream
Pointer to the output stream.
virtual void setDefaultStream(std::ostream *stream) override
virtual std::ostream *defaultStream ATLAS_NOT_CONST_THREAD_SAFE() const override
virtual void eraseStream(int) override
MsgAry()=default
Default constructor.
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
MsgStream & msg
Definition testRead.cxx:32