23 {
24
25 const Service* parent = dynamic_cast<const Service*>(iParent);
26 if ( !parent ) {
27 throw GaudiException("parent " + iParent->name() + " is not a service!",
28 "CloneService", StatusCode::FAILURE);
29 return StatusCode::FAILURE;
30 }
31
32 MsgStream mlog( parent->msgSvc(), "CloneService" );
33 ISvcLocator* svcLoc = parent->serviceLocator();
34
35
36
37 if ( svcLoc->existsService(childName) ) {
38 mlog << MSG::DEBUG
39 << "Found service " << childName
41 } else {
42
43 SmartIF<ISvcManager>
svcMgr(svcLoc);
45
46
47 const std::string& parentType = System::typeinfoName(typeid(*parent));
48 Gaudi::Utils::TypeNameString tn(childName, parentType);
49
50 child =
dynamic_cast<Service*
>(
svcMgr->createService(tn).
get());
51 if ( child ) {
53 << "Created service " << childName << " of type " << parentType
55 } else {
57 << "Failed to create " << childName << " of type " << parentType
59 return StatusCode::FAILURE;
60 }
61 }
62
63
64 for (Gaudi::Details::PropertyBase* prop :
parent->getProperties()) {
65 if ( child->setProperty(*prop).isFailure() ) {
67 <<
"Failed to set child property " << prop->name() <<
endmsg;
68 return StatusCode::FAILURE;
69 }
70 }
71
72
73
74 if (Gaudi::StateMachine::INITIALIZED ==
parent->FSMState() &&
75 Gaudi::StateMachine::CONFIGURED == child->FSMState())
76 return child->sysInitialize();
77 else {
79 << "Did not initialize " << childName
81 return StatusCode::SUCCESS;
82 }
83 }
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)