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