| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# AlgErrorAuditor.cpp

Go to the documentation of this file.

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