LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
geometry_unit_test_base.h
Go to the documentation of this file.
1 
27 #ifndef TEST_GEOMETRY_UNIT_TEST_BASE_H
28 #define TEST_GEOMETRY_UNIT_TEST_BASE_H
29 
30 // LArSoft libraries
35 
36 // Framework libraries
37 #include "cetlib/search_path.h"
38 #include "fhiclcpp/ParameterSet.h"
40 
41 // C/C++ standard libraries
42 #include <iostream> // for output before message facility is set up
43 #include <map>
44 #include <memory> // std::unique_ptr<>
45 #include <string>
46 #include <type_traits>
47 
48 namespace testing {
49 
61 
64 
67  : BasicEnvironmentConfiguration(argc, argv)
68  {
69  LocalInit();
70  }
71 
74  {
75  LocalInit();
76  }
77 
78  BasicGeometryEnvironmentConfiguration(int argc, char** argv, std::string name)
79  : BasicEnvironmentConfiguration(argc, argv, name)
80  {
81  LocalInit();
82  }
83 
87  std::string GeometryParameterSetPath() const
88  {
90  }
91 
93  std::string DefaultGeometryConfiguration() const
94  {
96  }
97 
99 
102 
104  void SetGeometryParameterSetPath(std::string path)
105  {
107  }
108 
110  void SetDefaultGeometryConfiguration(std::string cfg)
111  {
113  }
114 
116 
118  static std::string GeometryServiceName() { return "Geometry"; }
119 
120  protected:
122  void LocalInit()
123  {
125  SurfaceY: 200. # in cm, vertical distance to the surface
126  Name: "lartpcdetector"
127  GDML: "LArTPCdetector.gdml"
128  ROOT: "LArTPCdetector.gdml"
129  SortingParameters: { tool_type: GeoObjectSorterStandard }
130  )");
131  } // LocalInit()
132 
133  }; // class BasicGeometryEnvironmentConfiguration<>
134 
178  template <typename ConfigurationClass, typename ObjectSorter>
179  class GeometryTesterEnvironment : public TesterEnvironment<ConfigurationClass> {
181 
182  public:
189  GeometryTesterEnvironment(bool bSetup = true) : TesterEnvironment_t(false)
190  {
191  if (bSetup) Setup();
192  }
193 
195 
206  GeometryTesterEnvironment(ConfigurationClass const& cfg_obj, bool bSetup = true)
207  : TesterEnvironment_t(cfg_obj, false)
208  {
209  if (bSetup) Setup();
210  }
211  GeometryTesterEnvironment(ConfigurationClass&& cfg_obj, bool bSetup = true)
212  : TesterEnvironment_t(std::move(cfg_obj), false)
213  {
214  if (bSetup) Setup();
215  }
217 
218  geo::GeometryCore const* Geometry() const noexcept
219  {
220  return this->template Provider<geo::GeometryCore>();
221  }
222 
224  virtual ~GeometryTesterEnvironment();
225 
226  protected:
228  void Setup();
229 
231  virtual std::unique_ptr<geo::GeometryCore> CreateNewGeometry() const;
232 
233  private:
234  ConfigurationClass config;
235 
236  }; // class GeometryTesterEnvironment<>
237 
238  template <typename ObjectSorter>
239  auto createSorter(fhicl::ParameterSet const& pset [[maybe_unused]])
240  {
241  if constexpr (std::is_constructible_v<ObjectSorter>) {
242  return std::make_unique<ObjectSorter>();
243  }
244  else if constexpr (std::is_constructible_v<ObjectSorter, fhicl::ParameterSet>) {
245  return std::make_unique<ObjectSorter>(pset);
246  }
247  }
248 
249  //****************************************************************************
250  template <typename ConfigurationClass, typename ObjectSorter>
252  {
253  mf::LogInfo("Test") << config.ApplicationName() << " completed.";
254  }
255 
266  template <typename ConfigurationClass, typename ObjectSorter>
267  std::unique_ptr<geo::GeometryCore>
269  {
270  std::string ProviderParameterSetPath = this->Config().GeometryParameterSetPath();
271 
272  fhicl::ParameterSet ProviderConfig =
273  this->Parameters().template get<fhicl::ParameterSet>(ProviderParameterSetPath);
274 
275  return std::make_unique<geo::GeometryCore>(
276  ProviderConfig,
277  std::make_unique<geo::GeometryBuilderStandard>(
278  ProviderConfig.get<fhicl::ParameterSet>("Builder", {})),
279  createSorter<ObjectSorter>(ProviderConfig.get<fhicl::ParameterSet>("SortingParameters", {})));
280  }
281 
282  template <typename ConfigurationClass, typename ObjectSorter>
284  {
285  TesterEnvironment_t::Setup();
286  this->AcquireProvider(CreateNewGeometry());
287  mf::LogInfo("Test") << config.ApplicationName() << " Geometry setup complete.";
288  }
289 
290 } // namespace testing
291 
292 #endif // TEST_GEOMETRY_UNIT_TEST_BASE_H
BasicGeometryEnvironmentConfiguration()
Default constructor; this is what is used in Boost unit test.
LArSoft test utilities.
GeometryTesterEnvironment(bool bSetup=true)
Constructor: sets everything up and declares the test started.
static std::string GeometryServiceName()
Returns the name of the service.
virtual std::unique_ptr< geo::GeometryCore > CreateNewGeometry() const
Creates a new geometry.
geo::GeometryCore const * Geometry() const noexcept
void LocalInit()
Initialize with some default values.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
BasicGeometryEnvironmentConfiguration(int argc, char **argv, std::string name)
Class holding a configuration for a test environment.
void SetDefaultGeometryConfiguration(std::string cfg)
Sets a string describing the default parameter set to configure geometry.
STL namespace.
void SetGeometryParameterSetPath(std::string path)
Sets the FHiCL path for the geometry configuration.
auto createSorter(fhicl::ParameterSet const &pset[[maybe_unused]])
void AddDefaultServiceConfiguration(std::string service_name, std::string service_cfg)
Adds a default configuration for the specified service.
Access the description of the physical detector geometry.
std::string ServiceParameterSetPath(std::string name) const
FHiCL path for the configuration of the service.
BasicGeometryEnvironmentConfiguration(std::string name)
Constructor; accepts the name as parameter.
void Setup()
The complete initialization, ran at construction by default.
std::string DefaultServiceConfiguration(std::string service_name) const
A string describing the default parameter set to configure the test.
Environment for a geometry test.
BasicGeometryEnvironmentConfiguration(int argc, char **argv)
Constructor: acquires parameters from the command line.
GeometryTesterEnvironment(ConfigurationClass const &cfg_obj, bool bSetup=true)
Setup from a configuration.
std::string DefaultGeometryConfiguration() const
A string describing the default parameter set to configure geometry.
Description of the physical geometry of one entire detector.
Definition: GeometryCore.h:91
A test environment with some support for service providers.
Class holding a configuration for a test environment.
virtual ~GeometryTesterEnvironment()
Destructor: closing remarks.
std::string GeometryParameterSetPath() const
A string describing the default parameter set to configure geometry.
Base class for unit tests using FHiCL configuration.
ConfigurationClass config
instance of the configurer
void SetServiceParameterSetPath(std::string service_name, std::string path)
Sets the FHiCL path for the configuration of a test algorithm.
GeometryTesterEnvironment(ConfigurationClass &&cfg_obj, bool bSetup=true)
Setup from a configuration.