LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Environment for a geometry test. More...
#include "geometry_unit_test_base.h"
Public Types | |
using | SharedGeoPtr_t = GeoResources_t::ResourcePtr_t |
using | Configuration_t = ConfigurationClass |
Public Member Functions | |
GeometryTesterEnvironment (bool bSetup=true) | |
Constructor: sets everything up and declares the test started. More... | |
virtual | ~GeometryTesterEnvironment () |
Destructor: closing remarks. More... | |
template<typename Prov , typename... Args> | |
Prov * | SetupProvider (Args &&...args) |
Sets a service provider up by calling its testing::setupProvider() More... | |
template<typename Prov , typename... Args> | |
Prov * | SetupProviderFromService (std::string name, Args &&...args) |
Sets a service provider up by calling its testing::setupProvider() More... | |
template<typename Prov > | |
Prov * | AcquireProvider (std::unique_ptr< Prov > &&prov) |
Acquires a service provider. More... | |
template<typename Interface , typename Prov , typename... Args> | |
Prov * | SetupProviderFor (Args &&...args) |
Sets a provider up, recording it as implementation of Interface. More... | |
template<typename Interface , typename Prov , typename... Args> | |
Prov * | SetupProviderFromServiceFor (std::string name, Args &&...args) |
Sets a provider up, recording it as implementation of Interface. More... | |
template<typename Interface , typename Prov > | |
Prov * | AcquireProviderFor (std::unique_ptr< Prov > &&prov) |
Acquires a service provider implementing an interface. More... | |
template<typename Prov > | |
Prov * | SimpleProviderSetup () |
Oversimplified provider setup. More... | |
template<typename Prov > | |
void | DropProvider () |
Removes and destroys the specified provider. More... | |
template<typename Prov > | |
Prov const * | Provider () const |
Return the specified provider (throws if not available) More... | |
template<typename... Provs> | |
void | FillProviderPack (lar::ProviderPack< Provs... > &pack) const |
Fills the specified provider pack with providers. More... | |
template<typename Prov > | |
Prov::providers_type | ProviderPackFor () const |
Returns a provider pack for the specified provider. More... | |
GeometryTesterEnvironment (ConfigurationClass const &cfg_obj, bool bSetup=true) | |
Setup from a configuration. More... | |
GeometryTesterEnvironment (ConfigurationClass &&cfg_obj, bool bSetup=true) | |
Setup from a configuration. More... | |
geo::GeometryCore const * | Geometry () const |
Returns a pointer to the geometry. More... | |
SharedGeoPtr_t | SharedGeometry () const |
Returns a pointer to the geometry. More... | |
Configuration retrieval | |
fhicl::ParameterSet const & | Parameters () const |
Returns the full configuration. More... | |
fhicl::ParameterSet | ServiceParameters (std::string service_name) const |
Returns the configuration of the specified service. More... | |
fhicl::ParameterSet | TesterParameters (std::string test_name) const |
Returns the configuration of the specified test. More... | |
fhicl::ParameterSet | TesterParameters () const |
Returns the configuration of the main test (undefined if no main test) More... | |
Static Public Member Functions | |
static geo::GeometryCore const * | GlobalGeometry () |
static SharedGeoPtr_t | SharedGlobalGeometry () |
Returns the current global geometry instance (may be nullptr if none) More... | |
static fhicl::ParameterSet | CompileParameterSet (std::string cfg) |
Compiles a parameter set from a string. More... | |
Protected Types | |
using | ChannelMapClass = typename ConfigurationClass::ChannelMapClass |
Protected Member Functions | |
virtual void | Setup () |
The complete initialization, ran at construction by default. More... | |
virtual std::unique_ptr< geo::GeometryCore > | CreateNewGeometry () const |
Creates a new geometry. More... | |
virtual void | SetupGeometry () |
Sets up the geometry (creates and registers it) More... | |
Configuration_t const & | Config () const |
Returns a read-only version of the configuration. More... | |
virtual void | Configure () |
Reads and translates the configuration. More... | |
virtual fhicl::ParameterSet | DefaultParameters () const |
Creates a full configuration for the test. More... | |
virtual void | RegisterGeometry (SharedGeoPtr_t new_geom) |
Get ownership of the specified geometry and registers it as global. More... | |
virtual void | RegisterGeometry (geo::GeometryCore const *new_geom) |
Get ownership of the specified geometry and registers it as global. More... | |
virtual void | SetupMessageFacility (fhicl::ParameterSet const &pset, std::string appl_name="") const |
Sets up the message facility. More... | |
virtual void | SetupMessageFacility () const |
Sets up the message facility. More... | |
Static Protected Member Functions | |
static fhicl::ParameterSet | ParseParameters (std::string config_path) |
Fills the test configuration from file or from default. More... | |
Protected Attributes | |
ProviderList | providers |
list of available providers More... | |
Private Types | |
using | TesterEnvironment_t = TesterEnvironment< ConfigurationClass > |
Base class. More... | |
using | GeoResources_t = TestSharedGlobalResource< geo::GeometryCore const > |
this implements the singleton interface More... | |
Private Attributes | |
ConfigurationClass | config |
instance of the configurer More... | |
SharedGeoPtr_t | geom |
pointer to the geometry More... | |
Environment for a geometry test.
ConfigurationClass | a class providing compile-time configuration |
The test environment is set up on construction.
The environment provides:
This class or a derived one can be used as global fixture for unit tests that require the presence of geometry (in the form of geo::GeometryCore instance).
Unfortunately Boost does not give any control on the initialization of the object, so everything must be ready to go as hard coded. The ConfigurationClass class tries to alleviate that. That is another, small static class that GeometryTesterEnvironment uses to get its parameters.
The requirements for the ConfigurationClass are:
ChannelMapClass
: concrete type of channel mapping algorithm classstd::string ApplicationName()
: the application namestd::string ConfigurationPath()
: path to the configuration filestd::string GeometryParameterSetPath()
: FHiCL path to the configuration of the geometry; in art is "services.Geometry"
std::string TesterParameterSetPath()
: FHiCL path to the configuration of the geometrystd::string DefaultGeometryConfiguration()
returning a FHiCL string to be parsed to extract the default geometry configurationstd::string DefaultTesterConfiguration()
returning a FHiCL string to be parsed to extract the default test configurationWhether the configuration comes from a file or from the two provided defaults, it is always expected within the parameter set paths: the default configuration must also contain that path.
Note that there is no room for polymorphism here since the setup happens on construction. Some methods are declared virtual in order to allow to tweak some steps of the set up, but it's not trivial to create a derived class that works correctly: the derived class must declare a new default constructor, and that default constructor must call the protected constructor (GeometryTesterEnvironment<ConfigurationClass>(no_setup))
Definition at line 190 of file geometry_unit_test_base.h.
|
protected |
Definition at line 254 of file geometry_unit_test_base.h.
|
inherited |
Definition at line 563 of file unit_test_base.h.
|
private |
this implements the singleton interface
Definition at line 196 of file geometry_unit_test_base.h.
using testing::GeometryTesterEnvironment< ConfigurationClass >::SharedGeoPtr_t = GeoResources_t::ResourcePtr_t |
Definition at line 199 of file geometry_unit_test_base.h.
|
private |
Base class.
Definition at line 193 of file geometry_unit_test_base.h.
|
inline |
Constructor: sets everything up and declares the test started.
The configuration is from a default-constructed ConfigurationClass. This is suitable for use as Boost unit test fixture.
Definition at line 207 of file geometry_unit_test_base.h.
|
inline |
Setup from a configuration.
configurer | an instance of ConfigurationClass |
The configuration is from the specified configurer class.
This constructor allows to use a non-default-constructed configuration. This can't be used (at best of my knowledge) when using this class as Boost unit test fixture.
In the r-value-reference constructor, the configurer is moved.
Definition at line 225 of file geometry_unit_test_base.h.
|
inline |
Setup from a configuration.
configurer | an instance of ConfigurationClass |
The configuration is from the specified configurer class.
This constructor allows to use a non-default-constructed configuration. This can't be used (at best of my knowledge) when using this class as Boost unit test fixture.
In the r-value-reference constructor, the configurer is moved.
Definition at line 230 of file geometry_unit_test_base.h.
|
virtual |
Destructor: closing remarks.
Definition at line 283 of file geometry_unit_test_base.h.
|
inlineinherited |
Acquires a service provider.
Prov | type of provider |
prov | the provider to be acquired |
runtime_error | if the provider already exists |
This method registers and takes ownership of the specified provider. It is similar to SetupProvider() except that user is in charge of the preliminary creation and setup of the provider.
Definition at line 815 of file unit_test_base.h.
|
inlineinherited |
Acquires a service provider implementing an interface.
Prov | type of provider |
Interface | type provider alias |
prov | the provider to be acquired |
This method registers and takes ownership of the specified provider, like AcquireProvider() does. It also registers the provider as an implementation of Interface class, as SetupProviderFor does. It is similar to SetupProvider() except that user is in charge of the preliminar creation and setup of the provider.
Definition at line 887 of file unit_test_base.h.
|
staticinherited |
Compiles a parameter set from a string.
Definition at line 1069 of file unit_test_base.h.
References fhicl::ParameterSet::make().
|
inlineprotectedinherited |
Returns a read-only version of the configuration.
Definition at line 638 of file unit_test_base.h.
|
protectedvirtualinherited |
Reads and translates the configuration.
Fills the configuration.
The complete configuration (message facility and services) is read and saved, hence accessible by Parameters() method.
The configuration file path is taken by default from the first argument of the test. If that first argument is not present or empty, the default configuration path is received from the configurer. If the configuration path is still empty, a hard-coded configuration is used; otherwise, the FHiCL file specified in that path is parsed and used as full configuration.
Definition at line 1117 of file unit_test_base.h.
|
protectedvirtual |
Creates a new geometry.
Sets the geometry of the standard detector up.
This function sets up the geometry according to the provided information:
Definition at line 302 of file geometry_unit_test_base.h.
References fhicl::ParameterSet::get().
|
inlineprotectedvirtualinherited |
Creates a full configuration for the test.
Definition at line 650 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
inlineinherited |
Removes and destroys the specified provider.
Prov | type of provider to be destroyed |
runtime_error | if the provider was not present |
Definition at line 918 of file unit_test_base.h.
|
inlineinherited |
Fills the specified provider pack with providers.
runtime_error | and everything provider() method can throw |
Definition at line 936 of file unit_test_base.h.
References trkf::fill().
|
inline |
Returns a pointer to the geometry.
Definition at line 242 of file geometry_unit_test_base.h.
|
inlinestatic |
Returns the current global geometry instance
std::out_of_range | if not present |
Definition at line 248 of file geometry_unit_test_base.h.
|
inlineinherited |
Returns the full configuration.
Definition at line 609 of file unit_test_base.h.
|
staticprotectedinherited |
Fills the test configuration from file or from default.
Returns the configuration from a FHiCL file.
If a FHiCL configuration file is specified, the configuration of the test is read from it according to the parameter set path of the test. Otherwise, it is parsed from the default one provided by the configurer.Parses from file and returns a FHiCL data structure
config_path | full path of the FHiCL configuration file |
Definition at line 1083 of file unit_test_base.h.
References fhicl::ParameterSet::make(), and fhicl::parse_document().
|
inlineinherited |
Return the specified provider (throws if not available)
Definition at line 925 of file unit_test_base.h.
|
inlineinherited |
Returns a provider pack for the specified provider.
Prov | type of the provider |
runtime_error | and everything provider() method can throw |
The provider is required to have a providers_type
type defined as an specialisation of lar::ProviderPack.
Definition at line 952 of file unit_test_base.h.
|
protectedvirtual |
Get ownership of the specified geometry and registers it as global.
Definition at line 350 of file geometry_unit_test_base.h.
|
inlineprotectedvirtual |
Get ownership of the specified geometry and registers it as global.
Definition at line 265 of file geometry_unit_test_base.h.
References lar::standalone::SetupGeometry().
|
inlineinherited |
Returns the configuration of the specified service.
Definition at line 612 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
protectedvirtual |
The complete initialization, ran at construction by default.
Reimplemented from testing::BasicTesterEnvironment< ConfigurationClass >.
Definition at line 377 of file geometry_unit_test_base.h.
References lar::standalone::SetupGeometry().
|
protectedvirtual |
Sets up the geometry (creates and registers it)
Definition at line 363 of file geometry_unit_test_base.h.
|
protectedvirtualinherited |
Sets up the message facility.
Sets the message facility up.
Message facility configuration is expected in "services.message" parameter set. If not there, the default configuration is used.
Definition at line 1130 of file unit_test_base.h.
References fhicl::ParameterSet::get_if_present(), MF_LOG_TRACE, mf::SetApplicationName(), mf::SetContextIteration(), mf::SetContextSinglet(), mf::StartMessageFacility(), and fhicl::ParameterSet::to_indented_string().
|
inlineprotectedvirtualinherited |
Sets up the message facility.
Sets the message facility up.
Message facility configuration is expected in "services.message" parameter set. If not there, the default configuration is used.
Definition at line 659 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
inlineinherited |
Sets a service provider up by calling its testing::setupProvider()
Prov | type of provider |
Args | type of arguments for the setup function |
args | arguments for the setup function |
runtime_error | if the provider already exists |
A provider of type Prov is created, set up and recorded. Provider setup is delegated to testing::setupProvider
function specific to the provider itself (that is, testing::setupProvider<Prov>(args...)
) to which the setup arguments are forwarded. If the provider already exists, an exception is thrown.
Definition at line 775 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
inlineinherited |
Sets a provider up, recording it as implementation of Interface.
Interface | type of provider interface being implemented |
Prov | type of provider |
Args | type of arguments for the setup function |
args | arguments for the setup function |
This method performs the same type of setup as SetupProvider(). In addition, it registers the provider as an implementation of Interface. This means that the provider can be obtained not only with provider<Prov>()
, which returns a pointer to the actual class Prov, but also as provider<Interface>()
, which returns a pointer to the base class Interface.
Definition at line 838 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
inlineinherited |
Sets a service provider up by calling its testing::setupProvider()
Prov | type of provider |
Args | type of arguments for the setup function |
name | the service name (for configuration retrieval) |
args | arguments for the setup function |
runtime_error | if the provider already exists |
A provider of type Prov is created, set up and recorded. Provider setup is attempted by constructing the provider with a parameter set from the registered configuration of service with specified name
.
Definition at line 797 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
inlineinherited |
Sets a provider up, recording it as implementation of Interface.
Interface | type of provider interface being implemented |
Prov | type of provider |
Args | type of arguments for the setup function |
name | the service name (for configuration retrieval) |
args | arguments for the setup function |
runtime_error | if the provider already exists |
This method performs the same type of setup as SetupProviderFromService(). In addition, it registers the provider as an implementation of Interface. This means that the provider can be obtained not only with provider<Prov>()
, which returns a pointer to the actual class Prov, but also as provider<Interface>()
, which returns a pointer to the base class Interface.
Definition at line 865 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
inline |
Returns a pointer to the geometry.
Definition at line 243 of file geometry_unit_test_base.h.
|
inlinestatic |
Returns the current global geometry instance (may be nullptr if none)
Definition at line 251 of file geometry_unit_test_base.h.
|
inlineinherited |
Oversimplified provider setup.
Prov | provider type |
This is a one-step setup of the specified provider.
It is available only if Prov provider comes with an implementation of testing::SimpleEnvironmentSetupClass that explains how to set up an environment.
Definition at line 907 of file unit_test_base.h.
|
inlineinherited |
Returns the configuration of the specified test.
Definition at line 618 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
inlineinherited |
Returns the configuration of the main test (undefined if no main test)
Definition at line 624 of file unit_test_base.h.
|
private |
instance of the configurer
Definition at line 275 of file geometry_unit_test_base.h.
|
private |
pointer to the geometry
Definition at line 277 of file geometry_unit_test_base.h.
|
protectedinherited |
list of available providers
Definition at line 960 of file unit_test_base.h.