All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Private Types | Private Attributes | List of all members
testing::GeometryTesterEnvironment< ConfigurationClass > Class Template Reference

Environment for a geometry test. More...

#include <geometry_unit_test_base.h>

Inheritance diagram for testing::GeometryTesterEnvironment< ConfigurationClass >:
testing::TesterEnvironment< ConfigurationClass > testing::BasicTesterEnvironment< ConfigurationClass >

Public Types

using SharedGeoPtr_t = GeoResources_t::ResourcePtr_t
 
- Public Types inherited from testing::BasicTesterEnvironment< ConfigurationClass >
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...
 
 GeometryTesterEnvironment (ConfigurationClass const &cfg_obj, bool bSetup=true)
 Setup from a configuration. More...
 
 GeometryTesterEnvironment (ConfigurationClass &&cfg_obj, bool bSetup=true)
 
geo::GeometryCore const * Geometry () const
 Returns a pointer to the geometry. More...
 
SharedGeoPtr_t SharedGeometry () const
 
- Public Member Functions inherited from testing::TesterEnvironment< ConfigurationClass >
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...
 
- Public Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass >
 BasicTesterEnvironment (bool bSetup=true)
 Constructor: sets everything up and declares the test started. More...
 
virtual ~BasicTesterEnvironment ()
 Destructor: closing remarks. More...
 
 BasicTesterEnvironment (Configuration_t const &configurer, bool bSetup=true)
 Setup from a configuration. More...
 
 BasicTesterEnvironment (Configuration_t &&configurer, bool bSetup=true)
 
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 Public Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass >
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...
 
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)
 
- Protected Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass >
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
 

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...
 

Additional Inherited Members

- Static Protected Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass >
static fhicl::ParameterSet ParseParameters (std::string config_path)
 Fills the test configuration from file or from default. More...
 
- Protected Attributes inherited from testing::TesterEnvironment< ConfigurationClass >
ProviderList providers
 list of available providers More...
 

Detailed Description

template<typename ConfigurationClass>
class testing::GeometryTesterEnvironment< ConfigurationClass >

Environment for a geometry test.


Template Parameters
ConfigurationClassa 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:

Whether 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 191 of file geometry_unit_test_base.h.

Member Typedef Documentation

template<typename ConfigurationClass>
using testing::GeometryTesterEnvironment< ConfigurationClass >::ChannelMapClass = typename ConfigurationClass::ChannelMapClass
protected

Definition at line 258 of file geometry_unit_test_base.h.

template<typename ConfigurationClass>
using testing::GeometryTesterEnvironment< ConfigurationClass >::GeoResources_t = TestSharedGlobalResource<geo::GeometryCore const>
private

this implements the singleton interface

Definition at line 199 of file geometry_unit_test_base.h.

template<typename ConfigurationClass>
using testing::GeometryTesterEnvironment< ConfigurationClass >::SharedGeoPtr_t = GeoResources_t::ResourcePtr_t

Definition at line 202 of file geometry_unit_test_base.h.

template<typename ConfigurationClass>
using testing::GeometryTesterEnvironment< ConfigurationClass >::TesterEnvironment_t = TesterEnvironment<ConfigurationClass>
private

Base class.

Definition at line 196 of file geometry_unit_test_base.h.

Constructor & Destructor Documentation

template<typename ConfigurationClass>
testing::GeometryTesterEnvironment< ConfigurationClass >::GeometryTesterEnvironment ( bool  bSetup = true)
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 210 of file geometry_unit_test_base.h.

211  : TesterEnvironment_t(false)
212  { if (bSetup) Setup(); }
virtual void Setup()
The complete initialization, ran at construction by default.
TesterEnvironment< ConfigurationClass > TesterEnvironment_t
Base class.
template<typename ConfigurationClass>
testing::GeometryTesterEnvironment< ConfigurationClass >::GeometryTesterEnvironment ( ConfigurationClass const &  cfg_obj,
bool  bSetup = true 
)
inline

Setup from a configuration.

Parameters
configureran 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 228 of file geometry_unit_test_base.h.

229  : TesterEnvironment_t(cfg_obj, false)
230  { if (bSetup) Setup(); }
virtual void Setup()
The complete initialization, ran at construction by default.
TesterEnvironment< ConfigurationClass > TesterEnvironment_t
Base class.
template<typename ConfigurationClass>
testing::GeometryTesterEnvironment< ConfigurationClass >::GeometryTesterEnvironment ( ConfigurationClass &&  cfg_obj,
bool  bSetup = true 
)
inline

Definition at line 231 of file geometry_unit_test_base.h.

232  : TesterEnvironment_t(std::move(cfg_obj), false)
233  { if (bSetup) Setup(); }
virtual void Setup()
The complete initialization, ran at construction by default.
TesterEnvironment< ConfigurationClass > TesterEnvironment_t
Base class.
template<typename ConfigurationClass >
testing::GeometryTesterEnvironment< ConfigurationClass >::~GeometryTesterEnvironment ( )
virtual

Destructor: closing remarks.

Definition at line 289 of file geometry_unit_test_base.h.

289  {
290 
291  mf::LogInfo("Test") << config.ApplicationName() << " completed.";
292 
293  } // GeometryTesterEnvironment<>::~GeometryTesterEnvironment()
ConfigurationClass config
instance of the configurer

Member Function Documentation

template<typename ConfigurationClass >
std::unique_ptr< geo::GeometryCore > testing::GeometryTesterEnvironment< ConfigurationClass >::CreateNewGeometry ( ) const
protectedvirtual

Creates a new geometry.

Sets the geometry of the standard detector up.


This function sets up the geometry according to the provided information:

  • the configuration must contain enough information to locate the geometry description file
  • we trust that that geometry works well with the ChannelMapClass specified in ConfigurationClass

Definition at line 308 of file geometry_unit_test_base.h.

309  {
310 
311  std::string ProviderParameterSetPath
312  = this->Config().GeometryParameterSetPath();
313 
314  //
315  // create the new geometry service provider
316  //
317  fhicl::ParameterSet ProviderConfig
318  = this->Parameters().template get<fhicl::ParameterSet>
319  (ProviderParameterSetPath);
320  auto new_geom = std::make_unique<geo::GeometryCore>(ProviderConfig);
321 
322  std::string RelativePath
323  = ProviderConfig.get< std::string>("RelativePath", "");
324 
325  std::string
326  GDMLFileName = RelativePath + ProviderConfig.get<std::string>("GDML"),
327  ROOTFileName = RelativePath + ProviderConfig.get<std::string>("ROOT");
328 
329  // Search all reasonable locations for the geometry file;
330  // we see if by any chance art's FW_SEARCH_PATH directory is set and try
331  // there;
332  // if not, we do expect the path to be complete enough for ROOT to cope.
333  cet::search_path sp("FW_SEARCH_PATH");
334 
335  std::string ROOTfile;
336  if (!sp.find_file(ROOTFileName, ROOTfile)) ROOTfile = ROOTFileName;
337 
338  // we really don't care of GDML file, since we are not going to run Geant4
339  std::string GDMLfile;
340  if (!sp.find_file(GDMLFileName, GDMLfile)) {
341  mf::LogWarning("CreateNewGeometry") << "GDML file '"
342  << GDMLfile << "' not found.";
343  }
344 
345  // initialize the geometry with the files we have found
346  new_geom->LoadGeometryFile(GDMLfile, ROOTfile);
347 
348 
349  //
350  // create the new channel map
351  //
352  auto const SortingParameters
353  = ProviderConfig.get<fhicl::ParameterSet>("SortingParameters", {});
354 
355  // connect the channel map with the geometry, that shares ownsership
356  // (we give up ours at the end of this method)
357  new_geom->ApplyChannelMap(std::make_unique<ChannelMapClass>(SortingParameters));
358 
359  return new_geom;
360  } // GeometryTesterEnvironment<>::CreateNewGeometry()
fhicl::ParameterSet const & Parameters() const
Returns the full configuration.
Configuration_t const & Config() const
Returns a read-only version of the configuration.
std::string ROOTFileName
std::string GDMLFileName
BEGIN_PROLOG vertical distance to the surface table::sbnd_geo_source SortingParameters
template<typename ConfigurationClass>
geo::GeometryCore const* testing::GeometryTesterEnvironment< ConfigurationClass >::Geometry ( ) const
inline

Returns a pointer to the geometry.

Definition at line 242 of file geometry_unit_test_base.h.

242 { return geom.get(); }
SharedGeoPtr_t geom
pointer to the geometry
template<typename ConfigurationClass>
static geo::GeometryCore const* testing::GeometryTesterEnvironment< ConfigurationClass >::GlobalGeometry ( )
inlinestatic

Returns the current global geometry instance

Exceptions
std::out_of_rangeif not present

Definition at line 249 of file geometry_unit_test_base.h.

250  { return &GeoResources_t::Resource(); }
static Resource_t & Resource(std::string name="")
Retrieves the specified resource, or throws if not available.
template<typename ConfigurationClass >
void testing::GeometryTesterEnvironment< ConfigurationClass >::RegisterGeometry ( SharedGeoPtr_t  new_geom)
protectedvirtual

Get ownership of the specified geometry and registers it as global.

Definition at line 365 of file geometry_unit_test_base.h.

366  {
367  // update the current geometry, that becomes owner;
368  // also update the global one if it happens to be already our previous
369  // (in this case, it becomes co-owner)
370  SharedGeoPtr_t my_old_geom = geom;
371  geom = new_geom;
372  // if the global geometry is already the one we register, don't bother
373  if (SharedGlobalGeometry() != new_geom)
374  GeoResources_t::ReplaceDefaultSharedResource(my_old_geom, new_geom);
375  } // GeometryTesterEnvironment<>::RegisterGeometry()
static bool ReplaceDefaultSharedResource(Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource as default resource only if it is old_res_ptr.
SharedGeoPtr_t geom
pointer to the geometry
static SharedGeoPtr_t SharedGlobalGeometry()
Returns the current global geometry instance (may be nullptr if none)
GeoResources_t::ResourcePtr_t SharedGeoPtr_t
template<typename ConfigurationClass>
virtual void testing::GeometryTesterEnvironment< ConfigurationClass >::RegisterGeometry ( geo::GeometryCore const *  new_geom)
inlineprotectedvirtual

Definition at line 270 of file geometry_unit_test_base.h.

271  { RegisterGeometry(SharedGeoPtr_t(new_geom)); }
virtual void RegisterGeometry(SharedGeoPtr_t new_geom)
Get ownership of the specified geometry and registers it as global.
GeoResources_t::ResourcePtr_t SharedGeoPtr_t
template<typename ConfigurationClass >
void testing::GeometryTesterEnvironment< ConfigurationClass >::Setup ( )
protectedvirtual

The complete initialization, ran at construction by default.

Reimplemented from testing::BasicTesterEnvironment< ConfigurationClass >.

Definition at line 395 of file geometry_unit_test_base.h.

395  {
396 
397  //
398  // parse configuration, set up message facility
399  //
401 
402  //
403  // set up the geometry
404  //
405  SetupGeometry();
406 
407  mf::LogInfo("Test")
408  << config.ApplicationName() << " Geometry setup complete.";
409 
410  } // GeometryTesterEnvironment<>::Setup()
ConfigurationClass config
instance of the configurer
virtual void SetupGeometry()
Sets up the geometry (creates and registers it)
virtual void Setup()
The complete initialization, ran at construction by default.
template<typename ConfigurationClass >
void testing::GeometryTesterEnvironment< ConfigurationClass >::SetupGeometry ( )
protectedvirtual

Sets up the geometry (creates and registers it)

Definition at line 380 of file geometry_unit_test_base.h.

380  {
381  //
382  // horrible, shameful hack to support the "new" testing environment
383  // while the old one, informally deprecated, is still around;
384  // we will have TWO versions of GeometryCore around.
385  // Ugh.
386  //
388  // new
389  this->template AcquireProvider<geo::GeometryCore>(CreateNewGeometry());
390  } // GeometryTesterEnvironment<>::SetupGeometry()
virtual void RegisterGeometry(SharedGeoPtr_t new_geom)
Get ownership of the specified geometry and registers it as global.
virtual std::unique_ptr< geo::GeometryCore > CreateNewGeometry() const
Creates a new geometry.
template<typename ConfigurationClass>
SharedGeoPtr_t testing::GeometryTesterEnvironment< ConfigurationClass >::SharedGeometry ( ) const
inline

Definition at line 243 of file geometry_unit_test_base.h.

243 { return geom; }
SharedGeoPtr_t geom
pointer to the geometry
template<typename ConfigurationClass>
static SharedGeoPtr_t testing::GeometryTesterEnvironment< ConfigurationClass >::SharedGlobalGeometry ( )
inlinestatic

Returns the current global geometry instance (may be nullptr if none)

Definition at line 253 of file geometry_unit_test_base.h.

254  { return GeoResources_t::ShareResource(); }
static ResourcePtr_t ShareResource(std::string name="")
Retrieves the specified resource for sharing (nullptr if none)

Member Data Documentation

template<typename ConfigurationClass>
ConfigurationClass testing::GeometryTesterEnvironment< ConfigurationClass >::config
private

instance of the configurer

Definition at line 279 of file geometry_unit_test_base.h.

template<typename ConfigurationClass>
SharedGeoPtr_t testing::GeometryTesterEnvironment< ConfigurationClass >::geom
private

pointer to the geometry

Definition at line 281 of file geometry_unit_test_base.h.


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