All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PartitionSwitchAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // PartitionSwitchAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
8 #include "GaudiKernel/IPartitionControl.h"
9 #include "GaudiKernel/Algorithm.h"
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/IToolSvc.h"
12 #include "GaudiKernel/IAlgTool.h"
13 #include "GaudiKernel/SmartIF.h"
14 
25 class PartitionSwitchAlg : public extends1<Algorithm, IPartitionControl> {
26 
27  using STATUS = StatusCode;
28  using CSTR = const std::string&;
29 
30 private:
31 
33  std::string m_partName;
35  std::string m_toolType;
38 
39 public:
40 
42  PartitionSwitchAlg(const std::string& name, ISvcLocator* pSvcLocator)
43  : base_class(name, pSvcLocator)
44  {
45  declareProperty("Partition", m_partName);
46  declareProperty("Tool", m_toolType="PartitionSwitchTool");
47  }
49  ~PartitionSwitchAlg() override = default;
50 
52  STATUS initialize() override {
53  MsgStream log(msgSvc(), name());
54  SmartIF<IAlgTool> tool(m_actor);
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 = nullptr;
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  STATUS finalize() override {
75  SmartIF<IAlgTool> tool(m_actor);
76  if ( tool ) toolSvc()->releaseTool(tool);
77  m_actor = nullptr;
78  return STATUS::SUCCESS;
79  }
80 
82  STATUS execute() override {
83  if ( m_actor ) {
84  STATUS sc = m_actor->activate(m_partName);
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 private:
98  StatusCode log_(StatusCode sc, const std::string& msg) const {
99  MsgStream log(msgSvc(), name());
100  log << MSG::ERROR << msg << " Status=" << sc.getCode() << endmsg;
101  return sc;
102  }
103  template < typename...FArgs, typename...Args>
104  StatusCode fwd_( StatusCode (IPartitionControl::*fun)(FArgs...),Args&&... args) {
105  return m_actor ? (m_actor->*fun)(std::forward<Args>(args)...) : NO_INTERFACE;
106  }
107  template < typename...FArgs, typename...Args>
108  StatusCode fwd_( StatusCode (IPartitionControl::*fun)(FArgs...) const,Args&&... args) const {
109  return m_actor ? (m_actor->*fun)(std::forward<Args>(args)...) : NO_INTERFACE;
110  }
111 public:
113  STATUS create(CSTR nam, CSTR typ) override {
114  auto sc = fwd_<CSTR,CSTR>(&IPartitionControl::create,nam,typ);
115  return sc.isSuccess() ? sc : log_(sc, "Cannot create partition: "+nam+" of type "+typ);
116  }
118  STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) override {
119  auto sc = fwd_<CSTR,CSTR,IInterface*&>(&IPartitionControl::create,nam,typ,pPartition);
120  return sc.isSuccess() ? sc : log_(sc, "Cannot create partition: "+nam+" of type "+typ);
121  }
123  STATUS drop(CSTR nam) override {
124  auto sc = fwd_<CSTR>(&IPartitionControl::drop,nam);
125  return sc.isSuccess() ? sc : log_(sc, "Cannot drop partition: "+nam);
126  }
128  STATUS drop(IInterface* pPartition) override {
129  auto sc = fwd_<IInterface*>(&IPartitionControl::drop,pPartition);
130  return sc.isSuccess() ? sc : log_(sc, "Cannot drop partition by Interface.");
131  }
133  STATUS activate(CSTR nam) override {
134  auto sc = fwd_<CSTR>(&IPartitionControl::activate,nam);
135  return sc.isSuccess() ? sc : log_(sc, "Cannot activate partition: "+nam);
136  }
138  STATUS activate(IInterface* pPartition) override {
139  auto sc = fwd_<IInterface*>(&IPartitionControl::activate, pPartition);
140  return sc.isSuccess() ? sc : log_(sc, "Cannot activate partition by Interface.");
141  }
143  STATUS get(CSTR nam, IInterface*& pPartition) const override {
144  auto sc = fwd_<CSTR,IInterface*&>(&IPartitionControl::get, nam, pPartition);
145  return sc.isSuccess() ? sc : log_(sc, "Cannot get partition "+nam);
146  }
148  STATUS activePartition(std::string& nam, IInterface*& pPartition) const override {
149  auto sc = fwd_<std::string&,IInterface*&>(&IPartitionControl::activePartition,nam,pPartition);
150  return sc.isSuccess() ? sc : log_(sc, "Cannot determine active partition.");
151  }
152 };
153 
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&...args) const
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
STATUS initialize() override
Initialize.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
StatusCode log_(StatusCode sc, const std::string &msg) const
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
virtual StatusCode create(const std::string &name, const std::string &type)=0
Create a partition object. The name identifies the partition uniquely.
STATUS finalize() override
Finalize.
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&...args)
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
~PartitionSwitchAlg() override=default
Standard Destructor.
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
std::string m_partName
Job option to set the requested partition name.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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.
PartitionSwitchAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm constructor.
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
Small algorithm which switches the partition of a configurable multi-service.
STATUS activate(IInterface *pPartition) override
Activate a partition object.
list args
Definition: gaudirun.py:290
Create / access partitions.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
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 StatusCode activate(const std::string &name)=0
Activate a partition object. The name identifies the partition uniquely.
STATUS activate(CSTR nam) override
Activate 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_toolType
Job option to set the tool manipulating the multi-service name.
const std::string & CSTR
STATUS execute() override
Execute procedure.