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 
17 InertMessageSvc::InertMessageSvc(const std::string& name, ISvcLocator* pSvcLocator)
18  : MessageSvc(name, pSvcLocator),
19  m_isActive(false){
20 }
21 
22 //---------------------------------------------------------------------------
23 
25 }
26 
27 //---------------------------------------------------------------------------
28 
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;
35  this));
36 
37  return StatusCode::SUCCESS;
38 }
39 
40 //---------------------------------------------------------------------------
41 
42 StatusCode InertMessageSvc::InertMessageSvc::finalize() {
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 
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 
66 
67  if (m_isActive){
68  // This would be the last action
69  m_messageActionsQueue.push(messageActionPtr(new messageAction([this]() {m_isActive=false;})));
70  }
71 }
72 
73 //---------------------------------------------------------------------------
81  // msg has to be copied as the reference may become invalid by the time it's used
83  (messageActionPtr(new messageAction([this, m=Message(msg),outputLevel] ()
84  {this->i_reportMessage(m, outputLevel);})));
85 }
86 
87 //---------------------------------------------------------------------------
88 
90  // msg has to be copied as the reference may become invalid by the time it's used
92  (messageActionPtr(new messageAction([this,m=Message(msg)] ()
93  {this->i_reportMessage(m, this->outputLevel(m.getSource()));})));
94 }
95 
96 //---------------------------------------------------------------------------
97 
98 void InertMessageSvc::reportMessage(const StatusCode& code, const std::string& source) {
99  // msg has to be copied as the source may become invalid by the time it's used
101  messageActionPtr(new messageAction([this,code,s=std::string(source)] ()
102  {this->i_reportMessage(code, s);})));
103 }
104 
105 //---------------------------------------------------------------------------
StatusCode initialize() override
Initialization of the service.
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
~InertMessageSvc() override
Destructor.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
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:350
STL namespace.
std::shared_ptr< messageAction > messageActionPtr
This is done since the copy of the lambda storage is too expensive.
std::thread m_thread
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
STL class.
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:98
T join(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:93
T bind(T...args)
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:242
The Message class.
Definition: Message.h:15
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:227
int outputLevel() const override
Definition: MessageSvc.cpp:576
string s
Definition: gaudirun.py:245
tbb::concurrent_bounded_queue< messageActionPtr > m_messageActionsQueue
STL class.
std::function< void()> messageAction
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244