ATLAS Messaging (optional)

Last update: 30 Oct 2018 [History] [Edit]

Some extra words on the messaging: In ATLAS messages are usually identified by three things:

  • a message source: Typically an algorithm or a tool, generally identified by their name. Sometimes we also have standalone code messaging, which should then try to pick its own unique and identifiable names.
  • a message level: This indicates how important/severe the message is. The primary use of this is to filter out irrelevant messages. By default all messages of level INFO or higher will get displayed, but this is configurable.
  • the message content: This can in principle be just any string, but try to include enough information that users can understand what you are trying to say without having to look at your source code. Also, if your class is complex or spread out over multiple files, consider including information like the function name, so that users can find the source more easily. (Note that this is often a warning sign that your algorithm/tool has grown to be overly complex, and could benefit from being split up into multiple classes.)

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

tip 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.

Printing Out Values

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);

ANA_MSG_* vs. ATH_MSG_*

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).

Use in Standalone Functions

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 AsgTools/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 <AsgTools/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.

Changing Message Output Levels

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.