| The Gaudi Framework v27r1

- 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/IPartitionControl.h"
9 #include "GaudiKernel/Algorithm.h"
10 #include "GaudiKernel/IToolSvc.h"
11 #include "GaudiKernel/IAlgTool.h"
12 #include "GaudiKernel/SmartIF.h"
13
24 class PartitionSwitchAlg : public extends<Algorithm,
25 IPartitionControl> {
26
27 using STATUS = StatusCode;
28 using CSTR = const std::string&;
29
30 private:
31
33 std::string m_partName;
35 std::string m_toolType;
37 IPartitionControl* m_actor = nullptr;
38
39 public:
40
42 PartitionSwitchAlg(const std::string& name, ISvcLocator* pSvcLocator)
43 : base_class(name, pSvcLocator)
44 {
45 declareProperty("Partition", m_partName);
46 declareProperty("Tool", m_toolType="PartitionSwitchTool");
47 }
49 ~PartitionSwitchAlg() override = default;
50
52 STATUS initialize() override {
53 SmartIF<IAlgTool> tool(m_actor);
54 STATUS sc = toolSvc()->retrieveTool(m_toolType,m_actor,this);
55 if ( sc.isFailure() ) {
56 error() << "Unable to load PartitionSwitchTool "
57 << m_toolType << endmsg;
58 return sc;
59 }
61 if ( tool ) toolSvc()->releaseTool(tool);
63 IInterface* partititon = nullptr;
64 sc = m_actor->get(m_partName, partititon);
65 if ( !sc.isSuccess() ) {
66 error() << "Cannot access partition \""
67 << m_partName << "\"" << endmsg;
68 }
69 return sc;
70 }
71
73 STATUS finalize() override {
74 SmartIF<IAlgTool> tool(m_actor);
75 if ( tool ) toolSvc()->releaseTool(tool);
76 m_actor = nullptr;
77 return STATUS::SUCCESS;
78 }
79
81 STATUS execute() override {
82 if ( m_actor ) {
83 STATUS sc = m_actor->activate(m_partName);
84 if ( !sc.isSuccess() ) {
85 error() << "Cannot activate partition \""
86 << m_partName << "\"!" << endmsg;
87 }
88 return sc;
89 }
90 error() << "The partition control tool \"" << name()
91 << "." << m_toolType << "\" cannot be accessed!" << endmsg;
92 return STATUS::FAILURE;
93 }
94 private:
95 StatusCode log_(StatusCode sc, const std::string& msg) const {
96 error() << msg << " Status=" << sc.getCode() << endmsg;
97 return sc;
98 }
99 template < typename...FArgs, typename...Args>
100 StatusCode fwd_( StatusCode (IPartitionControl::*fun)(FArgs...),Args&&... args) {
101 return m_actor ? (m_actor->*fun)(std::forward<Args>(args)...) : NO_INTERFACE;
102 }
103 template < typename...FArgs, typename...Args>
104 StatusCode fwd_( StatusCode (IPartitionControl::*fun)(FArgs...) const,Args&&... args) const {
105 return m_actor ? (m_actor->*fun)(std::forward<Args>(args)...) : NO_INTERFACE;
106 }
107 public:
109 STATUS create(CSTR nam, CSTR typ) override {
110 auto sc = fwd_<CSTR,CSTR>(&IPartitionControl::create,nam,typ);
111 return sc.isSuccess() ? sc : log_(sc, "Cannot create partition: "+nam+" of type "+typ);
112 }
114 STATUS create(CSTR nam, CSTR typ, IInterface*& pPartition) override {
115 auto sc = fwd_<CSTR,CSTR,IInterface*&>(&IPartitionControl::create,nam,typ,pPartition);
116 return sc.isSuccess() ? sc : log_(sc, "Cannot create partition: "+nam+" of type "+typ);
117 }
119 STATUS drop(CSTR nam) override {
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 auto sc = fwd_<IInterface*>(&IPartitionControl::drop,pPartition);
126 return sc.isSuccess() ? sc : log_(sc, "Cannot drop partition by Interface.");
127 }
129 STATUS activate(CSTR nam) override {
130 auto sc = fwd_<CSTR>(&IPartitionControl::activate,nam);
131 return sc.isSuccess() ? sc : log_(sc, "Cannot activate partition: "+nam);
132 }
134 STATUS activate(IInterface* pPartition) override {
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 auto sc = fwd_<CSTR,IInterface*&>(&IPartitionControl::get, nam, pPartition);
141 return sc.isSuccess() ? sc : log_(sc, "Cannot get partition "+nam);
142 }
144 STATUS activePartition(std::string& nam, IInterface*& pPartition) const override {
145 auto sc = fwd_<std::string&,IInterface*&>(&IPartitionControl::activePartition,nam,pPartition);
146 return sc.isSuccess() ? sc : log_(sc, "Cannot determine active partition.");
147 }
148 };
149
150 DECLARE_COMPONENT(PartitionSwitchAlg)
PartitionSwitchAlg::fwd_
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...) const, Args &&...args) const
Definition: PartitionSwitchAlg.cpp:104
Algorithm.h
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:133
PartitionSwitchAlg::initialize
STATUS initialize() override
Initialize.
Definition: PartitionSwitchAlg.cpp:52
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
IPartitionControl::activePartition
virtual StatusCode activePartition(std::string &name, IInterface *&pPartition) const =0
Access the active partition object.
StatusCode::getCode
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:93
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:95
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
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:73
Algorithm::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:426
PartitionSwitchAlg::fwd_
StatusCode fwd_(StatusCode(IPartitionControl::*fun)(FArgs...), Args &&...args)
Definition: PartitionSwitchAlg.cpp:100
merge_files.sc
int sc
Definition: merge_files.py:167
IToolSvc.h
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
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:145
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
Algorithm::toolSvc
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
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:119
PartitionSwitchAlg::m_partName
std::string m_partName
Job option to set the requested partition name.
Definition: PartitionSwitchAlg.cpp:33
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
SmartIF.h
IPartitionControl::get
virtual StatusCode get(const std::string &name, IInterface *&pPartition) const =0
Access a partition object. The name identifies the partition uniquely.
PartitionSwitchAlg::PartitionSwitchAlg
PartitionSwitchAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm constructor.
Definition: PartitionSwitchAlg.cpp:42
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:114
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:134
gaudirun.args
list args
Definition: gaudirun.py:290
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:109
CommonMessaging
Definition: CommonMessaging.h:58
PartitionSwitchAlg::m_actor
IPartitionControl * m_actor
reference to Partition Controller
Definition: PartitionSwitchAlg.cpp:37
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:129
PartitionSwitchAlg::activePartition
STATUS activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
Definition: PartitionSwitchAlg.cpp:144
PartitionSwitchAlg::m_toolType
std::string m_toolType
Job option to set the tool manipulating the multi-service name.
Definition: PartitionSwitchAlg.cpp:35
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
PartitionSwitchAlg::execute
STATUS execute() override
Execute procedure.
Definition: PartitionSwitchAlg.cpp:81