Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #if defined( __clang__ ) || defined( __CLING__ )
49  m_messageActionsQueue.push( [this]() { m_isActive = false; } );
50 #else
51  m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
52 #endif
53  }
54 }
55 
56 //---------------------------------------------------------------------------
64 // msg has to be copied as the reference may become invalid by the time it is used
65 #if defined( __clang__ ) || defined( __CLING__ )
66  m_messageActionsQueue.push( [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
67 #else
68  m_messageActionsQueue.emplace(
69  [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
70 #endif
71 }
72 
73 //---------------------------------------------------------------------------
74 
76 // msg has to be copied as the reference may become invalid by the time it's used
77 #if defined( __clang__ ) || defined( __CLING__ )
79  [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
80 #else
81  m_messageActionsQueue.emplace(
82  [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
83 #endif
84 }
85 
86 //---------------------------------------------------------------------------
87 
88 void InertMessageSvc::reportMessage( const StatusCode& code, const std::string& source ) {
89 // msg has to be copied as the source may become invalid by the time it's used
90 #if defined( __clang__ ) || defined( __CLING__ )
91  m_messageActionsQueue.push( [this, code, s = std::string( source )]() { this->i_reportMessage( code, s ); } );
92 #else
93  m_messageActionsQueue.emplace( [this, code, s = std::string( source )]() { this->i_reportMessage( code, s ); } );
94 #endif
95 }
96 
97 //---------------------------------------------------------------------------
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
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:353
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
bool isFailure() const
Definition: StatusCode.h:130
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
The Message class.
Definition: Message.h:17
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:234
int outputLevel() const override
Definition: MessageSvc.cpp:563
string s
Definition: gaudirun.py:312
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192