| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

# AlgErrorAuditor.cpp

Go to the documentation of this file.

    00001 #include "AlgErrorAuditor.h"
    00002 #include "GaudiKernel/MsgStream.h"
    00003 #include "GaudiKernel/IMessageSvc.h"
    00004 #include "GaudiKernel/AudFactory.h"
    00005 #include "GaudiKernel/GaudiException.h"
    00006
    00007 DECLARE_AUDITOR_FACTORY(AlgErrorAuditor)
    00008
    00009 AlgErrorAuditor::AlgErrorAuditor(const std::string& name, ISvcLocator* pSvcLocator)
    00010   : Auditor(name, pSvcLocator), m_error(0), m_fatal(0) {
    00011
    00012   declareProperty( "Abort", m_abort = false,
    00013                    "Abort job upon illegal Algorithm return code");
    00014   declareProperty( "Throw", m_throw = false,
    00015                    "Throw GaudiException upon illegal Algorithm return code");
    00016 }
    00017
    00018 AlgErrorAuditor::~AlgErrorAuditor(){
    00019 }
    00020
    00021
    00022 void
    00023 AlgErrorAuditor:: beforeExecute(INamedInterface* ){
    00024   m_error = msgSvc()->messageCount(MSG::ERROR);
    00025   m_fatal = msgSvc()->messageCount(MSG::FATAL);
    00026 }
    00027
    00028 StatusCode
    00029 AlgErrorAuditor:: initialize() {
    00030
    00031   if (m_abort && m_throw) {
    00032     MsgStream log(msgSvc(), name());
    00033     log << MSG::INFO << "Both \"Throw\" and \"Abort\" options have been set."
    00034         << " Abort takes precedence." << endmsg;
    00035   }
    00036
    00037   return StatusCode::SUCCESS;
    00038 }
    00039
    00040
    00041 void
    00042 AlgErrorAuditor:: afterExecute(INamedInterface* alg, const StatusCode& sc) {
    00043
    00044   bool fail(false);
    00045   if (msgSvc()->messageCount(MSG::ERROR) != m_error && ! sc.isRecoverable() ) {
    00046     std::ostringstream os;
    00047     os << "Illegal Return Code: Algorithm " << alg->name()
    00048        << " reported an ERROR, but returned a StatusCode \"" << sc << "\"";
    00049     os << std::endl << "Error policy described in "
    00050          << "https://twiki.cern.ch/twiki/bin/view/Atlas/ReportingErrors";
    00051
    00052     MsgStream log(msgSvc(), name());
    00053     log << MSG::ERROR << os.str() << endmsg;
    00054     incrMap(alg->name(), 0);
    00055     fail = true;
    00056
    00057     if (m_throw && ! m_abort) {
    00058       throw GaudiException(os.str(),"AlgErrorAuditor",0);
    00059     }
    00060   }
    00061
    00062   if (msgSvc()->messageCount(MSG::FATAL) != m_fatal &&
    00063       sc != StatusCode::FAILURE ) {
    00064     std::ostringstream os;
    00065     os << "Illegal Return Code: Algorithm " << alg->name()
    00066        << " reported a FATAL, but returned a StatusCode \"" << sc << "\"";
    00067     os << std::endl << "Error policy described in "
    00068          << "https://twiki.cern.ch/twiki/bin/view/Atlas/ReportingErrors";
    00069
    00070     MsgStream log(msgSvc(), name());
    00071     log << MSG::ERROR << os.str() << endmsg;
    00072     incrMap(alg->name(), 1);
    00073     fail = true;
    00074
    00075     if (m_throw && ! m_abort) {
    00076       throw GaudiException(os.str(),"AlgErrorAuditor",0);
    00077     }
    00078
    00079   }
    00080
    00081   if (fail && m_abort) {
    00082     abort();
    00083   }
    00084
    00085 }
    00086
    00087 StatusCode
    00088 AlgErrorAuditor::finalize() {
    00089
    00090
    00091   std::map<std::string,int>::const_iterator itr;
    00092   if (m_algMap[0].size() != 0) {
    00093     MsgStream log(msgSvc(), name());
    00094     log << MSG::INFO << "Found " << m_algMap[0].size()
    00095         << " instances where an Algorithm::execute() produced an ERROR "
    00096         << "but returned a SUCCESS:" << std::endl;
    00097
    00098     for (itr = m_algMap[0].begin(); itr != m_algMap[0].end(); ++itr) {
    00099       log << itr->first << ": " << itr->second << std::endl;
    00100     }
    00101
    00102     log << endmsg;
    00103   }
    00104
    00105   if (m_algMap[1].size() != 0) {
    00106     MsgStream log(msgSvc(), name());
    00107     log << MSG::INFO << "Found " << m_algMap[1].size()
    00108         << " instances where an Algorithm::execute() produced a FATAL "
    00109         << "but returned a SUCCESS:" << std::endl;
    00110
    00111     for (itr = m_algMap[1].begin(); itr != m_algMap[1].end(); ++itr) {
    00112       log << itr->first << ": " << itr->second << std::endl;
    00113     }
    00114
    00115     log << endmsg;
    00116   }
    00117
    00118
    00119   return StatusCode::SUCCESS;
    00120
    00121 }
    00122
    00123 void
    00124 AlgErrorAuditor::incrMap(const std::string& alg, int level) {
    00125   std::map<std::string, int>::iterator itr;
    00126   if ( (itr=m_algMap[level].find(alg)) != m_algMap[level].end()) {
    00127     itr->second++;
    00128   } else {
    00129     m_algMap[level].insert( std::pair<std::string,int>(alg,1) );
    00130   }
    00131 }
    00132

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines