SFrame 3.6
core/src/SErrorHandler.cxx
Go to the documentation of this file.
00001 // $Id: SErrorHandler.cxx 271 2011-08-05 08:52:53Z krasznaa $
00002 /***************************************************************************
00003  * @Project: SFrame - ROOT-based analysis framework for ATLAS
00004  * @Package: Core
00005  *
00006  * @author Stefan Ask       <Stefan.Ask@cern.ch>           - Manchester
00007  * @author David Berge      <David.Berge@cern.ch>          - CERN
00008  * @author Johannes Haller  <Johannes.Haller@cern.ch>      - Hamburg
00009  * @author A. Krasznahorkay <Attila.Krasznahorkay@cern.ch> - CERN/Debrecen
00010  *
00011  ***************************************************************************/
00012 
00013 // STL include(s):
00014 #include <map>
00015 #include <cstdlib>
00016 
00017 // ROOT include(s):
00018 #include <TSystem.h>
00019 #include <TError.h>
00020 
00021 // Local include(s):
00022 #include "core/include/SErrorHandler.h"
00023 #include "core/include/SLogger.h"
00024 
00026 static std::map< int, SMsgType > msgLevelMap;
00027 
00044 void SErrorHandler( int level, Bool_t abort, const char* location,
00045                     const char* message ) {
00046 
00047    // Veto some message locations:
00048    TString tlocation( location );
00049    if( tlocation.Contains( "NotifyMemory" ) ) {
00050       return;
00051    }
00052 
00053    // Create a local logger object:
00054    SLogger logger( location );
00055 
00056    // Initialise the helper map the first time the function is called:
00057    if( ! msgLevelMap.size() ) {
00058       msgLevelMap[ kInfo ]     = INFO;
00059       msgLevelMap[ kWarning ]  = WARNING;
00060       msgLevelMap[ kError ]    = ERROR;
00061       msgLevelMap[ kBreak ]    = ERROR;
00062       msgLevelMap[ kSysError ] = ERROR;
00063       msgLevelMap[ kFatal ]    = FATAL;
00064    }
00065 
00066    // Print the message:
00067    logger << msgLevelMap[ level ] << message << SLogger::endmsg;
00068 
00069    // Abort the process if necessary:
00070    if( abort ) {
00071       logger << ERROR << "Aborting..." << SLogger::endmsg;
00072       if( gSystem ) {
00073          gSystem->StackTrace();
00074          gSystem->Abort();
00075       } else {
00076          ::abort();
00077       }
00078    }
00079 
00080    return;
00081 
00082 }
00083 
00092 Int_t SetSErrorHandler() {
00093 
00094    // Set up SFrame's error handler:
00095    SetErrorHandler( SErrorHandler );
00096 
00097    // Report this feat:
00098    SLogger logger( "SetSErrorHandler" );
00099    logger << DEBUG << "Redirected ROOT messages to SFrame's logger" << SLogger::endmsg;
00100 
00101    return 0;
00102 
00103 }
00104 
00105 // Call the function:
00106 static Int_t dummy = SetSErrorHandler();