| The Gaudi Framework v30r0 (c919700c)

- 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/GaudiException.h"
3 #include "GaudiKernel/IMessageSvc.h"
4 #include "GaudiKernel/MsgStream.h"
5
6 DECLARE_COMPONENT( AlgErrorAuditor )
7
8 void AlgErrorAuditor::beforeExecute( INamedInterface* )
9 {
10 m_error = msgSvc()->messageCount( MSG::ERROR );
11 m_fatal = msgSvc()->messageCount( MSG::FATAL );
12 }
13
14 StatusCode AlgErrorAuditor::initialize()
15 {
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 void AlgErrorAuditor::afterExecute( INamedInterface* alg, const StatusCode& sc )
26 {
27
28 bool fail( false );
29 if ( msgSvc()->messageCount( MSG::ERROR ) != m_error && !sc.isRecoverable() ) {
30 std::ostringstream os;
31 os << "Illegal Return Code: Algorithm " << alg->name() << " reported an ERROR, but returned a StatusCode \"" << sc
32 << "\"";
33 os << std::endl
34 << "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 && sc != StatusCode::FAILURE ) {
47 std::ostringstream os;
48 os << "Illegal Return Code: Algorithm " << alg->name() << " reported a FATAL, but returned a StatusCode \"" << sc
49 << "\"";
50 os << std::endl
51 << "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 if ( fail && m_abort ) {
64 abort();
65 }
66 }
67
68 StatusCode AlgErrorAuditor::finalize()
69 {
70
71 if ( m_algMap[0].size() != 0 ) {
72 info() << "Found " << m_algMap[0].size() << " instances where an Algorithm::execute() produced an ERROR "
73 << "but returned a SUCCESS:" << std::endl;
74
75 for ( const auto& i : m_algMap[0] ) {
76 msgStream() << i.first << ": " << i.second << std::endl;
77 }
78
79 msgStream() << endmsg;
80 }
81
82 if ( m_algMap[1].size() != 0 ) {
83 info() << "Found " << m_algMap[1].size() << " instances where an Algorithm::execute() produced a FATAL "
84 << "but returned a SUCCESS:" << std::endl;
85
86 for ( const auto& i : m_algMap[1] ) {
87 msgStream() << i.first << ": " << i.second << std::endl;
88 }
89
90 msgStream() << endmsg;
91 }
92 return StatusCode::SUCCESS;
93 }
94
95 void AlgErrorAuditor::incrMap( const std::string& alg, int level )
96 {
97 auto i = m_algMap[level].find( alg );
98 if ( i != m_algMap[level].end() ) {
99 i->second++;
100 } else {
101 m_algMap[level].emplace( alg, 1 );
102 }
103 }
StatusCode::SUCCESS
Definition: StatusCode.h:29
AlgErrorAuditor::finalize
StatusCode finalize() override
Definition: AlgErrorAuditor.cpp:68
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:112
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:23
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::string
STL class.
MSG::FATAL
Definition: IMessageSvc.h:16
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
AlgErrorAuditor::incrMap
void incrMap(const std::string &algName, int level)
Definition: AlgErrorAuditor.cpp:95
AlgErrorAuditor::afterExecute
void afterExecute(INamedInterface *alg, const StatusCode &) override
Definition: AlgErrorAuditor.cpp:25
AlgErrorAuditor::initialize
StatusCode initialize() override
Definition: AlgErrorAuditor.cpp:14
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::ostringstream
STL class.
GaudiException.h
std::ostringstream::str
T str(T...args)
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:64
AlgErrorAuditor::m_fatal
int m_fatal
Definition: AlgErrorAuditor.h:34
IMessageSvc.h
CommonMessagingBase::msgSvc
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:75
StatusCode::isRecoverable
bool isRecoverable() const
Definition: StatusCode.h:62
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:78
MSG::ERROR
Definition: IMessageSvc.h:16
AlgErrorAuditor.h
gaudirun.level
level
Definition: gaudirun.py:271
StatusCode::FAILURE
Definition: StatusCode.h:29
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.