The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
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// ====================================================================
22#include <GaudiKernel/SmartIF.h>
23
33
34class PartitionSwitchAlg : public extends<Algorithm, IPartitionControl> {
35
37 using CSTR = const std::string&;
38
39private:
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
47public:
48 using extends::extends;
49
51 STATUS initialize() override {
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 ) {
79 STATUS sc = m_actor->activate( m_partName );
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
87private:
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
101public:
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 }
107
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 }
112
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 }
117
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 }
122
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 }
127
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 }
132
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 }
137
138 STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override {
140 return sc.isSuccess() ? sc : log_( sc, "Cannot determine active partition." );
141 }
142};
143
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
const std::string & name() const override
The identifying name of the algorithm object.
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
Definition of the basic interface.
Definition IInterface.h:225
@ NO_INTERFACE
Requested interface is not available.
Definition IInterface.h:313
Create / access partitions.
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
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 create(const std::string &name, const std::string &type)=0
Create a partition object. The name identifies the partition uniquely.
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
StatusCode retrieveTool(std::string_view 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:147
Small algorithm which switches the partition of a configurable multi-service.
STATUS get(CSTR nam, IInterface *&pPartition) const override
Access a partition object. The name identifies the partition uniquely.
STATUS initialize() override
Initialize.
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
const std::string & CSTR
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&... args) const
STATUS activate(IInterface *pPartition) override
Activate a partition object.
STATUS create(CSTR nam, CSTR typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
IPartitionControl * m_actor
reference to Partition Controller
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
STATUS execute() override
Execute procedure.
Gaudi::Property< std::string > m_partName
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&... args)
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
STATUS finalize() override
Finalize.
Gaudi::Property< std::string > m_toolType
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
StatusCode log_(StatusCode sc, const std::string &msg) const
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto FAILURE
Definition StatusCode.h:100
code_t getCode() const
Retrieve value.
Definition StatusCode.h:136
Base class used to extend a class implementing other interfaces.
Definition extends.h:19