All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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_
10 #include "GaudiKernel/IService.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/SmartIF.h"
16 
17 #include <memory>
18 
22 template <class BASE>
23 class GAUDI_API CommonMessaging: public BASE {
24 public:
26 
28  template <typename A1, typename A2, typename A3> CommonMessaging(const A1& a1, const A2& a2, const A3& a3):
29  BASE(a1,a2,a3), m_streamWithService(false) {}
31  template <typename A1, typename A2> CommonMessaging(const A1& a1, const A2& a2):
32  BASE(a1, a2), m_streamWithService(false) {}
34  template <typename A1> CommonMessaging(const A1& a1):
35  BASE(a1), m_streamWithService(false) {}
38  BASE(), m_streamWithService(false) {}
39 
41  virtual ~CommonMessaging() {}
42 
44  virtual SmartIF<ISvcLocator>& serviceLocator() const = 0;
45 
47  virtual const std::string& name() const = 0;
48 
52  inline SmartIF<IMessageSvc>& msgSvc() const {
53  if (!m_msgsvc.get()) {
54  // Get default implementation of the message service.
55  m_msgsvc = this->serviceLocator();
56  }
57  return m_msgsvc;
58  }
59 
60 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NO_DEPRECATED)
61 
65  inline SmartIF<IMessageSvc>& messageService() const {
66  return msgSvc();
67  }
68 #endif
69 
71  inline MsgStream& msgStream() const {
72  if (UNLIKELY((!m_msgStream.get()) || (!m_streamWithService))) {
73  SmartIF<IMessageSvc>& ms = msgSvc();
74  m_msgStream.reset(new MsgStream(ms, this->name()));
75  m_streamWithService = ms.get() != 0;
76  }
77  return *m_msgStream;
78  }
79 
90  inline MsgStream& msgStream(const MSG::Level level) const {
91  return msgStream() << level;
92  }
93 
95  inline MsgStream& always() const { return msgStream(MSG::ALWAYS); }
96 
98  inline MsgStream& fatal() const { return msgStream(MSG::FATAL); }
99 
101  inline MsgStream& err() const { return msgStream(MSG::ERROR); }
102 
104  inline MsgStream& error() const { return msgStream(MSG::ERROR); }
105 
107  inline MsgStream& warning() const { return msgStream(MSG::WARNING); }
108 
110  inline MsgStream& info() const { return msgStream(MSG::INFO); }
111 
113  inline MsgStream& debug() const { return msgStream(MSG::DEBUG); }
114 
116  inline MsgStream& verbose() const { return msgStream(MSG::VERBOSE); }
117 
119  inline MsgStream& msg() const { return msgStream(MSG::INFO); }
120 
122  inline MSG::Level msgLevel() const {
123  return msgStream().level();
124  }
125 
127  inline bool msgLevel(MSG::Level lvl) const {
128  return UNLIKELY(msgLevel() <= lvl);
129  }
130 
131 protected:
134 
136  mutable std::auto_ptr<MsgStream> m_msgStream;
137 
139  mutable bool m_streamWithService;
140 
144  if (m_msgStream.get()) m_msgStream->setLevel(level);
145  }
146 
147 };
148 
149 
150 #endif /* COMMONMESSAGING_H_ */
#define UNLIKELY(x)
Definition: Kernel.h:127
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
bool m_streamWithService
Flag to create a new MsgStream if it was created without the message service.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
CommonMessaging(const A1 &a1, const A2 &a2, const A3 &a3)
Templated constructor with 3 arguments.
MsgStream & msgStream() const
Return an uninitialized MsgStream.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
SmartIF< IMessageSvc > m_msgsvc
Pointer to the message service;.
bool msgLevel(MSG::Level lvl) const
get the output level from the embedded MsgStream
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
MsgStream & msgStream(const MSG::Level level) const
Predefined configurable message stream for the efficient printouts.
CommonMessaging(const A1 &a1, const A2 &a2)
Templated constructor with 2 arguments.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
virtual ~CommonMessaging()
Virtual destructor.
std::auto_ptr< MsgStream > m_msgStream
The predefined message stream.
Templated class to add the standard messaging functionalities.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
CommonMessaging(const A1 &a1)
Templated constructor with 1 argument.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
#define GAUDI_API
Definition: Kernel.h:108
CommonMessaging()
Default constructor.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
CommonMessaging base_class
MSG::Level msgLevel() const
get the output level from the embedded MsgStream