The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PartitionSwitchTool.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 = nullptr;
44  IPartitionControl* tmpPtr = nullptr;
45  sc = service( m_actorName, tmpPtr );
46  m_actor = tmpPtr;
47  if ( !sc.isSuccess() ) {
48  error() << "Cannot retrieve partition controller \"" << m_actorName.value() << "\"!" << endmsg;
49  return sc;
50  }
51  return sc;
52  }
54  STATUS finalize() override {
55  m_actor = nullptr;
56  return AlgTool::finalize();
57  }
58 
59  void _check( STATUS sc, CSTR msg ) const { error() << msg << " Status=" << sc.getCode() << endmsg; }
60 #define CHECK( x, y ) \
61  if ( !x.isSuccess() ) _check( x, y ); \
62  return x;
63 
65  STATUS create( CSTR nam, CSTR typ ) override {
66  STATUS sc = m_actor ? m_actor->create( nam, typ ) : IInterface::Status::NO_INTERFACE;
67  CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
68  }
70  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override {
71  STATUS sc = m_actor ? m_actor->create( nam, typ, pPartition ) : IInterface::Status::NO_INTERFACE;
72  CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
73  }
75  STATUS drop( CSTR nam ) override {
77  CHECK( sc, "Cannot drop partition: " + nam );
78  }
80  STATUS drop( IInterface* pPartition ) override {
81  STATUS sc = m_actor ? m_actor->drop( pPartition ) : IInterface::Status::NO_INTERFACE;
82  CHECK( sc, "Cannot drop partition by Interface." );
83  }
85  STATUS activate( CSTR nam ) override {
86  STATUS sc = m_actor ? m_actor->activate( nam ) : IInterface::Status::NO_INTERFACE;
87  CHECK( sc, "Cannot activate partition: " + nam );
88  }
90  STATUS activate( IInterface* pPartition ) override {
91  STATUS sc = m_actor ? m_actor->activate( pPartition ) : IInterface::Status::NO_INTERFACE;
92  CHECK( sc, "Cannot activate partition by Interface." );
93  }
95  STATUS get( CSTR nam, IInterface*& pPartition ) const override {
96  STATUS sc = m_actor ? m_actor->get( nam, pPartition ) : IInterface::Status::NO_INTERFACE;
97  CHECK( sc, "Cannot get partition " + nam );
98  }
100  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
101  STATUS sc = m_actor ? m_actor->activePartition( nam, pPartition ) : IInterface::Status::NO_INTERFACE;
102  CHECK( sc, "Cannot determine active partition." );
103  }
104 };
105 
106 // 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:70
std::string
STL class.
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
PartitionSwitchTool
Definition: PartitionSwitchTool.cpp:22
IPartitionControl
Definition: IPartitionControl.h:76
PartitionSwitchTool::activate
STATUS activate(IInterface *pPartition) override
Activate a partition object.
Definition: PartitionSwitchTool.cpp:90
PartitionSwitchTool::finalize
STATUS finalize() override
Finalize.
Definition: PartitionSwitchTool.cpp:54
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:85
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:100
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:239
SmartIF< IPartitionControl >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
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:75
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:80
AlgTool::service
StatusCode service(std::string_view name, T *&svc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: AlgTool.h:137
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:237
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:95
PartitionSwitchTool::create
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchTool.cpp:65
IPartitionControl.h
PartitionSwitchTool::_check
void _check(STATUS sc, CSTR msg) const
Definition: PartitionSwitchTool.cpp:59
Gaudi::Property< std::string >
MsgStream.h
CHECK
#define CHECK(x, y)
Definition: PartitionSwitchTool.cpp:60
AlgTool::finalize
StatusCode finalize() override
Definition: AlgTool.cpp:266