ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
src
CloneTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
AthenaKernel/CloneTool.h
"
6
7
#include <cassert>
8
#include <vector>
9
10
#include "GaudiKernel/IToolSvc.h"
11
#include "GaudiKernel/MsgStream.h"
12
#include "GaudiKernel/AlgTool.h"
13
14
namespace
CloneTool
{
16
StatusCode
typeless_clone
(
const
IAlgTool& cloned,
17
const
std::string& cloneName,
18
const
InterfaceID& cloneID,
19
IAlgTool*& result)
20
{
21
//FIXME this only creates an uninitialized AlgTool
22
//FIXME it would be better if one could say cloned.clone()
23
//FIXME (its default implementation could be this one)
24
25
const
AlgTool* pCloned(
dynamic_cast<
const
AlgTool*
>
(&cloned));
26
if
(0 == pCloned) {
27
std::cerr <<
"CloneTool::FATAL: Could not dcast IAlgTool "
28
<< cloned.name() <<
" to an AlgTool"
<< std::endl;
29
return
StatusCode::FAILURE;
30
}
31
32
// can we access the AlgTool locator interface?
33
IToolSvc* toolSvc(pCloned->toolSvc());
34
assert (0 != toolSvc);
35
36
MsgStream mlog( pCloned->msgSvc(),
"CloneAlgTool::clone"
);
37
if
(!toolSvc->retrieve(pCloned->type(),
38
cloneName,
39
cloneID,
40
result,
41
pCloned->parent(),
//cloned's owner
42
/*createIf=*/
true
).isSuccess()) {
43
mlog << MSG::FATAL <<
"Could not clone AlgTool "
44
<< pCloned->name() <<
" to "
<< cloneName <<
endmsg
;
45
return
StatusCode::FAILURE;
46
}
47
48
//now copy cloned's properties into result
49
std::vector<Gaudi::Details::PropertyBase*>::const_iterator iProp(pCloned->getProperties().begin());
50
std::vector<Gaudi::Details::PropertyBase*>::const_iterator eProp(pCloned->getProperties().end());
51
52
AlgTool* aResult=
dynamic_cast<
AlgTool*
>
(result);
53
if
(0 == aResult) {
54
mlog << MSG::FATAL <<
"Could not dcast IAlgTool "
55
<< result->name() <<
" to an AlgTool"
<<
endmsg
;
56
return
StatusCode::FAILURE;
57
}
58
while
(iProp != eProp &&
59
(aResult->setProperty(**iProp)).isSuccess()) ++iProp;
60
if
(iProp != eProp) {
61
mlog << MSG::ERROR
62
<<
"Failed to set result property "
<< (**iProp).name()
63
<<
endmsg
;
64
return
StatusCode::FAILURE;
65
}
else
{
66
mlog << MSG::DEBUG
67
<< cloneName <<
" properties set"
68
<<
endmsg
;
69
}
70
71
//finally put the service in the same state as the cloned
72
//FIXME should we handle the case in which the cloned is RUNNING?
73
if
(Gaudi::StateMachine::INITIALIZED == pCloned->FSMState() &&
74
Gaudi::StateMachine::CONFIGURED == aResult->FSMState())
75
return
aResult->sysInitialize();
76
else
{
77
mlog << MSG::DEBUG
78
<<
"Did not initialize "
<< cloneName
79
<<
endmsg
;
80
return
StatusCode::SUCCESS;
81
}
82
}
83
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
CloneTool.h
CloneTool
Definition
CloneTool.h:11
CloneTool::typeless_clone
StatusCode typeless_clone(const IAlgTool &cloned, const std::string &cloneName, const InterfaceID &cloneID, IAlgTool *&result)
implementation, experts only
Definition
CloneTool.cxx:16
Generated on
for ATLAS Offline Software by
1.17.0