Skip to content
Snippets Groups Projects

Exit gracefully if no IDVAlgorithm is found

Closed Patrick Koppenburg requested to merge pkoppenb-IDVAlgorithm into master
/*****************************************************************************\
* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration *
* *
@@ -62,20 +63,31 @@ namespace {
} // namespace
// ============================================================================
IDVAlgorithm* Gaudi::Utils::getIDVAlgorithm( const IAlgContextSvc* svc ) {
if ( !svc ) { return NULL; } // RETURN
if ( !svc ) {
throw GaudiException( "Cannot find IAlgContextSvc. You probably cannot use this tool/functor in this context",
"Gaudi::Utils::getIDVAlgorithm", StatusCode::FAILURE );
}
// use context service:
IAlgorithm* alg = Gaudi::Utils::getAlgorithm( svc, IDVSelector() );
if ( !alg ) { return NULL; } // RETURN
return SmartIF<IDVAlgorithm>( alg );
if ( !alg ) {
throw GaudiException( "Cannot find IAlgorithm. You probably cannot use this tool/functor in this context",
"Gaudi::Utils::getIDVAlgorithm", StatusCode::FAILURE );
}
IDVAlgorithm* idv = SmartIF<IDVAlgorithm>( alg );
if ( !idv ) {
throw GaudiException( "Cannot find IDVAlgorithm. You probably cannot use this tool/functor in this context",
"Gaudi::Utils::getIDVAlgorithm", StatusCode::FAILURE );
}
return idv;
}
// ============================================================================
IDVAlgorithm* Gaudi::Utils::getIDVAlgorithm( const IAlgContextSvc* svc, const IAlgTool* tool ) {
if ( !tool ) { return NULL; }
if ( !tool ) { return nullptr; }
// Recurse down the ownership tree, to see with we ever end up at the ToolSvc
bool ownedByToolSvc = false;
unsigned int sanityCheck( 0 );
while ( tool && ++sanityCheck < 9999 ) {
ownedByToolSvc = ( NULL != dynamic_cast<const IToolSvc*>( tool->parent() ) );
ownedByToolSvc = ( nullptr != dynamic_cast<const IToolSvc*>( tool->parent() ) );
if ( ownedByToolSvc ) { break; }
// if parent is also a tool, try again
tool = dynamic_cast<const IAlgTool*>( tool->parent() );
Loading