LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
frequency.h
Go to the documentation of this file.
1 
24 #ifndef LARDATAALG_UTILITIES_QUANTITIES_FREQUENCY_H
25 #define LARDATAALG_UTILITIES_QUANTITIES_FREQUENCY_H
26 
27 // LArSoft libraries
29 #include "lardataalg/Utilities/quantities/spacetime.h" // ...::units::Second
30 
31 // C/C++ standard libraries
32 #include <ratio>
33 #include <string_view>
34 
35 //------------------------------------------------------------------------------
36 namespace util::quantities {
37 
38  namespace units {
39 
40  using namespace std::string_view_literals; // for operator""sv()
41 
42  struct Hertz : public concepts::UnitBase {
43  static constexpr auto symbol = "Hz"sv;
44  static constexpr auto name = "hertz"sv;
45  };
46 
47  } // namespace units
48 
49  // -- BEGIN Frequency --------------------------------------------------------
64 
67  template <typename R, typename T = double>
69 
70  //
71  // hertz
72  //
74  template <typename T = double>
76 
78  using hertz = hertz_as<>;
79 
80  //
81  // kilohertz
82  //
84  template <typename T = double>
86 
89 
90  //
91  // megahertz
92  //
94  template <typename T = double>
96 
99 
100  //
101  // gigahertz
102  //
104  template <typename T = double>
106 
109 
126  namespace frequency_literals {
127 
128  // @{
130  constexpr hertz operator""_Hz(long double v)
131  {
132  return hertz{static_cast<double>(v)};
133  }
134  constexpr hertz operator""_Hz(unsigned long long int v)
135  {
136  return hertz{static_cast<double>(v)};
137  }
138  // @}
139 
140  // @{
142  constexpr kilohertz operator""_kHz(long double v)
143  {
144  return kilohertz{static_cast<double>(v)};
145  }
146  constexpr kilohertz operator""_kHz(unsigned long long int v)
147  {
148  return kilohertz{static_cast<double>(v)};
149  }
150  // @}
151 
152  // @{
154  constexpr megahertz operator""_MHz(long double v)
155  {
156  return megahertz{static_cast<double>(v)};
157  }
158  constexpr megahertz operator""_MHz(unsigned long long int v)
159  {
160  return megahertz{static_cast<double>(v)};
161  }
162  // @}
163 
164  // @{
166  constexpr gigahertz operator""_GHz(long double v)
167  {
168  return gigahertz{static_cast<double>(v)};
169  }
170  constexpr gigahertz operator""_GHz(unsigned long long int v)
171  {
172  return gigahertz{static_cast<double>(v)};
173  }
174  // @}
175 
176  } // namespace frequency_literals
177 
179  // -- END Frequency ----------------------------------------------------------
180 
181  // -- BEGIN Special operations between Second and Hertz units ----------------
192 
194  namespace concepts {
196 
207  template <typename TR, typename TT, typename FR, typename FT>
208  constexpr auto operator*(scaled_quantity<util::quantities::units::Second, TR, TT> t,
209  scaled_quantity<util::quantities::units::Hertz, FR, FT> f)
210  -> decltype(std::declval<TT>() * std::declval<FT>());
211  template <typename FR, typename FT, typename TR, typename TT>
214  {
215  return t * f;
216  }
218 
232  template <typename T, typename TR, typename TT>
233  constexpr auto operator/(T v, scaled_second<TR, TT> t) -> std::enable_if_t<
234  std::is_convertible_v<T, TT>,
235  scaled_hertz<details::invert_t<TR>, decltype(std::declval<T>() / std::declval<TT>())>>;
236 
250  template <typename T, typename FR, typename FT>
251  constexpr auto operator/(T v, scaled_hertz<FR, FT> f) -> std::enable_if_t<
252  std::is_convertible_v<T, FT>,
253  scaled_second<details::invert_t<FR>, decltype(std::declval<T>() / std::declval<FT>())>>;
254 
255  } // namespace concepts
256 
258  // -- END Special operations between Second and Hertz units ------------------
259 
260 } // namespace util::quantities
261 
262 //------------------------------------------------------------------------------
263 //--- template implementation
264 template <typename TR, typename TT, typename FR, typename FT>
268  -> decltype(std::declval<TT>() * std::declval<FT>())
269 {
270  return details::applyRatioToValue<simplified_ratio_multiply<TR, FR>>(t.value() * f.value());
271 } // util::quantities::operator*(Second, Hertz)
272 
273 //------------------------------------------------------------------------------
274 template <typename T, typename TR, typename TT>
276  -> std::enable_if_t<
277  std::is_convertible_v<T, TT>,
278  scaled_hertz<details::invert_t<TR>, decltype(std::declval<T>() / std::declval<TT>())>>
279 {
280  return scaled_hertz<details::invert_t<TR>,
281  decltype(std::declval<T>() / std::declval<TT>())>::castFrom(v / t.value());
282 } // util::quantities::operator/(Second)
283 
284 //------------------------------------------------------------------------------
285 template <typename T, typename FR, typename FT>
287  -> std::enable_if_t<
288  std::is_convertible_v<T, FT>,
289  scaled_second<details::invert_t<FR>, decltype(std::declval<T>() / std::declval<FT>())>>
290 {
291  return scaled_second<details::invert_t<FR>,
292  decltype(std::declval<T>() / std::declval<FT>())>::castFrom(v / f.value());
293 } // util::quantities::operator/(Hertz)
294 
295 //------------------------------------------------------------------------------
296 
297 //------------------------------------------------------------------------------
298 
299 #endif // LARDATAALG_UTILITIES_QUANTITIES_FREQUENCY_H
constexpr std::enable_if_t< std::is_arithmetic_v< T >, Interval< Q, Cat > > operator/(Interval< Q, Cat > const iv, T const quot)
Definition: intervals.h:560
constexpr auto operator/(T v, scaled_hertz< FR, FT > f) -> std::enable_if_t< std::is_convertible_v< T, FT >, scaled_second< details::invert_t< FR >, decltype(std::declval< T >()/std::declval< FT >())>>
Returns a time as the inverse of a frequency.
Definition: frequency.h:286
TFile f
Definition: plotHisto.C:6
A value measured in the specified unit.
Definition: quantities.h:554
Numeric variable proxies with embedded unit of measurement.
Dimensioned variables representing space or time quantities.
constexpr std::enable_if_t< std::is_arithmetic_v< T >, Interval< Q, Cat > > operator*(Interval< Q, Cat > const iv, T const factor)
Multiplication with a scalar.
Definition: intervals.h:537
Types of variables with a unit.
Definition: intervals.h:20
QuadExpr operator*(double v, const QuadExpr &e)
Definition: QuadExpr.h:44