ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_FastCaloSim
ISF_FastCaloSimEvent
src
MLogging.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
ISF_FastCaloSimEvent/MLogging.h
"
6
7
// Declare the class in a namespace
8
namespace
ISF_FCS
{
9
// Define Athena like message macros such that they work stand alone
10
#if defined(__FastCaloSimStandAlone__)
11
13
void
MLogging::setLevel
(
int
level) {
14
level
= (
level
>= MSG::NUM_LEVELS) ? MSG::ALWAYS
15
: (
level
< MSG::
NIL
) ? MSG::
NIL
16
:
level
;
17
m_level = MSG::Level(
level
);
18
}
19
20
// startMsg defined at base of file.
21
23
MsgStream &
MLogging::msg
(
const
MSG::Level lvl)
const
{
24
return
this->
stream
(lvl,
""
, -1);
25
};
26
28
// check the lvl of logging is active, otherwise provide dummy stream.
29
// if the proposed streamer dosen't match the current one
30
// end any running lines and start a new decorated line
31
// provide the stream at the end
32
MsgStream &MLogging::stream(MSG::Level lvl, std::string
file
,
int
line)
const
{
33
// If we shouldn't print this just return a dummy stream.
34
if
(!this->
msgLvl
(lvl))
35
return
*m_null_msg_ptr;
36
// This is different to the last stream.
37
if
(this->streamerNeedStart(lvl,
file
)) {
38
// end the open stream
39
if
(this->streamerInLine())
40
std::cout << this->streamerEndLine(lvl);
41
this->
msg
() << this->
startMsg
(lvl,
file
, line);
42
this->streamerInLine(
true
);
43
}
44
return
*m_msg;
45
}
46
48
bool
MLogging::msgLvl
(
const
MSG::Level lvl)
const
{
49
if
(lvl == MSG::VERBOSE || lvl == MSG::DEBUG)
50
return
m_level <= lvl;
51
// All other messages print always
52
return
true
;
53
}
54
56
void
MLogging::print(MSG::Level lvl, std::string
file
,
int
line,
57
std::string message)
const
{
58
if
(this->
msgLvl
(lvl)) {
59
this->
stream
(lvl,
file
, line) <<
message
<< this->streamerEndLine(lvl);
60
}
61
}
62
64
std::string MLogging::streamerEndLine(MSG::Level lvl)
const
{
65
if
(this->
msgLvl
(lvl)) {
66
m_streamer_in_line =
false
;
67
*m_msg << std::endl;
68
}
69
return
""
;
70
}
71
73
void
MLogging::streamerInLine(
bool
is_in_line)
const
{
74
m_streamer_in_line = is_in_line;
75
}
76
78
bool
MLogging::streamerNeedStart(MSG::Level lvl, std::string
file
)
const
{
79
// Are we in the middle of a stream of the same level from the same file.
80
if
(lvl == m_streamer_has_lvl &&
file
== m_streamer_from_file &&
81
m_streamer_in_line)
82
return
false
;
83
// Otherwise time for a new start.
84
m_streamer_from_file =
file
;
85
m_streamer_has_lvl = lvl;
86
return
true
;
87
}
88
89
#else
// For inside Athena
90
91
MLogging::MLogging
(
const
std::string &name) :
m_nm
(name) {}
92
93
MLogging::~MLogging
() {}
94
95
MLogging::MLogging
(
const
MLogging
&rhs) :
m_nm
(rhs.
m_nm
) {
96
this->
setLevel
(rhs.
level
());
97
};
98
99
MLogging
&
MLogging::operator=
(
const
MLogging
&rhs) {
100
this->
m_nm
= rhs.
m_nm
;
101
this->
setLevel
(rhs.
level
());
102
return
*
this
;
103
}
104
105
void
MLogging::setLevel
(MSG::Level lvl) {
106
lvl = (lvl >= MSG::NUM_LEVELS) ? MSG::ALWAYS
107
: (lvl < MSG::NIL) ? MSG::NIL
108
: lvl;
109
msg
().setLevel(lvl);
110
}
111
112
#endif
// End inside Athena
113
114
// This is the same either way.
116
std::string
MLogging::startMsg
(MSG::Level lvl,
const
std::string&
file
,
int
line) {
117
int
col1_len = 20;
118
int
col2_len = 5;
119
int
col3_len = 10;
120
auto
last_slash =
file
.find_last_of(
'/'
);
121
int
path_len = last_slash == std::string::npos ? 0 : last_slash;
122
int
trim_point = path_len;
123
int
total_len =
file
.length();
124
if
(total_len - path_len > col1_len)
125
trim_point = total_len - col1_len;
126
std::string trimmed_name =
file
.substr(trim_point);
127
const
char
*LevelNames[MSG::NUM_LEVELS] = {
128
"NIL"
,
"VERBOSE"
,
"DEBUG"
,
"INFO"
,
"WARNING"
,
"ERROR"
,
"FATAL"
,
"ALWAYS"
};
129
std::string
level
= LevelNames[lvl];
130
std::string level_string = std::string(
"("
) +
level
+
") "
;
131
std::stringstream output;
132
output << std::setw(col1_len) << std::right << trimmed_name <<
":"
133
<< std::setw(col2_len) << std::left << line << std::setw(col3_len)
134
<< std::right << level_string;
135
return
output.str();
136
}
137
138
}
// namespace ISF_FCS
MLogging.h
ISF_FCS::MLogging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition
MLogging.h:222
ISF_FCS::MLogging::MLogging
MLogging(const std::string &name="ISF_FastCaloSimEvent")
Constructor.
Definition
MLogging.cxx:91
ISF_FCS::MLogging::~MLogging
virtual ~MLogging()
Destructor:
Definition
MLogging.cxx:93
ISF_FCS::MLogging::setLevel
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
Definition
MLogging.cxx:105
ISF_FCS::MLogging::operator=
MLogging & operator=(const MLogging &rhs)
Definition
MLogging.cxx:99
ISF_FCS::MLogging::startMsg
static std::string startMsg(MSG::Level lvl, const std::string &file, int line)
Make a message to decorate the start of logging.
Definition
MLogging.cxx:116
ISF_FCS::MLogging::m_nm
std::string m_nm
Message source name.
Definition
MLogging.h:211
ISF_FCS::MLogging::msg
MsgStream & msg() const
Return a stream for sending messages directly (no decoration).
Definition
MLogging.h:231
ISF_FCS::MLogging::level
MSG::Level level() const
Retrieve output level.
Definition
MLogging.h:201
AthenaPoolTestWrite.stream
str stream
Definition
AthenaPoolTestWrite.py:12
ISF_FCS
Definition
MLogging.h:66
ReweightUtils.message
message
Definition
ReweightUtils.py:15
TrigConf::MSGTC::NIL
@ NIL
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:22
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0