Commit 8d739107 authored by Charles Leggett's avatar Charles Leggett Committed by Marco Clemencic
Browse files

ToolHandle: throw exception if retrieval fails

parent d31c533b
......@@ -49,6 +49,19 @@ StatusCode MyGaudiAlgorithm::initialize()
info() << m_selectedTracks.objKey() << endmsg;
// m_wrongIfaceTool is being retrieved via the wrong interface.
// we expect the retrieve() to throw an exception.
try {
if ( m_wrongIfaceTool.retrieve().isFailure() ) {
error() << "unable to retrieve " << m_wrongIfaceTool.typeAndName() << " (unexpected)" << endmsg;
m_wrongIfaceTool.disable();
}
} catch ( GaudiException& ex ) {
info() << "unable to retrieve " << m_wrongIfaceTool.typeAndName() << " (expected) with exception: " << ex.what()
<< endmsg;
m_wrongIfaceTool.disable();
}
info() << "....initialization done" << endmsg;
return sc;
......
......@@ -53,6 +53,8 @@ private:
ToolHandle<IMyTool> m_undefinedToolHandle{this};
ToolHandle<IMyTool> m_invalidToolHandle{this, "InvalidToolHandle", "TestToolFailing"};
ToolHandle<IMyOtherTool> m_wrongIfaceTool{this, "WrongIfaceTool", "MyTool/WrongIfaceTool"};
PublicToolHandle<const IMyTool> m_myConstToolHandle{"MyTool/ConstGenericToolHandle"};
PublicToolHandle<const IMyTool> m_myCopiedConstToolHandle;
......
......@@ -25,6 +25,7 @@ expected = set(['ToolSvc.MyTool',
'MyGaudiAlg.MyGaudiTool',
'MyGaudiAlg.ToolWithName',
'MyGaudiAlg.PrivToolHandle',
'MyGaudiAlg.WrongIfaceTool',
'ToolSvc.TestPubToolHandle',
'ToolSvc.GenericToolHandle',
'ToolSvc.ConstGenericToolHandle',
......
JobOptionsSvc INFO # =======> /scratch/fwinkl/Gaudi/src/GaudiExamples/options/Services.opts
JobOptionsSvc INFO # =======> /bld2/leggett/work/ToolRetrieveError/gaudi/gsrc/GaudiExamples/options/Services.opts
JobOptionsSvc INFO # (12,1): AuditorSvc.Auditors = ["ChronoAuditor"]
JobOptionsSvc INFO # =======> /scratch/fwinkl/Gaudi/src/GaudiExamples/options/Common.opts
JobOptionsSvc INFO # =======> /bld2/leggett/work/ToolRetrieveError/gaudi/gsrc/GaudiExamples/options/Common.opts
JobOptionsSvc INFO # (9,1): ApplicationMgr.StatusCodeCheck = 1
JobOptionsSvc INFO # =======> /scratch/fwinkl/Gaudi/src/GaudiExamples/options/AlgTools2.opts
JobOptionsSvc INFO # =======> /bld2/leggett/work/ToolRetrieveError/gaudi/gsrc/GaudiExamples/options/AlgTools2.opts
JobOptionsSvc INFO # (10,1): ApplicationMgr.TopAlg = ["MyGaudiAlgorithm/MyAlg"]
JobOptionsSvc INFO # (13,1): MessageSvc.OutputLevel = 3
JobOptionsSvc INFO # (18,1): ApplicationMgr.EvtMax = 10
......@@ -24,24 +24,25 @@ JobOptionsSvc INFO # (46,1): ToolSvc.ToolA.Tools = ["TestTool/ToolB"]
JobOptionsSvc INFO # (47,1): ToolSvc.ToolB.Tools = ["TestTool/ToolA"]
JobOptionsSvc INFO # (48,1): ToolSvc.ToolA.OutputLevel = 2
JobOptionsSvc INFO # (49,1): ToolSvc.ToolB.OutputLevel = 2
JobOptionsSvc INFO Job options successfully read in from /home/marco/Devel/LHCb/workspace/Gaudi/GaudiExamples/options/AlgTools2.opts
JobOptionsSvc INFO Job options successfully read in from /bld2/leggett/work/ToolRetrieveError/gaudi/gsrc/GaudiExamples/options/AlgTools2.opts
ApplicationMgr SUCCESS
====================================================================================================================================
Welcome to ApplicationMgr (GaudiCoreSvc v29r0)
running on pc-tbed-pub-13.cern.ch on Mon Aug 14 15:59:47 2017
Welcome to ApplicationMgr (GaudiCoreSvc v30r1)
running on zeus on Mon Jan 29 11:30:04 2018
====================================================================================================================================
ApplicationMgr INFO Application Manager Configured successfully
StatusCodeSvc INFO initialize
MyAlg DEBUG Property update for OutputLevel : new value = 2
MyAlg DEBUG Initialize base class GaudiCommon<Algorithm>
MyAlg DEBUG could not locate CounterSummarySvc, no counter summary will be made
MyAlg DEBUG List of ALL properties of MyGaudiAlgorithm/MyAlg #properties = 48
MyAlg DEBUG List of ALL properties of MyGaudiAlgorithm/MyAlg #properties = 49
MyAlg DEBUG Property ['Name': Value] = 'UndefinedToolHandle':
MyAlg DEBUG Property ['Name': Value] = 'LegacyToolHandle':MyTool/LegacyToolHandle
MyAlg DEBUG Property ['Name': Value] = 'trackSelection':/Event/MyAnalysis/Tracks
MyAlg DEBUG Property ['Name': Value] = 'raw':/Rec/RAW
MyAlg DEBUG Property ['Name': Value] = 'hits':/Event/Rec/Hits
MyAlg DEBUG Property ['Name': Value] = 'tracks':/Event/Rec/Tracks
MyAlg DEBUG Property ['Name': Value] = 'WrongIfaceTool':MyTool/WrongIfaceTool
MyAlg DEBUG Property ['Name': Value] = 'InvalidToolHandle':
MyAlg DEBUG Property ['Name': Value] = 'UnusedToolHandle':TestToolFailing/UnusedToolHandle
MyAlg DEBUG Property ['Name': Value] = 'GenericToolHandle':MyTool/GenericToolHandle
......@@ -154,6 +155,13 @@ MyAlg INFO /Event/Rec/Tracks
MyAlg INFO /Event/Rec/Hits
MyAlg INFO /Rec/RAW
MyAlg INFO /Event/MyAnalysis/Tracks
MyAlg.WrongIfac... DEBUG Property update for OutputLevel : new value = 2
MyAlg.WrongIfac... INFO intialize() has been called
MyAlg.WrongIfac... INFO Int = 100
MyAlg.WrongIfac... INFO Double = 100
MyAlg.WrongIfac... INFO String = hundred
MyAlg.WrongIfac... INFO Bool = 1
MyAlg INFO unable to retrieve MyTool/WrongIfaceTool (expected) with exception: unable to dcast AlgTool MyTool/WrongIfaceTool to interface IMyOtherTool
MyAlg INFO ....initialization done
MyAlg DEBUG input handles: 3
MyAlg DEBUG output handles: 1
......@@ -177,6 +185,7 @@ ToolSvc.Generic... INFO String = hundred
ToolSvc.Generic... INFO Bool = 1
MyAlg DEBUG Adding public ToolHandle tool ToolSvc.GenericToolHandle (MyTool)
MyAlg DEBUG ToolHandle TestToolFailing/UnusedToolHandle not used
MyAlg DEBUG ToolHandle MyTool/WrongIfaceTool not used
MyAlg.LegacyToo... DEBUG Property update for OutputLevel : new value = 2
MyAlg.LegacyToo... INFO intialize() has been called
MyAlg.LegacyToo... INFO Int = 100
......@@ -572,6 +581,7 @@ ToolSvc.ToolA DEBUG The tool 'ToolSvc.ToolB' of type 'TestTool' is release
ToolSvc.ToolA DEBUG Services to release :
MyAlg.LegacyToo... INFO finalize() has been called
ToolSvc.Generic... INFO finalize() has been called
MyAlg.WrongIfac... INFO finalize() has been called
MyAlg.PrivToolH... INFO finalize() has been called
ToolSvc.ConstGe... INFO finalize() has been called
ToolSvc.PubTool... INFO finalize() has been called
......@@ -582,6 +592,7 @@ MyAlg.MyTool INFO destructor has been called
ToolSvc.MyTool INFO destructor has been called
MyAlg.LegacyToo... INFO destructor has been called
ToolSvc.Generic... INFO destructor has been called
MyAlg.WrongIfac... INFO destructor has been called
MyAlg.PrivToolH... INFO destructor has been called
ToolSvc.ConstGe... INFO destructor has been called
ToolSvc.PubTool... INFO destructor has been called
......
# setting LC_ALL to "C"
# --> Including file '/var/clus/usera/jonesc/LHCbCMake/Gaudi/GaudiExamples/options/AlgTools.py'
# <-- End of file '/var/clus/usera/jonesc/LHCbCMake/Gaudi/GaudiExamples/options/AlgTools.py'
# --> Including file '/bld2/leggett/work/ToolRetrieveError/gaudi/gsrc/GaudiExamples/options/AlgTools.py'
# <-- End of file '/bld2/leggett/work/ToolRetrieveError/gaudi/gsrc/GaudiExamples/options/AlgTools.py'
# applying configuration of GaudiExamplesCommonConf
# /***** User GaudiExamplesCommonConf/GaudiExamplesCommonConf ****************************************
# |-OutputLevel = 3
......@@ -8,8 +8,8 @@
# \----- (End of User GaudiExamplesCommonConf/GaudiExamplesCommonConf) -------------------------------
ApplicationMgr SUCCESS
====================================================================================================================================
Welcome to ApplicationMgr (GaudiCoreSvc v27r1)
running on pcmf on Mon Oct 31 14:20:24 2016
Welcome to ApplicationMgr (GaudiCoreSvc v30r1)
running on zeus on Mon Jan 29 11:30:05 2018
====================================================================================================================================
ApplicationMgr INFO Application Manager Configured successfully
StatusCodeSvc INFO initialize
......@@ -60,6 +60,12 @@ MyGaudiAlg INFO /Event/Rec/Tracks
MyGaudiAlg INFO /Event/Rec/Hits
MyGaudiAlg INFO /Rec/RAW
MyGaudiAlg INFO /Event/MyAnalysis/Tracks
MyGaudiAlg.Wron... INFO intialize() has been called
MyGaudiAlg.Wron... INFO Int = 100
MyGaudiAlg.Wron... INFO Double = 100
MyGaudiAlg.Wron... INFO String = hundred
MyGaudiAlg.Wron... INFO Bool = 1
MyGaudiAlg INFO unable to retrieve MyTool/WrongIfaceTool (expected) with exception: unable to dcast AlgTool MyTool/WrongIfaceTool to interface IMyOtherTool
MyGaudiAlg INFO ....initialization done
MyGaudiAlg.Priv... INFO intialize() has been called
MyGaudiAlg.Priv... INFO Int = 100
......@@ -479,6 +485,7 @@ ToolSvc.ToolA DEBUG The tool 'ToolSvc.ToolB' of type 'TestTool' is release
ToolSvc.ToolA DEBUG Services to release :
MyGaudiAlg.Lega... INFO finalize() has been called
ToolSvc.Generic... INFO finalize() has been called
MyGaudiAlg.Wron... INFO finalize() has been called
ToolSvc.PubTool... INFO finalize() has been called
ToolSvc.TestPub... INFO finalize() has been called
MyGaudiAlg.Priv... INFO finalize() has been called
......@@ -493,6 +500,7 @@ ToolSvc.MyGaudi... INFO destructor has been called
ToolSvc.MyTool INFO destructor has been called
MyGaudiAlg.Lega... INFO destructor has been called
ToolSvc.Generic... INFO destructor has been called
MyGaudiAlg.Wron... INFO destructor has been called
ToolSvc.PubTool... INFO destructor has been called
ToolSvc.TestPub... INFO destructor has been called
MyGaudiAlg.Priv... INFO destructor has been called
......
......@@ -250,8 +250,17 @@ public:
StatusCode retrieve( T*& algTool ) const override
{
IAlgTool* iface = nullptr;
algTool = i_retrieve( iface ) ? dynamic_cast<T*>( iface ) : nullptr;
return algTool ? StatusCode::SUCCESS : StatusCode::FAILURE;
if ( i_retrieve( iface ).isFailure() ) {
return StatusCode::FAILURE;
}
algTool = dynamic_cast<T*>( iface );
if ( algTool == nullptr ) {
throw GaudiException( "unable to dcast AlgTool " + typeAndName() + " to interface " +
System::typeinfoName( typeid( T ) ),
typeAndName() + " retrieve", StatusCode::FAILURE );
}
return StatusCode::SUCCESS;
}
/** Do the real release of the AlgTool. */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment