The Gaudi Framework  v33r1 (b1225454)
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 {
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 {
82  CHECK( sc, "Cannot drop partition by Interface." );
83  }
85  STATUS activate( CSTR nam ) override {
87  CHECK( sc, "Cannot activate partition: " + nam );
88  }
90  STATUS activate( IInterface* pPartition ) override {
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 {
102  CHECK( sc, "Cannot determine active partition." );
103  }
104 };
105 
106 // Declaration of the Tool Factory
code_t getCode() const
Retrieve value ("checks" the StatusCode)
Definition: StatusCode.h:152
Requested interface is not available.
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
Implementation of property with value of concrete type.
Definition: Property.h:370
StatusCode initialize() override
Definition: AlgTool.cpp:211
STATUS finalize() override
Finalize.
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
virtual StatusCode create(const std::string &name, const std::string &type)=0
Create a partition object. The name identifies the partition uniquely.
Gaudi::Property< std::string > m_actorName
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
STL class.
#define DECLARE_COMPONENT(type)
StatusCode finalize() override
Definition: AlgTool.cpp:278
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
#define CHECK(x, y)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
SmartIF< IPartitionControl > m_actor
reference to Partition Controller
STATUS get(CSTR nam, IInterface *&pPartition) const override
Access a partition object. The name identifies the partition uniquely.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
bool isSuccess() const
Definition: StatusCode.h:365
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Create / access partitions.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
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:138
STATUS initialize() override
Initialize.
virtual StatusCode drop(const std::string &name)=0
Drop a partition object. The name identifies the partition uniquely.
virtual StatusCode activate(const std::string &name)=0
Activate a partition object. The name identifies the partition uniquely.
STATUS activate(IInterface *pPartition) override
Activate a partition object.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
void _check(STATUS sc, CSTR msg) const
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.