ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
src
errorcheck.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
11
12
#include "
AthenaKernel/errorcheck.h
"
13
#include "
AthenaKernel/getMessageSvc.h
"
14
#include "
CxxUtils/normalizeFunctionName.h
"
15
#include "GaudiKernel/MsgStream.h"
16
#include "GaudiKernel/INamedInterface.h"
17
#include <ctype.h>
18
19
20
namespace
errorcheck
{
21
22
24
std::atomic<bool>
ReportMessage::s_hide_error_locus
;
25
26
28
std::atomic<bool>
ReportMessage::s_hide_function_names
;
29
30
38
std::string
munge_filename
(
const
std::string&
file
,
const
std::string& pkg)
39
{
40
// Extract package name in case there is a version (MyPackage-00-00-00)
41
const
std::string p = pkg.substr(0, pkg.find(
'-'
));
42
if
(!p.empty()) {
43
// Find package name in path and remove any leading entries
44
std::string::size_type ipos =
file
.find(
"/"
+p+
"/"
);
45
if
(ipos != std::string::npos) {
46
return
file
.substr(ipos+1, std::string::npos);
47
}
48
}
49
return
file
;
50
}
51
52
64
ReportMessage::ReportMessage
(MSG::Level level,
65
int
line,
66
const
char
*
file
,
67
const
char
* func,
68
const
char
* pkg,
69
const
std::string& context,
70
StatusCode
sc
)
71
: MsgStream (
Athena
::getMessageSvc(), context)
72
{
73
// The common part.
74
format_common
(level, line,
file
, func, pkg);
75
76
// The status code.
77
*
this
<<
": code "
<<
sc
;
78
79
// Remember the end of the header.
80
m_pos
= stream().str().size();
81
}
82
83
94
ReportMessage::ReportMessage
(MSG::Level level,
95
int
line,
96
const
char
*
file
,
97
const
char
* func,
98
const
char
* pkg,
99
const
std::string& context)
100
: MsgStream (
Athena
::getMessageSvc(), context)
101
{
102
// The common part.
103
format_common
(level, line,
file
, func, pkg);
104
105
// Remember the end of the header.
106
m_pos
= stream().str().size();
107
}
108
109
118
void
ReportMessage::format_common
(MSG::Level level,
119
int
line,
120
const
char
*
file
,
121
const
char
* func,
122
const
char
* pkg)
123
{
124
// Logging level.
125
*
this
<< level;
126
127
// Write the source file/line.
128
if
(
s_hide_error_locus
)
129
*
this
<<
"FILE:LINE"
;
130
else
{
131
if
(pkg && pkg[0] !=
'\0'
)
132
*
this
<<
munge_filename
(
file
, pkg) <<
":"
<< line;
133
else
134
*
this
<<
file
<<
":"
<< line;
135
}
136
137
// Include the function name if available.
138
if
(
s_hide_function_names
)
139
*
this
<<
" (FUNC)"
;
140
else
{
141
if
(func && func[0] !=
'\0'
) {
142
*
this
<<
" ("
<<
CxxUtils::normalizeFunctionName
(func) <<
")"
;
143
}
144
}
145
}
146
147
152
ReportMessage::~ReportMessage
()
153
{
154
// Don't do anything if the message has already been emitted
155
// (due to using << endmsg, for example).
156
if
(!stream().
str
().
empty
())
157
*
this
<<
endmsg
;
158
}
159
160
166
MsgStream&
ReportMessage::doOutput
()
167
{
168
// The deal here is this. We want
169
// REPORT_MESSAGE(MSG::INFO) << "foo";
170
// to get a `: ' before the `foo'.
171
// But we don't want
172
// REPORT_MESSAGE(MSG::INFO);
173
// to have a trailing `: '.
174
// So, after we generate the common header part, we remember
175
// where we are in the string. When the message is emitted, we look
176
// to see if additional text has been added. If not, then we don't
177
// need to do anything. But if so, we insert a `: ' after the header.
178
if
(
m_pos
!= stream().
str
().
size
()) {
179
std::string tmp1 = stream().str();
180
std::string tmp2 = tmp1.substr(0,
m_pos
);
181
tmp2 +=
": "
;
182
tmp2.append( tmp1,
m_pos
);
183
stream().str (tmp2);
184
}
185
return
MsgStream::doOutput();
186
}
187
188
197
void
ReportMessage::hideErrorLocus
(
bool
flag
/*= true*/
)
198
{
199
s_hide_error_locus
= flag;
200
}
201
202
211
void
ReportMessage::hideFunctionNames
(
bool
flag
/*= true*/
)
212
{
213
s_hide_function_names
= flag;
214
}
215
216
217
}
// namespace errorcheck
218
219
220
namespace
errorcheck
{
221
222
230
std::string
context_name
(
const
INamedInterface* context)
231
{
232
return
context->name();
233
}
234
235
244
std::string
context_name
(
const
void
*
/*context*/
)
245
{
246
return
""
;
247
}
248
249
250
}
// namespace errorcheck
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
errorcheck.h
Helpers for checking error return status codes and reporting errors.
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
size
size_t size() const
Number of registered mappings.
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
errorcheck::ReportMessage::m_pos
std::string::size_type m_pos
The position in the output message after the standard header.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:292
errorcheck::ReportMessage::s_hide_function_names
static std::atomic< bool > s_hide_function_names
If true, hide the function names in output messages.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:298
errorcheck::ReportMessage::doOutput
virtual MsgStream & doOutput() override
Emit the message.
Definition
errorcheck.cxx:166
errorcheck::ReportMessage::~ReportMessage
~ReportMessage()
Destructor.
Definition
errorcheck.cxx:152
errorcheck::ReportMessage::s_hide_error_locus
static std::atomic< bool > s_hide_error_locus
If true, hide the source file and line number in output messages.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:295
errorcheck::ReportMessage::hideFunctionNames
static void hideFunctionNames(bool flag=true)
If set to true, hide function names in the output.
Definition
errorcheck.cxx:211
errorcheck::ReportMessage::hideErrorLocus
static void hideErrorLocus(bool flag=true)
If set to true, hide the source file and line number in the output.
Definition
errorcheck.cxx:197
errorcheck::ReportMessage::ReportMessage
ReportMessage(MSG::Level level, int line, const char *file, const char *func, const char *pkg, const std::string &context, StatusCode sc)
Constructor.
Definition
errorcheck.cxx:64
errorcheck::ReportMessage::format_common
void format_common(MSG::Level level, int line, const char *file, const char *func, const char *pkg)
Generate the common header for messages.
Definition
errorcheck.cxx:118
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
Athena
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
Definition
AthDsoUtils.h:10
CxxUtils::normalizeFunctionName
std::string normalizeFunctionName(const std::string &fname)
Normalize a pretty-printed C++ function name.
Definition
normalizeFunctionName.cxx:135
errorcheck
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:138
errorcheck::munge_filename
std::string munge_filename(const std::string &file, const std::string &pkg)
Shorten filename.
Definition
errorcheck.cxx:38
errorcheck::context_name
std::string context_name(const INamedInterface *context)
Return the context name from a context (this) pointer.
Definition
errorcheck.cxx:230
str
Definition
BTagTrackIpAccessor.cxx:11
normalizeFunctionName.h
Normalize a pretty-printed C++ function name,.
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0