Rules for printout from algorithms running in production applications


Consider the following code:
if ( sc.isFailure() ) {
  error()  << "Non-positive cov. matrix in smoother for z = " << thisNode.z()
           << " thisNodeC = " << thisNodeC << endmsg;
  return StatusCode::FAILURE;

The error message will be printed out every time the error occurs, because the error() method is used. Even if Error() were used, it would never be switched off because the message string contains the values of thisNode.z() and thisNodeC, which change each time.

The code should be changed to something like:

if ( sc.isFailure() ) {
  // print error message
  Error( "Non-positive cov. matrix in smoother. More details in debug()").ignore();
  // test message level before evaluating MsgStream
  if( msgLevel( MSG::DEBUG ) ) {
    // give a more detailed explanation
    debug() << "z = " << thisNode.z() << " thisNodeC = " << thisNodeC << endmsg;
  return StatusCode::FAILURE ;

The advantage of this is that, in normal production, one would just see the error printout 10 times, and then a summary of the number of errors at the end. The experts who need to see the details of the failure can can run with OutputLevel = 2 for this particular tool. Note that the functions Warning(), Error() etc. return a StatusCode. This can be useful as it can be used as the return StatusCode of the function where the error occurs; most often though, the StatusCode can be ignored, this should be be done explicitly:  Error("Some error occurred").ignore();