The Gaudi Framework  v29r0 (ff2e7097)
PartitionSwitchTool.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/AlgTool.h"
5 #include "GaudiKernel/SmartIF.h"
6 
12 class PartitionSwitchTool : public extends<AlgTool, IPartitionControl>
13 {
14 
15  using CSTR = const std::string&;
16  using STATUS = StatusCode;
17 
18 private:
19  Gaudi::Property<std::string> m_actorName{this, "Actor", "EventDataService", "option to set the multi-service name"};
22 
23 public:
24  using extends::extends;
26  ~PartitionSwitchTool() override = default;
27 
29  STATUS initialize() override
30  {
33  if ( !sc.isSuccess() ) {
34  error() << "Cannot initialize base class!" << endmsg;
35  return sc;
36  }
37  m_actor = nullptr;
38  IPartitionControl* tmpPtr = nullptr;
39  sc = service( m_actorName, tmpPtr );
40  m_actor = tmpPtr;
41  if ( !sc.isSuccess() ) {
42  error() << "Cannot retrieve partition controller \"" << m_actorName.value() << "\"!" << endmsg;
43  return sc;
44  }
45  return sc;
46  }
48  STATUS finalize() override
49  {
50  m_actor = nullptr;
51  return AlgTool::finalize();
52  }
53 
54  void _check( STATUS sc, CSTR msg ) const { error() << msg << " Status=" << sc.getCode() << endmsg; }
55 #define CHECK( x, y ) \
56  if ( !x.isSuccess() ) _check( x, y ); \
57  return x;
58 
60  STATUS create( CSTR nam, CSTR typ ) override
61  {
62  STATUS sc = m_actor ? m_actor->create( nam, typ ) : NO_INTERFACE;
63  CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
64  }
66  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override
67  {
68  STATUS sc = m_actor ? m_actor->create( nam, typ, pPartition ) : NO_INTERFACE;
69  CHECK( sc, "Cannot create partition: " + nam + " of type " + typ );
70  }
72  STATUS drop( CSTR nam ) override
73  {
74  STATUS sc = m_actor ? m_actor->drop( nam ) : NO_INTERFACE;
75  CHECK( sc, "Cannot drop partition: " + nam );
76  }
78  STATUS drop( IInterface* pPartition ) override
79  {
80  STATUS sc = m_actor ? m_actor->drop( pPartition ) : NO_INTERFACE;
81  CHECK( sc, "Cannot drop partition by Interface." );
82  }
84  STATUS activate( CSTR nam ) override
85  {
86  STATUS sc = m_actor ? m_actor->activate( nam ) : NO_INTERFACE;
87  CHECK( sc, "Cannot activate partition: " + nam );
88  }
90  STATUS activate( IInterface* pPartition ) override
91  {
92  STATUS sc = m_actor ? m_actor->activate( pPartition ) : NO_INTERFACE;
93  CHECK( sc, "Cannot activate partition by Interface." );
94  }
96  STATUS get( CSTR nam, IInterface*& pPartition ) const override
97  {
98  STATUS sc = m_actor ? m_actor->get( nam, pPartition ) : NO_INTERFACE;
99  CHECK( sc, "Cannot get partition " + nam );
100  }
102  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override
103  {
104  STATUS sc = m_actor ? m_actor->activePartition( nam, pPartition ) : NO_INTERFACE;
105  CHECK( sc, "Cannot determine active partition." );
106  }
107 };
108 
109 // Declaration of the Tool Factory
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
Implementation of property with value of concrete type.
Definition: Property.h:319
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:94
StatusCode initialize() override
Definition: AlgTool.cpp:241
STATUS finalize() override
Finalize.
void _check(STATUS sc, CSTR msg) const
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
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.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
Gaudi::Property< std::string > m_actorName
STL class.
StatusCode finalize() override
Definition: AlgTool.cpp:311
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
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
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
Definition of the basic interface.
Definition: IInterface.h:277
StatusCode service(const std::string &name, T *&svc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: AlgTool.h:132
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
~PartitionSwitchTool() override=default
Standard destructor.
Create / access partitions.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
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:209
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
#define CHECK(x, y)