ExceptionSvc Class Reference

Simple implementation of IExceptionSvc abstract interface. More...

#include <src/ExceptionSvc.h>

Inheritance diagram for ExceptionSvc:
Collaboration diagram for ExceptionSvc:

Public Member Functions

StatusCode handle (const INamedInterface &o, const GaudiException &e) const override
 Handle caught GaudiExceptions. More...
 
StatusCode handle (const INamedInterface &o, const std::exception &e) const override
 Handle caught std::exceptions. More...
 
StatusCode handle (const INamedInterface &o) const override
 Handle caught (unknown)exceptions. More...
 
StatusCode handleErr (const INamedInterface &o, const StatusCode &s) const override
 Handle errors. More...
 
StatusCode initialize () override
 initialize the service More...
 
 ExceptionSvc (const std::string &name, ISvcLocator *svc)
 standard constructor More...
 
 ~ExceptionSvc () override=default
 Destructor. More...
 
- Public Member Functions inherited from extends< Service, IExceptionSvc >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Types

enum  Policy { ALL, NONE }
 
enum  ReturnState {
  SUCCESS, FAILURE, RECOVERABLE, RETHROW,
  DEFAULT
}
 

Private Member Functions

 ExceptionSvc ()=delete
 no default constructor More...
 
 ExceptionSvc (const ExceptionSvc &)=delete
 
ExceptionSvcoperator= (const ExceptionSvc &)=delete
 
virtual StatusCode process (const INamedInterface &o) const
 

Private Attributes

Policy m_mode_exc = ALL
 
Policy m_mode_err = NONE
 
StringProperty m_mode_exc_s
 
StringProperty m_mode_err_s
 
std::map< std::string, ReturnStatem_retCodesExc
 
std::map< std::string, ReturnStatem_retCodesErr
 
MsgStream m_log
 

Additional Inherited Members

- Public Types inherited from extends< Service, IExceptionSvc >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 

Detailed Description

Simple implementation of IExceptionSvc abstract interface.

Author
(1) ATLAS collaboration
(2) modified by Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-03-08

Definition at line 19 of file ExceptionSvc.h.

Member Enumeration Documentation

enum ExceptionSvc::Policy
private
Enumerator
ALL 
NONE 

Definition at line 61 of file ExceptionSvc.h.

Enumerator
SUCCESS 
FAILURE 
RECOVERABLE 
RETHROW 
DEFAULT 

Definition at line 62 of file ExceptionSvc.h.

Constructor & Destructor Documentation

ExceptionSvc::ExceptionSvc ( const std::string name,
ISvcLocator svc 
)

standard constructor

Parameters
nameservice instance name
pSvcpointer to Service Locator

Definition at line 36 of file ExceptionSvc.cpp.

37  : base_class( nam, svc )
38  , m_log(msgSvc(), name() )
39 {
40  // for exceptions
41  declareProperty( "Catch" , m_mode_exc_s="ALL" ) ;
42 
43  // for return codes
44  declareProperty( "Errors" , m_mode_err_s="NONE" ) ;
45 }
extends base_class
Typedef to this class.
Definition: extends.h:14
StringProperty m_mode_err_s
Definition: ExceptionSvc.h:65
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
StringProperty m_mode_exc_s
Definition: ExceptionSvc.h:65
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
MsgStream m_log
Definition: ExceptionSvc.h:68
ExceptionSvc::~ExceptionSvc ( )
overridedefault

Destructor.

ExceptionSvc::ExceptionSvc ( )
privatedelete

no default constructor

ExceptionSvc::ExceptionSvc ( const ExceptionSvc )
privatedelete

Member Function Documentation

StatusCode ExceptionSvc::handle ( const INamedInterface o,
const GaudiException e 
) const
override

Handle caught GaudiExceptions.

Handle caught exceptions

Definition at line 230 of file ExceptionSvc.cpp.

232 {
233  m_log << MSG::DEBUG << "Handling GaudiException: \"" << exc << "\" for "
234  << alg.name() << endmsg;
235  return process(alg);
236 }
virtual StatusCode process(const INamedInterface &o) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: ExceptionSvc.h:68
StatusCode ExceptionSvc::handle ( const INamedInterface o,
const std::exception e 
) const
override

Handle caught std::exceptions.

Handle caught exceptions

Definition at line 220 of file ExceptionSvc.cpp.

222 {
223  m_log << MSG::DEBUG << "Handling std:except: \"" << exc.what() << "\" for "
224  << alg.name() << endmsg;
225  return process(alg) ;
226 }
virtual StatusCode process(const INamedInterface &o) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: ExceptionSvc.h:68
StatusCode ExceptionSvc::handle ( const INamedInterface o) const
override

Handle caught (unknown)exceptions.

Handle caught exceptions

Definition at line 211 of file ExceptionSvc.cpp.

212 {
213  m_log << MSG::DEBUG << "Handling unknown exception for " << alg.name()
214  << endmsg;
215  return process(alg);
216 }
virtual StatusCode process(const INamedInterface &o) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: ExceptionSvc.h:68
StatusCode ExceptionSvc::handleErr ( const INamedInterface o,
const StatusCode s 
) const
override

Handle errors.

Handle errors

Definition at line 159 of file ExceptionSvc.cpp.

161 {
162  m_log << MSG::DEBUG << "Handling Error from " << alg.name() << endmsg;
163 
164  // is this Alg special?
165  auto i = m_retCodesErr.find(alg.name());
166  if ( i != m_retCodesErr.end()) {
167  switch ( i->second ) {
168  case SUCCESS: return StatusCode::SUCCESS;
169  case FAILURE: return StatusCode::FAILURE;
171  // should never get here
172  case RETHROW: break;
173  case DEFAULT: break;
174  }
175 
176  } else {
177 
178  if (m_mode_err == ALL) return StatusCode::FAILURE; // turn it into FAILURE
179  assert (m_mode_err == NONE );
180  // don't touch the return code
181  return st;
182  }
183  return StatusCode::FAILURE;
184 }
std::map< std::string, ReturnState > m_retCodesErr
Definition: ExceptionSvc.h:66
T end(T...args)
T find(T...args)
Policy m_mode_err
Definition: ExceptionSvc.h:64
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: ExceptionSvc.h:68
StatusCode ExceptionSvc::initialize ( )
override

initialize the service

Definition at line 50 of file ExceptionSvc.cpp.

50  {
53 
54  if ( status.isFailure() ) { return status ; } // RETURN
55 
56  string key = m_mode_exc_s.value();
57 
58  auto loc = key.find(" ");
59  std::string mode = key.substr(0,loc);
60 
61  toupper(mode);
62 
63  if (mode == "NONE") { m_mode_exc = NONE;
64  } else if (mode == "ALL") { m_mode_exc = ALL;
65  } else {
66  m_log << MSG::ERROR << "Unknown mode for Exception handling: \"" << mode
67  << "\". Default must be one of \"ALL\" or \"NONE\"" << endmsg;
69  return StatusCode::FAILURE;
70  }
71 
72  if (loc == string::npos) {
73  key.clear();
74  } else {
75  key = key.substr(loc+1);
76  }
77 
78  std::string VAL, TAG;
79 
80  static const boost::regex exp{"[[:space:]]*([^[:space:]]+)[[:space:]]*=[[:space:]]*([^[:space:]]+)"};
81  static const auto tok_end = boost::sregex_iterator();
82  for (auto tok_iter = boost::sregex_iterator(begin(key), end(key), exp);
83  tok_iter != tok_end; ++tok_iter)
84  {
85  TAG = (*tok_iter)[1];
86  VAL = (*tok_iter)[2];
87  toupper(VAL);
88 
89  if (VAL == "SUCCESS") { m_retCodesExc[TAG] = SUCCESS;
90  } else if ( VAL == "FAILURE" ) { m_retCodesExc[TAG] = FAILURE;
91  } else if ( VAL == "REVOVERABLE" ) { m_retCodesExc[TAG] = RECOVERABLE;
92  } else if ( VAL == "RETHROW" ) { m_retCodesExc[TAG] = RETHROW;
93  } else if ( VAL == "DEFAULT" ) { m_retCodesExc[TAG] = DEFAULT;
94  } else {
95  m_log << MSG::ERROR << "In JobOpts: unknown return code \"" << VAL
96  << "\" for Algorithm " << TAG << std::endl
97  << " Must be one of: DEFAULT, SUCCESS, FAILURE, RECOVERABLE, RETHROW"
98  << endmsg;
100  return StatusCode::FAILURE;
101  }
102 
103  m_log << MSG::DEBUG << "Will catch exceptions thrown by: " << TAG
104  << " -> action: " << VAL << endmsg;
105 
106  }
107 
108  // now process errors
109  key = m_mode_err_s.value();
110 
111  loc = key.find(" ");
112  mode = key.substr(0,loc);
113 
114  toupper(mode);
115 
116  if (mode == "NONE") { m_mode_err = NONE;
117  } else if (mode == "ALL") { m_mode_err = ALL;
118  } else {
119  m_log << MSG::ERROR << "Unknown mode for Error handling: \"" << mode
120  << "\". Default must be one of \"ALL\" or \"NONE\"" << endmsg;
122  return StatusCode::FAILURE;
123  }
124 
125  if (loc == string::npos) {
126  key.clear();
127  } else {
128  key = key.substr(loc+1);
129  }
130 
131  for (auto tok_iter = boost::sregex_iterator(begin(key), end(key), exp);
132  tok_iter != tok_end; ++tok_iter)
133  {
134  TAG = (*tok_iter)[1];
135  VAL = (*tok_iter)[2];
136  toupper(VAL);
137 
138  if (VAL == "SUCCESS") { m_retCodesErr[TAG] = SUCCESS;
139  } else if ( VAL == "FAILURE" ) { m_retCodesErr[TAG] = FAILURE;
140  } else if ( VAL == "RECOVERABLE" ) { m_retCodesErr[TAG] = RECOVERABLE;
141  } else {
142  m_log << MSG::ERROR << "In JobOpts: unknown return code \"" << VAL
143  << "\" for Algorithm " << TAG << std::endl
144  << " Must be one of: SUCCESS, FAILURE, RECOVERABLE"
145  << endmsg;
147  return StatusCode::FAILURE;
148  }
149 
150  m_log << MSG::DEBUG << "Will process Errors returned by: " << TAG
151  << " -> action: " << VAL << endmsg;
152  }
153  return status;
154 }
StatusCode initialize() override
Definition: Service.cpp:68
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:309
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:311
T exp(T...args)
T endl(T...args)
std::map< std::string, ReturnState > m_retCodesErr
Definition: ExceptionSvc.h:66
Policy m_mode_exc
Definition: ExceptionSvc.h:64
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
STL class.
StringProperty m_mode_err_s
Definition: ExceptionSvc.h:65
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
StringProperty m_mode_exc_s
Definition: ExceptionSvc.h:65
T clear(T...args)
const TYPE & value() const
explicit conversion
Definition: Property.h:341
std::map< std::string, ReturnState > m_retCodesExc
Definition: ExceptionSvc.h:66
T find(T...args)
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:106
T substr(T...args)
Policy m_mode_err
Definition: ExceptionSvc.h:64
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: ExceptionSvc.h:68
ExceptionSvc& ExceptionSvc::operator= ( const ExceptionSvc )
privatedelete
StatusCode ExceptionSvc::process ( const INamedInterface o) const
privatevirtual

Definition at line 188 of file ExceptionSvc.cpp.

189 {
190 
191  // is this Alg special?
192  auto i = m_retCodesExc.find(alg.name());
193  if ( i != m_retCodesExc.end()) {
194 
195  switch ( i->second ) {
196  case DEFAULT: return StatusCode::FAILURE; // there is no default
197  case SUCCESS: return StatusCode::SUCCESS;
198  case FAILURE: return StatusCode::FAILURE;
200  case RETHROW: throw;
201  }
202  }
203 
204  if (m_mode_exc == ALL) { throw; }
205  assert (m_mode_exc == NONE);
206  return StatusCode::FAILURE;
207 }
T end(T...args)
Policy m_mode_exc
Definition: ExceptionSvc.h:64
std::map< std::string, ReturnState > m_retCodesExc
Definition: ExceptionSvc.h:66
T find(T...args)
list i
Definition: ana.py:128

Member Data Documentation

MsgStream ExceptionSvc::m_log
mutableprivate

Definition at line 68 of file ExceptionSvc.h.

Policy ExceptionSvc::m_mode_err = NONE
private

Definition at line 64 of file ExceptionSvc.h.

StringProperty ExceptionSvc::m_mode_err_s
private

Definition at line 65 of file ExceptionSvc.h.

Policy ExceptionSvc::m_mode_exc = ALL
private

Definition at line 64 of file ExceptionSvc.h.

StringProperty ExceptionSvc::m_mode_exc_s
private

Definition at line 65 of file ExceptionSvc.h.

std::map<std::string,ReturnState> ExceptionSvc::m_retCodesErr
private

Definition at line 66 of file ExceptionSvc.h.

std::map<std::string,ReturnState> ExceptionSvc::m_retCodesExc
private

Definition at line 66 of file ExceptionSvc.h.


The documentation for this class was generated from the following files: