All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PartitionSwitchAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // PartitionSwitchAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/IToolSvc.h"
12 #include "GaudiKernel/IAlgTool.h"
13 #include "GaudiKernel/SmartIF.h"
14 
24 class PartitionSwitchAlg : public extends1<Algorithm, IPartitionControl> {
25 
26  typedef StatusCode STATUS;
27  typedef const std::string& CSTR;
28 
29 private:
30 
32  std::string m_partName;
34  std::string m_toolType;
37 
38 public:
39 
42  : base_class(name, pSvcLocator), m_actor(0)
43  {
44  declareProperty("Partition", m_partName);
45  declareProperty("Tool", m_toolType="PartitionSwitchTool");
46  }
48  virtual ~PartitionSwitchAlg() {
49  }
50 
52  virtual STATUS initialize() {
53  MsgStream log(msgSvc(), name());
55  STATUS sc = toolSvc()->retrieveTool(m_toolType,m_actor,this);
56  if ( sc.isFailure() ) {
57  log << MSG::ERROR << "Unable to load PartitionSwitchTool "
58  << m_toolType << endmsg;
59  return sc;
60  }
62  if ( tool ) toolSvc()->releaseTool(tool);
64  IInterface* partititon = 0;
65  sc = m_actor->get(m_partName, partititon);
66  if ( !sc.isSuccess() ) {
67  log << MSG::ERROR << "Cannot access partition \""
68  << m_partName << "\"" << endmsg;
69  }
70  return sc;
71  }
72 
74  virtual STATUS finalize() {
76  if ( tool ) toolSvc()->releaseTool(tool);
77  m_actor = 0;
78  return STATUS::SUCCESS;
79  }
80 
82  virtual STATUS execute() {
83  if ( m_actor ) {
85  if ( !sc.isSuccess() ) {
86  MsgStream log(msgSvc(), name());
87  log << MSG::ERROR << "Cannot activate partition \""
88  << m_partName << "\"!" << endmsg;
89  }
90  return sc;
91  }
92  MsgStream log(msgSvc(), name());
93  log << MSG::ERROR << "The partition control tool \"" << name()
94  << "." << m_toolType << "\" cannot be accessed!" << endmsg;
95  return STATUS::FAILURE;
96  }
97 
98  void _check(STATUS sc, CSTR msg) const {
99  MsgStream log(msgSvc(), name());
100  log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
101  }
102 #define CHECK(x,y) if ( !x.isSuccess() ) _check(x, y); return x;
103 
105  virtual STATUS create(CSTR nam, CSTR typ) {
106  STATUS sc = m_actor ? m_actor->create(nam,typ) : NO_INTERFACE;
107  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
108  }
110  virtual STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) {
111  STATUS sc = m_actor ? m_actor->create(nam,typ,pPartition) : NO_INTERFACE;
112  CHECK(sc, "Cannot create partition: "+nam+" of type "+typ);
113  }
115  virtual STATUS drop(CSTR nam) {
117  CHECK(sc, "Cannot drop partition: "+nam);
118  }
120  virtual STATUS drop(IInterface* pPartition) {
121  STATUS sc = m_actor ? m_actor->drop(pPartition) : NO_INTERFACE;
122  CHECK(sc, "Cannot drop partition by Interface.");
123  }
125  virtual STATUS activate(CSTR nam) {
127  CHECK(sc, "Cannot activate partition: "+nam);
128  }
130  virtual STATUS activate(IInterface* pPartition) {
131  STATUS sc = m_actor ? m_actor->activate(pPartition) : NO_INTERFACE;
132  CHECK(sc, "Cannot activate partition by Interface.");
133  }
135  virtual STATUS get(CSTR nam, IInterface*& pPartition) const {
136  STATUS sc = m_actor ? m_actor->get(nam, pPartition) : NO_INTERFACE;
137  CHECK(sc, "Cannot get partition "+nam);
138  }
140  virtual STATUS activePartition(std::string& nam, IInterface*& pPartition) const {
141  STATUS sc = m_actor ? m_actor->activePartition(nam, pPartition) : NO_INTERFACE;
142  CHECK(sc, "Cannot determine active partition.");
143  }
144 };
145 
virtual STATUS execute()
Execute procedure.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
virtual STATUS activePartition(std::string &nam, IInterface *&pPartition) const
Access the active partition object.
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:79
Requested interface is not available.
Definition: IInterface.h:221
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
virtual STATUS finalize()
Finalize.
virtual STATUS initialize()
Initialize.
virtual StatusCode create(const std::string &name, const std::string &type)=0
Create a partition object. The name identifies the partition uniquely.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:397
virtual STATUS activate(CSTR nam)
Activate a partition object. The name identifies the partition uniquely.
virtual STATUS drop(CSTR nam)
Drop a partition object. The name identifies the partition uniquely.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
const std::string & CSTR
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
PartitionSwitchAlg(CSTR name, ISvcLocator *pSvcLocator)
Standard algorithm constructor.
std::string m_partName
Job option to set the requested partition name.
#define CHECK(x, y)
virtual ~PartitionSwitchAlg()
Standard Destructor.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
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.
virtual const std::string & name() const
The identifying name of the algorithm object.
Definition: Algorithm.cpp:837
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:896
Small algorith, which switches the partition of a configurable multi-service.
virtual STATUS activate(IInterface *pPartition)
Activate a partition object.
virtual STATUS create(CSTR nam, CSTR typ)
Create a partition object. The name identifies the partition uniquely.
Create / access partitions.
void _check(STATUS sc, CSTR msg) const
IPartitionControl * m_actor
reference to Partition Controller
virtual StatusCode drop(const std::string &name)=0
Drop a partition object. The name identifies the partition uniquely.
virtual STATUS drop(IInterface *pPartition)
Drop a partition object. The name identifies the partition uniquely.
virtual STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition)
Create 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.
std::string m_toolType
Job option to set the tool manipulating the multi-service name.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244