![]() |
LArSoft
v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
|
Environment for a geometry test. More...
#include "geometry_unit_test_base.h"
Public Types | |
using | Configuration_t = ConfigurationClass |
Public Member Functions | |
GeometryTesterEnvironment (bool bSetup=true) | |
Constructor: sets everything up and declares the test started. More... | |
geo::GeometryCore const * | Geometry () const noexcept |
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... | |
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 fhicl::ParameterSet | CompileParameterSet (std::string cfg) |
Compiles a parameter set from a string. More... | |
Protected Member Functions | |
void | Setup () |
The complete initialization, ran at construction by default. More... | |
virtual std::unique_ptr< geo::GeometryCore > | CreateNewGeometry () const |
Creates a new geometry. 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 | 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 > |
Private Attributes | |
ConfigurationClass | config |
instance of the configurer 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 179 of file geometry_unit_test_base.h.
|
inherited |
Definition at line 561 of file unit_test_base.h.
|
private |
Definition at line 180 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 189 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 206 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 211 of file geometry_unit_test_base.h.
|
virtual |
Destructor: closing remarks.
Definition at line 251 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 813 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 885 of file unit_test_base.h.
|
staticinherited |
Compiles a parameter set from a string.
Definition at line 1035 of file unit_test_base.h.
References fhicl::ParameterSet::make().
|
inlineprotectedinherited |
Returns a read-only version of the configuration.
Definition at line 636 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 1077 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 268 of file geometry_unit_test_base.h.
|
inlineprotectedvirtualinherited |
Creates a full configuration for the test.
Definition at line 648 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 917 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 935 of file unit_test_base.h.
References trkf::fill().
|
inlinenoexcept |
Definition at line 218 of file geometry_unit_test_base.h.
|
inlineinherited |
Returns the full configuration.
Definition at line 607 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 1049 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 924 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 951 of file unit_test_base.h.
|
inlineinherited |
Returns the configuration of the specified service.
Definition at line 610 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 283 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 1090 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 657 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 773 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 836 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 795 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 863 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
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 906 of file unit_test_base.h.
|
inlineinherited |
Returns the configuration of the specified test.
Definition at line 616 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 622 of file unit_test_base.h.
|
private |
instance of the configurer
Definition at line 234 of file geometry_unit_test_base.h.
|
protectedinherited |
list of available providers
Definition at line 959 of file unit_test_base.h.