PartitionSwitchTool.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/AlgTool.h"
3 #include "GaudiKernel/SmartIF.h"
6 
12 class PartitionSwitchTool: public extends<AlgTool,
13  IPartitionControl> {
14 
15  using CSTR = const std::string&;
16  using STATUS = StatusCode;
17 
18 private:
19 
24 
25 public:
26 
29  : base_class( typ, nam , parent)
30  {
31  declareProperty("Actor", m_actorName = "EventDataService");
32  }
34  ~PartitionSwitchTool() override = default;
35 
37  STATUS initialize() override {
40  if ( !sc.isSuccess() ) {
41  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  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  error() << msg << " Status=" << sc.getCode() << endmsg;
63  }
64 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
65 
67  STATUS create(CSTR nam, CSTR typ) override {
68  STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
69  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
70  }
72  STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) override {
73  STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
74  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
75  }
77  STATUS drop(CSTR nam) override {
78  STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
79  CHECK(sc, "Cannot drop partition: "+nam);
80  }
82  STATUS drop(IInterface* pPartition) override {
83  STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
84  CHECK(sc, "Cannot drop partition by Interface.");
85  }
87  STATUS activate(CSTR nam) override {
88  STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
89  CHECK(sc, "Cannot activate partition: "+nam);
90  }
92  STATUS activate(IInterface* pPartition) override {
93  STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
94  CHECK(sc, "Cannot activate partition by Interface.");
95  }
97  STATUS get(CSTR nam, IInterface*& pPartition) const override {
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  STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
104  CHECK(sc, "Cannot determine active partition.");
105  }
106 };
107 
108 // 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.
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:290
STATUS finalize() override
Finalize.
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.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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.
STL class.
StatusCode finalize() override
Definition: AlgTool.cpp:360
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
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: AlgTool.h:249
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.
StatusCode service(const std::string &name, T *&svc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: AlgTool.h:195
~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:244
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
const IInterface * parent() const override
Retrieve parent of the sub-algtool.
Definition: AlgTool.cpp:79