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

fix ToolHandle initialization in AlgTools and Algorithms

(from Attila)
The current implementation in these functions instantiates
duplicate tools when we declare a public ToolHandleArray as
a property to an algorithm or a tool. This modification
fixes the duplication in the ATN tests that the error
originally showed up in.

See merge request !158
parents 32fdc558 54b8fc41
No related branches found
No related tags found
1 merge request!158fix ToolHandle initialization in AlgTools and Algorithms
Pipeline #
......@@ -468,27 +468,51 @@ void AlgTool::initToolHandles() const{
} else {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << "Registering all Tools in ToolHandleArray "
<< thArr->propertyName() ;
for (auto th_name : thArr->typesAndNames()) {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << std::endl << " + " << th_name;
if (toolSvc()->retrieveTool(th_name, tool, this).isSuccess()) {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << " (private)";
m_tools.push_back(tool);
} else if (toolSvc()->retrieveTool(th_name, tool, 0).isSuccess()) {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << " (public)";
m_tools.push_back(tool);
} else {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << " - ERROR" << endmsg;
warning() << "Error retrieving Tool " << th_name
<< " in ToolHandleArray" << thArr->propertyName()
<< ". Not registered" << endmsg;
}
<< thArr->propertyName() << endmsg;
// Iterate over its tools:
for( auto toolHandle : thArr->getBaseArray() ) {
// Try to cast it into a BaseToolHandle pointer:
BaseToolHandle* bth = dynamic_cast< BaseToolHandle* >( toolHandle );
if( bth ) {
// If the cast was successful, the code is pretty simple:
tool = bth->get();
if( UNLIKELY( msgLevel( MSG::DEBUG ) ) ) {
debug() << "Adding "
<< ( bth->isPublic() ? "public" : "private" )
<< " ToolHandle tool " << tool->name()
<< " (" << tool->type() << ") from ToolHandleArray "
<< thArr->propertyName() << endmsg;
}
m_tools.push_back( tool );
} else {
// If it wasn't for some strange reason, then fall back on the
// logic implemented previously:
if( toolSvc()->retrieveTool( toolHandle->typeAndName(), tool,
this, false ).isSuccess() ) {
if( UNLIKELY( msgLevel( MSG::DEBUG ) ) ) {
debug() << "Adding private"
<< " ToolHandle tool " << tool->name()
<< " (" << tool->type() << ") from ToolHandleArray "
<< thArr->propertyName() << endmsg;
}
m_tools.push_back( tool );
} else if( toolSvc()->retrieveTool( toolHandle->typeAndName(), tool,
0, false ).isSuccess() ) {
if( UNLIKELY( msgLevel( MSG::DEBUG ) ) ) {
debug() << "Adding public"
<< " ToolHandle tool " << tool->name()
<< " (" << tool->type() << ") from ToolHandleArray "
<< thArr->propertyName() << endmsg;
}
m_tools.push_back( tool );
} else {
warning() << "Error retrieving Tool "
<< toolHandle->typeAndName()
<< " in ToolHandleArray " << thArr->propertyName()
<< ". Not registered" << endmsg;
}
}
}
if (UNLIKELY(msgLevel(MSG::DEBUG))) debug() << endmsg;
}
}
......
......@@ -1013,27 +1013,51 @@ void Algorithm::initToolHandles() const{
} else {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << "Registering all Tools in ToolHandleArray "
<< thArr->propertyName() ;
for (auto th_name : thArr->typesAndNames()) {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << std::endl << " + " << th_name;
if (toolSvc()->retrieveTool(th_name, tool, this).isSuccess()) {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << " (private)";
m_tools.push_back(tool);
} else if (toolSvc()->retrieveTool(th_name, tool, 0).isSuccess()) {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << " (public)";
m_tools.push_back(tool);
} else {
if (UNLIKELY(msgLevel(MSG::DEBUG)))
debug() << " - ERROR" << endmsg;
warning() << "Error retrieving Tool " << th_name
<< " in ToolHandleArray" << thArr->propertyName()
<< ". Not registered" << endmsg;
}
<< thArr->propertyName() << endmsg;
// Iterate over its tools:
for( auto toolHandle : thArr->getBaseArray() ) {
// Try to cast it into a BaseToolHandle pointer:
BaseToolHandle* bth = dynamic_cast< BaseToolHandle* >( toolHandle );
if( bth ) {
// If the cast was successful, the code is pretty simple:
tool = bth->get();
if( UNLIKELY( msgLevel( MSG::DEBUG ) ) ) {
debug() << "Adding "
<< ( bth->isPublic() ? "public" : "private" )
<< " ToolHandle tool " << tool->name()
<< " (" << tool->type() << ") from ToolHandleArray "
<< thArr->propertyName() << endmsg;
}
m_tools.push_back( tool );
} else {
// If it wasn't for some strange reason, then fall back on the
// logic implemented previously:
if( toolSvc()->retrieveTool( toolHandle->typeAndName(), tool,
this, false ).isSuccess() ) {
if( UNLIKELY( msgLevel( MSG::DEBUG ) ) ) {
debug() << "Adding private"
<< " ToolHandle tool " << tool->name()
<< " (" << tool->type() << ") from ToolHandleArray "
<< thArr->propertyName() << endmsg;
}
m_tools.push_back( tool );
} else if( toolSvc()->retrieveTool( toolHandle->typeAndName(), tool,
0, false ).isSuccess() ) {
if( UNLIKELY( msgLevel( MSG::DEBUG ) ) ) {
debug() << "Adding public"
<< " ToolHandle tool " << tool->name()
<< " (" << tool->type() << ") from ToolHandleArray "
<< thArr->propertyName() << endmsg;
}
m_tools.push_back( tool );
} else {
warning() << "Error retrieving Tool "
<< toolHandle->typeAndName()
<< " in ToolHandleArray " << thArr->propertyName()
<< ". Not registered" << endmsg;
}
}
}
if (UNLIKELY(msgLevel(MSG::DEBUG))) debug() << endmsg;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment