ATLAS Offline Software
|
macros for messaging and checking status codes More...
#include "CxxUtils/AthUnlikelyMacros.h"
#include <type_traits>
#include <AsgMessaging/MsgHelpers.h>
#include <AsgMessaging/StatusCode.h>
#include "CxxUtils/checker_macros.h"
#include "CxxUtils/normalizeFunctionName.h"
#include <atomic>
Go to the source code of this file.
Classes | |
struct | asg::CheckHelper< T > |
this is an internal traits class for status codes used by the ANA_CHECK* macros More... | |
struct | asg::CheckHelper< StatusCode > |
struct | asg::CheckHelper< int > |
struct | asg::CheckHelper< bool > |
struct | asg::CheckHelper< T * > |
Namespaces | |
asg | |
asg::detail | |
Macros | |
#define | ANA_MSG_HEADER(NAME) |
for standalone code this creates a new message category More... | |
#define | ASG_TOOLS_MSG_STREAM(NAME, TITLE) static thread_local MsgStream NAME {::asg::MsgHelpers::pkgMsgStream (TITLE)}; |
#define | ANA_MSG_SOURCE(NAME, TITLE) |
the source code part of ANA_MSG_SOURCE More... | |
#define | MSGSTREAM_FNAME "" |
#define | ASG_TOOLS_MSGSTREAM_FNAME "" |
#define | ASG_TOOLS_MSGSTREAM_PREFIX __FILE__ << ":" << __LINE__ << " (" << ASG_TOOLS_MSGSTREAM_FNAME << "): " |
Common prefix for the non-usual messages. More... | |
#define | ANA_MSG_LVL_SERIOUS(lvl, xmsg) msg( lvl ) << ASG_TOOLS_MSGSTREAM_PREFIX << xmsg << endmsg |
Macro used to print "serious" messages. More... | |
#define | ANA_MSG_LVL_NOCHK(lvl, xmsg) msg( lvl ) << xmsg << endmsg |
Macro used to print "regular" messages. More... | |
#define | ANA_MSG_LVL(lvl, xmsg) |
Macro used to print "protected" messages. More... | |
#define | ANA_MSG_VERBOSE(xmsg) ANA_MSG_LVL( MSG::VERBOSE, xmsg ) |
Macro printing verbose messages. More... | |
#define | ANA_MSG_DEBUG(xmsg) ANA_MSG_LVL( MSG::DEBUG, xmsg ) |
Macro printing debug messages. More... | |
#define | ANA_MSG_INFO(xmsg) ANA_MSG_LVL_NOCHK( MSG::INFO, xmsg ) |
Macro printing info messages. More... | |
#define | ANA_MSG_WARNING(xmsg) ANA_MSG_LVL_NOCHK( MSG::WARNING, xmsg ) |
Macro printing warning messages. More... | |
#define | ANA_MSG_ERROR(xmsg) ANA_MSG_LVL_SERIOUS( MSG::ERROR, xmsg ) |
Macro printing error messages. More... | |
#define | ANA_MSG_FATAL(xmsg) ANA_MSG_LVL_SERIOUS( MSG::FATAL, xmsg ) |
Macro printing fatal messages. More... | |
#define | ANA_MSG_ALWAYS(xmsg) ANA_MSG_LVL_NOCHK( MSG::ALWAYS, xmsg ) |
Macro printing messages that should always appear. More... | |
#define | ANA_CHECK_SET_TYPE(TYPE) typedef TYPE AsgToolsCheckResultType; |
set the type for ANA_CHECK to report failures More... | |
#define | ANA_CHECK(EXP) |
check whether the given expression was successful More... | |
#define | ANA_CHECK_THROW(EXP) |
check whether the given expression was successful, throwing an exception on failure More... | |
Typedefs | |
typedef StatusCode | AsgToolsCheckResultType |
the return type used by ANA_CHECK More... | |
Functions | |
void | asg::detail::throw_check_fail (const std::string &str) |
throw an error for a failed check More... | |
macros for messaging and checking status codes
For the most part ANA_CHECK works just like ATH_CHECK, except it works for any kind of status code (and other things like bool). By default it will return a regular StatusCode object, but you can make it return a different type by specifying ANA_CHECK_SET_TYPE at the beginning of the function. In the example I use it to return an int instead.
Unfortunately the example will compile without that line, but it will not work as expected, i.e. when you return StatusCode::FAILURE it will convert to a value of 0, which the shell interprets as success. There is very little I can do about that from my side, as that is the intrinsic behavior of StatusCode itself. So it is very important that you remember to put that line in.
If you have a function that needs to indicate failure, but can't do so via a status code (e.g. a constructor) you can use the macro ANA_CHECK_THROW, which will throw an exception instead. However, where possible a status code is preferred.
If this is actually a unit test and you already had the chance to update it to GoogleTest, then there are also macros ASSERT_SUCCESS, ASSERT_FAILURE, EXPECT_SUCCESS and EXPECT_FAILURE defined that integrate with the GoogleTest reporting system.
The other thing needed in the above example is the using namespace line. This makes the standard messaging macros available in functions that are not member functions of a tool. Or almost: It works fine in RootCore, but for dual-use code you need to use ANA_MSG_* instead of ATH_MSG_* for sending messages yourself.
The msgUserCode category I used here is meant for things like main functions, etc. If you want to use this for other standalone functions you may consider making your own category (or indeed several). For that you put in one of your headers the line:
and then in one of the source files:
That way users get the chosen label as part of the messages. Plus they can actually set the message level separately for each category.
Definition in file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_CHECK | ( | EXP | ) |
check whether the given expression was successful
This works like ATH_CHECK except it can handle all kinds of status codes, not just the regular ones. In particular the user can also set the type of the status code returned via ANA_CHECK_SET_TYPE
Definition at line 325 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_CHECK_SET_TYPE | ( | TYPE | ) | typedef TYPE AsgToolsCheckResultType; |
set the type for ANA_CHECK to report failures
normally ANA_CHECK will report failures via a StatusCode object, but this macro can be called inside a function to tell it to report via a different type.
Definition at line 315 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_CHECK_THROW | ( | EXP | ) |
check whether the given expression was successful, throwing an exception on failure
This works like ANA_CHECK except it throws when an error occurs. This is meant for situations in which we perform a check inside a function that does not return a StatusCode.
Definition at line 340 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_ALWAYS | ( | xmsg | ) | ANA_MSG_LVL_NOCHK( MSG::ALWAYS, xmsg ) |
Macro printing messages that should always appear.
Definition at line 299 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_DEBUG | ( | xmsg | ) | ANA_MSG_LVL( MSG::DEBUG, xmsg ) |
Macro printing debug messages.
Definition at line 289 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_ERROR | ( | xmsg | ) | ANA_MSG_LVL_SERIOUS( MSG::ERROR, xmsg ) |
Macro printing error messages.
Definition at line 295 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_FATAL | ( | xmsg | ) | ANA_MSG_LVL_SERIOUS( MSG::FATAL, xmsg ) |
Macro printing fatal messages.
Definition at line 297 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_HEADER | ( | NAME | ) |
for standalone code this creates a new message category
The idea is that this provides a way to use the "standard" messaging macros in code that doesn't inherit from AsgTools. All you have to do is put
at the beginning of a function and then you can use the messaging macros as if you were inside an AsgTool.
Or almost, in RootCore this works just fine, but in Athena ATH_MSG_* is defined slightly differently so that this won't work. To that end we are providing ANA_MSG_* macros that work with this, and in both RootCore and Athena. This way you can also use ATH_CHECK/ANA_CHECK in your code.
Besides allowing to use the standard messaging macros, you can also set the message level similar to how you'd do it for an AsgTool:
Definition at line 114 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_INFO | ( | xmsg | ) | ANA_MSG_LVL_NOCHK( MSG::INFO, xmsg ) |
Macro printing info messages.
Definition at line 291 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_LVL | ( | lvl, | |
xmsg | |||
) |
Macro used to print "protected" messages.
Definition at line 279 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
Macro used to print "regular" messages.
Definition at line 275 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_LVL_SERIOUS | ( | lvl, | |
xmsg | |||
) | msg( lvl ) << ASG_TOOLS_MSGSTREAM_PREFIX << xmsg << endmsg |
Macro used to print "serious" messages.
Definition at line 271 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_SOURCE | ( | NAME, | |
TITLE | |||
) |
the source code part of ANA_MSG_SOURCE
For every message category that you introduce via ANA_MSG_SOURCE you have to add this in one of your source files, to add the source code needed for its function implementations
Definition at line 134 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_VERBOSE | ( | xmsg | ) | ANA_MSG_LVL( MSG::VERBOSE, xmsg ) |
Macro printing verbose messages.
Definition at line 287 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ANA_MSG_WARNING | ( | xmsg | ) | ANA_MSG_LVL_NOCHK( MSG::WARNING, xmsg ) |
Macro printing warning messages.
Definition at line 293 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ASG_TOOLS_MSG_STREAM | ( | NAME, | |
TITLE | |||
) | static thread_local MsgStream NAME {::asg::MsgHelpers::pkgMsgStream (TITLE)}; |
Definition at line 125 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ASG_TOOLS_MSGSTREAM_FNAME "" |
Definition at line 257 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define ASG_TOOLS_MSGSTREAM_PREFIX __FILE__ << ":" << __LINE__ << " (" << ASG_TOOLS_MSGSTREAM_FNAME << "): " |
Common prefix for the non-usual messages.
The idea is that a regular user usually only wants to see DEBUG, INFO and some WARNING messages. So those should be reasonably short. On the other hand serious warnings (ERROR, FATAL) messages should be as precise as possible to make debugging the issue easier.
Definition at line 267 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
#define MSGSTREAM_FNAME "" |
Definition at line 249 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.
typedef StatusCode AsgToolsCheckResultType |
the return type used by ANA_CHECK
this defaults to the regular StatusCode, but can be overriden via ANA_CHECK_SET_TYPE
Definition at line 306 of file Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h.