Loading [MathJax]/jax/output/HTML-CSS/config.js
The Gaudi Framework  v29r3 (fa547fc2)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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_
12 #include "GaudiKernel/IService.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 
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>
56  implementation_detail::add_name<Base>>::type;
57 template <typename Base>
59  implementation_detail::add_serviceLocator<Base>>::type;
60 
61 template <typename Base>
63 
65 {
66 public:
68  virtual ~CommonMessagingBase() = default;
70  virtual void create_msgStream() const = 0;
71 
75  inline const SmartIF<IMessageSvc>& msgSvc() const { return m_msgsvc; }
76 
78  inline MsgStream& msgStream() const
79  {
80  if ( UNLIKELY( ( !m_msgStream.get() ) ) ) create_msgStream();
81  return *m_msgStream;
82  }
83 
94  inline MsgStream& msgStream( const MSG::Level level ) const { return msgStream() << level; }
95 
97  inline MsgStream& always() const { return msgStream( MSG::ALWAYS ); }
98 
100  inline MsgStream& fatal() const { return msgStream( MSG::FATAL ); }
101 
103  inline MsgStream& err() const { return msgStream( MSG::ERROR ); }
104 
106  inline MsgStream& error() const { return msgStream( MSG::ERROR ); }
107 
109  inline MsgStream& warning() const { return msgStream( MSG::WARNING ); }
110 
112  inline MsgStream& info() const { return msgStream( MSG::INFO ); }
113 
115  inline MsgStream& debug() const { return msgStream( MSG::DEBUG ); }
116 
118  inline MsgStream& verbose() const { return msgStream( MSG::VERBOSE ); }
119 
121  inline MsgStream& msg() const { return msgStream( MSG::INFO ); }
122 
124  inline MSG::Level msgLevel() const
125  {
126  assert( m_commonMessagingReady );
127  return m_level;
128  }
129 
131  inline MSG::Level outputLevel() const __attribute__( ( deprecated ) ) { return msgLevel(); }
132 
134  inline bool msgLevel( MSG::Level lvl ) const { return UNLIKELY( msgLevel() <= lvl ); }
135 
136 private:
137  template <typename Base>
138  friend class CommonMessaging;
139 
141 
143  mutable boost::thread_specific_ptr<MsgStream> m_msgStream;
144 
146 
149 };
150 
151 template <typename BASE>
152 class GAUDI_API CommonMessaging : public add_serviceLocator<add_name<BASE>>, public CommonMessagingBase
153 {
154 public:
156 
159 
160 private:
161  // out-of-line 'cold' functions -- put here so as to not blow up the inline 'hot' functions
162  void create_msgStream() const override final { m_msgStream.reset( new MsgStream( msgSvc(), this->name() ) ); }
163 
164 protected:
167  {
168  if ( !m_commonMessagingReady ) {
169  if ( !m_msgsvc ) {
170  // Get default implementation of the message service.
171  m_msgsvc = this->serviceLocator();
172  }
173  create_msgStream();
174  m_level = MSG::Level( m_msgStream.get() ? m_msgStream->level() : MSG::NIL );
175  // if we could not get a MessageSvc, we should try again the initial set up
176  m_commonMessagingReady = m_msgsvc;
177  }
178  return m_level;
179  }
182  {
183  m_commonMessagingReady = false;
184  return setUpMessaging();
185  }
189  {
190  setUpMessaging();
191  if ( level != MSG::NIL && level != m_level ) {
192  if ( msgSvc() ) {
193  msgSvc()->setOutputLevel( this->name(), level );
194  }
195  if ( m_msgStream.get() ) m_msgStream->setLevel( level );
196  if ( UNLIKELY( MSG::Level( level ) <= MSG::DEBUG ) )
197  debug() << "Property update for OutputLevel : new value = " << level << endmsg;
198  m_level = MSG::Level( level );
199  }
200  }
201 };
202 
203 #endif /* COMMONMESSAGING_H_ */
#define UNLIKELY(x)
Definition: Kernel.h:128
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
#define __attribute__(x)
Definition: System.cpp:79
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level resetMessaging()
Reinitialize internal states.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
SmartIF< IMessageSvc > m_msgsvc
Pointer to the message service;.
class MergingTransformer< Out(const vector_of_const_< In > void
typename std::conditional< implementation_detail::has_name< Base >::value, Base, implementation_detail::add_name< Base >>::type add_name
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
boost::thread_specific_ptr< MsgStream > m_msgStream
The predefined message stream.
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void create_msgStream() const override final
cold functionality
MSG::Level outputLevel() const __attribute__((deprecated))
Backward compatibility function for getting the output level.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
generate_(name, const std::string &,()) generate_(serviceLocator
MsgStream & msgStream() const
Return an uninitialized MsgStream.
typename void_t< T >::type is_valid_t
MsgStream & msgStream(const MSG::Level level) const
Predefined configurable message stream for the efficient printouts.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
#define GAUDI_API
Definition: Kernel.h:110
typename std::conditional< implementation_detail::has_serviceLocator< Base >::value, Base, implementation_detail::add_serviceLocator< Base >>::type add_serviceLocator
MSG::Level setUpMessaging()
Set up local caches.
bool msgLevel(MSG::Level lvl) const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209