ATLAS Offline Software
AthMessaging.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // AthMessaging.h
8 // Header file for class AthMessaging
9 // Author: S.Binet<binet@cern.ch>, Frank Winklmeier
11 #ifndef ATHENABASECOMPS_ATHMESSAGING_H
12 #define ATHENABASECOMPS_ATHMESSAGING_H 1
13 
14 // STL includes
15 #include <iosfwd>
16 #include <string>
17 #include <atomic>
18 
19 // framework includes
20 #include "GaudiKernel/IMessageSvc.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "Gaudi/Property.h"
25 
26 #include <boost/thread/tss.hpp>
27 
28 
55 {
56 
58  // Public methods:
60  public:
61 
66  AthMessaging (IMessageSvc* msgSvc, const std::string& name);
67 
71  AthMessaging (const std::string& name);
72 
74  virtual ~AthMessaging();
75 
77  // Const methods:
79 
85  bool
86  msgLvl (const MSG::Level lvl) const;
87 
92  MsgStream& msg() const;
93 
98  MsgStream&
99  msg (const MSG::Level lvl) const;
100 
102  // Non-const methods:
104 
108  void setLevel (MSG::Level lvl);
109 
111  // Private methods:
113  private:
114 
116  AthMessaging(); //> not implemented
117  AthMessaging( const AthMessaging& rhs ); //> not implemented
118  AthMessaging& operator=( const AthMessaging& rhs ); //> not implemented
119 
121  void initMessaging() const;
122 
124  // Private data:
126  private:
127 
129  std::string m_nm;
130 
132  mutable boost::thread_specific_ptr<MsgStream> m_msg_tls;
133 
135  mutable std::atomic<IMessageSvc*> m_imsg{ nullptr };
136 
138  mutable std::atomic<MSG::Level> m_lvl{ MSG::NIL };
139 
141  mutable std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT;
142 
143 };
144 
146 // Inline methods:
148 
149 inline
150 bool
152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }
161 
162 inline
163 MsgStream&
165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }
176 
177 inline
178 MsgStream&
179 AthMessaging::msg (const MSG::Level lvl) const
180 { return msg() << lvl; }
181 
182 
183 #endif //> !ATHENABASECOMPS_ATHMESSAGING_H
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
AthMessaging::~AthMessaging
virtual ~AthMessaging()
Destructor:
Definition: AthMessaging.cxx:24
AthMessaging::AthMessaging
AthMessaging(const AthMessaging &rhs)
AthMsgStreamMacros.h
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
AthMessaging::ATLAS_THREAD_SAFE
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
Definition: AthMessaging.h:141
AthMessaging::setLevel
void setLevel(MSG::Level lvl)
Change the current logging level.
Definition: AthMessaging.cxx:28
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
AthMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level.
Definition: AthMessaging.h:151
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
AthMessaging::operator=
AthMessaging & operator=(const AthMessaging &rhs)
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
TrigConf::MSGTC::NIL
@ NIL
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:22
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
checker_macros.h
Define macros for attributes used to control the static checker.