ATLAS Offline Software
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
35 class ISvcLocator;
36 class TH1I;
37 class TH2I;
38 
56 class TrigMessageSvc : public extends<Service, IMessageSvc, IIncidentListener> {
57 public:
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  {
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 
104 private:
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};
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
TrigMessageSvc::eraseMessage
virtual void eraseMessage() override
Definition: TrigMessageSvc.h:94
NOTSUPPORTED
#define NOTSUPPORTED
Definition: TrigMessageSvc.h:31
TrigMessageSvc::setupThreshold
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: TrigMessageSvc.cxx:174
TrigMessageSvc::m_messageActionsQueue
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
Definition: TrigMessageSvc.h:198
TrigMessageSvc::MsgAry
Private helper class to keep the count of messages of a type (MSG::LEVEL).
Definition: TrigMessageSvc.h:175
TrigMessageSvc::m_defaultFormat
Gaudi::Property< std::string > m_defaultFormat
Definition: TrigMessageSvc.h:108
TrigMessageSvc::MsgAry::msg
std::array< int, MSG::NUM_LEVELS > msg
Internal array of counters.
Definition: TrigMessageSvc.h:177
TrigMessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: TrigMessageSvc.h:172
TH1I
Definition: rootspy.cxx:332
TrigMessageSvc::messageCount
virtual int messageCount(MSG::Level logLevel) const override
Definition: TrigMessageSvc.cxx:460
TrigMessageSvc::m_msgCount
std::array< int, MSG::NUM_LEVELS > m_msgCount
counts per level
Definition: TrigMessageSvc.h:183
TrigMessageSvc::eraseStream
virtual void eraseStream() override
Definition: TrigMessageSvc.h:98
python.TrigPSCPythonDbSetup.logLevel
logLevel
If HLT PSK is set on command line read it from DB instead of COOL (ATR-25974)
Definition: TrigPSCPythonDbSetup.py:27
TrigMessageSvc::m_msgCountHist
TH1I * m_msgCountHist
Message counting per level histogram.
Definition: TrigMessageSvc.h:191
TrigMessageSvc::m_msgLimit
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: TrigMessageSvc.h:137
TrigMessageSvc::eraseStream
virtual void eraseStream(int) override
Definition: TrigMessageSvc.h:99
TrigMessageSvc::m_ersFormat
Gaudi::Property< std::string > m_ersFormat
Definition: TrigMessageSvc.h:110
TrigMessageSvc::eraseMessage
virtual void eraseMessage(const StatusCode &, const Message &) override
Definition: TrigMessageSvc.h:96
TrigMessageSvc::getLogColor
virtual std::string getLogColor(int) const override
Definition: TrigMessageSvc.h:89
TrigMessageSvc::TrigMessageSvc
TrigMessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: TrigMessageSvc.cxx:38
ReweightUtils.message
message
Definition: ReweightUtils.py:15
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
TrigMessageSvc::m_thresholdMapMutex
std::recursive_mutex m_thresholdMapMutex
Definition: TrigMessageSvc.h:194
TrigMessageSvc::asyncReporting
void asyncReporting()
Definition: TrigMessageSvc.cxx:269
covarianceTool.filter
filter
Definition: covarianceTool.py:514
TrigMessageSvc::initialize
virtual StatusCode initialize() override
Definition: TrigMessageSvc.cxx:54
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
TrigMessageSvc::outputLevel
virtual int outputLevel() const override
Definition: TrigMessageSvc.cxx:430
TrigMessageSvc::m_ersEventLimit
Gaudi::Property< int > m_ersEventLimit
Definition: TrigMessageSvc.h:165
TrigMessageSvc::m_doPublish
bool m_doPublish
are we publishing message statistics?
Definition: TrigMessageSvc.h:188
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TH2I
Definition: rootspy.cxx:410
TrigMessageSvc::m_sourceMap
std::map< std::string, MsgAry > m_sourceMap
counts per source
Definition: TrigMessageSvc.h:182
TrigMessageSvc::m_msgCountSrcHist
TH2I * m_msgCountSrcHist
Message counting per message source.
Definition: TrigMessageSvc.h:192
TrigMessageSvc::setOutputLevel
virtual void setOutputLevel(int new_level) override
Definition: TrigMessageSvc.cxx:442
TrigMessageSvc::insertMessage
virtual void insertMessage(const StatusCode &, Message) override
Definition: TrigMessageSvc.h:93
TrigMessageSvc::handle
virtual void handle(const Incident &incident) override
Definition: TrigMessageSvc.cxx:106
TrigMessageSvc::m_thresholdProp
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: TrigMessageSvc.h:127
TrigMessageSvc::reportMessage
virtual void reportMessage(const Message &message) override
Definition: TrigMessageSvc.cxx:420
TrigMessageSvc
MessageSvc used by the HLT applications.
Definition: TrigMessageSvc.h:56
TrigMessageSvc::m_eventIDLevel
Gaudi::Property< unsigned int > m_eventIDLevel
Definition: TrigMessageSvc.h:119
TrigMessageSvc::MsgAry::MsgAry
MsgAry()=default
Default constructor.
TrigMessageSvc::passErsFilter
bool passErsFilter(const std::string &source, const std::vector< std::string > &filter) const
Definition: TrigMessageSvc.cxx:465
TrigMessageSvc::passErsLimit
bool passErsLimit(const Message &msg)
Definition: TrigMessageSvc.cxx:481
TrigMessageSvc::m_statLevel
Gaudi::Property< unsigned int > m_statLevel
Definition: TrigMessageSvc.h:115
TrigMessageSvc::ThresholdMap
std::map< std::string, int, std::less<> > ThresholdMap
Definition: TrigMessageSvc.h:58
TrigMessageSvc::i_reportMessage
void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: TrigMessageSvc.cxx:283
TrigMessageSvc::stop
virtual StatusCode stop() override
Definition: TrigMessageSvc.cxx:92
TrigMessageSvc::eraseStream
virtual void eraseStream(int, std::ostream *) override
Definition: TrigMessageSvc.h:100
TrigConf::MSGTC::NUM_LEVELS
@ NUM_LEVELS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigMessageSvc::m_thread
std::thread m_thread
Thread for asynchronous reporting.
Definition: TrigMessageSvc.h:197
TrigMessageSvc::m_defaultTimeFormat
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: TrigMessageSvc.h:112
TrigMessageSvc::m_stats
Gaudi::Property< bool > m_stats
Definition: TrigMessageSvc.h:114
TrigMessageSvc::m_doSuppress
bool m_doSuppress
is suppression currently enabled?
Definition: TrigMessageSvc.h:189
TrigMessageSvc::i_reportERS
void i_reportERS(const Message &msg) const
Report message to online messaging system (ERS)
Definition: TrigMessageSvc.cxx:375
TrigMessageSvc::eraseMessage
virtual void eraseMessage(const StatusCode &) override
Definition: TrigMessageSvc.h:95
TrigMessageSvc::m_defaultStream
std::ostream * m_defaultStream
Pointer to the output stream.
Definition: TrigMessageSvc.h:171
TrigMessageSvc::m_msgHashCount
std::map< size_t, unsigned int > m_msgHashCount
counts per message hash
Definition: TrigMessageSvc.h:184
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigMessageSvc::m_publishLevel
Gaudi::Property< unsigned int > m_publishLevel
Definition: TrigMessageSvc.h:117
TrigMessageSvc::m_asyncReporting
bool m_asyncReporting
(
Definition: TrigMessageSvc.h:196
copySelective.source
string source
Definition: copySelective.py:32
TrigMessageSvc::reinitialize
virtual StatusCode reinitialize() override
Definition: TrigMessageSvc.cxx:76
TrigMessageSvc::insertStream
virtual void insertStream(int, std::string, std::ostream *) override
Definition: TrigMessageSvc.h:97
TrigMessageSvc::m_slotMsgCount
std::unordered_map< EventContext::ContextID_t, std::pair< EventContext::ContextEvt_t, MsgAry > > m_slotMsgCount
counts per slot and level
Definition: TrigMessageSvc.h:186
TrigConf::MSGTC::NIL
@ NIL
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:22
checker_macros.h
Define macros for attributes used to control the static checker.
TrigMessageSvc::reportMessage
virtual void reportMessage(const StatusCode &, std::string_view) override
Not supported by this implementation.
Definition: TrigMessageSvc.h:92
TrigMessageSvc::setupLimits
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: TrigMessageSvc.cxx:147
TrigMessageSvc::m_useERS
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_useERS
Special properties to control output to ERS of individual sources.
Definition: TrigMessageSvc.h:155
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TrigMessageSvc::ATLAS_NOT_CONST_THREAD_SAFE
virtual std::ostream *defaultStream ATLAS_NOT_CONST_THREAD_SAFE() const override
Definition: TrigMessageSvc.h:72
run.Message
Message
Definition: run.py:57
TrigMessageSvc::m_suppressRunningOnly
Gaudi::Property< bool > m_suppressRunningOnly
Definition: TrigMessageSvc.h:124
TrigMessageSvc::setDefaultStream
virtual void setDefaultStream(std::ostream *stream) override
Definition: TrigMessageSvc.h:77
TrigMessageSvc::start
virtual StatusCode start() override
Definition: TrigMessageSvc.cxx:84
TrigMessageSvc::m_suppress
Gaudi::Property< bool > m_suppress
Definition: TrigMessageSvc.h:123
TrigMessageSvc::useColor
virtual bool useColor() const override
Definition: TrigMessageSvc.h:88
TrigMessageSvc::bookHistograms
void bookHistograms()
Definition: TrigMessageSvc.cxx:114
TrigMessageSvc::eraseStream
virtual void eraseStream(std::ostream *) override
Definition: TrigMessageSvc.h:101
TrigMessageSvc::finalize
virtual StatusCode finalize() override
Definition: TrigMessageSvc.cxx:207
TrigMessageSvc::m_color
Gaudi::Property< bool > m_color
Definition: TrigMessageSvc.h:121