ATLAS Offline Software
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 
31 namespace 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 
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 
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 }
asg::MsgHelpers::printAllPkgMsgLevels
static void printAllPkgMsgLevels()
print all package message levels
Definition: MsgHelpers.cxx:103
get_generator_info.result
result
Definition: get_generator_info.py:21
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
asg
Definition: DataHandleTestTool.h:28
MsgHelpers.h
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
asg::MsgHelpers::setPkgMsgLevel
static void setPkgMsgLevel(const std::string &package, MSG::Level level)
set the package message level for the given name
Definition: MsgHelpers.cxx:94
Athena::Options::Eager
@ Eager
Definition: getMessageSvc.h:22
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
asg::MsgHelpers::pkgMsgStream
static MsgStream & pkgMsgStream(const std::string &package)
the message stream for the given package identifier
Definition: MsgHelpers.cxx:71
checker_macros.h
Define macros for attributes used to control the static checker.
MessageCheckLocal.h