All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ICARUSstandaloneGeometrySetup.h
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/ICARUSstandaloneGeometrySetup.h
3  * @brief Functions to facilitate ICARUS geometry initialization outside _art_.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date April 16, 2020
6  *
7  * This is a header-only library.
8  * It does include some static code (inlined).
9  *
10  * If this library becomes too heavy, it can be left with only the template
11  * definition `icarus::geo::ICARUSStandaloneGeometrySetup()`,
12  * while each specialization of `lar::standalone::SetupGeometry()` can end up
13  * into its own header file.
14  */
15 
16 #ifndef ICARUSCODE_GEOMETRY_ICARUSSTANDALONEGEOMETRYSETUP_H
17 #define ICARUSCODE_GEOMETRY_ICARUSSTANDALONEGEOMETRYSETUP_H
18 
19 
20 // ICARUS libraries
22 
23 // LArSoft libraries
25 
26 // framework libraries
27 #include "fhiclcpp/types/Table.h"
28 #include "fhiclcpp/ParameterSet.h"
29 
30 // C/C++ standard libraries
31 #include <set>
32 #include <memory> // std::make_unique()
33 #include <utility> // std::forward()
34 #include <type_traits> // std::enable_if_t, std::void_t
35 
36 
37 namespace icarus::geo {
38 
39  namespace details {
40 
41  /// Creates a configuration object for `Class` from a parameter set.
42  template <typename Class, typename = void>
44 
45  } // namespace details
46 
47 
48 
49  /**
50  * @brief Initialization of geometry with ICARUS specific conventions.
51  * @tparam ChannelMapClass type of channel mapping to be used
52  * @param pset configuration of the geometry service
53  * @return an initialized instance of `geo::GeometryCore` service provider
54  *
55  * The conventions that are specific to ICARUS are:
56  *
57  * * a copy of the channel mapping algorithm configuration is kept in the
58  * `Geometry` service configuration table, as `ChannelMapping` table;
59  * because of the unusual requirement, this item is _mandatory_ (even if
60  * it may well be empty);
61  * * channel mapping objects may take a `ChannelMapClass::Config` object as
62  * configuration, which can be wrapped in a FHiCL table;
63  * * channel mapping configuration _may_ contain a spurious `tool_type` entry
64  * which is ignored.
65  *
66  */
67  template <typename ChannelMapClass, typename... Args>
68  std::unique_ptr<::geo::GeometryCore>
69  SetupICARUSGeometry(fhicl::ParameterSet const& pset, Args&&... args) {
70 
72  (pset.get<fhicl::ParameterSet>("ChannelMapping"));
73 
74  auto channelMap = std::make_unique<ChannelMapClass>
75  (config, std::forward<Args>(args)...);
76 
78  (pset, move(channelMap));
79 
80  } // SetupICARUSGeometry()
81 
82 } // namespace icarus::geo
83 
84 
85 // specializations
86 namespace icarus::geo::details {
87 
88  /// General implementation: passes the parameter set through
89  template <typename Class, typename /* = void */>
90  struct ConfigObjectMaker {
91 
92  static fhicl::ParameterSet const& make(fhicl::ParameterSet const& pset)
93  { return pset; }
94 
95  }; // struct ConfigObjectMaker
96 
97 
98  /// Specialization: class with a `Config` configuration data structure.
99  template <typename Class>
100  struct ConfigObjectMaker<Class, std::void_t<typename Class::Config>> {
101 
102  using Config = typename Class::Config;
103  using Parameters = fhicl::Table<Config>;
104 
105  static Config make(fhicl::ParameterSet const& pset)
106  { return Parameters{ pset, std::set<std::string>{ "tool_type" } }(); }
107 
108  }; // struct ConfigObjectMaker
109 
110 } // namespace icarus::geo::details
111 
112 
113 namespace lar::standalone {
114 
115  // ---------------------------------------------------------------------------
116  /// Specialization of `lar::standalone::SetupGeometry()`
117  /// for ICARUS channel mapping `icarus::ICARUSChannelMapAlg`.
118  template <>
119  inline std::unique_ptr<geo::GeometryCore>
120  SetupGeometry<icarus::ICARUSChannelMapAlg>(fhicl::ParameterSet const& pset)
121  { return icarus::geo::SetupICARUSGeometry<icarus::ICARUSChannelMapAlg>(pset); }
122 
123 
124  // ---------------------------------------------------------------------------
125 
126 
127 } // namespace lar::standalone
128 
129 
130 
131 #endif // ICARUSCODE_GEOMETRY_ICARUSSTANDALONEGEOMETRYSETUP_H
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
std::unique_ptr<::geo::GeometryCore > SetupICARUSGeometry(fhicl::ParameterSet const &pset, Args &&...args)
Initialization of geometry with ICARUS specific conventions.
Channel mapping algorithms for ICARUS detector.
Utilities for one-line geometry initialization.
static fhicl::ParameterSet const & make(fhicl::ParameterSet const &pset)
Creates a configuration object for Class from a parameter set.
std::unique_ptr< geo::GeometryCore > SetupGeometryWithChannelMapping(fhicl::ParameterSet const &pset, std::unique_ptr< geo::ChannelMapAlg > channelMap)
Initializes a LArSoft geometry object.
typename make_void< Ts...>::type void_t
Definition: json.hpp:2267