Some extra words on the messaging: In ATLAS messages are usually identified by three things:
For most of the tutorial we use the message level INFO
indicating
that we have something to tell the user, but that nothing went wrong
and there is nothing to worry about. It is also the lowest message
level that still gets displayed by default. The main reason we choose
INFO
is because we don’t want to complicate the tutorial further by
constantly adjusting message levels. However, for production level
code (which includes your analysis code) you typically want to reduce
the amount of print-out you get (otherwise you may miss important
messages). Generally all the print-out in this tutorial would really
be more appropriate at the DEBUG
or VERBOSE
level instead.
A good rule of thumb is that production level code should not use
INFO
messages inside execute()
, and should only use it sparingly
anywhere else. It is perfectly fine for an algorithm or tool not to
produce any INFO
level printout at all.
The complete list of message levels is:
FATAL |
something went severely wrong and we will end the program immediately |
ERROR |
an error occurred and we are about to return a StatusCode::FAILURE (normally leading to program termination) |
WARNING |
something went wrong that the user should investigate and fix, but the program can continue to run |
INFO |
information that may be relevant for the user, but that doesn’t in itself indicate that anything went wrong |
DEBUG |
additional information that can be enabled when trying to debug your code in an effort to understand what it is doing |
VERBOSE |
even more debugging output, that allows to follow in great detail what your code is doing |
If you look at existing/older code you may find them using any variety of other messaging mechanisms (e.g.
std::cout
,Info()
). While opinions are somewhat divided on how bad that is, for new code you should try to stick to the messaging macros below.
The ANA_MSG_INFO
macro works quite similar to std::cout
(it uses
an std::ostream
underneath), so you can print out variables using
the same syntax, e.g. you could print out a loop index like this:
for (unsigned iter = 0; iter != 10; ++ iter)
ANA_MSG_INFO ("iter = " << iter);
There are two sets of message macros, one starting with ANA_MSG_
the
other starting with ATH_MSG_
. By and large they do the same, though
in this tutorial we stick with the former rather than the later. The
main difference is that inside the Athena environment you can not use
ATH_MSG_
for standalone functions as described below (in
AnalysisBase there is literally no difference between the two).
If you want to use atlas messaging outside of a tool or an algorithm,
you need to do a little more work. There are multiple options for
this, one of the most simple ones is to use AsgMessaging/MessageCheck.h
.
Let’s say you have an existing function:
...
void function ()
{
...
std::cout << [some message] << std::endl;
...
}
...
With ATLAS messaging this would look like this:
#include <AsgMessaging/MessageCheck.h>
...
void function ()
{
using namespace asg::msgUserCode;
...
ANA_MSG_INFO ([some message]);
...
}
...
This will just attach all your messages to a component for user code, which is fine in some situations and problematic in others. If you use this for anything else than end-user analysis code you should probably define your own component just for that. That will both show the correct name with your messages and allow users to adjust the message level for it separately from other messages. Details can be found in the MessageCheck header.
To change the output level of an algorithm or tool, see the description about handing the “OutputLevel” property on such components.
Changing the output level of code outside of algorithms/tools is much
less straight forward, so in general the recommendation is to not
print DEBUG
and VERBOSE
messages outside of algorithms and
tools. As the users will have a very hard time seeing those messages.
Make an INFO
, DEBUG
, and VERBOSE
message in your execute function.
Change the output level in your configuration to print each of these levels.