| The Gaudi Framework v32r1 (f65d50dc)

PartitionSwitchTool.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/AlgTool.h"
3 #include "GaudiKernel/IPartitionControl.h"
4 #include "GaudiKernel/MsgStream.h"
5 #include "GaudiKernel/SmartIF.h"
6
12 class PartitionSwitchTool : public extends<AlgTool, IPartitionControl> {
13
14 using CSTR = const std::string&;
15 using STATUS = StatusCode;
16
17 private:
18 Gaudi::Property<std::string> m_actorName{this, "Actor", "EventDataService", "option to set the multi-service name"};
20 SmartIF<IPartitionControl> m_actor;
21
22 public:
23 using extends::extends;
24
26 STATUS initialize() override {
28 STATUS sc = AlgTool::initialize();
29 if ( !sc.isSuccess() ) {
30 error() << "Cannot initialize base class!" << endmsg;
31 return sc;
32 }
33 m_actor = nullptr;
34 IPartitionControl* tmpPtr = nullptr;
35 sc = service( m_actorName, tmpPtr );
36 m_actor = tmpPtr;
37 if ( !sc.isSuccess() ) {
38 error() << "Cannot retrieve partition controller \"" << m_actorName.value() << "\"!" << endmsg;
39 return sc;
40 }
41 return sc;
42 }
44 STATUS finalize() override {
45 m_actor = nullptr;
46 return AlgTool::finalize();
47 }
48
49 void _check( STATUS sc, CSTR msg ) const { error() << msg << " Status=" << sc.getCode() << endmsg; }
50 #define CHECK( x, y ) \
51 if ( !x.isSuccess() ) _check( x, y ); \
52 return x;
53
55 STATUS create( CSTR nam, CSTR typ ) override {
56 STATUS sc = m_actor ? m_actor->create( nam, typ ) : IInterface::Status::NO_INTERFACE;
57 CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
58 }
60 STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override {
61 STATUS sc = m_actor ? m_actor->create( nam, typ, pPartition ) : IInterface::Status::NO_INTERFACE;
62 CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
63 }
65 STATUS drop( CSTR nam ) override {
66 STATUS sc = m_actor ? m_actor->drop( nam ) : IInterface::Status::NO_INTERFACE;
67 CHECK( sc, "Cannot drop partition: " + nam );
68 }
70 STATUS drop( IInterface* pPartition ) override {
71 STATUS sc = m_actor ? m_actor->drop( pPartition ) : IInterface::Status::NO_INTERFACE;
72 CHECK( sc, "Cannot drop partition by Interface." );
73 }
75 STATUS activate( CSTR nam ) override {
76 STATUS sc = m_actor ? m_actor->activate( nam ) : IInterface::Status::NO_INTERFACE;
77 CHECK( sc, "Cannot activate partition: " + nam );
78 }
80 STATUS activate( IInterface* pPartition ) override {
81 STATUS sc = m_actor ? m_actor->activate( pPartition ) : IInterface::Status::NO_INTERFACE;
82 CHECK( sc, "Cannot activate partition by Interface." );
83 }
85 STATUS get( CSTR nam, IInterface*& pPartition ) const override {
86 STATUS sc = m_actor ? m_actor->get( nam, pPartition ) : IInterface::Status::NO_INTERFACE;
87 CHECK( sc, "Cannot get partition " + nam );
88 }
90 STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
91 STATUS sc = m_actor ? m_actor->activePartition( nam, pPartition ) : IInterface::Status::NO_INTERFACE;
92 CHECK( sc, "Cannot determine active partition." );
93 }
94 };
95
96 // Declaration of the Tool Factory
97 DECLARE_COMPONENT( PartitionSwitchTool )
StatusCode::getCode
code_t getCode() const
Retrieve value ("checks" the StatusCode)
Definition: StatusCode.h:137
IInterface::Status::NO_INTERFACE
Requested interface is not available.
SmartIF< IPartitionControl >
PartitionSwitchTool::create
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:55
IPartitionControl::activePartition
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
MsgStream.h
AlgTool::initialize
StatusCode initialize() override
Definition: AlgTool.cpp:201
PartitionSwitchTool::finalize
STATUS finalize() override
Finalize.
Definition: PartitionSwitchTool.cpp:44
AlgTool.h
PartitionSwitchTool::activate
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:75
IPartitionControl::create
virtual StatusCode create(const std::string &name, const std::string &type)=0
Create a partition object. The name identifies the partition uniquely.
PartitionSwitchTool::m_actorName
Gaudi::Property< std::string > m_actorName
Definition: PartitionSwitchTool.cpp:18
PartitionSwitchTool::activePartition
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
Definition: PartitionSwitchTool.cpp:90
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
AlgTool::finalize
StatusCode finalize() override
Definition: AlgTool.cpp:268
PartitionSwitchTool::drop
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:65
CHECK
#define CHECK(x, y)
Definition: PartitionSwitchTool.cpp:50
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
PartitionSwitchTool
Definition: PartitionSwitchTool.cpp:12
IPartitionControl.h
PartitionSwitchTool::drop
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:70
PartitionSwitchTool::m_actor
SmartIF< IPartitionControl > m_actor
reference to Partition Controller
Definition: PartitionSwitchTool.cpp:20
PartitionSwitchTool::get
STATUS get(CSTR nam, IInterface *&pPartition) const override
Access a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:85
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
SmartIF.h
IPartitionControl::get
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
AlgTool::service
StatusCode service(const std::string &name, T *&svc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: AlgTool.h:128
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:113
IPartitionControl
Create / access partitions.
Definition: IPartitionControl.h:66
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
PartitionSwitchTool::initialize
STATUS initialize() override
Initialize.
Definition: PartitionSwitchTool.cpp:26
IPartitionControl::drop
virtual StatusCode drop(const std::string &name)=0
Drop a partition object. The name identifies the partition uniquely.
IPartitionControl::activate
virtual StatusCode activate(const std::string &name)=0
Activate a partition object. The name identifies the partition uniquely.
PartitionSwitchTool::activate
STATUS activate(IInterface *pPartition) override
Activate a partition object.
Definition: PartitionSwitchTool.cpp:80
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
PartitionSwitchTool::_check
void _check(STATUS sc, CSTR msg) const
Definition: PartitionSwitchTool.cpp:49
PartitionSwitchTool::create
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:60