| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

InertMessageSvc.cpp
Go to the documentation of this file.
1 // Include files
2
3 // From Gaudi
4 #include "GaudiKernel/SvcFactory.h"
5 // local
6 #include "InertMessageSvc.h"
7
8 // ----------------------------------------------------------------------------
9 // Implementation file for class: InertMessageSvc
10 //
11 // 12/02/2013: Danilo Piparo
12 // ----------------------------------------------------------------------------
13 DECLARE_SERVICE_FACTORY( InertMessageSvc )
14
15 //---------------------------------------------------------------------------
16
17 InertMessageSvc::InertMessageSvc( const std::string& name, ISvcLocator* pSvcLocator )
18 : MessageSvc( name, pSvcLocator ), m_isActive( false )
19 {
20 }
21
22 //---------------------------------------------------------------------------
23
24 InertMessageSvc::~InertMessageSvc() {}
25
26 //---------------------------------------------------------------------------
27
28 StatusCode InertMessageSvc::initialize()
29 {
30 StatusCode sc = MessageSvc::initialize(); // must be executed first
31 if ( sc.isFailure() ) return sc; // error printed already by MessageSvc
32
33 info() << "Activating in a separate thread" << endmsg;
34 m_thread = std::thread( std::bind( &InertMessageSvc::m_activate, this ) );
35
36 return StatusCode::SUCCESS;
37 }
38
39 //---------------------------------------------------------------------------
40
41 StatusCode InertMessageSvc::InertMessageSvc::finalize()
42 {
43
44 m_deactivate();
45
46 m_thread.join();
47
48 return MessageSvc::finalize(); // must be called after all other actions
49 }
50
51 //---------------------------------------------------------------------------
52
53 void InertMessageSvc::m_activate()
54 {
55 m_isActive = true;
56 messageActionPtr thisMessageAction;
57 while ( m_isActive or not m_messageActionsQueue.empty() ) {
58 m_messageActionsQueue.pop( thisMessageAction );
59 ( *thisMessageAction )();
60 }
61 }
62
63 //---------------------------------------------------------------------------
64
65 void InertMessageSvc::m_deactivate()
66 {
67
68 if ( m_isActive ) {
69 // This would be the last action
70 m_messageActionsQueue.push( messageActionPtr( new messageAction( [this]() { m_isActive = false; } ) ) );
71 }
72 }
73
74 //---------------------------------------------------------------------------
81 void InertMessageSvc::reportMessage( const Message& msg, int outputLevel )
82 {
83 // msg has to be copied as the reference may become invalid by the time it's used
84 m_messageActionsQueue.push( messageActionPtr(
85 new messageAction( [ this, m = Message( msg ), outputLevel ]() { this->i_reportMessage( m, outputLevel ); } ) ) );
86 }
87
88 //---------------------------------------------------------------------------
89
90 void InertMessageSvc::reportMessage( const Message& msg )
91 {
92 // msg has to be copied as the reference may become invalid by the time it's used
93 m_messageActionsQueue.push( messageActionPtr( new messageAction(
94 [ this, m = Message( msg ) ]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } ) ) );
95 }
96
97 //---------------------------------------------------------------------------
98
99 void InertMessageSvc::reportMessage( const StatusCode& code, const std::string& source )
100 {
101 // msg has to be copied as the source may become invalid by the time it's used
102 m_messageActionsQueue.push( messageActionPtr(
103 new messageAction( [ this, code, s = std::string( source ) ]() { this->i_reportMessage( code, s ); } ) ) );
104 }
105
106 //---------------------------------------------------------------------------
InertMessageSvc::initialize
StatusCode initialize() override
Initialization of the service.
Definition: InertMessageSvc.cpp:28
StatusCode::SUCCESS
Definition: StatusCode.h:29
std::shared_ptr
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:121
InertMessageSvc
Thread safe extension to the standard MessageSvc.
Definition: InertMessageSvc.h:26
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
InertMessageSvc::~InertMessageSvc
~InertMessageSvc() override
Destructor.
Definition: InertMessageSvc.cpp:24
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:112
InertMessageSvc::reportMessage
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage()
Definition: InertMessageSvc.cpp:90
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:372
InertMessageSvc.h
std
STL namespace.
InertMessageSvc::messageActionPtr
std::shared_ptr< messageAction > messageActionPtr
This is done since the copy of the lambda storage is too expensive.
Definition: InertMessageSvc.h:58
InertMessageSvc::m_thread
std::thread m_thread
Definition: InertMessageSvc.h:61
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:61
std::string
STL class.
InertMessageSvc::m_deactivate
void m_deactivate()
Definition: InertMessageSvc.cpp:65
SvcFactory.h
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:113
std::thread::join
T join(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:94
std::bind
T bind(T...args)
DECLARE_SERVICE_FACTORY
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:211
Message
The Message class.
Definition: Message.h:15
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:249
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:598
gaudirun.s
string s
Definition: gaudirun.py:253
InertMessageSvc::m_messageActionsQueue
tbb::concurrent_bounded_queue< messageActionPtr > m_messageActionsQueue
Definition: InertMessageSvc.h:59
InertMessageSvc::m_activate
void m_activate()
Definition: InertMessageSvc.cpp:53
InertMessageSvc::m_isActive
bool m_isActive
Definition: InertMessageSvc.h:54
MessageSvc
Definition: MessageSvc.h:30
std::thread
STL class.
InertMessageSvc::messageAction
std::function< void()> messageAction
Definition: InertMessageSvc.h:56
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209