Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
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 // ====================================================================
9 #include "GaudiKernel/IAlgTool.h"
11 #include "GaudiKernel/IToolSvc.h"
12 #include "GaudiKernel/SmartIF.h"
13 
24 class PartitionSwitchAlg : public extends<Algorithm, IPartitionControl> {
25 
26  using STATUS = StatusCode;
27  using CSTR = const std::string&;
28 
29 private:
30  Gaudi::Property<std::string> m_partName{this, "Partition", "", "option to set the requested partition name"};
31  Gaudi::Property<std::string> m_toolType{this, "Tool", "PartitionSwitchTool",
32  "option to set the tool manipulating the multi-service name"};
33 
36 
37 public:
38  using extends::extends;
39 
41  STATUS initialize() override {
42  SmartIF<IAlgTool> tool( m_actor );
43  STATUS sc = toolSvc()->retrieveTool( m_toolType, m_actor, this );
44  if ( sc.isFailure() ) {
45  error() << "Unable to load PartitionSwitchTool " << m_toolType << endmsg;
46  return sc;
47  }
49  if ( tool ) toolSvc()->releaseTool( tool );
51  IInterface* partititon = nullptr;
52  sc = m_actor->get( m_partName, partititon );
53  if ( !sc.isSuccess() ) { error() << "Cannot access partition \"" << m_partName << "\"" << endmsg; }
54  return sc;
55  }
56 
58  STATUS finalize() override {
59  SmartIF<IAlgTool> tool( m_actor );
60  if ( tool ) toolSvc()->releaseTool( tool );
61  m_actor = nullptr;
62  return STATUS::SUCCESS;
63  }
64 
66  STATUS execute() override {
67  if ( m_actor ) {
68  STATUS sc = m_actor->activate( m_partName );
69  if ( !sc.isSuccess() ) { error() << "Cannot activate partition \"" << m_partName << "\"!" << endmsg; }
70  return sc;
71  }
72  error() << "The partition control tool \"" << name() << "." << m_toolType << "\" cannot be accessed!" << endmsg;
73  return STATUS::FAILURE;
74  }
75 
76 private:
77  StatusCode log_( StatusCode sc, const std::string& msg ) const {
78  error() << msg << " Status=" << sc.getCode() << endmsg;
79  return sc;
80  }
81  template <typename... FArgs, typename... Args>
82  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ), Args&&... args ) {
83  return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : IInterface::Status::NO_INTERFACE;
84  }
85  template <typename... FArgs, typename... Args>
86  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ) const, Args&&... args ) const {
87  return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : IInterface::Status::NO_INTERFACE;
88  }
89 
90 public:
92  STATUS create( CSTR nam, CSTR typ ) override {
93  auto sc = fwd_<CSTR, CSTR>( &IPartitionControl::create, nam, typ );
94  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
95  }
97  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override {
98  auto sc = fwd_<CSTR, CSTR, IInterface*&>( &IPartitionControl::create, nam, typ, pPartition );
99  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
100  }
102  STATUS drop( CSTR nam ) override {
103  auto sc = fwd_<CSTR>( &IPartitionControl::drop, nam );
104  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition: " + nam );
105  }
107  STATUS drop( IInterface* pPartition ) override {
108  auto sc = fwd_<IInterface*>( &IPartitionControl::drop, pPartition );
109  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition by Interface." );
110  }
112  STATUS activate( CSTR nam ) override {
113  auto sc = fwd_<CSTR>( &IPartitionControl::activate, nam );
114  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition: " + nam );
115  }
117  STATUS activate( IInterface* pPartition ) override {
118  auto sc = fwd_<IInterface*>( &IPartitionControl::activate, pPartition );
119  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition by Interface." );
120  }
122  STATUS get( CSTR nam, IInterface*& pPartition ) const override {
123  auto sc = fwd_<CSTR, IInterface*&>( &IPartitionControl::get, nam, pPartition );
124  return sc.isSuccess() ? sc : log_( sc, "Cannot get partition " + nam );
125  }
127  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
128  auto sc = fwd_<std::string&, IInterface*&>( &IPartitionControl::activePartition, nam, pPartition );
129  return sc.isSuccess() ? sc : log_( sc, "Cannot determine active partition." );
130  }
131 };
132 
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&...args) const
Requested interface is not available.
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
STATUS initialize() override
Initialize.
Implementation of property with value of concrete type.
Definition: Property.h:352
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Definition: Algorithm.cpp:673
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
StatusCode log_(StatusCode sc, const std::string &msg) const
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:635
bool isSuccess() const
Definition: StatusCode.h:267
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.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
Gaudi::Property< std::string > m_toolType
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&...args)
Gaudi::Property< std::string > m_partName
bool isFailure() const
Definition: StatusCode.h:130
StatusCode retrieveTool(const std::string &type, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name automatically assigned...
Definition: IToolSvc.h:138
STL class.
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
Definition of the basic interface.
Definition: IInterface.h:244
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.
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
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
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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.
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
code_t getCode() const
Retrieve value ("checks" the StatusCode)
Definition: StatusCode.h:137
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
STATUS execute() override
Execute procedure.