Skip to content
Snippets Groups Projects
Commit dabf7a3a authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Restore fixed ToolHandle.h

The version of ToolHandle.h before fa29ed33 included some improvements,
as well as the fixes for https://sft.its.cern.ch/jira/browse/CFHEP-177 and GAUDI-1127.

The version introduced with fa29ed33 does not work because of GAUDI-1127.

See merge request !106
parents a2a8c1ce 5244376e
No related merge requests found
...@@ -15,6 +15,7 @@ MyGaudiAlgorithm::MyGaudiAlgorithm(const std::string& name, ISvcLocator* ploc) ...@@ -15,6 +15,7 @@ MyGaudiAlgorithm::MyGaudiAlgorithm(const std::string& name, ISvcLocator* ploc)
: GaudiAlgorithm(name, ploc), : GaudiAlgorithm(name, ploc),
m_myPrivToolHandle("MyTool/PrivToolHandle",this), m_myPrivToolHandle("MyTool/PrivToolHandle",this),
m_myPubToolHandle("MyTool/PubToolHandle"), m_myPubToolHandle("MyTool/PubToolHandle"),
m_myGenericToolHandle("MyTool/GenericToolHandle"),
m_tracks("/Event/Rec/Tracks",Gaudi::DataHandle::Reader, this), m_tracks("/Event/Rec/Tracks",Gaudi::DataHandle::Reader, this),
m_hits("/Event/Rec/Hits",Gaudi::DataHandle::Reader,this), m_hits("/Event/Rec/Hits",Gaudi::DataHandle::Reader,this),
m_raw("/Rec/RAW",Gaudi::DataHandle::Reader,this), m_raw("/Rec/RAW",Gaudi::DataHandle::Reader,this),
...@@ -25,6 +26,7 @@ MyGaudiAlgorithm::MyGaudiAlgorithm(const std::string& name, ISvcLocator* ploc) ...@@ -25,6 +26,7 @@ MyGaudiAlgorithm::MyGaudiAlgorithm(const std::string& name, ISvcLocator* ploc)
"Type of the tool to use (internal name is ToolWithName)"); "Type of the tool to use (internal name is ToolWithName)");
declareProperty("PrivToolHandle", m_myPrivToolHandle); declareProperty("PrivToolHandle", m_myPrivToolHandle);
declareProperty("PubToolHandle", m_myPubToolHandle); declareProperty("PubToolHandle", m_myPubToolHandle);
declareProperty("GenericToolHandle", m_myGenericToolHandle);
declareProperty("tracks", m_tracks, "the tracks"); declareProperty("tracks", m_tracks, "the tracks");
declareProperty("hits", m_hits, "the hits"); declareProperty("hits", m_hits, "the hits");
...@@ -54,7 +56,8 @@ StatusCode MyGaudiAlgorithm::initialize() { ...@@ -54,7 +56,8 @@ StatusCode MyGaudiAlgorithm::initialize() {
m_privateOtherInterface = tool<IMyOtherTool>("MyGaudiTool", this); m_privateOtherInterface = tool<IMyOtherTool>("MyGaudiTool", this);
// force initialization of tool handles // force initialization of tool handles
if ( ! (m_myPrivToolHandle.retrieve() && if ( ! (m_myPrivToolHandle.retrieve() &&
m_myPubToolHandle.retrieve() ) ) { m_myPubToolHandle.retrieve() &&
m_myGenericToolHandle.retrieve() ) ) {
error() << "Unable to retrive one of the ToolHandles" << endmsg; error() << "Unable to retrive one of the ToolHandles" << endmsg;
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
......
...@@ -38,6 +38,8 @@ private: ...@@ -38,6 +38,8 @@ private:
ToolHandle<IMyTool> m_myPrivToolHandle; ToolHandle<IMyTool> m_myPrivToolHandle;
ToolHandle<IMyTool> m_myPubToolHandle; ToolHandle<IMyTool> m_myPubToolHandle;
ToolHandle<IAlgTool> m_myGenericToolHandle;
ToolHandleArray<IMyTool> m_tha; ToolHandleArray<IMyTool> m_tha;
DataObjectHandle<DataObject> m_tracks; DataObjectHandle<DataObject> m_tracks;
......
...@@ -26,6 +26,7 @@ expected = ['ToolSvc.MyTool', ...@@ -26,6 +26,7 @@ expected = ['ToolSvc.MyTool',
'MyGaudiAlg.ToolWithName', 'MyGaudiAlg.ToolWithName',
'MyGaudiAlg.PrivToolHandle', 'MyGaudiAlg.PrivToolHandle',
'ToolSvc.TestPubToolHandle', 'ToolSvc.TestPubToolHandle',
'ToolSvc.GenericToolHandle',
'ToolSvc.ToolA', 'ToolSvc.ToolA',
'ToolSvc.ToolB', 'ToolSvc.ToolB',
] ]
......
JobOptionsSvc INFO # =======> /afs/cern.ch/work/l/leggett/hive/DH/Gaudi/GaudiExamples/options/Services.opts JobOptionsSvc INFO # =======> /afs/cern.ch/work/m/marcocle/workspace/Gaudi/GaudiExamples/options/Services.opts
JobOptionsSvc INFO # (12,1): AuditorSvc.Auditors = ["ChronoAuditor"] JobOptionsSvc INFO # (12,1): AuditorSvc.Auditors = ["ChronoAuditor"]
JobOptionsSvc INFO # =======> /afs/cern.ch/work/l/leggett/hive/DH/Gaudi/GaudiExamples/options/Common.opts JobOptionsSvc INFO # =======> /afs/cern.ch/work/m/marcocle/workspace/Gaudi/GaudiExamples/options/Common.opts
JobOptionsSvc INFO # (9,1): ApplicationMgr.StatusCodeCheck = 1 JobOptionsSvc INFO # (9,1): ApplicationMgr.StatusCodeCheck = 1
JobOptionsSvc INFO # =======> /afs/cern.ch/work/l/leggett/hive/DH/Gaudi/GaudiExamples/options/AlgTools2.opts JobOptionsSvc INFO # =======> /afs/cern.ch/work/m/marcocle/workspace/Gaudi/GaudiExamples/options/AlgTools2.opts
JobOptionsSvc INFO # (10,1): ApplicationMgr.TopAlg = ["MyGaudiAlgorithm/MyAlg"] JobOptionsSvc INFO # (10,1): ApplicationMgr.TopAlg = ["MyGaudiAlgorithm/MyAlg"]
JobOptionsSvc INFO # (13,1): MessageSvc.OutputLevel = 3 JobOptionsSvc INFO # (13,1): MessageSvc.OutputLevel = 3
JobOptionsSvc INFO # (18,1): ApplicationMgr.EvtMax = 10 JobOptionsSvc INFO # (18,1): ApplicationMgr.EvtMax = 10
...@@ -23,11 +23,11 @@ JobOptionsSvc INFO # (44,1): ToolSvc.ToolA.Tools = ["TestTool/ToolB"] ...@@ -23,11 +23,11 @@ JobOptionsSvc INFO # (44,1): ToolSvc.ToolA.Tools = ["TestTool/ToolB"]
JobOptionsSvc INFO # (45,1): ToolSvc.ToolB.Tools = ["TestTool/ToolA"] JobOptionsSvc INFO # (45,1): ToolSvc.ToolB.Tools = ["TestTool/ToolA"]
JobOptionsSvc INFO # (46,1): ToolSvc.ToolA.OutputLevel = 2 JobOptionsSvc INFO # (46,1): ToolSvc.ToolA.OutputLevel = 2
JobOptionsSvc INFO # (47,1): ToolSvc.ToolB.OutputLevel = 2 JobOptionsSvc INFO # (47,1): ToolSvc.ToolB.OutputLevel = 2
JobOptionsSvc INFO Job options successfully read in from /afs/cern.ch/work/l/leggett/hive/DH/Gaudi/GaudiExamples/options/AlgTools2.opts JobOptionsSvc INFO Job options successfully read in from /afs/cern.ch/work/m/marcocle/workspace/Gaudi/GaudiExamples/options/AlgTools2.opts
ApplicationMgr SUCCESS ApplicationMgr SUCCESS
==================================================================================================================================== ====================================================================================================================================
Welcome to ApplicationMgr (GaudiCoreSvc v3r6) Welcome to ApplicationMgr (GaudiCoreSvc v4r0)
running on p05614910w96644.cern.ch on Wed Jan 13 22:59:53 2016 running on pclhcb117 on Thu Feb 11 12:52:41 2016
==================================================================================================================================== ====================================================================================================================================
ApplicationMgr INFO Application Manager Configured successfully ApplicationMgr INFO Application Manager Configured successfully
StatusCodeSvc INFO initialize StatusCodeSvc INFO initialize
...@@ -35,11 +35,12 @@ MyAlg DEBUG Property update for OutputLevel : new value = 2 ...@@ -35,11 +35,12 @@ MyAlg DEBUG Property update for OutputLevel : new value = 2
MyAlg DEBUG Property update for OutputLevel : new value = 2 MyAlg DEBUG Property update for OutputLevel : new value = 2
MyAlg DEBUG Initialize base class GaudiCommon<Algorithm> MyAlg DEBUG Initialize base class GaudiCommon<Algorithm>
MyAlg DEBUG could not locate CounterSummarySvc, no counter summary will be made MyAlg DEBUG could not locate CounterSummarySvc, no counter summary will be made
MyAlg DEBUG List of ALL properties of MyGaudiAlgorithm/MyAlg #properties = 44 MyAlg DEBUG List of ALL properties of MyGaudiAlgorithm/MyAlg #properties = 45
MyAlg DEBUG Property ['Name': Value] = 'trackSelection':('/Event/MyAnalysis/Tracks') m: 16 o: MyAlg opt: 0 MyAlg DEBUG Property ['Name': Value] = 'trackSelection':('/Event/MyAnalysis/Tracks') m: 16 o: MyAlg opt: 0
MyAlg DEBUG Property ['Name': Value] = 'raw':('/Rec/RAW') m: 4 o: MyAlg opt: 0 MyAlg DEBUG Property ['Name': Value] = 'raw':('/Rec/RAW') m: 4 o: MyAlg opt: 0
MyAlg DEBUG Property ['Name': Value] = 'hits':('/Event/Rec/Hits') m: 4 o: MyAlg opt: 0 MyAlg DEBUG Property ['Name': Value] = 'hits':('/Event/Rec/Hits') m: 4 o: MyAlg opt: 0
MyAlg DEBUG Property ['Name': Value] = 'tracks':('/Event/Rec/Tracks') m: 4 o: MyAlg opt: 0 MyAlg DEBUG Property ['Name': Value] = 'tracks':('/Event/Rec/Tracks') m: 4 o: MyAlg opt: 0
MyAlg DEBUG Property ['Name': Value] = 'GenericToolHandle':MyTool/GenericToolHandle
MyAlg DEBUG Property ['Name': Value] = 'PubToolHandle':MyTool/PubToolHandle MyAlg DEBUG Property ['Name': Value] = 'PubToolHandle':MyTool/PubToolHandle
MyAlg DEBUG Property ['Name': Value] = 'PrivToolHandle':MyTool/PrivToolHandle MyAlg DEBUG Property ['Name': Value] = 'PrivToolHandle':MyTool/PrivToolHandle
MyAlg DEBUG Property ['Name': Value] = 'ToolWithName':MyTool MyAlg DEBUG Property ['Name': Value] = 'ToolWithName':MyTool
...@@ -92,6 +93,12 @@ ToolSvc.PubTool... INFO Double = 100 ...@@ -92,6 +93,12 @@ ToolSvc.PubTool... INFO Double = 100
ToolSvc.PubTool... INFO String = hundred ToolSvc.PubTool... INFO String = hundred
ToolSvc.PubTool... INFO Bool = 1 ToolSvc.PubTool... INFO Bool = 1
MyAlg DEBUG Adding Public ToolHandle tool ToolSvc.PubToolHandle (MyTool) MyAlg DEBUG Adding Public ToolHandle tool ToolSvc.PubToolHandle (MyTool)
ToolSvc.Generic... INFO intialize() has been called
ToolSvc.Generic... INFO Int = 100
ToolSvc.Generic... INFO Double = 100
ToolSvc.Generic... INFO String = hundred
ToolSvc.Generic... INFO Bool = 1
MyAlg DEBUG Adding Public ToolHandle tool ToolSvc.GenericToolHandle (MyTool)
MyAlg INFO initializing.... MyAlg INFO initializing....
ToolSvc.MyTool INFO intialize() has been called ToolSvc.MyTool INFO intialize() has been called
ToolSvc.MyTool INFO Int = 201 ToolSvc.MyTool INFO Int = 201
...@@ -392,7 +399,7 @@ ToolSvc.PubTool... INFO doIt() has been called ...@@ -392,7 +399,7 @@ ToolSvc.PubTool... INFO doIt() has been called
ApplicationMgr INFO Application Manager Stopped successfully ApplicationMgr INFO Application Manager Stopped successfully
MyAlg INFO finalizing.... MyAlg INFO finalizing....
MyAlg DEBUG Finalize base class GaudiAlgorithm MyAlg DEBUG Finalize base class GaudiAlgorithm
MyAlg DEBUG Tools to release : MyAlg.PrivToolHandle ToolSvc.PubToolHandle ToolSvc.MyTool MyAlg.MyTool ToolSvc.MyGaudiTool MyAlg.MyGaudiTool MyAlg.ToolWithName MyAlg.MyGaudiTool MyAlg DEBUG Tools to release : MyAlg.PrivToolHandle ToolSvc.PubToolHandle ToolSvc.GenericToolHandle ToolSvc.MyTool MyAlg.MyTool ToolSvc.MyGaudiTool MyAlg.MyGaudiTool MyAlg.ToolWithName MyAlg.MyGaudiTool
MyAlg DEBUG Releasing tool 'MyAlg.MyGaudiTool' MyAlg DEBUG Releasing tool 'MyAlg.MyGaudiTool'
MyAlg DEBUG De-Registering tool MyAlg.MyGaudiTool MyAlg DEBUG De-Registering tool MyAlg.MyGaudiTool
MyAlg DEBUG The tool 'MyAlg.MyGaudiTool' of type 'MyGaudiTool' is released MyAlg DEBUG The tool 'MyAlg.MyGaudiTool' of type 'MyGaudiTool' is released
...@@ -411,6 +418,9 @@ MyAlg DEBUG The tool 'MyAlg.MyTool' of type 'MyTool' is released ...@@ -411,6 +418,9 @@ MyAlg DEBUG The tool 'MyAlg.MyTool' of type 'MyTool' is released
MyAlg DEBUG Releasing tool 'ToolSvc.MyTool' MyAlg DEBUG Releasing tool 'ToolSvc.MyTool'
MyAlg DEBUG De-Registering tool ToolSvc.MyTool MyAlg DEBUG De-Registering tool ToolSvc.MyTool
MyAlg DEBUG The tool 'ToolSvc.MyTool' of type 'MyTool' is released MyAlg DEBUG The tool 'ToolSvc.MyTool' of type 'MyTool' is released
MyAlg DEBUG Releasing tool 'ToolSvc.GenericToolHandle'
MyAlg DEBUG De-Registering tool ToolSvc.GenericToolHandle
MyAlg DEBUG The tool 'ToolSvc.GenericToolHandle' of type 'MyTool' is released
MyAlg DEBUG Releasing tool 'ToolSvc.PubToolHandle' MyAlg DEBUG Releasing tool 'ToolSvc.PubToolHandle'
MyAlg DEBUG De-Registering tool ToolSvc.PubToolHandle MyAlg DEBUG De-Registering tool ToolSvc.PubToolHandle
MyAlg DEBUG The tool 'ToolSvc.PubToolHandle' of type 'MyTool' is released MyAlg DEBUG The tool 'ToolSvc.PubToolHandle' of type 'MyTool' is released
...@@ -443,6 +453,7 @@ ToolSvc.ToolA DEBUG Releasing tool 'ToolSvc.ToolB' ...@@ -443,6 +453,7 @@ ToolSvc.ToolA DEBUG Releasing tool 'ToolSvc.ToolB'
ToolSvc.ToolA DEBUG De-Registering tool ToolSvc.ToolB ToolSvc.ToolA DEBUG De-Registering tool ToolSvc.ToolB
ToolSvc.ToolA DEBUG The tool 'ToolSvc.ToolB' of type 'TestTool' is released ToolSvc.ToolA DEBUG The tool 'ToolSvc.ToolB' of type 'TestTool' is released
ToolSvc.ToolA DEBUG Services to release : ToolSvc.ToolA DEBUG Services to release :
ToolSvc.Generic... INFO finalize() has been called
ToolSvc.PubTool... INFO finalize() has been called ToolSvc.PubTool... INFO finalize() has been called
MyAlg.PrivToolH... INFO finalize() has been called MyAlg.PrivToolH... INFO finalize() has been called
MyAlg.ToolWithName INFO destructor has been called MyAlg.ToolWithName INFO destructor has been called
...@@ -450,6 +461,7 @@ MyAlg.MyGaudiTool INFO destructor has been called ...@@ -450,6 +461,7 @@ MyAlg.MyGaudiTool INFO destructor has been called
ToolSvc.MyGaudi... INFO destructor has been called ToolSvc.MyGaudi... INFO destructor has been called
MyAlg.MyTool INFO destructor has been called MyAlg.MyTool INFO destructor has been called
ToolSvc.MyTool INFO destructor has been called ToolSvc.MyTool INFO destructor has been called
ToolSvc.Generic... INFO destructor has been called
ToolSvc.PubTool... INFO destructor has been called ToolSvc.PubTool... INFO destructor has been called
MyAlg.PrivToolH... INFO destructor has been called MyAlg.PrivToolH... INFO destructor has been called
ApplicationMgr INFO Application Manager Finalized successfully ApplicationMgr INFO Application Manager Finalized successfully
......
# --> Including file '/afs/cern.ch/work/l/leggett/hive/DH/Gaudi/GaudiExamples/options/AlgTools.py' # setting LC_ALL to "C"
# <-- End of file '/afs/cern.ch/work/l/leggett/hive/DH/Gaudi/GaudiExamples/options/AlgTools.py' # --> Including file '/afs/cern.ch/work/m/marcocle/workspace/Gaudi/GaudiExamples/options/AlgTools.py'
# <-- End of file '/afs/cern.ch/work/m/marcocle/workspace/Gaudi/GaudiExamples/options/AlgTools.py'
# applying configuration of GaudiExamplesCommonConf # applying configuration of GaudiExamplesCommonConf
# /***** User GaudiExamplesCommonConf/GaudiExamplesCommonConf **************************************** # /***** User GaudiExamplesCommonConf/GaudiExamplesCommonConf ****************************************
# |-OutputLevel = 3 # |-OutputLevel = 3
...@@ -7,8 +8,8 @@ ...@@ -7,8 +8,8 @@
# \----- (End of User GaudiExamplesCommonConf/GaudiExamplesCommonConf) ------------------------------- # \----- (End of User GaudiExamplesCommonConf/GaudiExamplesCommonConf) -------------------------------
ApplicationMgr SUCCESS ApplicationMgr SUCCESS
==================================================================================================================================== ====================================================================================================================================
Welcome to ApplicationMgr (GaudiCoreSvc v3r6) Welcome to ApplicationMgr (GaudiCoreSvc v4r0)
running on p05614910w96644.cern.ch on Wed Jan 13 22:59:58 2016 running on pclhcb117 on Thu Feb 11 12:52:43 2016
==================================================================================================================================== ====================================================================================================================================
ApplicationMgr INFO Application Manager Configured successfully ApplicationMgr INFO Application Manager Configured successfully
StatusCodeSvc INFO initialize StatusCodeSvc INFO initialize
...@@ -49,6 +50,11 @@ ToolSvc.TestPub... INFO Int = 100 ...@@ -49,6 +50,11 @@ ToolSvc.TestPub... INFO Int = 100
ToolSvc.TestPub... INFO Double = 100 ToolSvc.TestPub... INFO Double = 100
ToolSvc.TestPub... INFO String = Is a public tool ToolSvc.TestPub... INFO String = Is a public tool
ToolSvc.TestPub... INFO Bool = 1 ToolSvc.TestPub... INFO Bool = 1
ToolSvc.Generic... INFO intialize() has been called
ToolSvc.Generic... INFO Int = 100
ToolSvc.Generic... INFO Double = 100
ToolSvc.Generic... INFO String = hundred
ToolSvc.Generic... INFO Bool = 1
MyGaudiAlg INFO initializing.... MyGaudiAlg INFO initializing....
MyGaudiAlg.MyTool INFO intialize() has been called MyGaudiAlg.MyTool INFO intialize() has been called
MyGaudiAlg.MyTool INFO Int = 100 MyGaudiAlg.MyTool INFO Int = 100
...@@ -366,6 +372,7 @@ ToolSvc.ToolA DEBUG Releasing tool 'ToolSvc.ToolB' ...@@ -366,6 +372,7 @@ ToolSvc.ToolA DEBUG Releasing tool 'ToolSvc.ToolB'
ToolSvc.ToolA DEBUG De-Registering tool ToolSvc.ToolB ToolSvc.ToolA DEBUG De-Registering tool ToolSvc.ToolB
ToolSvc.ToolA DEBUG The tool 'ToolSvc.ToolB' of type 'TestTool' is released ToolSvc.ToolA DEBUG The tool 'ToolSvc.ToolB' of type 'TestTool' is released
ToolSvc.ToolA DEBUG Services to release : ToolSvc.ToolA DEBUG Services to release :
ToolSvc.Generic... INFO finalize() has been called
ToolSvc.TestPub... INFO finalize() has been called ToolSvc.TestPub... INFO finalize() has been called
MyGaudiAlg.Priv... INFO finalize() has been called MyGaudiAlg.Priv... INFO finalize() has been called
MyGaudiAlg.Tool... INFO destructor has been called MyGaudiAlg.Tool... INFO destructor has been called
...@@ -376,6 +383,7 @@ MyAlg.MyGaudiTool INFO destructor has been called ...@@ -376,6 +383,7 @@ MyAlg.MyGaudiTool INFO destructor has been called
MyAlg.MyTool INFO destructor has been called MyAlg.MyTool INFO destructor has been called
ToolSvc.MyGaudi... INFO destructor has been called ToolSvc.MyGaudi... INFO destructor has been called
ToolSvc.MyTool INFO destructor has been called ToolSvc.MyTool INFO destructor has been called
ToolSvc.Generic... INFO destructor has been called
ToolSvc.TestPub... INFO destructor has been called ToolSvc.TestPub... INFO destructor has been called
MyGaudiAlg.Priv... INFO destructor has been called MyGaudiAlg.Priv... INFO destructor has been called
ApplicationMgr INFO Application Manager Finalized successfully ApplicationMgr INFO Application Manager Finalized successfully
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include "GaudiKernel/IToolSvc.h" #include "GaudiKernel/IToolSvc.h"
#include "GaudiKernel/INamedInterface.h" #include "GaudiKernel/INamedInterface.h"
#include "GaudiKernel/IAlgTool.h" #include "GaudiKernel/IAlgTool.h"
//#include "GaudiKernel/SmartIF.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include <stdexcept> #include <stdexcept>
#include <type_traits>
// forward declarations // forward declarations
class IInterface; class IInterface;
...@@ -24,45 +24,30 @@ class Service; ...@@ -24,45 +24,30 @@ class Service;
/** General info and helper functions for toolhandles and arrays */ /** General info and helper functions for toolhandles and arrays */
class ToolHandleInfo { class ToolHandleInfo {
protected: protected:
ToolHandleInfo(const IInterface* parent = 0, bool createIf = true ) ToolHandleInfo(const IInterface* parent = nullptr, bool createIf = true )
: m_parent(parent), m_createIf(createIf) : m_parent(parent), m_createIf(createIf)
{} {}
public: public:
virtual ~ToolHandleInfo() {}; virtual ~ToolHandleInfo() = default;
bool isPublic() const { bool isPublic() const { return !m_parent; }
return !m_parent;
}
bool createIf() const { bool createIf() const { return m_createIf; }
return m_createIf;
}
const IInterface* parent() const { const IInterface* parent() const { return m_parent; }
return m_parent;
}
// //
// Some helper functions // Some helper functions
// //
const std::string toolComponentType( const IInterface* parent ) const { static std::string toolComponentType(const IInterface* parent) {
return parent ? "PrivateTool" : "PublicTool"; return parent ? "PrivateTool" : "PublicTool";
} }
const std::string toolParentName( const IInterface* parent ) const { static std::string toolParentName(const IInterface* parent) {
if (parent) { if (!parent) return "ToolSvc";
//SmartIF<INamedInterface> pNamed(const_cast<IInterface*>(parent));
//if (pNamed.isValid()) {
const INamedInterface* pNamed = dynamic_cast<const INamedInterface*>(parent); const INamedInterface* pNamed = dynamic_cast<const INamedInterface*>(parent);
if (pNamed) { return pNamed ? pNamed->name() : "";
return pNamed->name();
} else {
return "";
}
} else {
return "ToolSvc";
}
} }
protected: protected:
...@@ -81,17 +66,18 @@ protected: ...@@ -81,17 +66,18 @@ protected:
class BaseToolHandle: public ToolHandleInfo { class BaseToolHandle: public ToolHandleInfo {
protected: protected:
BaseToolHandle(const IInterface* parent = 0, bool createIf = true ) BaseToolHandle(const IInterface* parent = nullptr, bool createIf = true )
: ToolHandleInfo(parent, createIf) : ToolHandleInfo(parent, createIf)
{} {}
public: virtual StatusCode i_retrieve(IAlgTool*&) const = 0;
virtual ~BaseToolHandle() {};
public: public:
//Get a reference to the generic IAlgTool virtual ~BaseToolHandle() {}
virtual StatusCode retrieve( IAlgTool*& algTool ) const = 0;
StatusCode retrieve(IAlgTool*& tool) const {
return i_retrieve(tool);
}
}; };
/** @class ToolHandle ToolHandle.h GaudiKernel/ToolHandle.h /** @class ToolHandle ToolHandle.h GaudiKernel/ToolHandle.h
...@@ -107,6 +93,8 @@ public: ...@@ -107,6 +93,8 @@ public:
template< class T > template< class T >
class ToolHandle : public BaseToolHandle, public GaudiHandle<T> { class ToolHandle : public BaseToolHandle, public GaudiHandle<T> {
static_assert(std::is_base_of<IAlgTool,T>::value, "T must inherit from IAlgTool");
friend class Algorithm; friend class Algorithm;
friend class AlgTool; friend class AlgTool;
friend class Service; friend class Service;
...@@ -115,11 +103,11 @@ public: ...@@ -115,11 +103,11 @@ public:
/** Constructor for a tool with default tool type and name. /** Constructor for a tool with default tool type and name.
Can be called only if the type T is a concrete tool type (not an interface), Can be called only if the type T is a concrete tool type (not an interface),
and you want to use the default name. */ and you want to use the default name. */
ToolHandle(const IInterface* parent=0, bool createIf = true ) ToolHandle(const IInterface* parent = nullptr, bool createIf = true)
: BaseToolHandle(parent,createIf), : BaseToolHandle(parent,createIf),
GaudiHandle<T>( GaudiHandle<T>::getDefaultType(), GaudiHandle<T>( GaudiHandle<T>::getDefaultType(),
ToolHandleInfo::toolComponentType(parent), toolComponentType(parent),
ToolHandleInfo::toolParentName(parent) ), toolParentName(parent) ),
m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() ) m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
{ } { }
...@@ -147,30 +135,30 @@ public: ...@@ -147,30 +135,30 @@ public:
@param createIf: if true, create tool if not yet existing. @param createIf: if true, create tool if not yet existing.
*/ */
// #if defined(ATLAS) && defined(TOOLHANDLE_DEPR_WARN) #if defined(TOOLHANDLE_DEPR_WARN)
// //warn about using deprecated explicit ToolHandle construction //warn about using deprecated explicit ToolHandle construction
// #pragma message("Untracked ToolHandle: Migrate explicit DataHandle constructor to declareTool Algorithm Property") #pragma message("Untracked ToolHandle: Migrate explicit DataHandle constructor to declareTool Algorithm Property")
// __attribute__ ((deprecated))
// #endif __attribute__ ((deprecated))
ToolHandle(const std::string& toolTypeAndName, const IInterface* parent = 0, bool createIf = true ) #endif
ToolHandle(const std::string& toolTypeAndName,
const IInterface* parent = nullptr, bool createIf = true )
: BaseToolHandle(parent,createIf), : BaseToolHandle(parent,createIf),
GaudiHandle<T>( toolTypeAndName, GaudiHandle<T>( toolTypeAndName,
ToolHandleInfo::toolComponentType(parent), toolComponentType(parent),
ToolHandleInfo::toolParentName(parent) ), toolParentName(parent) ),
m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() ) m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
{ } { }
public: public:
StatusCode initialize(const std::string& toolTypeAndName, StatusCode initialize(const std::string& toolTypeAndName,
const IInterface* parent = 0, bool createIf = true){ const IInterface* parent = nullptr, bool createIf = true){
GaudiHandleBase::setTypeAndName(toolTypeAndName); GaudiHandleBase::setTypeAndName(toolTypeAndName);
GaudiHandleBase::setComponentType(ToolHandleInfo::toolComponentType(parent)); GaudiHandleBase::setComponentType(toolComponentType(parent));
GaudiHandleBase::setParentName(ToolHandleInfo::toolParentName(parent)); GaudiHandleBase::setParentName(toolParentName(parent));
m_parent = parent; m_parent = parent;
m_createIf = createIf; m_createIf = createIf;
...@@ -192,155 +180,23 @@ public: ...@@ -192,155 +180,23 @@ public:
return GaudiHandle<T>::release(); return GaudiHandle<T>::release();
} }
// virtual StatusCode retrieve( T*& algTool ) const;
/** Do the real retrieval of the AlgTool. */ /** Do the real retrieval of the AlgTool. */
virtual StatusCode retrieve( T*& algTool ) const { StatusCode retrieve( T*& algTool ) const override {
IAlgTool* iface = nullptr;
return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), T::interfaceID(), algTool = i_retrieve(iface) ? dynamic_cast<T*>(iface) : nullptr;
(IAlgTool*&)(algTool), return algTool ? StatusCode::SUCCESS : StatusCode::FAILURE;
ToolHandleInfo::parent(), ToolHandleInfo::createIf() );
}
/** Get a generic reference of the IAlgTool for processing in the sysInitialize. */
virtual StatusCode retrieve( IAlgTool*& algTool ) const {
//This explicit casting is required in order to properly re-interpret the <T> Tool
T * tool;
StatusCode sc = retrieve(tool);
algTool = tool;
return sc;
} }
/** Do the real release of the AlgTool. */ /** Do the real release of the AlgTool. */
virtual StatusCode release( T* algTool ) const { StatusCode release( T* algTool ) const override {
return m_pToolSvc->releaseTool( algTool ); return m_pToolSvc->releaseTool( algTool );
} }
private: protected:
// StatusCode i_retrieve(IAlgTool*& algTool) const override {
// Private data members
//
mutable ServiceHandle<IToolSvc> m_pToolSvc;
};
//-----------------------------------------------------------------------//
// specialization for IAlgTool
template<>
class ToolHandle<IAlgTool> : public BaseToolHandle, public GaudiHandle<IAlgTool> {
friend class Algorithm;
friend class AlgTool;
friend class Service;
public:
/** Constructor for a tool with default tool type and name.
Can be called only if the type T is a concrete tool type (not an interface),
and you want to use the default name. */
ToolHandle(const IInterface* parent=0, bool createIf = true )
: BaseToolHandle(parent,createIf),
GaudiHandle<IAlgTool>( GaudiHandle<IAlgTool>::getDefaultType(),
ToolHandleInfo::toolComponentType(parent),
ToolHandleInfo::toolParentName(parent) ),
m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
{ }
public:
//
// Constructors etc.
//
/** Create a handle ('smart pointer') to a tool.
The arguments are passed on to ToolSvc, and have the same meaning:
@code
StatusCode ToolSvc::retrieveTool ( const std::string& type ,
IAlgTool*& tool ,
const IInterface* parent = 0 ,
bool createIf = true )
@endcode
@param owner: class owning the ToolHandle
@param toolType: "MyToolType/MyToolName"
"MyToolType" is short for "MyToolType/MyToolType"
'MyToolType' is the name of the class of the concrete tool
'MyToolName' is to distinguish several tool instances of the same class
@param parent: the parent Algorithm,Tool or Service of which this tool is a member.
If non-zero, the the tool is a private tool of the parent, otherwise it is
a public (shared) tool.
@param createIf: if true, create tool if not yet existing.
*/
// #if defined(ATLAS) && defined(TOOLHANDLE_DEPR_WARN)
// //warn about using deprecated explicit ToolHandle construction
// #pragma message("Untracked ToolHandle: Migrate explicit DataHandle constructor to declareTool Algorithm Property")
// __attribute__ ((deprecated))
// #endif
ToolHandle(const std::string& toolTypeAndName, const IInterface* parent = 0, bool createIf = true )
: BaseToolHandle(parent,createIf),
GaudiHandle<IAlgTool>( toolTypeAndName,
ToolHandleInfo::toolComponentType(parent),
ToolHandleInfo::toolParentName(parent) ),
m_pToolSvc( "ToolSvc", GaudiHandleBase::parentName() )
{ }
public:
StatusCode initialize(const std::string& toolTypeAndName,
const IInterface* parent = 0, bool createIf = true){
GaudiHandleBase::setTypeAndName(toolTypeAndName);
GaudiHandleBase::setComponentType(ToolHandleInfo::toolComponentType(parent));
GaudiHandleBase::setParentName(ToolHandleInfo::toolParentName(parent));
m_parent = parent;
m_createIf = createIf;
StatusCode sc = m_pToolSvc.initialize("ToolSvc", GaudiHandleBase::parentName());
return sc;
}
/** Retrieve the AlgTool. Release existing tool if needed.
Function must be repeated here to avoid hiding the function retrieve( T*& ) */
StatusCode retrieve() const { // not really const, because it updates m_pObject
return GaudiHandle<IAlgTool>::retrieve();
}
/** Release the AlgTool.
Function must be repeated here to avoid hiding the function release( T*& ) */
StatusCode release() const { // not really const, because it updates m_pObject
return GaudiHandle<IAlgTool>::release();
}
/** Get a generic reference of the IAlgTool for processing in the sysInitialize. */
virtual StatusCode retrieve( IAlgTool*& algTool ) const {
return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), IAlgTool::interfaceID(), return m_pToolSvc->retrieve( GaudiHandleBase::typeAndName(), IAlgTool::interfaceID(),
(IAlgTool*&)(algTool), algTool,
ToolHandleInfo::parent(), ToolHandleInfo::createIf() ); ToolHandleInfo::parent(), ToolHandleInfo::createIf() );
//This explicit casting is required in order to properly re-interpret the <T> Tool
// IAlgTool * tool;
// StatusCode sc = retrieve(tool);
// algTool = tool;
// return sc;
}
/** Do the real release of the AlgTool. */
virtual StatusCode release( IAlgTool* algTool ) const {
return m_pToolSvc->releaseTool( algTool );
} }
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment