LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE > Class Template Reference

Service implementation returning a provider. More...

#include "ServiceProviderWrappers.h"

Inheritance diagram for lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >:

Public Types

using concrete_provider_type = PROVIDER
 type of service provider implementation More...
 
using service_interface_type = INTERFACE
 art service interface class More...
 
using provider_type = typename service_interface_type::provider_type
 type of service provider interface More...
 
using Parameters = art::ServiceTable< typename concrete_provider_type::Config >
 Type of configuration parameter (for art description) More...
 

Public Member Functions

 ServiceProviderImplementationWrapper (Parameters const &config, art::ActivityRegistry &)
 Constructor (using a configuration table) More...
 

Private Member Functions

virtual provider_type const * do_provider () const override
 Returns a constant pointer to the service provider. More...
 

Private Attributes

std::unique_ptr< concrete_provider_typeprov
 service provider More...
 

Detailed Description

template<typename PROVIDER, typename INTERFACE>
class lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >

Service implementation returning a provider.


Template Parameters
INTERFACEtype of art service being implemented
PROVIDERtype of service provider to be returned
See also
ServiceProviderInterfaceWrapper

This class is suitable for a simple art service implementing an interface. This is the case of a service that can have multiple implementations, for example an experiment-specific access to a database. In this case, the art service is described by an interface, and many services can inherit and implement it.

In the factorisation model recommended in LArSoft, this hierarchy of art service implementations derived by a common interface is mirrored in a matching hierarchy of service provider implementation derived by a common service provider interface. In this model, services are basically trivial classes that return a pointer to the provider through a prescribed interface. The only relevant exception is that services may also register framework callbacks.

Given the nature of the service returning a provider, its structure is repetitive. This class implements most of that repetitive frame. The resulting service is not reacting to any framework events.

The configuration of the service is passed directly to the provider.

Given that we want to have a service that implements the service MyServiceInterface and returns a provider implementation "A" called MyProviderA, the simplest way to create it with this template is:

#include "larcore/CoreUtils/ServiceProviderWrappers.h"
#include "path/to/MyProviderA.h"
#include "path/to/MyServiceInterface.h"


namespace myprov {

  using MyServiceA = lar::ServiceProviderImplementationWrapper
    <MyProviderA, MyServiceInterface>;

}

DECLARE_ART_SERVICE_INTERFACE_IMPL
  (myprov::MyServiceA, myprov::MyService, LEGACY)

The class MyServiceInterface is expected to have been defined via ServiceProviderInterfaceWrapper. An implementation file is necessary too, that will look like:

#include "path/to/MyServiceA.h"

DEFINE_ART_SERVICE_INTERFACE_IMPL
  (myprov::MyServiceA, myprov::MyService)

If callback registration is needed, a class can derive from this template and still gain a bit of boilerplate facility. That is:

  • a provider_type definition (required by lar::providerFrom())
  • a provider() method to access the provider (required by lar::providerFrom())
  • a Parameters definition (used by art to print accepted configuration)
  • a constructor supporting FHiCL configuration validation
  • transparent life management of the provider instance
  • a concrete_provider_type definition (that is PROVIDER)
  • a service_interface_type definition (that is INTERFACE)

Requirements on the service provider (PROVIDER):

  • a data type Config being the configuration object. This is the object wrapped by fhicl::Table when performing FHiCL validation.
  • a constructor with as argument a constant reference to a Config object. The provider should be configured by that constructor.

Requirements on the service interface (INTERFACE):

  • a data type provider_type representing the abstract interface of the service provider
  • a virtual method do_provider() where the retrieval of the provider is expected to happen; this method is overridden

Definition at line 224 of file ServiceProviderWrappers.h.

Member Typedef Documentation

template<typename PROVIDER , typename INTERFACE >
using lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::concrete_provider_type = PROVIDER

type of service provider implementation

Definition at line 228 of file ServiceProviderWrappers.h.

template<typename PROVIDER , typename INTERFACE >
using lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::Parameters = art::ServiceTable<typename concrete_provider_type::Config>

Type of configuration parameter (for art description)

Definition at line 237 of file ServiceProviderWrappers.h.

template<typename PROVIDER , typename INTERFACE >
using lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::provider_type = typename service_interface_type::provider_type

type of service provider interface

Definition at line 234 of file ServiceProviderWrappers.h.

template<typename PROVIDER , typename INTERFACE >
using lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::service_interface_type = INTERFACE

art service interface class

Definition at line 231 of file ServiceProviderWrappers.h.

Constructor & Destructor Documentation

template<typename PROVIDER , typename INTERFACE >
lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::ServiceProviderImplementationWrapper ( Parameters const &  config,
art::ActivityRegistry  
)
inline

Constructor (using a configuration table)

Definition at line 240 of file ServiceProviderWrappers.h.

241  : prov(std::make_unique<concrete_provider_type>(config()))
242  {}
std::unique_ptr< concrete_provider_type > prov
service provider

Member Function Documentation

template<typename PROVIDER , typename INTERFACE >
virtual provider_type const* lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::do_provider ( ) const
inlineoverrideprivatevirtual

Returns a constant pointer to the service provider.

Definition at line 248 of file ServiceProviderWrappers.h.

248 { return prov.get(); }
std::unique_ptr< concrete_provider_type > prov
service provider

Member Data Documentation

template<typename PROVIDER , typename INTERFACE >
std::unique_ptr<concrete_provider_type> lar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::prov
private

service provider

Definition at line 245 of file ServiceProviderWrappers.h.


The documentation for this class was generated from the following file: