The Gaudi Framework
master (1a7a3838)
Toggle main menu visibility
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
13
namespace
GaudiTesting
{
14
17
class
FailingSvc
:
public
Service
{
18
public
:
20
using
Service::Service
;
21
22
StatusCode
initialize
()
override
{
23
StatusCode
sc =
Service::initialize
();
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
{
31
StatusCode
sc =
Service::start
();
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
:
50
Gaudi::Property<std::string>
m_transition
{
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"
) {
59
return
StatusCode::FAILURE
;
60
}
else
{
61
warning
() <<
"Unknown type of failure '"
<<
m_mode
<<
"', use 'failure' or 'exception'"
<<
endmsg
;
62
}
63
}
64
return
StatusCode::SUCCESS
;
65
}
66
};
67
68
DECLARE_COMPONENT
( FailingSvc )
69
}
// namespace GaudiTesting
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
Service.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition
CommonMessaging.h:112
Gaudi::Property
Implementation of property with value of concrete type.
Definition
Property.h:35
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
GaudiTesting::FailingSvc
Special service that issue a failure in one of the transitions (for testing).
Definition
TestingSvcs.cpp:17
GaudiTesting::FailingSvc::m_transition
Gaudi::Property< std::string > m_transition
Definition
TestingSvcs.cpp:50
GaudiTesting::FailingSvc::initialize
StatusCode initialize() override
Definition
TestingSvcs.cpp:22
GaudiTesting::FailingSvc::finalize
StatusCode finalize() override
Definition
TestingSvcs.cpp:43
GaudiTesting::FailingSvc::stop
StatusCode stop() override
Definition
TestingSvcs.cpp:38
GaudiTesting::FailingSvc::handle
StatusCode handle(const std::string &transition)
Definition
TestingSvcs.cpp:54
GaudiTesting::FailingSvc::start
StatusCode start() override
Definition
TestingSvcs.cpp:30
GaudiTesting::FailingSvc::Service
Service(std::string name, ISvcLocator *svcloc)
Standard Constructor.
Definition
Service.cpp:340
GaudiTesting::FailingSvc::m_mode
Gaudi::Property< std::string > m_mode
Definition
TestingSvcs.cpp:52
Service::finalize
StatusCode finalize() override
Definition
Service.cpp:223
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition
Service.cpp:333
Service::stop
StatusCode stop() override
Definition
Service.cpp:181
Service::start
StatusCode start() override
Definition
Service.cpp:187
Service::initialize
StatusCode initialize() override
Definition
Service.cpp:118
Service::Service
Service(std::string name, ISvcLocator *svcloc)
Standard Constructor.
Definition
Service.cpp:340
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
GaudiTesting
Definition
__init__.py:1
GaudiTestSuite
src
testing
TestingSvcs.cpp
Generated on
for The Gaudi Framework by
1.17.0