| The Gaudi Framework v28r2p1 (f1a77ff4)

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