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/ToolFactory.h"
6 #include "GaudiKernel/IPartitionControl.h"
7 
13 class PartitionSwitchTool: public extends1<AlgTool, IPartitionControl> {
14 
15  typedef const std::string& CSTR;
16  typedef StatusCode STATUS;
17 
18 private:
19 
21  std::string m_actorName;
24 
25 public:
26 
28  PartitionSwitchTool(CSTR typ, CSTR nam, const IInterface* parent)
29  : base_class(typ, nam , parent)
30  {
31  declareProperty("Actor", m_actorName = "EventDataService");
32  }
35  m_actor = 0;
36  }
37 
39  virtual STATUS initialize() {
41  STATUS sc = AlgTool::initialize();
42  MsgStream log(msgSvc(), name());
43  if ( !sc.isSuccess() ) {
44  log << MSG::ERROR << "Cannot initialize base class!" << endmsg;
45  return sc;
46  }
47  m_actor = 0;
48  IPartitionControl* tmpPtr = 0;
49  sc = service(m_actorName, tmpPtr);
50  m_actor = tmpPtr;
51  if ( !sc.isSuccess() ) {
52  log << MSG::ERROR << "Cannot retrieve partition controller \""
53  << m_actorName << "\"!" << endmsg;
54  return sc;
55  }
56  return sc;
57  }
59  virtual STATUS finalize() {
60  m_actor = 0;
61  return AlgTool::finalize();
62  }
63 
64  void _check(STATUS sc, CSTR msg) const {
65  MsgStream log(msgSvc(), name());
66  log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
67  }
68 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
69 
71  virtual STATUS create(CSTR nam, CSTR typ) {
72  STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
73  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
74  }
76  virtual STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) {
77  STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
78  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
79  }
81  virtual STATUS drop(CSTR nam) {
82  STATUS sc = m_actor ? m_actor->drop(nam) : NO_INTERFACE;
83  CHECK(sc, "Cannot drop partition: "+nam);
84  }
86  virtual STATUS drop(IInterface* pPartition) {
87  STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
88  CHECK(sc, "Cannot drop partition by Interface.");
89  }
91  virtual STATUS activate(CSTR nam) {
92  STATUS sc = m_actor ? m_actor->activate(nam) : NO_INTERFACE;
93  CHECK(sc, "Cannot activate partition: "+nam);
94  }
96  virtual STATUS activate(IInterface* pPartition) {
97  STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
98  CHECK(sc, "Cannot activate partition by Interface.");
99  }
101  virtual STATUS get(CSTR nam, IInterface*& pPartition) const {
102  STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
103  CHECK(sc, "Cannot get partition "+nam);
104  }
106  virtual STATUS activePartition(std::string& nam, IInterface*& pPartition) const {
107  STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
108  CHECK(sc, "Cannot determine active partition.");
109  }
110 };
111 
112 // Declaration of the Tool Factory
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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:92
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: AlgTool.cpp:438
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:75
virtual STATUS create(CSTR nam, CSTR typ)
Create a partition object. The name identifies the partition uniquely.
virtual STATUS drop(CSTR nam)
Drop 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.
virtual STATUS activate(IInterface *pPartition)
Activate a partition object.
virtual ~PartitionSwitchTool()
Standard destructor.
std::string m_actorName
Job option to set the multi-service name.
virtual STATUS initialize()
Initialize.
#define CHECK(x, y)
IMessageSvc * msgSvc() const
Retrieve pointer to message service.
Definition: AlgTool.cpp:79
#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:30
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: AlgTool.h:235
Definition of the basic interface.
Definition: IInterface.h:160
Requested interface is not available.
Definition: IInterface.h:221
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
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:180
PartitionSwitchTool(CSTR typ, CSTR nam, const IInterface *parent)
Standard constructor.
virtual STATUS activate(CSTR nam)
Activate a partition object. The name identifies the partition uniquely.
virtual STATUS activePartition(std::string &nam, IInterface *&pPartition) const
Access the active partition object.
Create / access partitions.
virtual StatusCode drop(const std::string &name)=0
Drop a partition object. The name identifies the partition uniquely.
virtual const IInterface * parent() const
Retrieve parent of the sub-algtool.
Definition: AlgTool.cpp:65
virtual StatusCode activate(const std::string &name)=0
Activate a partition object. The name identifies the partition uniquely.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: AlgTool.cpp:311
virtual STATUS finalize()
Finalize.
virtual STATUS drop(IInterface *pPartition)
Drop a partition object. The name identifies the partition uniquely.
virtual const std::string & name() const
Retrieve full identifying name of the concrete tool object.
Definition: AlgTool.cpp:51
virtual STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition)
Create a partition object. The name identifies the partition uniquely.
const std::string & CSTR