electronics.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/Utilities/quantities/electronics.h
3  * @brief Dimensioned variables related to electronics.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 2, 2018
6  * @see lardataalg/Utilities/quantities.h
7  *
8  * Set of basic quantities related to electronics. Currently, quantities are
9  * defined based on the following units:
10  * * tick
11  *
12  * This is a header-only library.
13  *
14  */
15 
16 #ifndef LARDATAALG_UTILITIES_QUANTITIES_ELECTRONICS_H
17 #define LARDATAALG_UTILITIES_QUANTITIES_ELECTRONICS_H
18 
19 // LArSoft libraries
22 
23 // C/C++ standard libraries
24 #include <string_view>
25 #include <ratio>
26 #include <cstddef> // std::ptrdiff_t
27 
28 
29 //------------------------------------------------------------------------------
30 namespace util::quantities {
31 
32  namespace units {
33 
34  using namespace std::string_view_literals; // for operator""sv()
35 
36  struct Tick: public concepts::UnitBase {
37  static constexpr auto symbol = "#"sv;
38  static constexpr auto name = "tick"sv;
39  };
40 
41  struct Counts: public concepts::UnitBase {
42  static constexpr auto symbol = "#"sv;
43  static constexpr auto name = "counts"sv;
44  };
45 
46  } // namespace units
47 
48 
49  // -- BEGIN Ticks ------------------------------------------------------------
50  /**
51  * @name Ticks
52  *
53  * These tick quantities are tied to `util::quantities::units::Tick`.
54  * A few options are provided:
55  *
56  * * generic template (`tick_as`), allowing to choose which numerical
57  * representation to use
58  * * unsigned integer (`tick`), based on `std::ptrdiff_t`, ready for use
59  *
60  * For this unit in particular, additional options are provided to accommodate
61  * the custom of using the unit in plural form: `ticks_as` and `ticks`
62  * are exactly equivalent to the singular-named counterparts.
63  */
64  /// @{
65 
66  /// Tick number, represented by the specified type `T`.
67  template <typename T = std::ptrdiff_t>
69 
70  /// Alias for common language habits.
71  template <typename T = tick_as<>::value_t>
73 
74  /// Tick number, represented by `std::ptrdiff_t`.
75  using tick = tick_as<>;
76 
77  /// Alias for common language habits.
78  using ticks = tick;
79 
80  /// Tick number, represented by `float`.
82 
83  /// Alias for common language habits.
84  using ticks_f = tick_f;
85 
86  /// Tick number, represented by `double`.
88 
89  /// Alias for common language habits.
90  using ticks_d = tick_d;
91 
92 
93  /// @}
94  // -- END Ticks --------------------------------------------------------------
95 
96 
97  // -- BEGIN ADC counts -------------------------------------------------------
98  /**
99  * @name ADC counts
100  *
101  * These ADC count quantities are tied to `util::quantities::units::Counts`.
102  * A few options are provided:
103  *
104  * * generic template (`counts_as`), allowing to choose which numerical
105  * representation to use
106  * * unsigned integer (`counts`), based on `signed short int`, ready for use
107  *
108  */
109  /// @{
110 
111  /// Number of ADC counts, represented by the specified type `T`.
112  template <typename T = signed short int>
114 
115  /// Number of ADC counts, represented by `signed short int`.
117 
118  /// Number of ADC counts, represented by `float`.
120 
121  // -- END ADC counts ---------------------------------------------------------
122 
123 
124  /**
125  * @brief Literal constants for electronics quantities.
126  *
127  * These functions allow a simplified syntax for specifying a tick quantity.
128  * In order to use these, their namespace must be used:
129  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
130  * using namespace util::quantities::electronics_literals;
131  *
132  * // definition of `util::quantities::tick` constant:
133  * constexpr auto i = 56_tick;
134  *
135  * // definition of `util::quantities::counts` constant:
136  * constexpr auto q = 675_ADC;
137  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138  *
139  */
140  namespace electronics_literals {
141 
142  // @{
143  /// Literal tick value.
144  constexpr tick operator""_tick (long double v)
145  { return tick::castFrom(v); }
146  constexpr tick operator""_tick (unsigned long long int v)
147  { return tick::castFrom(v); }
148  // @}
149 
150  // @{
151  /// Literal tick (`double`-based, `tick_d`) value.
152  constexpr tick_d operator""_tickd (long double v)
153  { return tick_d::castFrom(v); }
154  constexpr tick_d operator""_tickd (unsigned long long int v)
155  { return tick_d::castFrom(v); }
156  // @}
157 
158  // @{
159  /// Literal ADC count value.
160  constexpr counts operator""_ADC (long double v)
161  { return counts{ static_cast<signed short int>(v) }; }
162  constexpr counts operator""_ADC (unsigned long long int v)
163  { return counts{ static_cast<signed short int>(v) }; }
164  // @}
165 
166  // @{
167  /// Literal ADC count value (single precision floating points).
168  constexpr counts_f operator""_ADCf (long double v)
169  { return counts_f{ static_cast<float>(v) }; }
170  constexpr counts_f operator""_ADCf (unsigned long long int v)
171  { return counts_f{ static_cast<float>(v) }; }
172  // @}
173 
174 
175  } // electronics_literals
176 
177 
178  // --- BEGIN Tick intervals --------------------------------------------------
179 
180  namespace intervals {
181 
182  /// A `units::Ticks`-based interval.
183  template <typename T = util::quantities::tick_as<>::value_t>
185 
186  /// A tick interval based on `std::ptrdiff_t`.
187  using ticks = ticks_as<>;
188 
189  /// A tick interval based on single precision real number.
191 
192  /// A tick interval based on double precision real number.
194 
195  } // namespace intervals
196 
197  // --- END Time intervals ----------------------------------------------------
198 
199 
200  // --- BEGIN Time points -----------------------------------------------------
201 
202  namespace points {
203 
204  /// A `units::Ticks`-based point.
205  template <
207  typename Cat = NoCategory
208  >
210 
211  /// A tick value based on `std::ptrdiff_t`.
212  using tick = tick_as<>;
213 
214  /// A tick value based on single precision real number.
216 
217  /// A tick value based on double precision real number.
219 
220  } // namespace points
221 
222  // --- END Tick points -------------------------------------------------------
223 
224 
225  /// @}
226 
227 } // namespace util::quantities
228 
229 //------------------------------------------------------------------------------
230 
231 
232 #endif // LARDATAALG_UTILITIES_QUANTITIES_ELECTRONICS_H
static QCString name
Definition: declinfo.cpp:673
static constexpr quantity_t castFrom(U value)
Returns a new quantity initialized with the specified value.
Definition: quantities.h:825
tick_as< double > tick_d
Tick number, represented by double.
Definition: electronics.h:87
Defines point and interval variables based on quantities.
A value measured in the specified unit.
Definition: quantities.h:566
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
T value_t
Type of the stored value.
Definition: quantities.h:570
Numeric variable proxies with embedded unit of measurement.
Types of variables with a unit.
Definition: intervals.h:20
tick_as< float > tick_f
Tick number, represented by float.
Definition: electronics.h:81