LArPropertiesStandardTestHelpers.h
Go to the documentation of this file.
1 /**
2  * @file LArPropertiesStandardTestHelpers.h
3  * @brief Helper functions for support of LArPropertiesService in LArSoft tests
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date May 5th, 2016
6  *
7  * This library is a pure header.
8  * It requires linkage with:
9  *
10  * * `lardata_DetectorInfo`
11  * * `mf_MessageLogger`
12  * * `mf_Utilities`
13  * * `fhiclcpp`
14  *
15  */
16 
17 #ifndef LARDATA_DETECTORINFO_LARPROPERTIESSTANDARDTESTHELPERS_H
18 #define LARDATA_DETECTORINFO_LARPROPERTIESSTANDARDTESTHELPERS_H 1
19 
20 // LArSoft libraries
23 
24 // framework and utility libraries
25 #include "fhiclcpp/ParameterSet.h"
27 
28 // C/C++ standard libraries
29 #include <string>
30 #include <memory> // std::unique_ptr<>
31 
32 
33 namespace testing {
34 
35  /**
36  * @brief Set up a detinfo::LArPropertiesStandard from a parameter set
37  * @return pointer to a newly created and set up LArPropertiesService
38  *
39  * This function specialization enables the support of `SetupProvider()`
40  * methods of `testing::TesterEnvironment`.
41  */
42  template <>
43  struct ProviderSetupClass<detinfo::LArPropertiesStandard> {
44 
45  static std::unique_ptr<detinfo::LArPropertiesStandard> setup
46  (fhicl::ParameterSet const& pset)
47  {
48  // some feedback about whether we are using the right configuration
49  std::string ServiceProviderPath;
50  if (pset.get_if_present("service_provider", ServiceProviderPath)) {
51  std::string ServiceProviderName = ServiceProviderPath;
52  size_t iSlash = ServiceProviderPath.rfind('/');
53  if (iSlash != std::string::npos)
54  ServiceProviderName.erase(0, iSlash + 1);
55 
56  if (ServiceProviderName == "LArPropertiesServiceStandard") {
57  MF_LOG_TRACE("setupProvider")
58  << "Verified service implementation for LArPropertiesService: '"
59  << ServiceProviderPath << "'";
60  }
61  else {
62  mf::LogWarning("setupProvider")
63  << "This set up is for a LArPropertiesStandard provider.\n"
64  "Your configuration specifies a '" << ServiceProviderPath
65  << "' service implementation that is not known to use that provider.";
66  }
67  }
68 
69  //
70  // create the new LArPropertiesStandard service provider
71  //
72  return std::make_unique<detinfo::LArPropertiesStandard>(pset);
73  } // setup()
74  }; // ProviderSetup<LArPropertiesStandard>
75 
76 
77  /**
78  * @brief Environment setup helper for LArPropertiesStandard
79  * @tparam TestEnv type of environment to set up
80  * @see simpleEnvironmentSetup
81  *
82  * A service provider is set up in the environment, associated with the types
83  * detinfo::LArPropertiesStandard and detinfo::LArProperties.
84  * Its configuration is read from "services.LArPropertiesService".
85  *
86  * The environment is expected to expose an interface equivalent to the one
87  * of `testing::TesterEnvironment`.
88  *
89  * This class specialisation enables the support of `SimpleProviderSetup()`
90  * methods of `testing::TesterEnvironment`.
91  * It should be possible to set up a testing environment by calling:
92  *
93  * env.SimpleProviderSetup<detinfo::LArPropertiesStandard>();
94  *
95  * The provider will be available from any of these two calls:
96  *
97  * env.Provider<detinfo::LArPropertiesStandard>();
98  * env.Provider<detinfo::LArProperties>();
99  *
100  *
101  */
102  template <typename TestEnv>
103  struct SimpleEnvironmentSetupClass<detinfo::LArPropertiesStandard, TestEnv> {
104  static detinfo::LArPropertiesStandard* setup(TestEnv& env)
105  {
108  (env, "LArPropertiesService");
109  }
110  }; // SimpleEnvironmentSetupClass<detinfo::LArPropertiesStandard>
111 
112 
113 } // namespace testing
114 
115 
116 #endif // LARDATA_DETECTORINFO_LARPROPERTIESSTANDARDTESTHELPERS_H
LArSoft test utilities.
Service provider with utility LAr functions.
std::string string
Definition: nybbler.cc:12
static std::unique_ptr< Prov > setup(Args &&...args)
Instantiates a new provider with specified arguments for constructor.
Environment helper to set up a service provider.
#define MF_LOG_TRACE(id)
Class to create and set up a new provider.
General LArSoft Utilities.
Prov * SimpleEnvironmentStandardSetupByName(TestEnv &env, std::string service_name)
Basic implementation of a environment setup helper.
Properties related to liquid argon environment in the detector.
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning