The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
TestingSvcs.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include <GaudiKernel/Service.h>
12
13namespace GaudiTesting {
14
17 class FailingSvc : public Service {
18 public:
20 using Service::Service;
21
24 if ( sc.isFailure() ) {
25 error() << "failed to initialize base class" << endmsg;
26 return sc;
27 }
28 return handle( "initialize" );
29 }
30 StatusCode start() override {
32 if ( sc.isFailure() ) {
33 error() << "failed to start base class" << endmsg;
34 return sc;
35 }
36 return handle( "start" );
37 }
38 StatusCode stop() override {
39 StatusCode sc = handle( "stop" );
40 if ( sc.isFailure() ) return sc;
41 return Service::stop();
42 }
43 StatusCode finalize() override {
44 StatusCode sc = handle( "finalize" );
45 if ( sc.isFailure() ) return sc;
46 return Service::finalize();
47 }
48
49 private:
51 this, "Transition", "", "In which transition to fail ['initialize', 'start', 'stop', 'finalize']" };
52 Gaudi::Property<std::string> m_mode{ this, "Mode", "failure", "Type of failure ['failure', 'exception']" };
53
54 inline StatusCode handle( const std::string& transition ) {
55 if ( m_transition == transition ) {
56 if ( m_mode == "exception" ) {
57 throw GaudiException( "forced failure in " + transition, name(), StatusCode::FAILURE );
58 } else if ( m_mode == "failure" ) {
60 } else {
61 warning() << "Unknown type of failure '" << m_mode << "', use 'failure' or 'exception'" << endmsg;
62 }
63 }
65 }
66 };
67
68 DECLARE_COMPONENT( FailingSvc )
69} // namespace GaudiTesting
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
Define general base for Gaudi exception.
Special service that issue a failure in one of the transitions (for testing).
Gaudi::Property< std::string > m_transition
StatusCode initialize() override
StatusCode finalize() override
StatusCode stop() override
StatusCode handle(const std::string &transition)
StatusCode start() override
Service(std::string name, ISvcLocator *svcloc)
Standard Constructor.
Definition Service.cpp:340
Gaudi::Property< std::string > m_mode
StatusCode finalize() override
Definition Service.cpp:223
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
StatusCode stop() override
Definition Service.cpp:181
StatusCode start() override
Definition Service.cpp:187
StatusCode initialize() override
Definition Service.cpp:118
Service(std::string name, ISvcLocator *svcloc)
Standard Constructor.
Definition Service.cpp:340
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100