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