Commit 69734abb authored by John Derek Chapman's avatar John Derek Chapman
Browse files

Merge branch 'Merge21.0.37into21.3' into '21.3'

Merge 21.0.37 into 21.3 branch

See merge request !4608

Former-commit-id: 312cb3e33522f889d4a1a9f770997aa9bb0624ab
parents 0b3112f9 f02136b6
// Dear emacs, this is -*- c++ -*-
// $Id: AsgExampleToolsDict.h 744643 2016-05-03 19:12:00Z krumnack $
// $Id: AsgExampleToolsDict.h 773002 2016-09-13 13:21:21Z krumnack $
#ifndef ASGTOOLS_ASGTOOLSDICT_H
#define ASGTOOLS_ASGTOOLSDICT_H
......@@ -7,6 +7,7 @@
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "AsgExampleTools/UnitTestTool3.h"
#include "AsgExampleTools/UnitTestTool2.h"
#include "AsgExampleTools/UnitTestTool1A.h"
......
......@@ -12,6 +12,7 @@
#include <AsgTools/IAsgTool.h>
#include <AsgTools/MsgLevel.h>
namespace asg
{
......@@ -22,6 +23,10 @@ namespace asg
// Declare the interface that this class provides
ASG_TOOL_INTERFACE( CP::IUnitTestTool1 )
/// \brief get the integer property
public:
virtual std::string getPropertyString () const = 0;
/// \brief get the integer property
public:
virtual int getPropertyInt () const = 0;
......@@ -33,6 +38,10 @@ namespace asg
/// \brief get whether we have been initialized
public:
virtual bool isInitialized () const = 0;
/// \brief the message level during initialize()
public:
virtual MSG::Level getOrigMsgLevel () const = 0;
};
}
......
......@@ -24,9 +24,14 @@ namespace asg
// Declare the interface that this class provides
ASG_TOOL_INTERFACE( CP::IUnitTestTool2 )
/// \brief whether the given ToolHandle is empty
public:
virtual bool
toolHandleEmpty (const std::string& handleName) const = 0;
/// \brief get the tool from the regular ToolHandle
public:
virtual IUnitTestTool1 *
virtual const IUnitTestTool1 *
getToolHandle (const std::string& handleName) const = 0;
/// \brief call retrieve on the regular ToolHandle
......
#ifndef ASG_TOOLS__I_UNIT_TEST_TOOL3_H
#define ASG_TOOLS__I_UNIT_TEST_TOOL3_H
// Copyright Iowa State University 2016.
// Author: Nils Krumnack
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Please feel free to contact me (nils.erik.krumnack@cern.ch) for bug
// reports, feature suggestions, praise and complaints.
#include <AsgTools/IAsgTool.h>
namespace asg
{
class IUnitTestTool1;
/// \brief the interface for \ref UnitTestTool3
class IUnitTestTool3 : virtual public IAsgTool
{
// Declare the interface that this class provides
ASG_TOOL_INTERFACE( CP::IUnitTestTool3 )
/// \brief get the subtool we configured
public:
virtual const IUnitTestTool1 *getSubtool () const = 0;
/// \brief get whether the subtool configured for our subtool is empty
public:
virtual bool subsubtoolEmpty () const = 0;
/// \brief get the subtool configured for our subtool
public:
virtual const IUnitTestTool1 *getSubsubtool () const = 0;
};
}
#endif
......@@ -30,9 +30,16 @@ namespace asg
public:
UnitTestTool1 (const std::string& val_name);
/// \brief standard destructor
public:
~UnitTestTool1 ();
public:
StatusCode initialize () override;
public:
virtual std::string getPropertyString () const override;
public:
virtual int getPropertyInt () const override;
......@@ -42,10 +49,18 @@ namespace asg
public:
virtual bool isInitialized () const override;
public:
virtual MSG::Level getOrigMsgLevel () const override;
/// \brief whether initialize has been called
public:
bool m_isInitialized = false;
/// \brief the string property
public:
std::string m_propertyString;
/// \brief the integer property
public:
int m_propertyInt = 0;
......@@ -53,6 +68,15 @@ namespace asg
/// \brief whether initialize should fail
public:
bool m_initializeFail = false;
/// \brief the message level at initialize
public:
MSG::Level m_origMsgLevel = MSG::INFO;
/// \brief the number of times the tool of the given name has been
/// instantiated
public:
static int& instance_counts (const std::string& name);
};
}
......
......@@ -33,6 +33,9 @@ namespace asg
public:
StatusCode initialize () override;
public:
virtual std::string getPropertyString () const override;
public:
virtual int getPropertyInt () const override;
......@@ -42,14 +45,25 @@ namespace asg
public:
virtual bool isInitialized () const override;
public:
virtual MSG::Level getOrigMsgLevel () const override;
/// \brief whether initialize has been called
public:
bool m_isInitialized = false;
/// \brief the string property
public:
std::string m_propertyString;
/// \brief the integer property
public:
int m_propertyInt = -7;
/// \brief the message level at initialize
public:
MSG::Level m_origMsgLevel = MSG::INFO;
/// \brief whether initialize should fail
public:
bool m_initializeFail = false;
......
......@@ -35,7 +35,11 @@ namespace asg
StatusCode initialize () override;
public:
virtual IUnitTestTool1 *
virtual bool
toolHandleEmpty (const std::string& handleName) const override;
public:
virtual const IUnitTestTool1 *
getToolHandle (const std::string& handleName) const override;
public:
......@@ -63,6 +67,9 @@ namespace asg
private:
bool m_wasUserConfiguredPrivate = false;
private:
bool m_allowEmpty = false;
};
}
......
#ifndef ASG_TOOLS__UNIT_TEST_TOOL3_H
#define ASG_TOOLS__UNIT_TEST_TOOL3_H
// Copyright Iowa State University 2016.
// Author: Nils Krumnack
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Please feel free to contact me (nils.erik.krumnack@cern.ch) for bug
// reports, feature suggestions, praise and complaints.
#include <AsgTools/AnaToolHandle.h>
#include <AsgTools/AsgTool.h>
#include <AsgExampleTools/IUnitTestTool3.h>
namespace asg
{
class IUnitTestTool2;
/// \brief a tool used to unit test AnaToolHandle
///
/// This allows to unit test that I can use an AnaToolHandle
/// property to provide a customization point to the user and then
/// pass it on as a property to another tool it holds and creates
/// via an AnaToolHandle.
struct UnitTestTool3 : virtual public IUnitTestTool3,
public AsgTool
{
ASG_TOOL_CLASS (UnitTestTool3, IUnitTestTool3)
/// \brief standard constructor
public:
UnitTestTool3 (const std::string& val_name);
public:
StatusCode initialize () override;
/// \brief get the subtool we configured
public:
virtual const IUnitTestTool1 *getSubtool () const override;
/// \brief get the subtool configured for our subtool
public:
virtual const IUnitTestTool1 *getSubsubtool () const override;
public:
virtual bool subsubtoolEmpty () const override;
/// \brief a public tool handle the tool the user configures
private:
ToolHandle<IUnitTestTool1> m_subtool0;
/// \brief the tool the user configures
private:
AnaToolHandle<IUnitTestTool1> m_subtool1;
/// \brief the tool we configure
private:
AnaToolHandle<IUnitTestTool2> m_subtool2;
/// \brief the property name we set on \ref m_subsubtool
private:
std::string m_propertyName;
/// \brief whether to use the public tool handle
private:
bool m_usePublic = false;
};
}
#endif
<!-- $Id: selection.xml 744643 2016-05-03 19:12:00Z krumnack $ -->
<!-- $Id: selection.xml 773002 2016-09-13 13:21:21Z krumnack $ -->
<lcgdict>
<!-- Unit test types: -->
<class name="asg::UnitTestTool3" />
<class name="asg::UnitTestTool2" />
<class name="asg::UnitTestTool1A" />
......
# $Id: CMakeLists.txt 765747 2016-08-01 09:00:33Z will $
# $Id: CMakeLists.txt 779405 2016-10-20 13:44:57Z krasznaa $
################################################################################
# Package: AsgExampleTools
################################################################################
......@@ -6,44 +6,61 @@
# Declare the package name:
atlas_subdir( AsgExampleTools )
# External dependencies:
find_package( GTest )
# Extra dependencies based on the build environment:
set( extra_deps )
if( XAOD_STANDALONE )
set( extra_deps Control/xAODRootAccess )
else()
set( extra_deps Control/AthenaBaseComps GaudiKernel )
endif()
# Declare the package's dependencies:
atlas_depends_on_subdirs(
PUBLIC
Control/AthToolSupport/AsgTools
PRIVATE
Control/AthenaBaseComps
GaudiKernel )
${extra_deps} )
# External dependencies:
find_package( GTest )
# Component(s) in the package:
atlas_add_component( AsgExampleTools
src/*.cxx
Root/AsgHelloTool.cxx
AsgTools/UnitTestTool1.h AsgTools/UnitTestTool1A.h AsgTools/UnitTestTool2.h
Root/UnitTestTool1.cxx Root/UnitTestTool1A.cxx Root/UnitTestTool2.cxx
src/components/*.cxx
LINK_LIBRARIES AsgTools AthenaBaseComps GaudiKernel )
# Libraries in the package:
atlas_add_root_dictionary( AsgExampleToolsLib AsgExampleToolsCintDict
ROOT_HEADERS AsgExampleTools/UnitTestTool1.h Root/LinkDef.h
EXTERNAL_PACKAGES ROOT )
# Install files from the package:
atlas_install_headers( AsgExampleTools )
atlas_add_library( AsgExampleToolsLib
AsgExampleTools/*.h Root/*.cxx ${AsgExampleToolsCintDict}
PUBLIC_HEADERS AsgExampleTools
LINK_LIBRARIES AsgTools )
if( NOT XAOD_STANDALONE )
atlas_add_component( AsgExampleTools
src/*.h src/*.cxx src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps GaudiKernel AsgExampleToolsLib )
endif()
atlas_add_dictionary( AsgExampleToolsDict
AsgExampleTools/AsgExampleToolsDict.h
AsgExampleTools/selection.xml
LINK_LIBRARIES AsgExampleToolsLib )
# Executable(s) in the package:
atlas_add_executable( AsgExampleTools_hello
util/hello.cxx
LINK_LIBRARIES AsgExampleToolsLib )
# Test(s) in the package:
set( extra_libs )
if( XAOD_STANDALONE )
set( extra_libs xAODRootAccess )
endif()
atlas_add_test( gt_ToolHandle_test
SOURCES test/gt_ToolHandle_test.cxx
Root/UnitTestTool1.cxx Root/UnitTestTool2.cxx
INCLUDE_DIRS ${GTEST_INCLUDE_DIRS}
LINK_LIBRARIES ${GTEST_LIBRARIES} AsgTools )
LINK_LIBRARIES ${GTEST_LIBRARIES} AsgTools AsgExampleToolsLib ${extra_libs} )
atlas_add_test( gt_AnaToolHandle_test
SOURCES test/gt_AnaToolHandle_test.cxx
Root/UnitTestTool1.cxx Root/UnitTestTool2.cxx
INCLUDE_DIRS ${GTEST_INCLUDE_DIRS}
LINK_LIBRARIES ${GTEST_LIBRARIES} AsgTools )
#atlas_add_test( gt_UnitTest_test
# SOURCES test/gt_UnitTest_test.cxx
# INCLUDE_DIRS ${GTEST_INCLUDE_DIRS}
# LINK_LIBRARIES ${GTEST_LIBRARIES} AsgTools )
LINK_LIBRARIES ${GTEST_LIBRARIES} AsgTools AsgExampleToolsLib )
......@@ -27,7 +27,10 @@ int AsgHelloTool::talk() const {
// Create and execute a temporary tool.
if ( name() != "tmphello" ) {
AsgHelloTool tmptool("tmphello");
tmptool.setProperty("Message", "Hi from the temporary tool.");
if( ! tmptool.setProperty("Message", "Hi from the temporary tool.").isSuccess() ) {
ATH_MSG_ERROR( "Failed to set property on temporary tool" );
return 1;
}
tmptool.talk();
}
return 0;
......
......@@ -14,6 +14,9 @@
#include <AsgExampleTools/UnitTestTool1.h>
#include <gtest/gtest.h>
#include <map>
//
// method implementations
//
......@@ -25,7 +28,18 @@ namespace asg
: AsgTool (val_name)
{
declareProperty ("propertyInt", m_propertyInt, "the integer property");
declareProperty ("propertyString", m_propertyString, "the string property");
declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail");
++ instance_counts (name());
}
UnitTestTool1 ::
~UnitTestTool1 ()
{
-- instance_counts (name());
}
......@@ -33,6 +47,7 @@ namespace asg
StatusCode UnitTestTool1 ::
initialize ()
{
m_origMsgLevel = msg().level();
if (m_initializeFail)
{
ATH_MSG_ERROR ("tool configured to fail initialize");
......@@ -49,6 +64,14 @@ namespace asg
std::string UnitTestTool1 ::
getPropertyString () const
{
return m_propertyString;
}
int UnitTestTool1 ::
getPropertyInt () const
{
......@@ -70,4 +93,25 @@ namespace asg
{
return m_isInitialized;
}
int& UnitTestTool1 ::
instance_counts (const std::string& name)
{
static std::map<std::string,int> counts;
auto iter = counts.find (name);
if (iter == counts.end())
iter = counts.insert (std::make_pair (name, 0)).first;
assert (iter != counts.end());
return iter->second;
}
MSG::Level UnitTestTool1 ::
getOrigMsgLevel () const
{
return m_origMsgLevel;
}
}
......@@ -25,6 +25,7 @@ namespace asg
: AsgTool (val_name)
{
declareProperty ("propertyInt", m_propertyInt, "the integer property");
declareProperty ("propertyString", m_propertyString, "the string property");
declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail");
}
......@@ -33,6 +34,7 @@ namespace asg
StatusCode UnitTestTool1A ::
initialize ()
{
m_origMsgLevel = msg().level();
if (m_initializeFail)
{
ATH_MSG_ERROR ("tool configured to fail initialize");
......@@ -49,6 +51,14 @@ namespace asg
std::string UnitTestTool1A ::
getPropertyString () const
{
return m_propertyString;
}
int UnitTestTool1A ::
getPropertyInt () const
{
......@@ -70,4 +80,12 @@ namespace asg
{
return m_isInitialized;
}
MSG::Level UnitTestTool1A ::
getOrigMsgLevel () const
{
return m_origMsgLevel;
}
}
......@@ -27,9 +27,11 @@ namespace asg
: AsgTool (val_name),
m_regPublicHandle ("regPublicHandle", nullptr),
m_regPrivateHandle ("regPrivateHandle", this),
m_anaPublicHandle ("anaPublicHandle", nullptr),
m_anaPrivateHandle ("anaPrivateHandle", this)
m_anaPublicHandle ("asg::UnitTestTool1/anaPublicHandle", nullptr),
m_anaPrivateHandle ("asg::UnitTestTool1/anaPrivateHandle", this)
{
declareProperty ("allowEmpty", m_allowEmpty);
declareProperty ("regPublicHandle", m_regPublicHandle);
declareProperty ("regPrivateHandle", m_regPrivateHandle);
m_anaPublicHandle.declarePropertyFor (this, "anaPublicHandle");
......@@ -41,13 +43,14 @@ namespace asg
StatusCode UnitTestTool2 ::
initialize ()
{
m_anaPublicHandle.setAllowEmpty (m_allowEmpty);
m_anaPrivateHandle.setAllowEmpty (m_allowEmpty);
m_wasUserConfiguredPublic = m_anaPublicHandle.isUserConfigured();
ANA_CHECK (m_anaPublicHandle.make ("asg::UnitTestTool1/anaPublicTool"));
ANA_CHECK (m_anaPublicHandle.setProperty ("propertyInt", 111));
ANA_CHECK (m_anaPublicHandle.initialize ());
m_wasUserConfiguredPrivate = m_anaPrivateHandle.isUserConfigured();
ANA_CHECK (m_anaPrivateHandle.make ("asg::UnitTestTool1/anaPrivateTool"));
ANA_CHECK (m_anaPrivateHandle.setProperty ("propertyInt", 222));
ANA_CHECK (m_anaPrivateHandle.initialize ());
......@@ -56,7 +59,23 @@ namespace asg
IUnitTestTool1 *UnitTestTool2 ::
bool UnitTestTool2 ::
toolHandleEmpty (const std::string& handleName) const
{
if (handleName == "regPublicHandle")
return m_regPublicHandle.empty();
if (handleName == "regPrivateHandle")
return m_regPrivateHandle.empty();
if (handleName == "anaPublicHandle")
return m_anaPublicHandle.empty();
if (handleName == "anaPrivateHandle")
return m_anaPrivateHandle.empty();
throw std::runtime_error ("unknown handle: " + handleName);
}
const IUnitTestTool1 *UnitTestTool2 ::
getToolHandle (const std::string& handleName) const
{
if (handleName == "regPublicHandle")
......
// Copyright Iowa State University 2016.
// Author: Nils Krumnack
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Please feel free to contact me (nils.erik.krumnack@cern.ch) for bug
// reports, feature suggestions, praise and complaints.
//
// includes
//
#include <AsgExampleTools/UnitTestTool3.h>
#include <AsgExampleTools/IUnitTestTool1.h>
#include <AsgExampleTools/IUnitTestTool2.h>
//
// method implementations
//
namespace asg
{