ATLAS Offline Software
Loading...
Searching...
No Matches
AthMessaging.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 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
149inline
150bool
151AthMessaging::msgLvl (const MSG::Level lvl) const
152{
153 if (m_lvl <= lvl) {
154 msg() << lvl;
155 return true;
156 } else {
157 return false;
158 }
159}
160
161inline
162MsgStream&
164{
165 MsgStream* ms = m_msg_tls.get();
166 if (!ms) {
167 if (!m_initialized.test_and_set()) initMessaging();
168 ms = new MsgStream(m_imsg,m_nm);
169 m_msg_tls.reset( ms );
170 }
171
172 ms->setLevel (m_lvl);
173 return *ms;
174}
175
176inline
177MsgStream&
178AthMessaging::msg (const MSG::Level lvl) const
179{ return msg() << lvl; }
180
181
182#endif //> !ATHENABASECOMPS_ATHMESSAGING_H
Define macros for attributes used to control the static checker.
AthMessaging & operator=(const AthMessaging &rhs)
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
void setLevel(MSG::Level lvl)
Change the current logging level.
AthMessaging(const AthMessaging &rhs)
std::string m_nm
Message source name.
AthMessaging()
Default constructor:
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
virtual ~AthMessaging()
Destructor:
MsgStream & msg() const
The standard message stream.
std::atomic< MSG::Level > m_lvl
Current logging level.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
void initMessaging() const
Initialize our message level and MessageSvc.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.