intervals_fhicl.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/Utilities/intervals_fhicl.h
3  * @brief Utilities to read interval and point quantity FHiCL configuration.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 27, 2019
6  *
7  */
8 
9 #ifndef LARDATAALG_UTILITIES_INTERVALS_FHICL_H
10 #define LARDATAALG_UTILITIES_INTERVALS_FHICL_H
11 
12 // LArSoft libraries
15 #include "larcorealg/CoreUtils/StdUtils.h" // util::to_string()
16 
17 // support libraries
18 #include "fhiclcpp/coding.h"
19 
20 // C++ libraries
21 #include <string_view>
22 #include <string>
23 #include <any>
24 
25 
27 
28  // --- BEGIN -- FHiCL encoding ---------------------------------------------
29  /// @name FHiCL encoding
30  /// @{
31 
32  // these utilities need to be defined in the same namespace as `Quantity`
33 
34  /**
35  * @brief Decodes an interval.
36  * @tparam Args types defining the interval type
37  * @param src the data to decode
38  * @param iv the interval where to store the result
39  *
40  * This function fills the object `iv` with information decoded from `src`.
41  *
42  * The decoding happens with `util::quantities::makeInterval()`.
43  *
44  * @note The signature of this function is dictated by FHiCL requirements.
45  */
46  template <typename... Args>
47  void decode(std::any const& src, Interval<Args...>& iv);
48 
49  /**
50  * @brief Decodes a quantity point.
51  * @tparam Args types defining the quantity point type
52  * @param src the data to decode
53  * @param p the quantity point where to store the result
54  *
55  * This function fills the object `iv` with information decoded from `src`.
56  *
57  * The decoding happens with `util::quantities::makePoint()`.
58  *
59  * @note The signature of this function is dictated by FHiCL requirements.
60  */
61  template <typename... Args>
62  void decode(std::any const& src, Point<Args...>& p);
63 
64 
65  /**
66  * @brief Encodes a quantity interval into a FHiCL parameter set atom.
67  * @tparam Args types defining the quantity interval type
68  * @param iv the interval to be encoded
69  * @return the interval encoded into a FHiCL parameter set atom
70  *
71  * This function returns a parameter set atom with the content of the
72  * quantity interval `iv`.
73  *
74  * @note The signature of this function is dictated by FHiCL requirements.
75  */
76  template <typename... Args>
77  ::fhicl::detail::ps_atom_t encode(Interval<Args...> const& iv);
78 
79  /**
80  * @brief Encodes a quantity point into a FHiCL parameter set atom.
81  * @tparam Args types defining the quantity point type
82  * @param pt the quantity point to be encoded
83  * @return the point encoded into a FHiCL parameter set atom
84  *
85  * This function returns a parameter set atom with the content of the
86  * quantity point `p`.
87  *
88  * @note The signature of this function is dictated by FHiCL requirements.
89  */
90  template <typename... Args>
92 
93  /// @}
94  // --- END -- FHiCL encoding -----------------------------------------------
95 
96 } // namespace util::quantities::concepts
97 
98 
99 // -----------------------------------------------------------------------------
100 // --- template implementation
101 // -----------------------------------------------------------------------------
102 template <typename... Args>
104  (std::any const& src, Interval<Args...>& iv)
105 {
106  using interval_t = Interval<Args...>;
107  using quantity_t = typename interval_t::quantity_t;
108 
109  quantity_t q;
111  iv = interval_t{ q };
112 
113 } // util::quantities::concepts::decode(Interval)
114 
115 
116 // -----------------------------------------------------------------------------
117 template <typename... Args>
119  (std::any const& src, Point<Args...>& pt)
120 {
121  using point_t = Point<Args...>;
122  using quantity_t = typename point_t::quantity_t;
123 
124  quantity_t q;
126  pt = point_t{ q };
127 
128 } // util::quantities::concepts::decode(Point)
129 
130 
131 // -----------------------------------------------------------------------------
132 template <typename... Args>
134  (Interval<Args...> const& iv)
135 {
137 } // util::quantities::concepts::encode(Interval)
138 
139 
140 // -----------------------------------------------------------------------------
141 template <typename... Args>
143  (Point<Args...> const& p)
144 {
146 } // util::quantities::concepts::encode(Point)
147 
148 
149 // -----------------------------------------------------------------------------
150 
151 
152 #endif // LARDATAALG_UTILITIES_INTERVALS_FHICL_H
::fhicl::detail::ps_atom_t encode(Point< Args... > const &pt)
Encodes a quantity point into a FHiCL parameter set atom.
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
Infrastructure for the quantities library.
Definition: intervals.h:26
Defines point and interval variables based on quantities.
Utilities to read and write quantities in FHiCL configuration.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
p
Definition: test.py:223
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
void decode(std::any const &src, Interval< Args... > &iv)
Decodes an interval.
std::string ps_atom_t
Definition: coding.h:44
Functions pulling in STL customization if available.