| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

PartitionSwitchAlg.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // PartitionSwitchAlg.cpp
3 // --------------------------------------------------------------------
4 //
5 // Author : Markus Frank
6 //
7 // ====================================================================
8 #include "GaudiKernel/Algorithm.h"
9 #include "GaudiKernel/IAlgTool.h"
10 #include "GaudiKernel/IPartitionControl.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
36 IPartitionControl* m_actor = nullptr;
37
38 public:
39 using extends::extends;
40
42 ~PartitionSwitchAlg() override = default;
43
45 STATUS initialize() override
46 {
47 SmartIF<IAlgTool> tool( m_actor );
48 STATUS sc = toolSvc()->retrieveTool( m_toolType, m_actor, this );
49 if ( sc.isFailure() ) {
50 error() << "Unable to load PartitionSwitchTool " << m_toolType << endmsg;
51 return sc;
52 }
54 if ( tool ) toolSvc()->releaseTool( tool );
56 IInterface* partititon = nullptr;
57 sc = m_actor->get( m_partName, partititon );
58 if ( !sc.isSuccess() ) {
59 error() << "Cannot access partition \"" << m_partName << "\"" << endmsg;
60 }
61 return sc;
62 }
63
65 STATUS finalize() override
66 {
67 SmartIF<IAlgTool> tool( m_actor );
68 if ( tool ) toolSvc()->releaseTool( tool );
69 m_actor = nullptr;
70 return STATUS::SUCCESS;
71 }
72
74 STATUS execute() override
75 {
76 if ( m_actor ) {
77 STATUS sc = m_actor->activate( m_partName );
78 if ( !sc.isSuccess() ) {
79 error() << "Cannot activate partition \"" << m_partName << "\"!" << endmsg;
80 }
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 {
90 error() << msg << " Status=" << sc.getCode() << endmsg;
91 return sc;
92 }
93 template <typename... FArgs, typename... Args>
94 StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ), Args&&... args )
95 {
96 return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : NO_INTERFACE;
97 }
98 template <typename... FArgs, typename... Args>
99 StatusCode fwd_( StatusCode ( IPartitionControl::*fun )( FArgs... ) const, Args&&... args ) const
100 {
101 return m_actor ? ( m_actor->*fun )( std::forward<Args>( args )... ) : NO_INTERFACE;
102 }
103
104 public:
106 STATUS create( CSTR nam, CSTR typ ) override
107 {
108 auto sc = fwd_<CSTR, CSTR>( &IPartitionControl::create, nam, typ );
109 return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
110 }
112 STATUS create( CSTR nam, CSTR typ, IInterface*& pPartition ) override
113 {
114 auto sc = fwd_<CSTR, CSTR, IInterface*&>( &IPartitionControl::create, nam, typ, pPartition );
115 return sc.isSuccess() ? sc : log_( sc, "Cannot create partition: " + nam + " of type " + typ );
116 }
118 STATUS drop( CSTR nam ) override
119 {
120 auto sc = fwd_<CSTR>( &IPartitionControl::drop, nam );
121 return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition: " + nam );
122 }
124 STATUS drop( IInterface* pPartition ) override
125 {
126 auto sc = fwd_<IInterface*>( &IPartitionControl::drop, pPartition );
127 return sc.isSuccess() ? sc : log_( sc, "Cannot drop partition by Interface." );
128 }
130 STATUS activate( CSTR nam ) override
131 {
132 auto sc = fwd_<CSTR>( &IPartitionControl::activate, nam );
133 return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition: " + nam );
134 }
136 STATUS activate( IInterface* pPartition ) override
137 {
138 auto sc = fwd_<IInterface*>( &IPartitionControl::activate, pPartition );
139 return sc.isSuccess() ? sc : log_( sc, "Cannot activate partition by Interface." );
140 }
142 STATUS get( CSTR nam, IInterface*& pPartition ) const override
143 {
144 auto sc = fwd_<CSTR, IInterface*&>( &IPartitionControl::get, nam, pPartition );
145 return sc.isSuccess() ? sc : log_( sc, "Cannot get partition " + nam );
146 }
148 STATUS activePartition( std::string& nam, IInterface*& pPartition ) const override
149 {
150 auto sc = fwd_<std::string&, IInterface*&>( &IPartitionControl::activePartition, nam, pPartition );
151 return sc.isSuccess() ? sc : log_( sc, "Cannot determine active partition." );
152 }
153 };
154
155 DECLARE_COMPONENT( PartitionSwitchAlg )
PartitionSwitchAlg::fwd_
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&...args) const
Definition: PartitionSwitchAlg.cpp:99
StatusCode::SUCCESS
Definition: StatusCode.h:29
Algorithm.h
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:121
PartitionSwitchAlg::initialize
STATUS initialize() override
Initialize.
Definition: PartitionSwitchAlg.cpp:45
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:737
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:319
StatusCode::getCode
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:69
PartitionSwitchAlg::drop
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:124
PartitionSwitchAlg::log_
StatusCode log_(StatusCode sc, const std::string &msg) const
Definition: PartitionSwitchAlg.cpp:88
gaudirun.args
args
Definition: gaudirun.py:244
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
Algorithm::toolSvc
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Definition: Algorithm.cpp:809
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::finalize
STATUS finalize() override
Finalize.
Definition: PartitionSwitchAlg.cpp:65
PartitionSwitchAlg::activePartition
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
Definition: PartitionSwitchAlg.cpp:148
PartitionSwitchAlg::m_toolType
Gaudi::Property< std::string > m_toolType
Definition: PartitionSwitchAlg.cpp:32
PartitionSwitchAlg::fwd_
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&...args)
Definition: PartitionSwitchAlg.cpp:94
IToolSvc.h
PartitionSwitchAlg::m_partName
Gaudi::Property< std::string > m_partName
Definition: PartitionSwitchAlg.cpp:31
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:61
IToolSvc::retrieveTool
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
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
PartitionSwitchAlg::~PartitionSwitchAlg
~PartitionSwitchAlg() override=default
Standard Destructor.
IPartitionControl.h
PartitionSwitchAlg::drop
STATUS drop(CSTR nam) override
Drop a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:118
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IPartitionControl::get
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
IInterface
Definition of the basic interface.
Definition: IInterface.h:277
SmartIF.h
IAlgTool.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:112
PartitionSwitchAlg
Small algorithm which switches the partition of a configurable multi-service.
Definition: PartitionSwitchAlg.cpp:24
PartitionSwitchAlg::activate
STATUS activate(IInterface *pPartition) override
Activate a partition object.
Definition: PartitionSwitchAlg.cpp:136
IPartitionControl::activePartition
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
IPartitionControl
Create / access partitions.
Definition: IPartitionControl.h:66
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
PartitionSwitchAlg::create
STATUS create(CSTR nam, CSTR typ) override
Create a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:106
PartitionSwitchAlg::m_actor
IPartitionControl * m_actor
reference to Partition Controller
Definition: PartitionSwitchAlg.cpp:36
IPartitionControl::drop
virtual StatusCode drop(const std::string &name)=0
Drop a partition object. The name identifies the partition uniquely.
IPartitionControl::activate
virtual StatusCode activate(const std::string &name)=0
Activate a partition object. The name identifies the partition uniquely.
IToolSvc::releaseTool
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
PartitionSwitchAlg::activate
STATUS activate(CSTR nam) override
Activate a partition object. The name identifies the partition uniquely.
Definition: PartitionSwitchAlg.cpp:130
StatusCode::FAILURE
Definition: StatusCode.h:29
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
PartitionSwitchAlg::execute
STATUS execute() override
Execute procedure.
Definition: PartitionSwitchAlg.cpp:74