AlgErrorAuditor.cpp
Go to the documentation of this file.
1 #include "AlgErrorAuditor.h"
2 #include "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/IMessageSvc.h"
4 #include "GaudiKernel/GaudiException.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 
17 void
21 }
22 
25 
26  if (m_abort && m_throw) {
27  MsgStream log(msgSvc(), name());
28  log << MSG::INFO << "Both \"Throw\" and \"Abort\" options have been set."
29  << " Abort takes precedence." << endmsg;
30  }
31 
32  return StatusCode::SUCCESS;
33 }
34 
35 
36 void
38 
39  bool fail(false);
40  if (msgSvc()->messageCount(MSG::ERROR) != m_error && ! sc.isRecoverable() ) {
41  std::ostringstream os;
42  os << "Illegal Return Code: Algorithm " << alg->name()
43  << " reported an ERROR, but returned a StatusCode \"" << sc << "\"";
44  os << std::endl << "Error policy described in "
45  << "https://twiki.cern.ch/twiki/bin/view/AtlasComputing/ReportingErrors";
46 
47  MsgStream log(msgSvc(), name());
48  log << MSG::ERROR << os.str() << endmsg;
49  incrMap(alg->name(), 0);
50  fail = true;
51 
52  if (m_throw && ! m_abort) {
53  throw GaudiException(os.str(),"AlgErrorAuditor",0);
54  }
55  }
56 
58  sc != StatusCode::FAILURE ) {
59  std::ostringstream os;
60  os << "Illegal Return Code: Algorithm " << alg->name()
61  << " reported a FATAL, but returned a StatusCode \"" << sc << "\"";
62  os << std::endl << "Error policy described in "
63  << "https://twiki.cern.ch/twiki/bin/view/AtlasComputing/ReportingErrors";
64 
65  MsgStream log(msgSvc(), name());
66  log << MSG::ERROR << os.str() << endmsg;
67  incrMap(alg->name(), 1);
68  fail = true;
69 
70  if (m_throw && ! m_abort) {
71  throw GaudiException(os.str(),"AlgErrorAuditor",0);
72  }
73 
74  }
75 
76  if (fail && m_abort) {
77  abort();
78  }
79 
80 }
81 
84 
85 
86  if (m_algMap[0].size() != 0) {
87  MsgStream log(msgSvc(), name());
88  log << MSG::INFO << "Found " << m_algMap[0].size()
89  << " instances where an Algorithm::execute() produced an ERROR "
90  << "but returned a SUCCESS:" << std::endl;
91 
92  for (const auto& i : m_algMap[0] ) {
93  log << i.first << ": " << i.second << std::endl;
94  }
95 
96  log << endmsg;
97  }
98 
99  if (m_algMap[1].size() != 0) {
100  MsgStream log(msgSvc(), name());
101  log << MSG::INFO << "Found " << m_algMap[1].size()
102  << " instances where an Algorithm::execute() produced a FATAL "
103  << "but returned a SUCCESS:" << std::endl;
104 
105  for (const auto& i : m_algMap[1]) {
106  log << i.first << ": " << i.second << std::endl;
107  }
108 
109  log << endmsg;
110  }
111  return StatusCode::SUCCESS;
112 }
113 
114 void
115 AlgErrorAuditor::incrMap(const std::string& alg, int level) {
116  auto i=m_algMap[level].find(alg);
117  if ( i != m_algMap[level].end()) {
118  i->second++;
119  } else {
120  m_algMap[level].emplace( alg,1 );
121  }
122 }
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:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:220
std::map< std::string, int > m_algMap[2]
Monitors the cpu time usage of each algorithm.
STL namespace.
virtual void beforeExecute(INamedInterface *alg)
virtual StatusCode finalize()
BooleanProperty m_abort
virtual const std::string & name() const =0
Retrieve the name of the instance.
void incrMap(const std::string &algName, int level)
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual int messageCount(MSG::Level level) const =0
Get the number of messages issued at a particular level.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
bool isRecoverable() const
Definition: StatusCode.h:87
IInterface compliant class extending IInterface with the name() method.
virtual void afterExecute(INamedInterface *alg, const StatusCode &)
BooleanProperty m_throw
virtual StatusCode initialize()
const std::string & name() const override
Definition: Auditor.cpp:212
list i
Definition: ana.py:128
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34