All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlgErrorAuditor.cpp
Go to the documentation of this file.
1 #include "AlgErrorAuditor.h"
5 
7 
8 AlgErrorAuditor::AlgErrorAuditor(const std::string& name, ISvcLocator* pSvcLocator)
9  : Auditor(name, pSvcLocator), m_error(0), m_fatal(0) {
10 
11  declareProperty( "Abort", m_abort = false,
12  "Abort job upon illegal Algorithm return code");
13  declareProperty( "Throw", m_throw = false,
14  "Throw GaudiException upon illegal Algorithm return code");
15 }
16 
18 }
19 
20 
21 void
23  m_error = msgSvc()->messageCount(MSG::ERROR);
24  m_fatal = msgSvc()->messageCount(MSG::FATAL);
25 }
26 
29 
30  if (m_abort && m_throw) {
31  MsgStream log(msgSvc(), name());
32  log << MSG::INFO << "Both \"Throw\" and \"Abort\" options have been set."
33  << " Abort takes precedence." << endmsg;
34  }
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 void
42 
43  bool fail(false);
44  if (msgSvc()->messageCount(MSG::ERROR) != m_error && ! sc.isRecoverable() ) {
45  std::ostringstream os;
46  os << "Illegal Return Code: Algorithm " << alg->name()
47  << " reported an ERROR, but returned a StatusCode \"" << sc << "\"";
48  os << std::endl << "Error policy described in "
49  << "https://twiki.cern.ch/twiki/bin/view/AtlasComputing/ReportingErrors";
50 
51  MsgStream log(msgSvc(), name());
52  log << MSG::ERROR << os.str() << endmsg;
53  incrMap(alg->name(), 0);
54  fail = true;
55 
56  if (m_throw && ! m_abort) {
57  throw GaudiException(os.str(),"AlgErrorAuditor",0);
58  }
59  }
60 
61  if (msgSvc()->messageCount(MSG::FATAL) != m_fatal &&
62  sc != StatusCode::FAILURE ) {
63  std::ostringstream os;
64  os << "Illegal Return Code: Algorithm " << alg->name()
65  << " reported a FATAL, but returned a StatusCode \"" << sc << "\"";
66  os << std::endl << "Error policy described in "
67  << "https://twiki.cern.ch/twiki/bin/view/AtlasComputing/ReportingErrors";
68 
69  MsgStream log(msgSvc(), name());
70  log << MSG::ERROR << os.str() << endmsg;
71  incrMap(alg->name(), 1);
72  fail = true;
73 
74  if (m_throw && ! m_abort) {
75  throw GaudiException(os.str(),"AlgErrorAuditor",0);
76  }
77 
78  }
79 
80  if (fail && m_abort) {
81  abort();
82  }
83 
84 }
85 
88 
89 
90  std::map<std::string,int>::const_iterator itr;
91  if (m_algMap[0].size() != 0) {
92  MsgStream log(msgSvc(), name());
93  log << MSG::INFO << "Found " << m_algMap[0].size()
94  << " instances where an Algorithm::execute() produced an ERROR "
95  << "but returned a SUCCESS:" << std::endl;
96 
97  for (itr = m_algMap[0].begin(); itr != m_algMap[0].end(); ++itr) {
98  log << itr->first << ": " << itr->second << std::endl;
99  }
100 
101  log << endmsg;
102  }
103 
104  if (m_algMap[1].size() != 0) {
105  MsgStream log(msgSvc(), name());
106  log << MSG::INFO << "Found " << m_algMap[1].size()
107  << " instances where an Algorithm::execute() produced a FATAL "
108  << "but returned a SUCCESS:" << std::endl;
109 
110  for (itr = m_algMap[1].begin(); itr != m_algMap[1].end(); ++itr) {
111  log << itr->first << ": " << itr->second << std::endl;
112  }
113 
114  log << endmsg;
115  }
116 
117 
118  return StatusCode::SUCCESS;
119 
120 }
121 
122 void
123 AlgErrorAuditor::incrMap(const std::string& alg, int level) {
124  std::map<std::string, int>::iterator itr;
125  if ( (itr=m_algMap[level].find(alg)) != m_algMap[level].end()) {
126  itr->second++;
127  } else {
128  m_algMap[level].insert( std::pair<std::string,int>(alg,1) );
129  }
130 }
131 
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
std::map< std::string, int > m_algMap[2]
Monitors the cpu time usage of each algorithm.
virtual ~AlgErrorAuditor()
virtual void beforeExecute(INamedInterface *alg)
virtual StatusCode finalize()
BooleanProperty m_abort
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual const std::string & name() const =0
Retrieve the name of the instance.
void incrMap(const std::string &algName, int level)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
bool isRecoverable() const
Definition: StatusCode.h:86
tuple end
Definition: IOTest.py:101
IInterface compliant class extending IInterface with the name() method.
virtual void afterExecute(INamedInterface *alg, const StatusCode &)
BooleanProperty m_throw
virtual StatusCode initialize()
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34