The Gaudi Framework  master (da3d77e1)
PartitionSwitchTool.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 // Framework include files
12 #include <GaudiKernel/AlgTool.h>
14 #include <GaudiKernel/MsgStream.h>
15 #include <GaudiKernel/SmartIF.h>
16 
22 class PartitionSwitchTool : public extends<AlgTool, IPartitionControl> {
23 
24  using CSTR = const std::string&;
25  using STATUS = StatusCode;
26 
27 private:
28  Gaudi::Property<std::string> m_actorName{ this, "Actor", "EventDataService", "option to set the multi-service name" };
31 
32 public:
33  using extends::extends;
34 
36  STATUS initialize() override {
39  if ( !sc.isSuccess() ) {
40  error() << "Cannot initialize base class!" << endmsg;
41  return sc;
42  }
43  m_actor = service<IPartitionControl>( m_actorName );
44  if ( !m_actor ) {
45  error() << "Cannot retrieve partition controller \"" << m_actorName.value() << "\"!" << endmsg;
46  return StatusCode::FAILURE;
47  }
48  return sc;
49  }
51  STATUS finalize() override {
52  m_actor = nullptr;
53  return AlgTool::finalize();
54  }
55 
56  void _check( STATUS sc, CSTR msg ) const { error() << msg << " Status=" << sc.getCode() << endmsg; }
57 #define CHECK( x, y ) \
58  if ( !x.isSuccess() ) _check( x, y ); \
59  return x;
60 
62  STATUS create( CSTR nam, CSTR typ ) override {
63  STATUS sc = m_actor ? m_actor->create( nam, typ ) : IInterface::Status::NO_INTERFACE;
64  CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
65  }
67  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override {
68  STATUS sc = m_actor ? m_actor->create( nam, typ, pPartition ) : IInterface::Status::NO_INTERFACE;
69  CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
70  }
72  STATUS drop( CSTR nam ) override {
74  CHECK( sc, "Cannot drop partition: " + nam );
75  }
77  STATUS drop( IInterface* pPartition ) override {
78  STATUS sc = m_actor ? m_actor->drop( pPartition ) : IInterface::Status::NO_INTERFACE;
79  CHECK( sc, "Cannot drop partition by Interface." );
80  }
82  STATUS activate( CSTR nam ) override {
83  STATUS sc = m_actor ? m_actor->activate( nam ) : IInterface::Status::NO_INTERFACE;
84  CHECK( sc, "Cannot activate partition: " + nam );
85  }
87  STATUS activate( IInterface* pPartition ) override {
88  STATUS sc = m_actor ? m_actor->activate( pPartition ) : IInterface::Status::NO_INTERFACE;
89  CHECK( sc, "Cannot activate partition by Interface." );
90  }
92  STATUS get( CSTR nam, IInterface*& pPartition ) const override {
93  STATUS sc = m_actor ? m_actor->get( nam, pPartition ) : IInterface::Status::NO_INTERFACE;
94  CHECK( sc, "Cannot get partition " + nam );
95  }
97  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
98  STATUS sc = m_actor ? m_actor->activePartition( nam, pPartition ) : IInterface::Status::NO_INTERFACE;
99  CHECK( sc, "Cannot determine active partition." );
100  }
101 };
102 
103 // Declaration of the Tool Factory
PartitionSwitchTool::create
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:67
std::string
STL class.
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
PartitionSwitchTool
Definition: PartitionSwitchTool.cpp:22
PartitionSwitchTool::activate
STATUS activate(IInterface *pPartition) override
Activate a partition object.
Definition: PartitionSwitchTool.cpp:87
PartitionSwitchTool::finalize
STATUS finalize() override
Finalize.
Definition: PartitionSwitchTool.cpp:51
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
AlgTool::initialize
StatusCode initialize() override
Definition: AlgTool.cpp:199
IInterface::Status::NO_INTERFACE
@ NO_INTERFACE
Requested interface is not available.
PartitionSwitchTool::activate
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:82
SmartIF.h
StatusCode
Definition: StatusCode.h:65
PartitionSwitchTool::m_actorName
Gaudi::Property< std::string > m_actorName
Definition: PartitionSwitchTool.cpp:28
PartitionSwitchTool::activePartition
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
Definition: PartitionSwitchTool.cpp:97
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
SmartIF< IPartitionControl >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
PartitionSwitchTool::m_actor
SmartIF< IPartitionControl > m_actor
reference to Partition Controller
Definition: PartitionSwitchTool.cpp:30
PartitionSwitchTool::drop
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:72
PartitionSwitchTool::initialize
STATUS initialize() override
Initialize.
Definition: PartitionSwitchTool.cpp:36
PartitionSwitchTool::drop
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:77
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IInterface
Definition: IInterface.h:239
StatusCode::getCode
code_t getCode() const
Retrieve value.
Definition: StatusCode.h:136
AlgTool.h
PartitionSwitchTool::get
STATUS get(CSTR nam, IInterface *&pPartition) const override
Access a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:92
PartitionSwitchTool::create
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:62
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
IPartitionControl.h
PartitionSwitchTool::_check
void _check(STATUS sc, CSTR msg) const
Definition: PartitionSwitchTool.cpp:56
Gaudi::Property< std::string >
MsgStream.h
CHECK
#define CHECK(x, y)
Definition: PartitionSwitchTool.cpp:57
AlgTool::finalize
StatusCode finalize() override
Definition: AlgTool.cpp:266