The Gaudi Framework  master (37c0b60a)
PartitionSwitchAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 {
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 )
60  if ( sc = toolSvc()->releaseTool( tool ); !sc ) return sc;
62  IInterface* partititon = nullptr;
63  sc = m_actor->get( m_partName, partititon );
64  if ( !sc.isSuccess() ) { error() << "Cannot access partition \"" << m_partName << "\"" << endmsg; }
65  return sc;
66  }
67 
69  STATUS finalize() override {
71  if ( tool ) toolSvc()->releaseTool( tool ).ignore();
72  m_actor = nullptr;
73  return extends::finalize();
74  }
75 
77  STATUS execute() override {
78  if ( m_actor ) {
80  if ( !sc.isSuccess() ) { error() << "Cannot activate partition \"" << m_partName << "\"!" << endmsg; }
81  return sc;
82  }
83  error() << "The partition control tool \"" << name() << "." << m_toolType << "\" cannot be accessed!" << endmsg;
84  return STATUS::FAILURE;
85  }
86 
87 private:
88  StatusCode log_( StatusCode sc, const std::string& msg ) const {
89  error() << msg << " Status=" << sc.getCode() << endmsg;
90  return sc;
91  }
92  template <typename... FArgs, typename... Args>
93  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ), Args&&... args ) {
94  return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : IInterface::Status::NO_INTERFACE;
95  }
96  template <typename... FArgs, typename... Args>
97  StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ) const, Args&&... args ) const {
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  auto sc = fwd_<CSTR, CSTR>( &IPartitionControl::create, nam, typ );
105  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
106  }
108  STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override {
109  auto sc = fwd_<CSTR, CSTR, IInterface*&>( &IPartitionControl::create, nam, typ, pPartition );
110  return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
111  }
113  STATUS drop( CSTR nam ) override {
114  auto sc = fwd_<CSTR>( &IPartitionControl::drop, nam );
115  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition: " + nam );
116  }
118  STATUS drop( IInterface* pPartition ) override {
119  auto sc = fwd_<IInterface*>( &IPartitionControl::drop, pPartition );
120  return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition by Interface." );
121  }
123  STATUS activate( CSTR nam ) override {
124  auto sc = fwd_<CSTR>( &IPartitionControl::activate, nam );
125  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition: " + nam );
126  }
128  STATUS activate( IInterface* pPartition ) override {
129  auto sc = fwd_<IInterface*>( &IPartitionControl::activate, pPartition );
130  return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition by Interface." );
131  }
133  STATUS get( CSTR nam, IInterface*& pPartition ) const override {
134  auto sc = fwd_<CSTR, IInterface*&>( &IPartitionControl::get, nam, pPartition );
135  return sc.isSuccess() ? sc : log_( sc, "Cannot get partition " + nam );
136  }
138  STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
139  auto sc = fwd_<std::string&, IInterface*&>( &IPartitionControl::activePartition, nam, pPartition );
140  return sc.isSuccess() ? sc : log_( sc, "Cannot determine active partition." );
141  }
142 };
143 
PartitionSwitchAlg::drop
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:118
PartitionSwitchAlg::m_actor
IPartitionControl * m_actor
reference to Partition Controller
Definition: PartitionSwitchAlg.cpp:45
PartitionSwitchAlg::fwd_
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&... args) const
Definition: PartitionSwitchAlg.cpp:97
PartitionSwitchAlg::activate
STATUS activate(IInterface *pPartition) override
Activate a partition object.
Definition: PartitionSwitchAlg.cpp:128
PartitionSwitchAlg::m_toolType
Gaudi::Property< std::string > m_toolType
Definition: PartitionSwitchAlg.cpp:41
std::string
STL class.
Gaudi::Algorithm::toolSvc
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Definition: Algorithm.cpp:564
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:526
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
PartitionSwitchAlg::initialize
STATUS initialize() override
Initialize.
Definition: PartitionSwitchAlg.cpp:51
PartitionSwitchAlg::create
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:103
IPartitionControl
Definition: IPartitionControl.h:76
Algorithm.h
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
IInterface::Status::NO_INTERFACE
@ NO_INTERFACE
Requested interface is not available.
PartitionSwitchAlg::activePartition
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
Definition: PartitionSwitchAlg.cpp:138
PartitionSwitchAlg::fwd_
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&... args)
Definition: PartitionSwitchAlg.cpp:93
IPartitionControl::create
virtual StatusCode create(const std::string &name, const std::string &type)=0
Create a partition object. The name identifies the partition uniquely.
PartitionSwitchAlg::activate
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:123
PartitionSwitchAlg::drop
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:113
IToolSvc.h
PartitionSwitchAlg::create
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:108
SmartIF.h
bug_34121.tool
tool
Definition: bug_34121.py:18
StatusCode
Definition: StatusCode.h:65
PartitionSwitchAlg::m_partName
Gaudi::Property< std::string > m_partName
Definition: PartitionSwitchAlg.cpp:40
PartitionSwitchAlg
Definition: PartitionSwitchAlg.cpp:34
IPartitionControl::drop
virtual StatusCode drop(const std::string &name)=0
Drop a partition object. The name identifies the partition uniquely.
IAlgTool.h
PartitionSwitchAlg::finalize
STATUS finalize() override
Finalize.
Definition: PartitionSwitchAlg.cpp:69
SmartIF
Definition: IConverter.h:25
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
IPartitionControl::get
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
PartitionSwitchAlg::execute
STATUS execute() override
Execute procedure.
Definition: PartitionSwitchAlg.cpp:77
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
IPartitionControl::activePartition
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
PartitionSwitchAlg::log_
StatusCode log_(StatusCode sc, const std::string &msg) const
Definition: PartitionSwitchAlg.cpp:88
gaudirun.args
args
Definition: gaudirun.py:336
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IInterface
Definition: IInterface.h:239
StatusCode::getCode
code_t getCode() const
Retrieve value.
Definition: StatusCode.h:136
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
IPartitionControl.h
IPartitionControl::activate
virtual StatusCode activate(const std::string &name)=0
Activate a partition object. The name identifies the partition uniquely.
PartitionSwitchAlg::get
STATUS get(CSTR nam, IInterface *&pPartition) const override
Access a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:133
Gaudi::Property< std::string >