| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

CommonMessaging.h
Go to the documentation of this file.
1 /*
2 * CommonMessaging.h
3 *
4 * Created on: Feb 20, 2009
5 * Author: Marco Clemencic
6 */
7
8 #ifndef COMMONMESSAGING_H_
9 #define COMMONMESSAGING_H_
10 #include "GaudiKernel/GaudiException.h"
11 #include "GaudiKernel/IMessageSvc.h"
12 #include "GaudiKernel/IService.h"
13 #include "GaudiKernel/ISvcLocator.h"
14 #include "GaudiKernel/MsgStream.h"
15 #include "GaudiKernel/SmartIF.h"
16 #include <boost/thread/tss.hpp>
17
18 #include <memory>
19 #include <utility>
20
25 #define generate_( method, ret, args ) \
26 \
27 template <typename T, typename SFINAE = void> \
28 struct has_##method : std::false_type { \
29 }; \
30 template <typename T> \
31 struct has_##method<T, is_valid_t<decltype( std::declval<const T&>().method args )>> : std::true_type { \
32 }; \
33 \
34 template <typename Base> \
35 struct add_##method : public Base { \
36 using Base::Base; \
37 virtual ~add_##method() = default; \
38 virtual ret method args const = 0; \
39 };
40
41 namespace implementation_detail
42 {
43 template <typename>
44 struct void_t {
45 using type = void;
46 };
47 template <typename T>
48 using is_valid_t = typename void_t<T>::type;
49
50 generate_( name, const std::string&, () ) generate_( serviceLocator, SmartIF<ISvcLocator>&, () )
51 }
52 #undef generate_
53
54 template <typename Base>
55 using add_name = typename std::conditional<implementation_detail::has_name<Base>::value, Base,
56 implementation_detail::add_name<Base>>::type;
57 template <typename Base>
58 using add_serviceLocator = typename std::conditional<implementation_detail::has_serviceLocator<Base>::value, Base,
59 implementation_detail::add_serviceLocator<Base>>::type;
60
61 template <typename Base>
62 class CommonMessaging;
63
64 class CommonMessagingBase
65 {
66 public:
68 virtual ~CommonMessagingBase() = default;
70 virtual void create_msgSvc() const = 0;
71 virtual void create_msgStream() const = 0;
72
76 inline SmartIF<IMessageSvc>& msgSvc() const
77 {
78 if ( UNLIKELY( !m_msgsvc ) ) create_msgSvc();
79 return m_msgsvc;
80 }
81
83 inline MsgStream& msgStream() const
84 {
85 if ( UNLIKELY( ( !m_msgStream.get() ) ) ) create_msgStream();
86 return *m_msgStream;
87 }
88
99 inline MsgStream& msgStream( const MSG::Level level ) const { return msgStream() << level; }
100
102 inline MsgStream& always() const { return msgStream( MSG::ALWAYS ); }
103
105 inline MsgStream& fatal() const { return msgStream( MSG::FATAL ); }
106
108 inline MsgStream& err() const { return msgStream( MSG::ERROR ); }
109
111 inline MsgStream& error() const { return msgStream( MSG::ERROR ); }
112
114 inline MsgStream& warning() const { return msgStream( MSG::WARNING ); }
115
117 inline MsgStream& info() const { return msgStream( MSG::INFO ); }
118
120 inline MsgStream& debug() const { return msgStream( MSG::DEBUG ); }
121
123 inline MsgStream& verbose() const { return msgStream( MSG::VERBOSE ); }
124
126 inline MsgStream& msg() const { return msgStream( MSG::INFO ); }
127
129 inline MSG::Level msgLevel() const
130 {
131 if ( UNLIKELY( ( !m_msgStream.get() ) ) ) create_msgStream();
132 if ( UNLIKELY( ( !m_level.get() ) ) ) {
133 return MSG::NIL;
134 }
135 return *m_level;
136 }
137
139 inline MSG::Level outputLevel() const __attribute__( ( deprecated ) ) { return msgLevel(); }
140
142 inline bool msgLevel( MSG::Level lvl ) const { return UNLIKELY( msgLevel() <= lvl ); }
143
144 private:
145 template <typename Base>
146 friend class CommonMessaging;
147
149 mutable boost::thread_specific_ptr<MsgStream> m_msgStream;
150
151 // mutable MSG::Level m_level = MSG::NIL;
152 mutable boost::thread_specific_ptr<MSG::Level> m_level;
153
155 mutable SmartIF<IMessageSvc> m_msgsvc;
156 };
157
158 template <typename BASE>
159 class GAUDI_API CommonMessaging : public add_serviceLocator<add_name<BASE>>, public CommonMessagingBase
160 {
161 public:
162 using base_class = CommonMessaging;
163
165 using add_serviceLocator<add_name<BASE>>::add_serviceLocator;
166
167 private:
168 // out-of-line 'cold' functions -- put here so as to not blow up the inline 'hot' functions
169 void create_msgSvc() const override final
170 {
171 // Get default implementation of the message service.
172 m_msgsvc = this->serviceLocator();
173 }
174 void create_msgStream() const override final
175 {
176 auto& ms = msgSvc();
177 m_msgStream.reset( new MsgStream( ms, this->name() ) );
178 m_level.reset( new MSG::Level( m_msgStream.get() ? m_msgStream->level() : MSG::NIL ) );
179 }
180
181 protected:
184 void updateMsgStreamOutputLevel( int level )
185 {
186 if ( !m_msgStream.get() ) {
187 create_msgStream();
188 }
189 if ( level != MSG::NIL && level != *m_level ) {
190 if ( msgSvc() ) {
191 msgSvc()->setOutputLevel( this->name(), level );
192 }
193 if ( m_msgStream.get() ) m_msgStream->setLevel( level );
194 if ( UNLIKELY( MSG::Level( level ) <= MSG::DEBUG ) )
195 debug() << "Property update for OutputLevel : new value = " << level << endmsg;
196 *m_level = MSG::Level( level );
197 }
198 }
199 };
200
201 #endif /* COMMONMESSAGING_H_ */
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:126
__attribute__
#define __attribute__(x)
Definition: System.cpp:79
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
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:117
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:123
MSG::DEBUG
Definition: IMessageSvc.h:16
CommonMessagingBase::m_msgsvc
SmartIF< IMessageSvc > m_msgsvc
Pointer to the message service;.
Definition: CommonMessaging.h:155
Gaudi::Functional::void
class MergingTransformer< Out(const vector_of_const_< In > void
Definition: MergingTransformer.h:23
add_name
typename std::conditional< implementation_detail::has_name< Base >::value, Base, implementation_detail::add_name< Base >>::type add_name
Definition: CommonMessaging.h:56
MSG::VERBOSE
Definition: IMessageSvc.h:16
CommonMessaging::create_msgSvc
void create_msgSvc() const override final
cold functionality
Definition: CommonMessaging.h:169
CommonMessagingBase::err
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:108
BrunelScenarioForwardScheduler.ms
ms
Definition: BrunelScenarioForwardScheduler.py:130
std::string
STL class.
MSG::FATAL
Definition: IMessageSvc.h:16
MSG::Level
Level
Definition: IMessageSvc.h:16
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:111
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:114
CommonMessaging::updateMsgStreamOutputLevel
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
Definition: CommonMessaging.h:184
ForwardSchedulerSimpleTest.msgSvc
msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
GaudiException.h
SmartIF.h
CommonMessagingBase::m_level
boost::thread_specific_ptr< MSG::Level > m_level
Definition: CommonMessaging.h:152
MSG::NIL
Definition: IMessageSvc.h:16
implementation_detail::void_t
Definition: CommonMessaging.h:44
CommonMessagingBase::m_msgStream
boost::thread_specific_ptr< MsgStream > m_msgStream
The predefined message stream.
Definition: CommonMessaging.h:149
IMessageSvc.h
CommonMessagingBase
Definition: CommonMessaging.h:64
CommonMessaging::create_msgStream
void create_msgStream() const override final
Definition: CommonMessaging.h:174
IService.h
implementation_detail
Definition: CommonMessaging.h:41
CommonMessagingBase::outputLevel
MSG::Level outputLevel() const __attribute__((deprecated))
Backward compatibility function for getting the output level.
Definition: CommonMessaging.h:139
std::conditional
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:120
implementation_detail::generate_
generate_(name, const std::string &,()) generate_(serviceLocator
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:83
implementation_detail::void_t::type
void type
Definition: CommonMessaging.h:45
CommonMessaging
Definition: CommonMessaging.h:62
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:76
MSG::ERROR
Definition: IMessageSvc.h:16
gaudirun.level
level
Definition: gaudirun.py:271
implementation_detail::is_valid_t
typename void_t< T >::type is_valid_t
Definition: CommonMessaging.h:48
MSG::WARNING
Definition: IMessageSvc.h:16
CommonMessagingBase::msgStream
MsgStream & msgStream(const MSG::Level level) const
Predefined configurable message stream for the efficient printouts.
Definition: CommonMessaging.h:99
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:105
MSG::INFO
Definition: IMessageSvc.h:16
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:129
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition: CommonMessaging.h:102
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
add_serviceLocator
typename std::conditional< implementation_detail::has_serviceLocator< Base >::value, Base, implementation_detail::add_serviceLocator< Base >>::type add_serviceLocator
Definition: CommonMessaging.h:59
ISvcLocator.h
CommonMessagingBase::msgLevel
bool msgLevel(MSG::Level lvl) const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:142
MSG::ALWAYS
Definition: IMessageSvc.h:16
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209