The Gaudi Framework  v30r1 (5d4f4ae2)
InertMessageSvc.cpp
Go to the documentation of this file.
1 // Include files
2 
3 // From Gaudi
5 // local
6 #include "InertMessageSvc.h"
7 
8 // ----------------------------------------------------------------------------
9 // Implementation file for class: InertMessageSvc
10 //
11 // 12/02/2013: Danilo Piparo
12 // ----------------------------------------------------------------------------
14 
15 //---------------------------------------------------------------------------
16 
18 {
19  StatusCode sc = MessageSvc::initialize(); // must be executed first
20  if ( sc.isFailure() ) return sc; // error printed already by MessageSvc
21 
22  info() << "Activating in a separate thread" << endmsg;
23  m_thread = std::thread( &InertMessageSvc::m_activate, this );
24 
25  return StatusCode::SUCCESS;
26 }
27 
28 //---------------------------------------------------------------------------
29 
30 StatusCode InertMessageSvc::InertMessageSvc::finalize()
31 {
32  m_deactivate();
33  m_thread.join();
34  return MessageSvc::finalize(); // must be called after all other actions
35 }
36 
37 //---------------------------------------------------------------------------
38 
40 {
41  m_isActive = true;
42  std::function<void()> thisMessageAction;
43  while ( m_isActive || !m_messageActionsQueue.empty() ) {
44  m_messageActionsQueue.pop( thisMessageAction );
45  if ( thisMessageAction ) thisMessageAction();
46  }
47 }
48 
49 //---------------------------------------------------------------------------
50 
52 {
53  if ( m_isActive ) {
54 // This would be the last action
55 #if defined( __clang__ ) || defined( __CLING__ )
56  m_messageActionsQueue.push( [this]() { m_isActive = false; } );
57 #else
58  m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
59 #endif
60  }
61 }
62 
63 //---------------------------------------------------------------------------
71 {
72 // msg has to be copied as the reference may become invalid by the time it is used
73 #if defined( __clang__ ) || defined( __CLING__ )
75  [ this, m = Message( msg ), outputLevel ]() { this->i_reportMessage( m, outputLevel ); } );
76 #else
77  m_messageActionsQueue.emplace(
78  [ this, m = Message( msg ), outputLevel ]() { this->i_reportMessage( m, outputLevel ); } );
79 #endif
80 }
81 
82 //---------------------------------------------------------------------------
83 
85 {
86 // msg has to be copied as the reference may become invalid by the time it's used
87 #if defined( __clang__ ) || defined( __CLING__ )
89  [ this, m = Message( msg ) ]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
90 #else
91  m_messageActionsQueue.emplace(
92  [ this, m = Message( msg ) ]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
93 #endif
94 }
95 
96 //---------------------------------------------------------------------------
97 
98 void InertMessageSvc::reportMessage( const StatusCode& code, const std::string& source )
99 {
100 // msg has to be copied as the source may become invalid by the time it's used
101 #if defined( __clang__ ) || defined( __CLING__ )
102  m_messageActionsQueue.push( [ this, code, s = std::string( source ) ]() { this->i_reportMessage( code, s ); } );
103 #else
104  m_messageActionsQueue.emplace( [ this, code, s = std::string( source ) ]() { this->i_reportMessage( code, s ); } );
105 #endif
106 }
107 
108 //---------------------------------------------------------------------------
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
Test for a status code of FAILURE.
Definition: StatusCode.h:61
STL class.
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:113
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:94
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:211
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
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