The Gaudi Framework  master (d98a2936)
InertMessageSvc.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "InertMessageSvc.h"
12 
14 
15 StatusCode InertMessageSvc::initialize() {
16  StatusCode sc = MessageSvc::initialize(); // must be executed first
17  if ( sc.isFailure() ) return sc; // error printed already by MessageSvc
18 
19  info() << "Activating in a separate thread" << endmsg;
20  m_thread = std::thread( &InertMessageSvc::m_activate, this );
21 
22  return StatusCode::SUCCESS;
23 }
24 
25 StatusCode InertMessageSvc::InertMessageSvc::finalize() {
26  m_deactivate();
27  m_thread.join();
28  return MessageSvc::finalize(); // must be called after all other actions
29 }
30 
32  m_isActive = true;
33  std::function<void()> thisMessageAction;
34  while ( m_isActive || !m_messageActionsQueue.empty() ) {
35  m_messageActionsQueue.pop( thisMessageAction );
36  if ( thisMessageAction ) thisMessageAction();
37  }
38 }
39 
41  if ( m_isActive ) {
42  // This would be the last action
43  m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
44  }
45 }
46 
53 void InertMessageSvc::reportMessage( const Message& msg, int outputLevel ) {
54  // msg has to be copied as the reference may become invalid by the time it is used
55  m_messageActionsQueue.emplace(
56  [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
57 }
58 
60  // msg has to be copied as the reference may become invalid by the time it's used
61  m_messageActionsQueue.emplace(
62  [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
63 }
64 
65 void InertMessageSvc::reportMessage( const StatusCode& code, std::string_view source ) {
66  // msg has to be copied as the source may become invalid by the time it's used
67  m_messageActionsQueue.emplace( [this, code, s = std::string{ source }]() { this->i_reportMessage( code, s ); } );
68 }
InertMessageSvc::m_isActive
bool m_isActive
Definition: InertMessageSvc.h:56
gaudirun.s
string s
Definition: gaudirun.py:346
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:310
InertMessageSvc
Definition: InertMessageSvc.h:32
StatusCode
Definition: StatusCode.h:64
Message
Definition: Message.h:25
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:107
InertMessageSvc::m_deactivate
void m_deactivate()
Definition: InertMessageSvc.cpp:40
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:198
InertMessageSvc.h
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:428
MessageSvc::finalize
StatusCode finalize() override
Definition: MessageSvc.cpp:198
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
InertMessageSvc::m_activate
void m_activate()
Definition: InertMessageSvc.cpp:31
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:45
ProduceConsume.Message
Message
Definition: ProduceConsume.py:110
MessageSvc::initialize
StatusCode initialize() override
Definition: MessageSvc.cpp:89
InertMessageSvc::m_messageActionsQueue
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
Definition: InertMessageSvc.h:58
InertMessageSvc::reportMessage
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage()
Definition: InertMessageSvc.cpp:59