ATLAS Offline Software
Toggle main menu visibility
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
5
#include "
ActsInterop/Logger.h
"
6
#include "
ActsInterop/LoggerUtils.h
"
7
#include "
AthenaKernel/getMessageSvc.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
{
std
::move(
msg
)},
24
m_name
{
name
} {}
25
void
26
ActsAthenaPrintPolicy::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
32
const
std::string&
33
ActsAthenaPrintPolicy::name
()
const
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
43
bool
ActsAthenaFilterPolicy::doPrint
(
const
Acts::Logging::Level& lvl)
const
{
44
45
MSG::Level athLevel =
ActsTrk::athLevelVector
(lvl);
46
return
m_msg
->level() <= athLevel;
47
}
48
49
Acts::Logging::Level
50
ActsAthenaFilterPolicy::level
()
const
51
{
52
return
ActsTrk::actsLevelVector
(
m_msg
->level());
53
}
54
55
std::unique_ptr<Acts::Logging::OutputFilterPolicy>
56
ActsAthenaFilterPolicy::clone
(Acts::Logging::Level
level
)
const
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, std::move(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, std::move(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
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:61
LoggerUtils.h
makeActsAthenaLogger
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition
Logger.cxx:64
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
Logger.h
ActsAthenaFilterPolicy::m_msg
std::shared_ptr< MsgStream > m_msg
Definition
Tracking/Acts/ActsInterop/ActsInterop/Logger.h:55
ActsAthenaFilterPolicy::level
virtual Acts::Logging::Level level() const override
Definition
Logger.cxx:50
ActsAthenaFilterPolicy::clone
virtual std::unique_ptr< Acts::Logging::OutputFilterPolicy > clone(Acts::Logging::Level level) const override
Definition
Logger.cxx:56
ActsAthenaFilterPolicy::doPrint
bool doPrint(const Acts::Logging::Level &lvl) const override
Definition
Logger.cxx:43
ActsAthenaPrintPolicy::name
virtual const std::string & name() const override
Definition
Logger.cxx:33
ActsAthenaPrintPolicy::m_svc
IMessageSvc * m_svc
Definition
Tracking/Acts/ActsInterop/ActsInterop/Logger.h:35
ActsAthenaPrintPolicy::m_name
std::string m_name
Definition
Tracking/Acts/ActsInterop/ActsInterop/Logger.h:37
ActsAthenaPrintPolicy::clone
virtual std::unique_ptr< Acts::Logging::OutputPrintPolicy > clone(const std::string &name) const override
Definition
Logger.cxx:39
ActsAthenaPrintPolicy::flush
void flush(const Acts::Logging::Level &lvl, const std::string &input) override
Definition
Logger.cxx:26
ActsAthenaPrintPolicy::ActsAthenaPrintPolicy
ActsAthenaPrintPolicy(std::shared_ptr< MsgStream > msg, const std::string &name)
Definition
Logger.cxx:21
ActsAthenaPrintPolicy::m_msg
std::shared_ptr< MsgStream > m_msg
Definition
Tracking/Acts/ActsInterop/ActsInterop/Logger.h:36
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition
AthMessaging.h:55
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
ActsTrk::athLevelVector
MSG::Level athLevelVector(Acts::Logging::Level lvl)
Definition
LoggerUtils.cxx:29
ActsTrk::actsLevelVector
Acts::Logging::Level actsLevelVector(MSG::Level lvl)
Definition
LoggerUtils.cxx:9
Athena
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
Definition
AthDsoUtils.h:10
std
STL namespace.
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0