Sending NAG C library errors to the GAUDI Message Service
The GaudiNagC package in the Gaudi software distribution contains classes to
handle NAG C library errors within Gaudi. Please note that the current release only allows to create one instance of the GaudiErrorHandler
class. The following steps are needed in order to use them in your algorithm:
-
Use the package in the requirements file:
use GaudiNagC v*
-
In your header file, declare a member variable to hold a pointer to the
error handling object, e.g.:
class GaudiErrorHandler;
private
GaudiErrorHandler*
m_handler;
-
Add the following to your implementation file:
-
Include the header file of the GaudiNagHandler
class, which interfaces NAG errors to the Gaudi MessageSvc:
#include "GaudiNagC/GaudiNagHandler.h"
-
In the constructor, set the pointer to the error handling object to zero:
m_handler = 0;
-
In the algorithm's initialize()
method, create a new GaudiErrorHandler
object which will remember the address of the message service, and the
name of your algorithm:
if( m_handler == 0 ) m_handler = new
GaudiErrorHandler(messageService(), name());
Do not forget to delete this
object in your destructor.....
-
Whenever you call a NAG C function that can return an error, use the syntax
in the example below to declare an error handler:
g05cgc( istate, xstate, GaudiNagHandler::declareHandler(m_handler)
);
The default behaviour of this service is given by the execute()
method of the GaudiErrorHandler
class. If you wish to have a different behaviour, you should write your
own class derived from GaudiErrorHandler,
reimplement the execute() method,
then use your new class instead of GaudiErrorHandler.
The implementation of GaudiErrorHandler::execute()
is shown below:
void GaudiErrorHandler::execute(char
*string, int code, char *name) {
MsgStream log(messageSvc(), algName());
if (code != NE_NOERROR ) {
if( !strncmp( string, "NE",
2 )) {
log <<
MSG::ERROR << " from " << name << " (NAG): " <<
string << endreq;
}
else {
log <<
MSG::WARNING << " from " << name << " (NAG): " <<
string << endreq;
}
}
else {
log << MSG::INFO
<< name << " (NAG) called successfully" << endreq;
}
}