The Gaudi Framework  v33r0 (d5ea422b)
PartitionSwitchAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ====================================================================
12 // PartitionSwitchAlg.cpp
13 // --------------------------------------------------------------------
14 //
15 // Author : Markus Frank
16 //
17 // ====================================================================
18 #include "GaudiKernel/Algorithm.h"
19 #include "GaudiKernel/IAlgTool.h"
21 #include "GaudiKernel/IToolSvc.h"
22 #include "GaudiKernel/SmartIF.h"
23 
34 class PartitionSwitchAlg : public extends<Algorithm, IPartitionControl> {
35 
36  using STATUS = StatusCode;
37  using CSTR = const std::string&;
38 
39 private:
40  Gaudi::Property<std::string> m_partName{this, "Partition", "", "option to set the requested partition name"};
41  Gaudi::Property<std::string> m_toolType{this, "Tool", "PartitionSwitchTool",
42  "option to set the tool manipulating the multi-service name"};
43 
46 
47 public:
48  using extends::extends;
49 
51  STATUS initialize() override {
52  SmartIF<IAlgTool> tool( m_actor );
53  STATUS sc = toolSvc()->retrieveTool( m_toolType, m_actor, this );
54  if ( sc.isFailure() ) {
55  error() << "Unable to load PartitionSwitchTool " << m_toolType << endmsg;
56  return sc;
57  }
59  if ( tool ) toolSvc()->releaseTool( tool );
61  IInterface* partititon = nullptr;
62  sc = m_actor->get( m_partName, partititon );
63  if ( !sc.isSuccess() ) { error() << "Cannot access partition \"" << m_partName << "\"" << endmsg; }
64  return sc;
65  }
66 
68  STATUS finalize() override {
69  SmartIF<IAlgTool> tool( m_actor );
70  if ( tool ) toolSvc()->releaseTool( tool );
71  m_actor = nullptr;
72  return STATUS::SUCCESS;
73  }
74 
76  STATUS execute() override {
77  if ( m_actor ) {
79  if ( !sc.isSuccess() ) { error() << "Cannot activate partition \"" << m_partName << "\"!" << endmsg; }
80  return sc;
81  }
82  error() << "The partition control tool \"" << name() << "." << m_toolType << "\" cannot be accessed!" << endmsg;
83  return STATUS::FAILURE;
84  }
85 
86 private:
87  StatusCode log_( StatusCode sc, const std::string& msg ) const {
88  error() << msg << " Status=" << sc.getCode() << endmsg;
89  return sc;
90  }
91  template <typename... FArgs, typename... Args>
92  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ), Args&&... args ) {
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  return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : IInterface::Status::NO_INTERFACE;
98  }
99 
100 public:
102  STATUS create( CSTR nam, CSTR typ ) override {
103  auto sc = fwd_<CSTR, CSTR>( &IPartitionControl::create, nam, typ );
104  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
105  }
107  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override {
108  auto sc = fwd_<CSTR, CSTR, IInterface*&>( &IPartitionControl::create, nam, typ, pPartition );
109  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
110  }
112  STATUS drop( CSTR nam ) override {
113  auto sc = fwd_<CSTR>( &IPartitionControl::drop, nam );
114  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition: " + nam );
115  }
117  STATUS drop( IInterface* pPartition ) override {
118  auto sc = fwd_<IInterface*>( &IPartitionControl::drop, pPartition );
119  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition by Interface." );
120  }
122  STATUS activate( CSTR nam ) override {
123  auto sc = fwd_<CSTR>( &IPartitionControl::activate, nam );
124  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition: " + nam );
125  }
127  STATUS activate( IInterface* pPartition ) override {
128  auto sc = fwd_<IInterface*>( &IPartitionControl::activate, pPartition );
129  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition by Interface." );
130  }
132  STATUS get( CSTR nam, IInterface*& pPartition ) const override {
133  auto sc = fwd_<CSTR, IInterface*&>( &IPartitionControl::get, nam, pPartition );
134  return sc.isSuccess() ? sc : log_( sc, "Cannot get partition " + nam );
135  }
137  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
138  auto sc = fwd_<std::string&, IInterface*&>( &IPartitionControl::activePartition, nam, pPartition );
139  return sc.isSuccess() ? sc : log_( sc, "Cannot determine active partition." );
140  }
141 };
142 
code_t getCode() const
Retrieve value ("checks" the StatusCode)
Definition: StatusCode.h:148
Requested interface is not available.
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:25
STATUS initialize() override
Initialize.
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
Implementation of property with value of concrete type.
Definition: Property.h:370
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&... args)
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:96
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Definition: Algorithm.cpp:594
Gaudi::Property< std::string > m_toolType
Gaudi::Property< std::string > m_partName
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:148
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.
StatusCode log_(StatusCode sc, const std::string &msg) const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
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.
bool isSuccess() const
Definition: StatusCode.h:361
STATUS activate(IInterface *pPartition) override
Activate a partition object.
STATUS get(CSTR nam, IInterface *&pPartition) const override
Access a partition object. The name identifies the partition uniquely.
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Create / access partitions.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
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:97
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.
bool isFailure() const
Definition: StatusCode.h:141
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&... args) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:556
STATUS execute() override
Execute procedure.