The Gaudi Framework  v30r3 (a5ef0a68)
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 
27  using STATUS = StatusCode;
28  using CSTR = const std::string&;
29 
30 private:
31  Gaudi::Property<std::string> m_partName{this, "Partition", "", "option to set the requested partition name"};
32  Gaudi::Property<std::string> m_toolType{this, "Tool", "PartitionSwitchTool",
33  "option to set the tool manipulating the multi-service name"};
34 
37 
38 public:
39  using extends::extends;
40 
42  STATUS initialize() override
43  {
44  SmartIF<IAlgTool> tool( m_actor );
45  STATUS sc = toolSvc()->retrieveTool( m_toolType, m_actor, this );
46  if ( sc.isFailure() ) {
47  error() << "Unable to load PartitionSwitchTool " << m_toolType << endmsg;
48  return sc;
49  }
51  if ( tool ) toolSvc()->releaseTool( tool );
53  IInterface* partititon = nullptr;
54  sc = m_actor->get( m_partName, partititon );
55  if ( !sc.isSuccess() ) {
56  error() << "Cannot access partition \"" << m_partName << "\"" << endmsg;
57  }
58  return sc;
59  }
60 
62  STATUS finalize() override
63  {
64  SmartIF<IAlgTool> tool( m_actor );
65  if ( tool ) toolSvc()->releaseTool( tool );
66  m_actor = nullptr;
67  return STATUS::SUCCESS;
68  }
69 
71  STATUS execute() override
72  {
73  if ( m_actor ) {
74  STATUS sc = m_actor->activate( m_partName );
75  if ( !sc.isSuccess() ) {
76  error() << "Cannot activate partition \"" << m_partName << "\"!" << endmsg;
77  }
78  return sc;
79  }
80  error() << "The partition control tool \"" << name() << "." << m_toolType << "\" cannot be accessed!" << endmsg;
81  return STATUS::FAILURE;
82  }
83 
84 private:
86  {
87  error() << msg << " Status=" << sc.getCode() << endmsg;
88  return sc;
89  }
90  template <typename... FArgs, typename... Args>
91  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ), Args&&... args )
92  {
93  return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : IInterface::Status::NO_INTERFACE;
94  }
95  template <typename... FArgs, typename... Args>
96  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ) const, Args&&... args ) const
97  {
98  return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : IInterface::Status::NO_INTERFACE;
99  }
100 
101 public:
103  STATUS create( CSTR nam, CSTR typ ) override
104  {
105  auto sc = fwd_<CSTR, CSTR>( &IPartitionControl::create, nam, typ );
106  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
107  }
109  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override
110  {
111  auto sc = fwd_<CSTR, CSTR, IInterface*&>( &IPartitionControl::create, nam, typ, pPartition );
112  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
113  }
115  STATUS drop( CSTR nam ) override
116  {
117  auto sc = fwd_<CSTR>( &IPartitionControl::drop, nam );
118  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition: " + nam );
119  }
121  STATUS drop( IInterface* pPartition ) override
122  {
123  auto sc = fwd_<IInterface*>( &IPartitionControl::drop, pPartition );
124  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition by Interface." );
125  }
127  STATUS activate( CSTR nam ) override
128  {
129  auto sc = fwd_<CSTR>( &IPartitionControl::activate, nam );
130  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition: " + nam );
131  }
133  STATUS activate( IInterface* pPartition ) override
134  {
135  auto sc = fwd_<IInterface*>( &IPartitionControl::activate, pPartition );
136  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition by Interface." );
137  }
139  STATUS get( CSTR nam, IInterface*& pPartition ) const override
140  {
141  auto sc = fwd_<CSTR, IInterface*&>( &IPartitionControl::get, nam, pPartition );
142  return sc.isSuccess() ? sc : log_( sc, "Cannot get partition " + nam );
143  }
145  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override
146  {
147  auto sc = fwd_<std::string&, IInterface*&>( &IPartitionControl::activePartition, nam, pPartition );
148  return sc.isSuccess() ? sc : log_( sc, "Cannot determine active partition." );
149  }
150 };
151 
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&...args) const
Requested interface is not available.
constexpr static const auto FAILURE
Definition: StatusCode.h:88
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.
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:765
Implementation of property with value of concrete type.
Definition: Property.h:381
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
Definition: StatusCode.h:287
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Definition: Algorithm.cpp:828
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.
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:139
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:139
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:51
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:277
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.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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
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:146
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
STATUS execute() override
Execute procedure.