| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

ExceptionSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <algorithm>
7 #include <cassert>
8 // ============================================================================
9 // GaudiKernel
10 // ============================================================================
11 #include "GaudiKernel/ISvcLocator.h"
12 // ============================================================================
13 // Local
14 // ============================================================================
15 #include "ExceptionSvc.h"
16 // ============================================================================
17
18 #include <boost/regex.hpp>
19
20 using namespace std;
21
22 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23
24 DECLARE_COMPONENT( ExceptionSvc )
25
26 inline void toupper( std::string& s ) { std::transform( s.begin(), s.end(), s.begin(), (int ( * )( int ))toupper ); }
27
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
29
30 StatusCode ExceptionSvc::initialize()
31 {
32 StatusCode status = Service::initialize();
33 if ( status.isFailure() ) {
34 return status;
35 }
36
37 string key = m_mode_exc_s.value();
38
39 auto loc = key.find( " " );
40 std::string mode = key.substr( 0, loc );
41
42 toupper( mode );
43
44 if ( mode == "NONE" ) {
45 m_mode_exc = NONE;
46 } else if ( mode == "ALL" ) {
47 m_mode_exc = ALL;
48 } else {
49 error() << "Unknown mode for Exception handling: \"" << mode << "\". Default must be one of \"ALL\" or \"NONE\""
50 << endmsg;
51 m_state = Gaudi::StateMachine::OFFLINE;
52 return StatusCode::FAILURE;
53 }
54
55 if ( loc == string::npos ) {
56 key.clear();
57 } else {
58 key = key.substr( loc + 1 );
59 }
60
61 std::string VAL, TAG;
62
63 static const boost::regex exp{"[[:space:]]*([^[:space:]]+)[[:space:]]*=[[:space:]]*([^[:space:]]+)"};
64 static const auto tok_end = boost::sregex_iterator();
65 for ( auto tok_iter = boost::sregex_iterator( begin( key ), end( key ), exp ); tok_iter != tok_end; ++tok_iter ) {
66 TAG = ( *tok_iter )[1];
67 VAL = ( *tok_iter )[2];
68 toupper( VAL );
69
70 if ( VAL == "SUCCESS" ) {
71 m_retCodesExc[TAG] = SUCCESS;
72 } else if ( VAL == "FAILURE" ) {
73 m_retCodesExc[TAG] = FAILURE;
74 } else if ( VAL == "REVOVERABLE" ) {
75 m_retCodesExc[TAG] = RECOVERABLE;
76 } else if ( VAL == "RETHROW" ) {
77 m_retCodesExc[TAG] = RETHROW;
78 } else if ( VAL == "DEFAULT" ) {
79 m_retCodesExc[TAG] = DEFAULT;
80 } else {
81 error() << "In JobOpts: unknown return code \"" << VAL << "\" for Algorithm " << TAG << std::endl
82 << " Must be one of: DEFAULT, SUCCESS, FAILURE, RECOVERABLE, RETHROW" << endmsg;
83 m_state = Gaudi::StateMachine::OFFLINE;
84 return StatusCode::FAILURE;
85 }
86
87 if ( msgLevel( MSG::DEBUG ) )
88 debug() << "Will catch exceptions thrown by: " << TAG << " -> action: " << VAL << endmsg;
89 }
90
91 // now process errors
92 key = m_mode_err_s.value();
93
94 loc = key.find( " " );
95 mode = key.substr( 0, loc );
96
97 toupper( mode );
98
99 if ( mode == "NONE" ) {
100 m_mode_err = NONE;
101 } else if ( mode == "ALL" ) {
102 m_mode_err = ALL;
103 } else {
104 error() << "Unknown mode for Error handling: \"" << mode << "\". Default must be one of \"ALL\" or \"NONE\""
105 << endmsg;
106 m_state = Gaudi::StateMachine::OFFLINE;
107 return StatusCode::FAILURE;
108 }
109
110 if ( loc == string::npos ) {
111 key.clear();
112 } else {
113 key = key.substr( loc + 1 );
114 }
115
116 for ( auto tok_iter = boost::sregex_iterator( begin( key ), end( key ), exp ); tok_iter != tok_end; ++tok_iter ) {
117 TAG = ( *tok_iter )[1];
118 VAL = ( *tok_iter )[2];
119 toupper( VAL );
120
121 if ( VAL == "SUCCESS" ) {
122 m_retCodesErr[TAG] = SUCCESS;
123 } else if ( VAL == "FAILURE" ) {
124 m_retCodesErr[TAG] = FAILURE;
125 } else if ( VAL == "RECOVERABLE" ) {
126 m_retCodesErr[TAG] = RECOVERABLE;
127 } else {
128 error() << "In JobOpts: unknown return code \"" << VAL << "\" for Algorithm " << TAG << std::endl
129 << " Must be one of: SUCCESS, FAILURE, RECOVERABLE" << endmsg;
130 m_state = Gaudi::StateMachine::OFFLINE;
131 return StatusCode::FAILURE;
132 }
133
134 if ( msgLevel( MSG::DEBUG ) )
135 debug() << "Will process Errors returned by: " << TAG << " -> action: " << VAL << endmsg;
136 }
137 return status;
138 }
139
140 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
141
142 StatusCode ExceptionSvc::handleErr( const INamedInterface& alg, const StatusCode& st ) const
143 {
144 if ( msgLevel( MSG::DEBUG ) ) debug() << "Handling Error from " << alg.name() << endmsg;
145
146 // is this Alg special?
147 auto i = m_retCodesErr.find( alg.name() );
148 if ( i != m_retCodesErr.end() ) {
149 switch ( i->second ) {
150 case SUCCESS:
151 return StatusCode::SUCCESS;
152 case FAILURE:
153 return StatusCode::FAILURE;
154 case RECOVERABLE:
155 return StatusCode::RECOVERABLE;
156 // should never get here
157 case RETHROW:
158 break;
159 case DEFAULT:
160 break;
161 }
162
163 } else {
164
165 if ( m_mode_err == ALL ) return StatusCode::FAILURE; // turn it into FAILURE
166 assert( m_mode_err == NONE );
167 // don't touch the return code
168 return st;
169 }
170 return StatusCode::FAILURE;
171 }
172 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
173
174 StatusCode ExceptionSvc::process( const INamedInterface& alg ) const
175 {
176
177 // is this Alg special?
178 auto i = m_retCodesExc.find( alg.name() );
179 if ( i != m_retCodesExc.end() ) {
180
181 switch ( i->second ) {
182 case DEFAULT:
183 return StatusCode::FAILURE; // there is no default
184 case SUCCESS:
185 return StatusCode::SUCCESS;
186 case FAILURE:
187 return StatusCode::FAILURE;
188 case RECOVERABLE:
189 return StatusCode::RECOVERABLE;
190 case RETHROW:
191 throw;
192 }
193 }
194
195 if ( m_mode_exc == ALL ) {
196 throw;
197 }
198 assert( m_mode_exc == NONE );
199 return StatusCode::FAILURE;
200 }
201 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
202
203 StatusCode ExceptionSvc::handle( const INamedInterface& alg ) const
204 {
205 if ( msgLevel( MSG::DEBUG ) ) debug() << "Handling unknown exception for " << alg.name() << endmsg;
206 return process( alg );
207 }
208 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
209
210 StatusCode ExceptionSvc::handle( const INamedInterface& alg, const std::exception& exc ) const
211 {
212 if ( msgLevel( MSG::DEBUG ) ) debug() << "Handling std:except: \"" << exc.what() << "\" for " << alg.name() << endmsg;
213 return process( alg );
214 }
215 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
216
217 StatusCode ExceptionSvc::handle( const INamedInterface& alg, const GaudiException& exc ) const
218 {
219 if ( msgLevel( MSG::DEBUG ) ) debug() << "Handling GaudiException: \"" << exc << "\" for " << alg.name() << endmsg;
220 return process( alg );
221 }
222
223 // ============================================================================
224 // The END
225 // ============================================================================
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::SUCCESS
Definition: StatusCode.h:31
GaudiKernel.Constants.ALL
int ALL
Definition: Constants.py:11
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
StatusCode::FAILURE
Definition: StatusCode.h:31
std::exp
T exp(T...args)
GaudiPython.Bindings.SUCCESS
SUCCESS
Definition: Bindings.py:56
MSG::DEBUG
Definition: IMessageSvc.h:16
std::endl
T endl(T...args)
std
STL namespace.
std::end
T end(T...args)
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::string
STL class.
GaudiPython.Bindings.FAILURE
FAILURE
Definition: Bindings.py:57
std::toupper
T toupper(T...args)
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
ExceptionSvc
Simple implementation of IExceptionSvc abstract interface.
Definition: ExceptionSvc.h:19
ExceptionSvc::initialize
StatusCode initialize() override
initialize the service
Definition: ExceptionSvc.cpp:30
std::string::clear
T clear(T...args)
std::exception
STL class.
ExceptionSvc::handle
StatusCode handle(const INamedInterface &o, const GaudiException &e) const override
Handle caught GaudiExceptions.
Definition: ExceptionSvc.cpp:217
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
std::string::find
T find(T...args)
StatusCode::RECOVERABLE
Definition: StatusCode.h:31
std::begin
T begin(T...args)
ExceptionSvc::handleErr
StatusCode handleErr(const INamedInterface &o, const StatusCode &s) const override
Handle errors.
Definition: ExceptionSvc.cpp:142
gaudirun.s
string s
Definition: gaudirun.py:253
std::string::substr
T substr(T...args)
std::transform
T transform(T...args)
ExceptionSvc.h
ExceptionSvc::process
virtual StatusCode process(const INamedInterface &o) const
Definition: ExceptionSvc.cpp:174
Gaudi::StateMachine::OFFLINE
Definition: StateMachine.h:15
ISvcLocator.h
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.