ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
errorcheck::ReportMessage Class Reference

Helper class to use to report a message. More...

#include <errorcheck.h>

Inheritance diagram for errorcheck::ReportMessage:
Collaboration diagram for errorcheck::ReportMessage:

Public Member Functions

 ReportMessage (MSG::Level level, int line, const char *file, const char *func, const char *pkg, const std::string &context, StatusCode sc)
 Constructor. More...
 
 ReportMessage (MSG::Level level, int line, const char *file, const char *func, const char *pkg, const std::string &context)
 Constructor. More...
 
 ~ReportMessage ()
 Destructor. More...
 
virtual MsgStream & doOutput ()
 Emit the message. More...
 
MsgStream & msgstream ()
 Convert to a MsgStream reference. More...
 

Static Public Member Functions

static void hideErrorLocus (bool flag=true)
 If set to true, hide the source file and line number in the output. More...
 
static void hideFunctionNames (bool flag=true)
 If set to true, hide function names in the output. More...
 

Private Member Functions

void format_common (MSG::Level level, int line, const char *file, const char *func, const char *pkg)
 Generate the common header for messages. More...
 

Private Attributes

std::string::size_type m_pos
 The position in the output message after the standard header. More...
 

Static Private Attributes

static std::atomic< bool > s_hide_error_locus
 If true, hide the source file and line number in output messages. More...
 
static std::atomic< bool > s_hide_function_names
 If true, hide the function names in output messages. More...
 

Detailed Description

Helper class to use to report a message.

To report a message, create an instance of this class. A standard header, containing the file/line, context name, and so forth, is automatically put at the start of the message. More text may be added using the standard MsgStream streaming operators. The message is actually emitted when this object is destroyed.

Definition at line 171 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

Constructor & Destructor Documentation

◆ ReportMessage() [1/2]

errorcheck::ReportMessage::ReportMessage ( MSG::Level  level,
int  line,
const char *  file,
const char *  func,
const char *  pkg,
const std::string &  context,
StatusCode  sc 
)

Constructor.

Parameters
levelThe error logging level for the message.
lineThe source line from which the report is being made.
fileThe source file name from which the report is being made.
funcThe name of the function from which the report is being made.
pkgThe name of the package from which the report is being made.
contextThe name of the context (algorithm/tool/service/etc.) from which the report is being made.
scThe StatusCode to include in the error message.

Definition at line 64 of file errorcheck.cxx.

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 }

◆ ReportMessage() [2/2]

errorcheck::ReportMessage::ReportMessage ( MSG::Level  level,
int  line,
const char *  file,
const char *  func,
const char *  pkg,
const std::string &  context 
)

Constructor.

Parameters
levelThe error logging level for the message.
lineThe source line from which the report is being made.
fileThe source file name from which the report is being made.
funcThe name of the function from which the report is being made.
pkgThe name of the package from which the report is being made.
contextThe name of the context (algorithm/tool/service/etc.) from which the report is being made.

Definition at line 94 of file errorcheck.cxx.

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 }

◆ ~ReportMessage()

errorcheck::ReportMessage::~ReportMessage ( )

Destructor.

This will cause the message to be emitted, if it hasn't already been.

Definition at line 152 of file errorcheck.cxx.

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 }

Member Function Documentation

◆ doOutput()

MsgStream & errorcheck::ReportMessage::doOutput ( )
virtual

Emit the message.

We override this method from MsgStream in order to fix up the message punctuation.

Definition at line 166 of file errorcheck.cxx.

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 }

◆ format_common()

void errorcheck::ReportMessage::format_common ( MSG::Level  level,
int  line,
const char *  file,
const char *  func,
const char *  pkg 
)
private

Generate the common header for messages.

Parameters
levelThe error logging level for the message.
lineThe source line from which the report is being made.
fileThe source file name from which the report is being made.
funcThe name of the function from which the report is being made.
pkgThe name of the package from which the report is being made.

Definition at line 118 of file errorcheck.cxx.

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.
139  *this << " (FUNC)";
140  else {
141  if (func && func[0] != '\0') {
142  *this << " (" << CxxUtils::normalizeFunctionName(func) << ")";
143  }
144  }
145 }

◆ hideErrorLocus()

void errorcheck::ReportMessage::hideErrorLocus ( bool  flag = true)
static

If set to true, hide the source file and line number in the output.

This is intended for use in regression tests, where it's undesirable to have the output change if source lines are added or deleted.

Definition at line 197 of file errorcheck.cxx.

198 {
200 }

◆ hideFunctionNames()

void errorcheck::ReportMessage::hideFunctionNames ( bool  flag = true)
static

If set to true, hide function names in the output.

in the output.

This is intended for use in regression tests, where function names may be formatted differently on different platforms.

Definition at line 211 of file errorcheck.cxx.

212 {
214 }

◆ msgstream()

MsgStream& errorcheck::ReportMessage::msgstream ( )
inline

Convert to a MsgStream reference.

Trying to use a ReportMessage like

ReportMessage(...) << "foo";

doesn't work, because (as of Gaudi 19) the MsgStream inserters are written as free functions:

MsgStream& operator<< (MsgStream&, ...);

and the non-const MsgStream reference won't bind to the temporary. We can work around this problem with this method, which will convert the temporary to a non-const reference. So, this should work:

ReportMessage(...).stream() << "foo";

Definition at line 251 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

251 { return *this; }

Member Data Documentation

◆ m_pos

std::string::size_type errorcheck::ReportMessage::m_pos
private

The position in the output message after the standard header.

Definition at line 292 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

◆ s_hide_error_locus

std::atomic< bool > errorcheck::ReportMessage::s_hide_error_locus
staticprivate

If true, hide the source file and line number in output messages.

Definition at line 295 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

◆ s_hide_function_names

std::atomic< bool > errorcheck::ReportMessage::s_hide_function_names
staticprivate

If true, hide the function names in output messages.

Definition at line 298 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.


The documentation for this class was generated from the following files:
checkFileSG.line
line
Definition: checkFileSG.py:75
DeMoUpdate.tmp2
string tmp2
Definition: DeMoUpdate.py:1168
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
errorcheck::munge_filename
std::string munge_filename(const std::string &file, const std::string &pkg)
Shorten filename.
Definition: errorcheck.cxx:38
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
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
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
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
master.flag
bool flag
Definition: master.py:29
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
file
TFile * file
Definition: tile_monitor.h:29
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
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
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
CxxUtils::normalizeFunctionName
std::string normalizeFunctionName(const std::string &fname)
Normalize a pretty-printed C++ function name.
Definition: normalizeFunctionName.cxx:135