ATLAS Offline Software
Loading...
Searching...
No Matches
getMessageSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <iostream>
6#include "GaudiKernel/Bootstrap.h"
7#include "GaudiKernel/IMessageSvc.h"
8#include "GaudiKernel/ISvcLocator.h"
9#include "GaudiKernel/ServiceHandle.h"
11
13
14using namespace Athena;
15
19
20IMessageSvc* Athena::getMessageSvc( bool quiet ) { return getMessageSvc( Options::Lazy, quiet ); }
21IMessageSvc* Athena::getMessageSvc( const Options::CreateOptions opt, bool quiet ) {
22
23 // We cache the MessageSvc, but only once it has been found. This ensures that an
24 // early call to this method (before MessageSvc is available) does not prevent
25 // from finding it in subsequent calls. The limited use of ServiceHandle for this
26 // purpose should be thread-safe:
27 static ServiceHandle<IMessageSvc> msgSvc ATLAS_THREAD_SAFE ("MessageSvc", "getMessageSvc");
28
29 IMessageSvc* svc = nullptr;
30 try {
31 svc = msgSvc.get();
32 if (svc) {
33 svc->addRef(); // even if cached, maintain correct ref-count
34 return svc;
35 }
36
37 const bool warn = !(quiet || Athena::getMessageSvcQuiet);
38 if ( ((opt==Athena::Options::Lazy && !Gaudi::svcLocator()->existsService("MessageSvc")) ||
39 msgSvc.retrieve().isFailure()) && warn ) {
40 std::cerr << "Athena::getMessageSvc: WARNING MessageSvc not found, will use std::cout" << std::endl;
41 }
42 svc = msgSvc.get();
43 }
44 catch (const GaudiException& e)
45 {
46 std::cerr << "Athena::getMessageSvc: WARNING Got Gaudi exception " << e
47 << "; will use std::out" << std::endl;
48 return nullptr;
49 }
50
51
52 return svc;
53}
54
55
56void Athena::reportMessage (IMessageSvc* ims, const std::string &source, int type, const std::string &message) {
57 if (ims) ims->reportMessage(source, type, message);
58}
59
60int Athena::outputLevel(const IMessageSvc* ims, const std::string &source) {
61 if (ims) return ims->outputLevel(source);
62 else return MSG::INFO;
63}
64
65void Athena::setOutputLevel(IMessageSvc* ims, const std::string &source, int level) {
66 if(ims) ims->setOutputLevel(source, level);
67}
68
70 assert(m_ims);
71 m_ims->addRef(); //take ownership till we go out of scope
72}
73
75 m_ims(rhs.m_ims)
76{
77 if (m_ims) m_ims->addRef(); //take ownership till we go out of scope
78}
79
82 if (this != & rhs && m_ims != rhs.m_ims) {
83 if (m_ims) m_ims->release(); //give up our IMessageSvc*
84 m_ims = rhs.m_ims;
85 if (m_ims) m_ims->addRef(); //take ownership till we go out of scope
86 }
87 return *this;
88}
89
95
99
100IMessageSvc*
102 if (!m_ims) m_ims = getMessageSvc();
103 return m_ims;
104}
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
get a IMessageSvc* on 1st use (if not set) and release it on ~
~IMessageSvcHolder()
releases the IMessageSvc
IMessageSvcHolder()
will take the IMessageSvc* lazily from getMessageSvc() in get() Slow, but useful for classes without ...
IMessageSvcHolder & operator=(const IMessageSvcHolder &)
IMessageSvc * get()
upon first access sets m_ims as needed
singleton-like access to IMessageSvc via open function and helper
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
IMessageSvc * getMessageSvc(bool quiet=false)
int outputLevel(const IMessageSvc *ims, const std::string &source)
void reportMessage(IMessageSvc *ims, const std::string &source, int type, const std::string &message)
Wrappers for some of the IMessageSvc methods These can be used from libraries without explicit Gaudi ...
std::atomic< bool > getMessageSvcQuiet
Set this to force off the warning messages from getMessageSvc (in unit tests, for example).
void setOutputLevel(IMessageSvc *ims, const std::string &source, int level)