ATLAS Offline Software
Tracking/Acts/ActsInterop/src/Logger.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 "ActsInterop/Logger.h"
8 #include "GaudiKernel/INamedInterface.h"
9 #include "GaudiKernel/CommonMessaging.h"
10 #include "GaudiKernel/IMessageSvc.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/CommonMessaging.h"
13 
14 #include "Acts/Utilities/Logger.hpp"
15 
16 #include <optional>
17 #include <iostream>
18 #include <string>
19 
20 
21 ActsAthenaPrintPolicy::ActsAthenaPrintPolicy(std::shared_ptr<MsgStream> msg, const std::string& name):
22  m_svc{Athena::getMessageSvc()},
23  m_msg{msg},
24  m_name{name} {}
25 void
27 {
28  MSG::Level athLevel = ActsTrk::athLevelVector(lvl);
29  (*m_msg) << athLevel << input << endmsg;
30 }
31 
32 const std::string&
34 {
35  return m_name;
36 }
37 
38 std::unique_ptr<Acts::Logging::OutputPrintPolicy>
39 ActsAthenaPrintPolicy::clone(const std::string& name) const {
40  return std::make_unique<ActsAthenaPrintPolicy>(m_msg, name);
41 }
42 
44 
45  MSG::Level athLevel = ActsTrk::athLevelVector(lvl);
46  return m_msg->level() <= athLevel;
47 }
48 
51 {
52  return ActsTrk::actsLevelVector(m_msg->level());
53 }
54 
55 std::unique_ptr<Acts::Logging::OutputFilterPolicy>
57 {
58  auto msg = std::make_shared<MsgStream>(*m_msg);
59  msg->setLevel(ActsTrk::athLevelVector(level));
60  return std::make_unique<ActsAthenaFilterPolicy>(msg);
61 }
62 
63 std::unique_ptr<const Acts::Logger>
64 makeActsAthenaLogger(IMessageSvc *svc, const std::string& name, int level, std::optional<std::string> parent_name)
65 {
66  using namespace Acts::Logging;
67 
68  std::string full_name = name;
69  if (parent_name) {
70  full_name = *parent_name + "." + full_name;
71  }
72 
73  auto msg = std::make_shared<MsgStream>(svc, full_name);
74  msg->setLevel(level);
75  auto filter = std::make_unique<ActsAthenaFilterPolicy>(msg);
76  auto print = std::make_unique<ActsAthenaPrintPolicy>(msg, full_name);
77  return std::make_unique<const Acts::Logger>(std::move(print), std::move(filter));
78 }
79 
80 std::unique_ptr<const Acts::Logger>
81 makeActsAthenaLogger(const AthMessaging* parent, const std::string& name) {
82  auto msg = std::make_shared<MsgStream>(parent->msg());
83  auto filter = std::make_unique<ActsAthenaFilterPolicy>(msg);
84  auto print = std::make_unique<ActsAthenaPrintPolicy>(msg, name);
85  return std::make_unique<const Acts::Logger>(std::move(print), std::move(filter));
86 }
87 std::unique_ptr<const Acts::Logger>
88 makeActsAthenaLogger(const CommonMessagingBase* parent, const std::string& name)
89 {
90  // no explicit name, get from component
91  const INamedInterface *inamed = dynamic_cast<const INamedInterface*>(parent);
92  std::optional<std::string> parent_name = std::nullopt;
93  // this will not prefix if parent is not named (which it should be)
94  if (inamed == nullptr) {
95  throw std::invalid_argument("parent needs to be INamedInterface");
96  }
97  parent_name = inamed->name();
98  return makeActsAthenaLogger(parent, name, parent_name);
99 }
100 
101 std::unique_ptr<const Acts::Logger>
102 makeActsAthenaLogger(const CommonMessagingBase* parent, const std::string& name, std::optional<std::string> parent_name)
103 {
104  int level = 0;
105  const INamedInterface *inamed = dynamic_cast<const INamedInterface*>(parent);
106  if (inamed != nullptr) {
107  level = parent->msg().level();
108  }
109  return makeActsAthenaLogger(parent->msgSvc().get(), name, level, parent_name);
110 }
111 
112 std::unique_ptr<const Acts::Logger>
113 makeActsAthenaLogger(const CommonMessagingBase* parent, const std::string& name, const std::string& parent_name)
114 {
115 
116  return makeActsAthenaLogger(parent, name, std::optional<std::string>(parent_name));
117 }
ActsAthenaPrintPolicy::name
virtual const std::string & name() const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:33
ActsAthenaPrintPolicy::m_msg
std::shared_ptr< MsgStream > m_msg
Definition: Tracking/Acts/ActsInterop/ActsInterop/Logger.h:36
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
ActsAthenaFilterPolicy::m_msg
std::shared_ptr< MsgStream > m_msg
Definition: Tracking/Acts/ActsInterop/ActsInterop/Logger.h:55
ActsAthenaFilterPolicy::clone
virtual std::unique_ptr< Acts::Logging::OutputFilterPolicy > clone(Acts::Logging::Level level) const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:56
ActsTrk::actsLevelVector
Acts::Logging::Level actsLevelVector(MSG::Level lvl)
Definition: LoggerUtils.cxx:9
m_name
std::string m_name
Definition: ColumnarPhysliteTest.cxx:63
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
covarianceTool.filter
filter
Definition: covarianceTool.py:514
makeActsAthenaLogger
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:64
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ActsAthenaPrintPolicy::clone
virtual std::unique_ptr< Acts::Logging::OutputPrintPolicy > clone(const std::string &name) const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:39
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsAthenaPrintPolicy::flush
void flush(const Acts::Logging::Level &lvl, const std::string &input) override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:26
ActsAthenaPrintPolicy::ActsAthenaPrintPolicy
ActsAthenaPrintPolicy(std::shared_ptr< MsgStream > msg, const std::string &name)
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:21
LoggerUtils.h
ActsAthenaFilterPolicy::level
virtual Acts::Logging::Level level() const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:50
ActsAthenaPrintPolicy::m_name
std::string m_name
Definition: Tracking/Acts/ActsInterop/ActsInterop/Logger.h:37
ActsTrk::athLevelVector
MSG::Level athLevelVector(Acts::Logging::Level lvl)
Definition: LoggerUtils.cxx:29
Logger.h
ActsAthenaFilterPolicy::doPrint
bool doPrint(const Acts::Logging::Level &lvl) const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:43
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7