ATLAS Offline Software
Loading...
Searching...
No Matches
MsgHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
16
17#include <cassert>
18#include <mutex>
19#include <unordered_map>
20
21#ifndef XAOD_STANDALONE
22#include <GaudiKernel/Bootstrap.h>
23#include <GaudiKernel/ISvcLocator.h>
25#endif
26
27//
28// method implementations
29//
30
31namespace asg
32{
33 namespace
34 {
47 std::unordered_map<std::string,MsgStream>& packageMsgStreamMap ()
48 {
49 // access is protected through packageMsgMutex()
50 static std::unordered_map<std::string,MsgStream> result ATLAS_THREAD_SAFE;
51 return result;
52 }
53
63 std::recursive_mutex& packageMsgMutex ()
64 {
65 static std::recursive_mutex result;
66 return result;
67 }
68 }
69
70 MsgStream& MsgHelpers ::
71 pkgMsgStream (const std::string& package)
72 {
73 std::lock_guard<std::recursive_mutex> lock {packageMsgMutex()};
74 auto iter = packageMsgStreamMap().find (package);
75 if (iter != packageMsgStreamMap().end())
76 return iter->second;
77
78 const std::string fullName {"Package." + package};
79#ifdef XAOD_STANDALONE
80 auto result = packageMsgStreamMap().emplace (package, fullName);
81#else
82 auto result = packageMsgStreamMap().emplace
83 (std::piecewise_construct,
84 std::forward_as_tuple (package),
85 std::forward_as_tuple (Athena::getMessageSvc(Athena::Options::Eager), fullName));
86#endif
87 assert (result.second);
88 return result.first->second;
89 }
90
91
92
93 void MsgHelpers ::
94 setPkgMsgLevel (const std::string& package, MSG::Level level)
95 {
96 std::lock_guard<std::recursive_mutex> lock {packageMsgMutex()};
97 pkgMsgStream (package).setLevel (level);
98 }
99
100
101
102 void MsgHelpers ::
103 printAllPkgMsgLevels ()
104 {
105 using namespace msgAsgMessaging;
106 std::lock_guard<std::recursive_mutex> lock {packageMsgMutex()};
107 ANA_MSG_INFO ("package message levels:");
108 for (auto& msgStream : packageMsgStreamMap())
109 {
110 ANA_MSG_INFO (" package=" << msgStream.first << " level=" << name (msgStream.second.level()) << "(" << unsigned (msgStream.second.level()) << ")");
111 }
112 }
113}
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
static MsgStream & pkgMsgStream(const std::string &package)
the message stream for the given package identifier