DetectorClocksStandardTestHelpers.h
Go to the documentation of this file.
1 /**
2  * @file DetectorClocksStandardTestHelpers.h
3  * @brief Helper functions for support of DetectorClocksService in LArSoft tests
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date May 6th, 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_DETECTORCLOCKSSTANDARDTESTHELPERS_H
18 #define LARDATA_DETECTORINFO_DETECTORCLOCKSSTANDARDTESTHELPERS_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 <memory> // std::unique_ptr<>
30 #include <string>
31 
32 namespace testing {
33 
34  /**
35  * @brief Set up a detinfo::DetectorClocksStandard from a parameter set.
36  * @return pointer to a newly created and set up DetectorClocksService
37  *
38  * This function specialization enables the support of `SetupProvider()`
39  * methods of `testing::TesterEnvironment`.
40  */
41  template <>
42  struct ProviderSetupClass<detinfo::DetectorClocksStandard> {
43 
44  static std::unique_ptr<detinfo::DetectorClocksStandard>
46  {
47  // some feedback about whether we are using the right configuration
48  std::string ServiceProviderPath;
49  if (pset.get_if_present("service_provider", ServiceProviderPath)) {
50  std::string ServiceProviderName = ServiceProviderPath;
51  size_t iSlash = ServiceProviderPath.rfind('/');
52  if (iSlash != std::string::npos) ServiceProviderName.erase(0, iSlash + 1);
53 
54  if (ServiceProviderName == "DetectorClocksServiceStandard") {
55  MF_LOG_TRACE("setupProvider")
56  << "Verified service implementation for DetectorClocksService: '" << ServiceProviderPath
57  << "'";
58  }
59  else {
60  mf::LogWarning("setupProvider")
61  << "This set up is for a DetectorClocksStandard provider.\n"
62  "Your configuration specifies a '"
63  << ServiceProviderPath
64  << "' service implementation"
65  " that is not known to use that provider.";
66  }
67  }
68 
69  //
70  // create the new DetectorClocksStandard service provider
71  //
72  auto detClocks = std::make_unique<detinfo::DetectorClocksStandard>(pset);
73 
74  //
75  // all done
76  //
77  return detClocks;
78  } // setup()
79 
80  }; // ProviderSetupClass<DetectorClocksStandard>
81 
82  /**
83  * @brief Environment setup helper for DetectorClocksStandard.
84  * @tparam TestEnv type of environment to set up
85  * @see simpleEnvironmentSetup
86  *
87  * A service provider is set up in the environment, associated with the types
88  * detinfo::DetectorClocksStandard and detinfo::DetectorClocks.
89  * Its configuration is read from "services.DetectorClocksService".
90  *
91  * The environment is expected to expose an interface equivalent to the one
92  * of `testing::TesterEnvironment`.
93  *
94  * This class specialisation enables the support of `SimpleProviderSetup()`
95  * methods of `testing::TesterEnvironment`.
96  * It should be possible to set up a testing environment by calling:
97  *
98  * env.SimpleProviderSetup<detinfo::DetectorClocksStandard>();
99  *
100  * The provider will be available from any of these two calls:
101  *
102  * env.Provider<detinfo::DetectorClocksStandard>();
103  * env.Provider<detinfo::DetectorClocks>();
104  *
105  *
106  */
107  template <typename TestEnv>
108  struct SimpleEnvironmentSetupClass<detinfo::DetectorClocksStandard, TestEnv> {
110  setup(TestEnv& env)
111  {
114  TestEnv>(env, "DetectorClocksService");
115  }
116  };
117 
118 } // namespace testing
119 
120 #endif // LARDATA_DETECTORINFO_DETECTORCLOCKSSTANDARDTESTHELPERS_H
LArSoft test utilities.
std::string string
Definition: nybbler.cc:12
Environment helper to set up a service provider.
#define MF_LOG_TRACE(id)
Class to create and set up a new provider.
static std::unique_ptr< detinfo::DetectorClocksStandard > setup(fhicl::ParameterSet const &pset)
General LArSoft Utilities.
Class used for the conversion of times between different formats and references.
Prov * SimpleEnvironmentStandardSetupByName(TestEnv &env, std::string service_name)
Basic implementation of a environment setup helper.
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.