ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
21ActsAthenaPrintPolicy::ActsAthenaPrintPolicy(std::shared_ptr<MsgStream> msg, const std::string& name):
22 m_svc{Athena::getMessageSvc()},
23 m_msg{std::move(msg)},
24 m_name{name} {}
25void
26ActsAthenaPrintPolicy::flush(const Acts::Logging::Level& lvl, const std::string& input)
27{
28 MSG::Level athLevel = ActsTrk::athLevelVector(lvl);
29 (*m_msg) << athLevel << input << endmsg;
30}
31
32const std::string&
34{
35 return m_name;
36}
37
38std::unique_ptr<Acts::Logging::OutputPrintPolicy>
39ActsAthenaPrintPolicy::clone(const std::string& name) const {
40 return std::make_unique<ActsAthenaPrintPolicy>(m_msg, name);
41}
42
43bool ActsAthenaFilterPolicy::doPrint(const Acts::Logging::Level& lvl) const {
44
45 MSG::Level athLevel = ActsTrk::athLevelVector(lvl);
46 return m_msg->level() <= athLevel;
47}
48
49Acts::Logging::Level
54
55std::unique_ptr<Acts::Logging::OutputFilterPolicy>
56ActsAthenaFilterPolicy::clone(Acts::Logging::Level level) const
57{
58 auto msg = std::make_shared<MsgStream>(*m_msg);
60 return std::make_unique<ActsAthenaFilterPolicy>(msg);
61}
62
63std::unique_ptr<const Acts::Logger>
64makeActsAthenaLogger(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
80std::unique_ptr<const Acts::Logger>
81makeActsAthenaLogger(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}
87std::unique_ptr<const Acts::Logger>
88makeActsAthenaLogger(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, std::move(parent_name));
99}
100
101std::unique_ptr<const Acts::Logger>
102makeActsAthenaLogger(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, std::move(parent_name));
110}
111
112std::unique_ptr<const Acts::Logger>
113makeActsAthenaLogger(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}
#define endmsg
void print(char *figname, TCanvas *c1)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
virtual Acts::Logging::Level level() const override
virtual std::unique_ptr< Acts::Logging::OutputFilterPolicy > clone(Acts::Logging::Level level) const override
bool doPrint(const Acts::Logging::Level &lvl) const override
virtual const std::string & name() const override
virtual std::unique_ptr< Acts::Logging::OutputPrintPolicy > clone(const std::string &name) const override
void flush(const Acts::Logging::Level &lvl, const std::string &input) override
ActsAthenaPrintPolicy(std::shared_ptr< MsgStream > msg, const std::string &name)
Class to provide easy MsgStream access and capabilities.
singleton-like access to IMessageSvc via open function and helper
MSG::Level athLevelVector(Acts::Logging::Level lvl)
Acts::Logging::Level actsLevelVector(MSG::Level lvl)
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
STL namespace.
MsgStream & msg
Definition testRead.cxx:32