The Gaudi Framework  v32r2 (46d42edc)
InertMessageSvc.cpp
Go to the documentation of this file.
1 // Include files
2 
3 #include "InertMessageSvc.h"
4 
5 // ----------------------------------------------------------------------------
6 // Implementation file for class: InertMessageSvc
7 //
8 // 12/02/2013: Danilo Piparo
9 // ----------------------------------------------------------------------------
11 
12 //---------------------------------------------------------------------------
13 
14 StatusCode InertMessageSvc::initialize() {
15  StatusCode sc = MessageSvc::initialize(); // must be executed first
16  if ( sc.isFailure() ) return sc; // error printed already by MessageSvc
17 
18  info() << "Activating in a separate thread" << endmsg;
19  m_thread = std::thread( &InertMessageSvc::m_activate, this );
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 //---------------------------------------------------------------------------
25 
26 StatusCode InertMessageSvc::InertMessageSvc::finalize() {
27  m_deactivate();
28  m_thread.join();
29  return MessageSvc::finalize(); // must be called after all other actions
30 }
31 
32 //---------------------------------------------------------------------------
33 
35  m_isActive = true;
36  std::function<void()> thisMessageAction;
37  while ( m_isActive || !m_messageActionsQueue.empty() ) {
38  m_messageActionsQueue.pop( thisMessageAction );
39  if ( thisMessageAction ) thisMessageAction();
40  }
41 }
42 
43 //---------------------------------------------------------------------------
44 
46  if ( m_isActive ) {
47  // This would be the last action
48  m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
49  }
50 }
51 
52 //---------------------------------------------------------------------------
59 void InertMessageSvc::reportMessage( const Message& msg, int outputLevel ) {
60  // msg has to be copied as the reference may become invalid by the time it is used
61  m_messageActionsQueue.emplace(
62  [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
63 }
64 
65 //---------------------------------------------------------------------------
66 
68  // msg has to be copied as the reference may become invalid by the time it's used
69  m_messageActionsQueue.emplace(
70  [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
71 }
72 
73 //---------------------------------------------------------------------------
74 
75 void InertMessageSvc::reportMessage( const StatusCode& code, const std::string& source ) {
76  // msg has to be copied as the source may become invalid by the time it's used
77  m_messageActionsQueue.emplace( [this, code, s = std::string( source )]() { this->i_reportMessage( code, s ); } );
78 }
79 
80 //---------------------------------------------------------------------------
Thread safe extension to the standard MessageSvc.
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage()
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:356
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL class.
#define DECLARE_COMPONENT(type)
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:106
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
constexpr double m
Definition: SystemOfUnits.h:92
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
The Message class.
Definition: Message.h:17
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:237
string s
Definition: gaudirun.py:318
bool isFailure() const
Definition: StatusCode.h:130
int outputLevel() const override
Definition: MessageSvc.cpp:566
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192