ATLAS Offline Software
Tracking/Acts/ActsInterop/src/Logger.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ActsInterop/Logger.h"
7 
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 void
22 {
23  MSG::Level athLevel = ActsTrk::athLevelVector(lvl);
24  (*m_msg) << athLevel << input << endmsg;
25 }
26 
27 const std::string&
29 {
30  return m_name;
31 }
32 
33 std::unique_ptr<Acts::Logging::OutputPrintPolicy>
34 ActsAthenaPrintPolicy::clone(const std::string& name) const
35 {
36  auto msg = std::make_shared<MsgStream>(m_svc, name);
37  msg->setLevel(m_msg->level());
38  return std::make_unique<ActsAthenaPrintPolicy>(m_svc, msg, name);
39 }
40 
41 bool
43 {
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.get());
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>(svc, 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 CommonMessagingBase* parent, const std::string& name)
82 {
83  // no explicit name, get from component
84  const INamedInterface *inamed = dynamic_cast<const INamedInterface*>(parent);
85  std::optional<std::string> parent_name = std::nullopt;
86  // this will not prefix if parent is not named (which it should be)
87  if (inamed == nullptr) {
88  throw std::invalid_argument("parent needs to be INamedInterface");
89  }
90  parent_name = inamed->name();
91  return makeActsAthenaLogger(parent, name, parent_name);
92 }
93 
94 std::unique_ptr<const Acts::Logger>
95 makeActsAthenaLogger(const CommonMessagingBase* parent, const std::string& name, std::optional<std::string> parent_name)
96 {
97  int level = 0;
98  const INamedInterface *inamed = dynamic_cast<const INamedInterface*>(parent);
99  if (inamed != nullptr) {
100  level = parent->msg().level();
101  }
102  return makeActsAthenaLogger(parent->msgSvc().get(), name, level, parent_name);
103 }
104 
105 std::unique_ptr<const Acts::Logger>
106 makeActsAthenaLogger(const CommonMessagingBase* parent, const std::string& name, const std::string& parent_name)
107 {
108 
109  return makeActsAthenaLogger(parent, name, std::optional<std::string>(parent_name));
110 }
ActsAthenaPrintPolicy::name
virtual const std::string & name() const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:28
ActsAthenaPrintPolicy::m_msg
std::shared_ptr< MsgStream > m_msg
Definition: Tracking/Acts/ActsInterop/ActsInterop/Logger.h:36
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
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:34
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsAthenaPrintPolicy::flush
void flush(const Acts::Logging::Level &lvl, const std::string &input) override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:21
LoggerUtils.h
ActsAthenaPrintPolicy::m_svc
IMessageSvc * m_svc
Definition: Tracking/Acts/ActsInterop/ActsInterop/Logger.h:35
ActsAthenaFilterPolicy::level
virtual Acts::Logging::Level level() const override
Definition: Tracking/Acts/ActsInterop/src/Logger.cxx:50
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
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:42
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7