Commit 4a6a0176 authored by Nils Erik Krumnack's avatar Nils Erik Krumnack Committed by Nils Krumnack
Browse files

rework subtools in AsgComponentConfig (was wrap AnaToolHandle around AsgToolConfig)

Since I'm back-porting to 21.2 I didn't modify the AnaToolHandle
implementation, but I did update AsgComponentConfig accordingly.

Original commit message:

The basic reasoning here is that AnaToolHandle is essentially the
out-dated and discouraged mechanism for creating tools, and has been
replaced with AsgToolConfig for quite a while (or alternatively
indirectly via AnaAlgorithmConfig).

I did have to disable some Athena tests for setting sub-tools in
Athena.  There are already some of those disabled, and the basic logic
is that since this is the legacy way of doing things, unless this
breaks existing code (as verified by CI tests) I no longer want to
support all the possible edge cases in this rather brittle and complex
piece of code.
parent fa68ca0d
......@@ -30,6 +30,8 @@ namespace asg
declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail");
++ instance_counts (name());
ANA_MSG_INFO ("create UnitTestTool1 " << this);
}
......@@ -37,6 +39,8 @@ namespace asg
UnitTestTool1 ::
~UnitTestTool1 ()
{
ANA_MSG_INFO ("destroy UnitTestTool1 " << this);
-- instance_counts (name());
}
......@@ -46,6 +50,11 @@ namespace asg
initialize ()
{
m_origMsgLevel = msg().level();
ANA_MSG_INFO ("initialize UnitTestTool1 " << this);
ANA_MSG_INFO (" propertyString: " << m_propertyString);
ANA_MSG_INFO (" propertyInt: " << m_propertyInt);
if (m_initializeFail)
{
ATH_MSG_ERROR ("tool configured to fail initialize");
......
......@@ -1067,14 +1067,14 @@ namespace asg
std::make_tuple ("anaPublicHandle", "public", "ATH"),
std::make_tuple ("regPublicHandle", "public", "TH"),
std::make_tuple ("anaPublicHandle", "public", "TH"),
std::make_tuple ("regPublicHandle", "public", "NOINIT"),
std::make_tuple ("anaPublicHandle", "public", "NOINIT"),
std::make_tuple ("regPublicHandle", "public", "empty"),
std::make_tuple ("anaPublicHandle", "public", "empty"),
std::make_tuple ("regPrivateHandle", "private", "ATH"),
std::make_tuple ("anaPrivateHandle", "private", "ATH"),
std::make_tuple ("regPrivateHandle", "private", "TH"),
std::make_tuple ("anaPrivateHandle", "private", "TH"),
std::make_tuple ("regPublicHandle", "public", "NOINIT"),
std::make_tuple ("anaPublicHandle", "public", "NOINIT"),
std::make_tuple ("regPrivateHandle", "private", "NOINIT"),
std::make_tuple ("anaPrivateHandle", "private", "NOINIT"),
std::make_tuple ("regPrivateHandle", "private", "empty"),
......
......@@ -141,6 +141,34 @@ namespace asg
TEST (AsgToolConfigTest, basic_subtoolConfigureIndirect)
{
const std::string name = makeUniqueName();
AsgToolConfig config ("asg::UnitTestTool2/" + name);
{
AsgToolConfig subconfig ("asg::UnitTestTool1A");
subconfig.setPropertyFromString ("propertyInt", "17");
ASSERT_SUCCESS (config.addPrivateTool ("regPrivateHandle", subconfig));
}
{
AsgToolConfig subconfig ("asg::UnitTestTool1A");
subconfig.setPropertyFromString ("propertyInt", "42");
ASSERT_SUCCESS (config.addPrivateTool ("anaPrivateHandle", subconfig));
}
std::shared_ptr<void> cleanup;
ToolHandle<IUnitTestTool2> tool;
ASSERT_SUCCESS (config.makeTool (tool, cleanup));
EXPECT_EQ ("ToolSvc." + name, tool->name());
EXPECT_SUCCESS (tool->retrieveToolHandle("regPrivateHandle"));
EXPECT_TRUE (tool->getToolHandle ("regPrivateHandle")->isInitialized());
EXPECT_EQ (17, tool->getToolHandle ("regPrivateHandle")->getPropertyInt());
EXPECT_TRUE (tool->wasUserConfigured("anaPrivateHandle"));
EXPECT_TRUE (tool->getToolHandle ("anaPrivateHandle")->isInitialized());
EXPECT_EQ (42, tool->getToolHandle ("anaPrivateHandle")->getPropertyInt());
}
TEST (AsgToolConfigTest, privateTool)
{
const std::string name1 = makeUniqueName();
......
......@@ -19,6 +19,7 @@ class StatusCode;
namespace asg
{
class AsgComponent;
class AsgToolConfig;
}
namespace asg
......@@ -50,6 +51,13 @@ namespace asg
explicit AsgComponentConfig (const std::string& val_typeAndName);
/// \brief whether all properties are unset
/// \par Guarantee
/// no-fail
public:
bool empty () const noexcept;
/// \brief the type of the component
/// \par Guarantee
/// no-fail
......
......@@ -64,6 +64,14 @@ namespace asg
/// updated to at the very least work on a ToolHandle, but so far
/// this code isn't even dual-use.
///
/// The argument `allowNestedName` should probably be omitted in
/// most cases. I mostly added it to allow AnaToolHandle to
/// create new tools via an AsgToolConfig (06 Jan 21), for which a
/// number of existing users rely on making nested names. Usually
/// when you want a nested name you ought to set the parent on the
/// `ToolHandle` and then use a non-nested name for the name of
/// the config.
///
/// \par Guarantee
/// basic
/// \par Failures
......@@ -72,7 +80,8 @@ namespace asg
public:
template<typename T> ::StatusCode
makeTool (ToolHandle<T>& toolHandle,
std::shared_ptr<void>& cleanup) const;
std::shared_ptr<void>& cleanup,
bool allowNestedName = false) const;
/// \brief make a private tool with the given configuration
......@@ -113,14 +122,15 @@ namespace asg
template<typename T> ::StatusCode AsgToolConfig ::
makeTool (ToolHandle<T>& toolHandle,
std::shared_ptr<void>& cleanup) const
std::shared_ptr<void>& cleanup,
bool allowNestedName) const
{
using namespace msgComponentConfig;
std::string prefix = toolHandle.parentName() + ".";
std::unique_ptr<T> tool;
ANA_CHECK (makeComponentExpert (tool, "new %1% (\"%2%\")", false, prefix));
ANA_CHECK (makeComponentExpert (tool, "new %1% (\"%2%\")", allowNestedName, prefix));
ANA_CHECK (tool->initialize());
std::shared_ptr<T> mycleanup (tool.release());
......@@ -160,13 +170,14 @@ namespace asg
template<typename T> ::StatusCode AsgToolConfig ::
makeTool (ToolHandle<T>& toolHandle,
std::shared_ptr<void>& /*cleanup*/) const
std::shared_ptr<void>& /*cleanup*/,
bool allowNestedName) const
{
using namespace msgComponentConfig;
std::string prefix = toolHandle.parentName() + ".";
ANA_CHECK (configureComponentExpert (prefix, false));
ANA_CHECK (configureComponentExpert (prefix, allowNestedName));
toolHandle.setTypeAndName (type() + "/" + name());
ANA_CHECK (toolHandle.retrieve());
......
......@@ -12,6 +12,7 @@
#include <AsgTools/AsgComponentConfig.h>
#include <AsgTools/AsgToolConfig.h>
#include <regex>
#ifdef XAOD_STANDALONE
......@@ -58,6 +59,16 @@ namespace asg
bool AsgComponentConfig ::
empty () const noexcept
{
return
m_type.empty() && m_name.empty() &&
m_privateTools.empty() && m_propertyValues.empty();
}
const std::string& AsgComponentConfig ::
type () const noexcept
{
......@@ -351,7 +362,11 @@ namespace asg
if (std::get<1>(tool.second).empty())
{
std::string toolPath = prefix + m_name + "." + tool.first;
joSvc->set (toolPath, std::get<0>(tool.second).typeAndName());
const auto split = toolPath.rfind ('.');
std::string toolName = toolPath.substr (split+1);
std::string componentName = toolPath.substr (0, split);
StringProperty athenaProperty (toolName, std::get<0>(tool.second).typeAndName());
ANA_CHECK (joSvc->addPropertyToCatalogue (componentName, std::move (athenaProperty)));
}
}
......@@ -365,7 +380,11 @@ namespace asg
}
std::string valueString = Gaudi::Utils::toString (valueArray);
std::string propertyPath = prefix + m_name + "." + toolArray.first;
joSvc->set (propertyPath, valueString);
const auto split = propertyPath.rfind ('.');
std::string propertyName = propertyPath.substr (split+1);
std::string componentName = propertyPath.substr (0, split);
StringProperty athenaProperty (propertyName, valueString);
ANA_CHECK (joSvc->addPropertyToCatalogue (componentName, std::move (athenaProperty)));
}
for (const auto& property : m_propertyValues)
......
Markdown is supported
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