Skip to content
Snippets Groups Projects
Commit 74c3cdea authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

AthToolSupport: support Gaudi interface base classes

Add support for the usage of the Gaudi `extends` formalism for interface
declarations. This removes the need to use the explicit `declareServiceInterface` calls.

Introduce the new `AsgTools/Interfaces.h` header that contains the
standalone versions of these classes. Also move the `DeclareInterfaceID`
here.
parent 6817d4bf
No related branches found
No related tags found
No related merge requests found
/* /*
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
/// @author Nils Krumnack /// @author Nils Krumnack
...@@ -22,8 +22,7 @@ namespace asg ...@@ -22,8 +22,7 @@ namespace asg
/// This allows to unit test the various capabilities of /// This allows to unit test the various capabilities of
/// AnaToolHandle in a controlled fashion. /// AnaToolHandle in a controlled fashion.
struct UnitTestService1 : virtual public IUnitTestService1, struct UnitTestService1 : extends<AsgService, IUnitTestService1>
public AsgService
{ {
/// \brief standard constructor /// \brief standard constructor
public: public:
......
/* /*
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
/// @author Nils Krumnack /// @author Nils Krumnack
...@@ -27,10 +27,8 @@ namespace asg ...@@ -27,10 +27,8 @@ namespace asg
{ {
UnitTestService1 :: UnitTestService1 ::
UnitTestService1 (const std::string& name, ISvcLocator* pSvcLocator) UnitTestService1 (const std::string& name, ISvcLocator* pSvcLocator)
: AsgService (name, pSvcLocator) : base_class (name, pSvcLocator)
{ {
declareServiceInterface<IUnitTestService1>();
declareProperty ("propertyInt", m_propertyInt, "the integer property"); declareProperty ("propertyInt", m_propertyInt, "the integer property");
declareProperty ("propertyString", m_propertyString, "the string property"); declareProperty ("propertyString", m_propertyString, "the string property");
declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail"); declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail");
......
...@@ -39,17 +39,12 @@ namespace asg ...@@ -39,17 +39,12 @@ namespace asg
/// Loosely based on the \ref AsgTool implementation. /// Loosely based on the \ref AsgTool implementation.
class AsgService : class AsgService :
#ifndef XAOD_STANDALONE
public extends<AsgServiceBase, IAsgService> public extends<AsgServiceBase, IAsgService>
#else
public AsgServiceBase, public virtual IAsgService
#endif
{ {
public: public:
AsgService (const std::string& name, AsgService (const std::string& name,
ISvcLocator* pSvcLocator); ISvcLocator* pSvcLocator);
/// set up/tear down functions /// set up/tear down functions
/// \{ /// \{
virtual StatusCode initialize (); virtual StatusCode initialize ();
...@@ -59,28 +54,8 @@ namespace asg ...@@ -59,28 +54,8 @@ namespace asg
/// Print the state of the service /// Print the state of the service
virtual void print() const; virtual void print() const;
/// add the given interface to the list of interfaces
template<typename T> void declareServiceInterface ();
#ifndef XAOD_STANDALONE
private:
/// list of interfaces we have
std::vector<std::pair<const InterfaceID& (*)(),void *(*)(AsgService*)>> m_interfaces;
#endif
}; // class AsgService }; // class AsgService
template<typename T>
void AsgService :: declareServiceInterface ()
{
#ifndef XAOD_STANDALONE
m_interfaces.emplace_back (T::interfaceID, [] (AsgService *self) -> void* {return dynamic_cast<T*>(self);});
#endif
}
} // namespace asg } // namespace asg
#endif // ASGSERVICES_ASGSERVICE_H #endif // ASGSERVICES_ASGSERVICE_H
/* /*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
/// @author Nils Krumnack /// @author Nils Krumnack
...@@ -13,16 +13,7 @@ ...@@ -13,16 +13,7 @@
// Local include(s): // Local include(s):
#include "AsgMessaging/INamedInterface.h" #include "AsgMessaging/INamedInterface.h"
#include "AsgTools/Interfaces.h"
#ifdef XAOD_STANDALONE
/// \brief standalone version of the Gaudi interface declaration
///
/// This can't be a no-op, because the Gaudi version needs to be
/// followed by a semicolon, so we need a statement that requires to
/// be followed by a semi-colon.
#define DeclareInterfaceID(iface, major, minor) \
static constexpr std::nullptr_t interfaceID = nullptr
#endif
namespace asg namespace asg
{ {
......
...@@ -21,10 +21,10 @@ namespace asg ...@@ -21,10 +21,10 @@ namespace asg
#ifndef XAOD_STANDALONE #ifndef XAOD_STANDALONE
: base_class(name, pSvcLocator) : base_class(name, pSvcLocator)
#else #else
: AsgServiceBase(name) : base_class(name)
#endif #endif
{ {
(void) pSvcLocator; (void) pSvcLocator; // suppress compiler warning in XAOD_STANDALONE
} }
StatusCode AsgService :: StatusCode AsgService ::
......
/* /*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
/// \author Nils Krumnack /// \author Nils Krumnack
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <AsgMessaging/INamedInterface.h> #include <AsgMessaging/INamedInterface.h>
#include <AsgMessaging/MessageCheck.h> #include <AsgMessaging/MessageCheck.h>
#include <AsgMessaging/MsgLevel.h> #include <AsgMessaging/MsgLevel.h>
#include <AsgTools/Interfaces.h>
#include <memory> #include <memory>
#include <vector> #include <vector>
......
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ASGTOOLS_INTERFACES_H
#define ASGTOOLS_INTERFACES_H
///
/// Standalone versions of Gaudi interface declarations.
//
#if defined(XAOD_STANDALONE)
/// This can't be a no-op, because the Gaudi version needs to be
/// followed by a semicolon, so we need a statement that requires to
/// be followed by a semi-colon.
#define DeclareInterfaceID(iface, major, minor) \
static_assert(true)
/// See GaudiKernel/extend_interfaces.h
template <typename... Interfaces>
struct extend_interfaces : virtual public Interfaces... {
};
/// See GaudiKernel/extends.h
template <typename BASE, typename... Interfaces>
struct extends : public BASE, virtual public extend_interfaces<Interfaces...> {
using base_class = extends;
using BASE::BASE;
};
/// See GaudiKernel/implements.h
template <typename... Interfaces>
struct implements : virtual public extend_interfaces<Interfaces...> {
using base_class = implements<Interfaces...>;
};
#endif
#endif
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