| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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/IService.h"
11 #include "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/IMessageSvc.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/SmartIF.h"
15 #include "GaudiKernel/GaudiException.h"
16
17 #include <memory>
18 #include <utility>
19
24 #define generate_( method, ret, args ) \
25 \
26 template <typename T, typename SFINAE = void> \
27 struct has_ ## method : std::false_type {}; \
28 template <typename T> \
29 struct has_ ## method<T, is_valid_t<decltype(std::declval<const T&>().method args)>> : std::true_type {}; \
30 \
31 template <typename Base> \
32 struct add_ ## method : public Base { \
33 using Base::Base; \
34 virtual ~add_ ## method () = default; \
35 virtual ret method args const = 0; \
36 };
37
38 namespace implementation_detail {
39 template <typename> struct void_t { using type = void; };
40 template <typename T> using is_valid_t = typename void_t<T>::type;
41
42 generate_( name, const std::string&, () )
43 generate_( serviceLocator, SmartIF<ISvcLocator>&, () )
44 }
45 #undef generate_
46
47 template <typename Base> using add_name = typename std::conditional<implementation_detail::has_name<Base>::value,
48 Base,
49 implementation_detail::add_name< Base>>::type;
50 template <typename Base> using add_serviceLocator = typename std::conditional<implementation_detail::has_serviceLocator<Base>::value,
51 Base,
52 implementation_detail::add_serviceLocator< Base>>::type;
53
54
55 template <typename Base> class CommonMessaging;
56
57 class CommonMessagingBase {
58 public:
60 virtual ~CommonMessagingBase() = default;
62 virtual void create_msgSvc() const = 0;
63 virtual void create_msgStream() const = 0;
64
65
66
70 inline SmartIF<IMessageSvc>& msgSvc() const {
71 if (UNLIKELY(!m_msgsvc)) create_msgSvc();
72 return m_msgsvc;
73 }
74
75 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NO_DEPRECATED)
76
81 [[deprecated("will be removed in v29r0, use msgSvc() instead, see https://gitlab.cern.ch/gaudi/Gaudi/merge_requests/80")]]
82 inline SmartIF<IMessageSvc>& messageService() const {
83 return msgSvc();
84 }
85 #endif
86
88 inline MsgStream& msgStream() const {
89 if (UNLIKELY((m_createMsgStream))) create_msgStream();
90 return *m_msgStream;
91 }
92
103 inline MsgStream& msgStream(const MSG::Level level) const {
104 return msgStream() << level;
105 }
106
108 inline MsgStream& always() const { return msgStream(MSG::ALWAYS); }
109
111 inline MsgStream& fatal() const { return msgStream(MSG::FATAL); }
112
114 inline MsgStream& err() const { return msgStream(MSG::ERROR); }
115
117 inline MsgStream& error() const { return msgStream(MSG::ERROR); }
118
120 inline MsgStream& warning() const { return msgStream(MSG::WARNING); }
121
123 inline MsgStream& info() const { return msgStream(MSG::INFO); }
124
126 inline MsgStream& debug() const { return msgStream(MSG::DEBUG); }
127
129 inline MsgStream& verbose() const { return msgStream(MSG::VERBOSE); }
130
132 inline MsgStream& msg() const { return msgStream(MSG::INFO); }
133
135 inline MSG::Level msgLevel() const {
136 if (UNLIKELY(!m_msgStream)) create_msgStream();
137 return m_level;
138 }
139
141 inline MSG::Level outputLevel() const __attribute__ ((deprecated)) { return msgLevel(); }
142
144 inline bool msgLevel(MSG::Level lvl) const { return UNLIKELY(msgLevel() <= lvl); }
145
146 private:
147 template <typename Base> friend class CommonMessaging;
148
150 mutable std::unique_ptr<MsgStream> m_msgStream;
151
152 mutable MSG::Level m_level = MSG::NIL;
154 mutable bool m_createMsgStream = true;
155
157 mutable SmartIF<IMessageSvc> m_msgsvc;
158
159
160 };
161
162 template <typename BASE>
163 class GAUDI_API CommonMessaging: public add_serviceLocator<add_name<BASE>>, public CommonMessagingBase {
164 public:
165 using base_class = CommonMessaging;
166
168 using add_serviceLocator<add_name<BASE>>::add_serviceLocator;
169
170 private:
171 // out-of-line 'cold' functions -- put here so as to not blow up the inline 'hot' functions
172 void create_msgSvc() const override final {
173 // Get default implementation of the message service.
174 m_msgsvc = this->serviceLocator();
175 }
176 void create_msgStream() const override final {
177 auto& ms = msgSvc();
178 m_msgStream.reset(new MsgStream(ms, this->name()));
179 m_createMsgStream = (!ms.isValid() || !m_msgStream);
180 m_level = m_msgStream ? m_msgStream->level() : MSG::NIL;
181 }
182
183 protected:
186 void updateMsgStreamOutputLevel(int level) {
187 if (level != MSG::NIL && level != m_level) {
188 if (msgSvc()) {
189 msgSvc()->setOutputLevel(this->name(), level);
190 }
191 if (m_msgStream) m_msgStream->setLevel(level);
192 if (UNLIKELY(MSG::Level(level) <= MSG::DEBUG))
193 debug() << "Property update for OutputLevel : new value = " << level << endmsg;
194 m_level = MSG::Level(level);
195 }
196 }
197
198 };
199
200
201 #endif /* COMMONMESSAGING_H_ */
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
add_serviceLocator
typename std::conditional< implementation_detail::has_serviceLocator< Base >::value, Base, implementation_detail::add_serviceLocator< Base >>::type add_serviceLocator
Definition: CommonMessaging.h:52
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:132
__attribute__
#define __attribute__(x)
Definition: System.cpp:72
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:28
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:129
MSG::DEBUG
Definition: IMessageSvc.h:18
Gaudi::Functional::deprecated
struct deprecated("use MergingTransformer instead")]] ListTransformer
Definition: ListTransformer.h:9
CommonMessagingBase::m_msgsvc
SmartIF< IMessageSvc > m_msgsvc
Pointer to the message service;.
Definition: CommonMessaging.h:157
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
Gaudi::Functional::void
class MergingTransformer< Out(const vector_of_const_< In > void
Definition: MergingTransformer.h:19
CommonMessagingBase::m_msgStream
std::unique_ptr< MsgStream > m_msgStream
The predefined message stream.
Definition: CommonMessaging.h:150
MSG::VERBOSE
Definition: IMessageSvc.h:17
CommonMessaging::create_msgSvc
void create_msgSvc() const override final
cold functionality
Definition: CommonMessaging.h:172
CommonMessagingBase::err
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:114
BrunelScenarioForwardScheduler.ms
ms
Definition: BrunelScenarioForwardScheduler.py:120
std::string
STL class.
MSG::FATAL
Definition: IMessageSvc.h:22
MSG::Level
Level
Definition: IMessageSvc.h:15
CommonMessagingBase::m_level
MSG::Level m_level
Definition: CommonMessaging.h:152
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:120
CommonMessaging::updateMsgStreamOutputLevel
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
Definition: CommonMessaging.h:186
ForwardSchedulerSimpleTest.msgSvc
msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
GaudiException.h
SmartIF.h
MSG::NIL
Definition: IMessageSvc.h:16
implementation_detail::void_t
Definition: CommonMessaging.h:39
IMessageSvc.h
CommonMessagingBase
Definition: CommonMessaging.h:57
CommonMessaging::create_msgStream
void create_msgStream() const override final
Definition: CommonMessaging.h:176
IService.h
implementation_detail
Definition: CommonMessaging.h:38
CommonMessagingBase::outputLevel
MSG::Level outputLevel() const __attribute__((deprecated))
Backward compatibility function for getting the output level.
Definition: CommonMessaging.h:141
std::unique_ptr< MsgStream >
std::conditional
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
implementation_detail::generate_
generate_(name, const std::string &,()) generate_(serviceLocator
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:88
implementation_detail::void_t::type
void type
Definition: CommonMessaging.h:39
CommonMessaging
Definition: CommonMessaging.h:55
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:70
MSG::ERROR
Definition: IMessageSvc.h:21
gaudirun.level
level
Definition: gaudirun.py:261
add_name
typename std::conditional< implementation_detail::has_name< Base >::value, Base, implementation_detail::add_name< Base >>::type add_name
Definition: CommonMessaging.h:49
implementation_detail::is_valid_t
typename void_t< T >::type is_valid_t
Definition: CommonMessaging.h:40
MSG::WARNING
Definition: IMessageSvc.h:20
CommonMessagingBase::msgStream
MsgStream & msgStream(const MSG::Level level) const
Predefined configurable message stream for the efficient printouts.
Definition: CommonMessaging.h:103
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:111
MSG::INFO
Definition: IMessageSvc.h:19
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:135
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition: CommonMessaging.h:108
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
CommonMessagingBase::m_createMsgStream
bool m_createMsgStream
Flag to trigger a new MsgStream.
Definition: CommonMessaging.h:154
ISvcLocator.h
CommonMessagingBase::msgLevel
bool msgLevel(MSG::Level lvl) const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:144
MSG::ALWAYS
Definition: IMessageSvc.h:23
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244