PartitionSwitchTool.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/AlgTool.h"
3 #include "GaudiKernel/SmartIF.h"
4 #include "GaudiKernel/MsgStream.h"
5 #include "GaudiKernel/IPartitionControl.h"
6 
12 class PartitionSwitchTool: public extends1<AlgTool, IPartitionControl> {
13 
14  using CSTR = const std::string&;
15  using STATUS = StatusCode;
16 
17 private:
18 
20  std::string m_actorName;
23 
24 public:
25 
27  PartitionSwitchTool(const std::string& typ, const std::string& nam, const IInterface* parent)
28  : base_class( typ, nam , parent)
29  {
30  declareProperty("Actor", m_actorName = "EventDataService");
31  }
33  ~PartitionSwitchTool() override = default;
34 
36  STATUS initialize() override {
39  MsgStream log(msgSvc(), name());
40  if ( !sc.isSuccess() ) {
41  log << MSG::ERROR << "Cannot initialize base class!" << endmsg;
42  return sc;
43  }
44  m_actor = nullptr;
45  IPartitionControl* tmpPtr = nullptr;
46  sc = service(m_actorName, tmpPtr);
47  m_actor = tmpPtr;
48  if ( !sc.isSuccess() ) {
49  log << MSG::ERROR << "Cannot retrieve partition controller \""
50  << m_actorName << "\"!" << endmsg;
51  return sc;
52  }
53  return sc;
54  }
56  STATUS finalize() override {
57  m_actor = nullptr;
58  return AlgTool::finalize();
59  }
60 
61  void _check(STATUS sc, CSTR msg) const {
62  MsgStream log(msgSvc(), name());
63  log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
64  }
65 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
66 
68  STATUS create(CSTR nam, CSTR typ) override {
69  STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
70  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
71  }
73  STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) override {
74  STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
75  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
76  }
78  STATUS drop(CSTR nam) override {
79  STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
80  CHECK(sc, "Cannot drop partition: "+nam);
81  }
83  STATUS drop(IInterface* pPartition) override {
84  STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
85  CHECK(sc, "Cannot drop partition by Interface.");
86  }
88  STATUS activate(CSTR nam) override {
89  STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
90  CHECK(sc, "Cannot activate partition: "+nam);
91  }
93  STATUS activate(IInterface* pPartition) override {
94  STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
95  CHECK(sc, "Cannot activate partition by Interface.");
96  }
98  STATUS get(CSTR nam, IInterface*& pPartition) const override {
99  STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
100  CHECK(sc, "Cannot get partition "+nam);
101  }
103  STATUS activePartition(std::string& nam, IInterface*& pPartition) const override {
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
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
const std::string & CSTR
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:93
StatusCode initialize() override
Definition: AlgTool.cpp:281
STATUS finalize() override
Finalize.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void _check(STATUS sc, CSTR msg) const
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
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.
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
std::string m_actorName
Job option to set the multi-service name.
StatusCode finalize() override
Definition: AlgTool.cpp:351
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
#define CHECK(x, y)
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
SmartIF< IPartitionControl > m_actor
reference to Partition Controller
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
PartitionSwitchTool(const std::string &typ, const std::string &nam, const IInterface *parent)
Standard constructor.
~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.
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.