The Gaudi Framework  v30r3 (a5ef0a68)
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 
15 {
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 //---------------------------------------------------------------------------
26 
27 StatusCode InertMessageSvc::InertMessageSvc::finalize()
28 {
29  m_deactivate();
30  m_thread.join();
31  return MessageSvc::finalize(); // must be called after all other actions
32 }
33 
34 //---------------------------------------------------------------------------
35 
37 {
38  m_isActive = true;
39  std::function<void()> thisMessageAction;
40  while ( m_isActive || !m_messageActionsQueue.empty() ) {
41  m_messageActionsQueue.pop( thisMessageAction );
42  if ( thisMessageAction ) thisMessageAction();
43  }
44 }
45 
46 //---------------------------------------------------------------------------
47 
49 {
50  if ( m_isActive ) {
51 // This would be the last action
52 #if defined( __clang__ ) || defined( __CLING__ )
53  m_messageActionsQueue.push( [this]() { m_isActive = false; } );
54 #else
55  m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
56 #endif
57  }
58 }
59 
60 //---------------------------------------------------------------------------
68 {
69 // msg has to be copied as the reference may become invalid by the time it is used
70 #if defined( __clang__ ) || defined( __CLING__ )
72  [ this, m = Message( msg ), outputLevel ]() { this->i_reportMessage( m, outputLevel ); } );
73 #else
74  m_messageActionsQueue.emplace(
75  [ this, m = Message( msg ), outputLevel ]() { this->i_reportMessage( m, outputLevel ); } );
76 #endif
77 }
78 
79 //---------------------------------------------------------------------------
80 
82 {
83 // msg has to be copied as the reference may become invalid by the time it's used
84 #if defined( __clang__ ) || defined( __CLING__ )
86  [ this, m = Message( msg ) ]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
87 #else
88  m_messageActionsQueue.emplace(
89  [ this, m = Message( msg ) ]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
90 #endif
91 }
92 
93 //---------------------------------------------------------------------------
94 
95 void InertMessageSvc::reportMessage( const StatusCode& code, const std::string& source )
96 {
97 // msg has to be copied as the source may become invalid by the time it's used
98 #if defined( __clang__ ) || defined( __CLING__ )
99  m_messageActionsQueue.push( [ this, code, s = std::string( source ) ]() { this->i_reportMessage( code, s ); } );
100 #else
101  m_messageActionsQueue.emplace( [ this, code, s = std::string( source ) ]() { this->i_reportMessage( code, s ); } );
102 #endif
103 }
104 
105 //---------------------------------------------------------------------------
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:372
bool isFailure() const
Definition: StatusCode.h:139
STL class.
#define DECLARE_COMPONENT(type)
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:113
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr double m
Definition: SystemOfUnits.h:94
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
The Message class.
Definition: Message.h:15
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:249
int outputLevel() const override
Definition: MessageSvc.cpp:598
string s
Definition: gaudirun.py:253
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209