| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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