All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spacetime.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/Utilities/quantities/spacetime.h
3  * @brief Dimensioned variables representing space or time quantities.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date October 30, 2018
6  * @see lardataalg/Utilities/quantities.h
7  *
8  * Set of basic quantities related to space and time. Currently, quantities are
9  * defined based on the following units:
10  * * seconds (ps, ns, us, ms, s), with intervals in `intervals` namespace
11  *
12  * This is a header-only library.
13  *
14  */
15 
16 #ifndef LARDATAALG_UTILITIES_QUANTITIES_SPACETIME_H
17 #define LARDATAALG_UTILITIES_QUANTITIES_SPACETIME_H
18 
19 // LArSoft libraries
22 
23 // C/C++ standard libraries
24 #include <string_view>
25 #include <ratio>
26 
27 
28 //------------------------------------------------------------------------------
29 namespace util::quantities {
30 
31  namespace units {
32 
33  using namespace std::string_view_literals; // for operator""sv()
34 
35  struct Second: public concepts::UnitBase {
36  static constexpr auto symbol = "s"sv;
37  static constexpr auto name = "second"sv;
38  };
39 
40  struct Meter: public concepts::UnitBase {
41  static constexpr auto symbol = "m"sv;
42  static constexpr auto name = "meter"sv;
43  };
44 
45  } // namespace units
46 
47 
48  // -- BEGIN Time -------------------------------------------------------------
49  /**
50  * @name Time quantities
51  *
52  * These time quantities are tied to `util::quantities::units::Second`.
53  * A few options are provided:
54  *
55  * * most general template, `scaled_second`, allowing to choose both the scale
56  * of the unit (e.g. `std::milli` for milliseconds) and the type of the
57  * numerical representation
58  * * generic templates (e.g. `second_as`), allowing to choose which numerical
59  * representation to use
60  * * double precision (e.g. `second`), ready for use
61  *
62  * For this unit in particular, additional options are provided to accommodate
63  * the custom of using the unit in plural form: `seconds_as` and `seconds`
64  * are exactly equivalent to the singular-named counterparts.
65  */
66  /// @{
67 
68 
69  /// The most generic `units::Second`-based quantity.
70  template <typename R, typename T = double>
72 
73  //
74  // seconds
75  //
76  /// Type of time stored in seconds.
77  template <typename T = double>
79 
80  /// Alias for common language habits.
81  template <typename T = double>
83 
84  /// Type of time stored in seconds, in double precision.
86 
87  /// Alias for common language habits.
88  using seconds = second;
89 
90  //
91  // milliseconds
92  //
93  /// Type of time stored in milliseconds.
94  template <typename T = double>
96 
97  /// Alias for common language habits.
98  template <typename T = double>
100 
101  /// Type of time stored in milliseconds, in double precision.
103 
104  /// Alias for common language habits.
106 
107  //
108  // microseconds
109  //
110  /// Type of time stored in microseconds.
111  template <typename T = double>
113 
114  /// Alias for common language habits.
115  template <typename T = double>
117 
118  /// Type of time stored in microseconds, in double precision.
120 
121  /// Alias for common language habits.
123 
124  //
125  // nanoseconds
126  //
127  /// Type of time stored in nanoseconds.
128  template <typename T = double>
130 
131  /// Alias for common language habits.
132  template <typename T = double>
134 
135  /// Type of time stored in nanoseconds, in double precision.
137 
138  /// Alias for common language habits.
140 
141  //
142  // picoseconds
143  //
144  /// Type of time stored in picoseconds.
145  template <typename T = double>
147 
148  /// Alias for common language habits.
149  template <typename T = double>
151 
152  /// Type of time stored in picoseconds, in double precision.
154 
155  /// Alias for common language habits.
157 
158  /**
159  * @brief Literal constants for time quantities.
160  *
161  * These functions allow a simplified syntax for specifying a time quantity.
162  * In order to use these, their namespace must be used:
163  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
164  * using namespace util::quantities::time_literals;
165  *
166  * // definition of `util::quantities::second` constant:
167  * constexpr auto t_s = 12_s;
168  *
169  * // assignment (likely to a quantity) of
170  * // `util::quantities::millisecond{500.0}`
171  * t_s = 500_ms;
172  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173  *
174  */
175  namespace time_literals {
176 
177  // @{
178  /// Literal second value.
179  constexpr second operator""_s (long double v)
180  { return second{ static_cast<double>(v) }; }
181  constexpr second operator""_s (unsigned long long int v)
182  { return second{ static_cast<double>(v) }; }
183  // @}
184 
185  // @{
186  /// Literal millisecond value.
187  constexpr millisecond operator""_ms (long double v)
188  { return millisecond{ static_cast<double>(v) }; }
189  constexpr millisecond operator""_ms (unsigned long long int v)
190  { return millisecond{ static_cast<double>(v) }; }
191  // @}
192 
193  // @{
194  /// Literal microsecond value.
195  constexpr microsecond operator""_us (long double v)
196  { return microsecond{ static_cast<double>(v) }; }
197  constexpr microsecond operator""_us (unsigned long long int v)
198  { return microsecond{ static_cast<double>(v) }; }
199  // @}
200 
201  // @{
202  /// Literal nanosecond value.
203  constexpr nanosecond operator""_ns (long double v)
204  { return nanosecond{ static_cast<double>(v) }; }
205  constexpr nanosecond operator""_ns (unsigned long long int v)
206  { return nanosecond{ static_cast<double>(v) }; }
207  // @}
208 
209  // @{
210  /// Literal picosecond value.
211  constexpr picosecond operator""_ps (long double v)
212  { return picosecond{ static_cast<double>(v) }; }
213  constexpr picosecond operator""_ps (unsigned long long int v)
214  { return picosecond{ static_cast<double>(v) }; }
215  // @}
216 
217  } // time_literals
218 
219 
220  // --- BEGIN Time intervals --------------------------------------------------
221 
222  namespace intervals {
223 
224  /// The most generic `units::Second`-based interval.
225  template <typename R, typename T = double>
226  using scaled_seconds
228 
229  //
230  // seconds
231  //
232  /// Type of time interval stored in seconds.
233  template <typename T = double>
235 
236  /// Type of time stored in seconds, in double precision.
238 
239  //
240  // milliseconds
241  //
242 
243  /// Type of time interval stored in milliseconds.
244  template <typename T = double>
246 
247  /// Type of time interval stored in milliseconds, in double precision.
249 
250  //
251  // microseconds
252  //
253 
254  /// Type of time interval stored in microseconds.
255  template <typename T = double>
257 
258  /// Type of time interval stored in microseconds, in double precision.
260 
261  //
262  // nanoseconds
263  //
264 
265  /// Type of time interval stored in nanoseconds.
266  template <typename T = double>
268 
269  /// Type of time interval stored in nanoseconds, in double precision.
271 
272  //
273  // picoseconds
274  //
275 
276  /// Type of time interval stored in picoseconds.
277  template <typename T = double>
279 
280  /// Type of time interval stored in picoseconds, in double precision.
282 
283 
284  } // namespace intervals
285 
286  // --- END Time intervals ----------------------------------------------------
287 
288 
289  // --- BEGIN Time points -----------------------------------------------------
290 
291  namespace points {
292 
293  /// The most generic `units::Second`-based point.
294  template <typename R, typename T = double, typename Cat = NoCategory>
295  using scaled_second
297 
298  //
299  // second
300  //
301  /// Type of time point stored in seconds.
302  template <typename T = double, typename Cat = NoCategory>
304 
305  /// Type of time point stored in seconds, in double precision.
307 
308  //
309  // millisecond
310  //
311 
312  /// Type of time point stored in milliseconds.
313  template <typename T = double, typename Cat = NoCategory>
315 
316  /// Type of time point stored in milliseconds, in double precision.
318 
319  //
320  // microsecond
321  //
322 
323  /// Type of time point stored in microseconds.
324  template <typename T = double, typename Cat = NoCategory>
326 
327  /// Type of time point stored in microseconds, in double precision.
329 
330  //
331  // nanosecond
332  //
333 
334  /// Type of time point stored in nanoseconds.
335  template <typename T = double, typename Cat = NoCategory>
337 
338  /// Type of time point stored in nanoseconds, in double precision.
340 
341  //
342  // picosecond
343  //
344 
345  /// Type of time point stored in picoseconds.
346  template <typename T = double, typename Cat = NoCategory>
348 
349  /// Type of time point stored in picoseconds, in double precision.
351 
352 
353  } // namespace points
354 
355  // --- END Time points -------------------------------------------------------
356 
357 
358  /// @}
359  // -- END Time ---------------------------------------------------------------
360 
361 
362 
363  // -- BEGIN Space ------------------------------------------------------------
364  /**
365  * @name Linear space quantities
366  *
367  * These space quantities are tied to `util::quantities::units::Meter`.
368  * A few options are provided:
369  *
370  * * most general template, `scaled_meter`, allowing to choose both the scale
371  * of the unit (e.g. `std::milli` for millimeters) and the type of the
372  * numerical representation
373  * * generic templates (e.g. `meter_as`), allowing to choose which numerical
374  * representation to use
375  * * double precision (e.g. `meter`), ready for use
376  *
377  * For this unit in particular, additional options are provided to accommodate
378  * the custom of using the unit in plural form: `meters_as` and `meters`
379  * are exactly equivalent to the singular-named counterparts.
380  */
381  /// @{
382 
383 
384  /// The most generic `units::Meter`-based quantity.
385  template <typename R, typename T = double>
387 
388  //
389  // meters
390  //
391  /// Type of space stored in meters.
392  template <typename T = double>
394 
395  /// Alias for common language habits.
396  template <typename T = double>
398 
399  /// Type of space stored in meters, in double precision.
400  using meter = meter_as<>;
401 
402  /// Alias for common language habits.
403  using meters = meter;
404 
405  //
406  // kilometers
407  //
408  /// Type of space stored in kilometers.
409  template <typename T = double>
411 
412  /// Alias for common language habits.
413  template <typename T = double>
415 
416  /// Type of space stored in kilometers, in double precision.
418 
419  /// Alias for common language habits.
421 
422  //
423  // centimeters
424  //
425  /// Type of space stored in centimeters.
426  template <typename T = double>
428 
429  /// Alias for common language habits.
430  template <typename T = double>
432 
433  /// Type of space stored in centimeters, in double precision.
435 
436  /// Alias for common language habits.
438 
439  //
440  // millimeters
441  //
442  /// Type of space stored in millimeters.
443  template <typename T = double>
445 
446  /// Alias for common language habits.
447  template <typename T = double>
449 
450  /// Type of space stored in millimeters, in double precision.
452 
453  /// Alias for common language habits.
455 
456  //
457  // micrometers
458  //
459  /// Type of space stored in micrometers.
460  template <typename T = double>
462 
463  /// Alias for common language habits.
464  template <typename T = double>
466 
467  /// Type of space stored in micrometers, in double precision.
469 
470  /// Alias for common language habits.
472 
473  //
474  // nanometers
475  //
476  /// Type of space stored in nanometers.
477  template <typename T = double>
479 
480  /// Alias for common language habits.
481  template <typename T = double>
483 
484  /// Type of space stored in nanometers, in double precision.
486 
487  /// Alias for common language habits.
489 
490  //
491  // picometers
492  //
493  /// Type of space stored in picometers.
494  template <typename T = double>
496 
497  /// Alias for common language habits.
498  template <typename T = double>
500 
501  /// Type of space stored in picometers, in double precision.
503 
504  /// Alias for common language habits.
506 
507  //
508  // femtometers
509  //
510  /// Type of space stored in femtometers.
511  template <typename T = double>
513 
514  /// Alias for common language habits.
515  template <typename T = double>
517 
518  /// Type of space stored in femtometers, in double precision.
520 
521  /// Alias for common language habits.
523 
524  /**
525  * @brief Literal constants for space quantities.
526  *
527  * These functions allow a simplified syntax for specifying a space quantity.
528  * In order to use these, their namespace must be used:
529  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
530  * using namespace util::quantities::space_literals;
531  *
532  * // definition of `util::quantities::meter` constant:
533  * constexpr auto d_m = 12_m;
534  *
535  * [...]
536  *
537  * // assignment (likely to a quantity) of
538  * // `util::quantities::centimeter{500.0}`
539  * d_m = 500_cm;
540  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
541  *
542  */
543  namespace space_literals {
544 
545  // @{
546  /// Literal meter value.
547  constexpr meter operator""_m (long double v)
548  { return meter{ static_cast<double>(v) }; }
549  constexpr meter operator""_m (unsigned long long int v)
550  { return meter{ static_cast<double>(v) }; }
551  // @}
552 
553  // @{
554  /// Literal kilometer value.
555  constexpr kilometer operator""_km (long double v)
556  { return kilometer{ static_cast<double>(v) }; }
557  constexpr kilometer operator""_km (unsigned long long int v)
558  { return kilometer{ static_cast<double>(v) }; }
559  // @}
560 
561  // @{
562  /// Literal centimeter value.
563  constexpr centimeter operator""_cm (long double v)
564  { return centimeter{ static_cast<double>(v) }; }
565  constexpr centimeter operator""_cm (unsigned long long int v)
566  { return centimeter{ static_cast<double>(v) }; }
567  // @}
568 
569  // @{
570  /// Literal millimeter value.
571  constexpr millimeter operator""_mm (long double v)
572  { return millimeter{ static_cast<double>(v) }; }
573  constexpr millimeter operator""_mm (unsigned long long int v)
574  { return millimeter{ static_cast<double>(v) }; }
575  // @}
576 
577  // @{
578  /// Literal micrometer value.
579  constexpr micrometer operator""_um (long double v)
580  { return micrometer{ static_cast<double>(v) }; }
581  constexpr micrometer operator""_um (unsigned long long int v)
582  { return micrometer{ static_cast<double>(v) }; }
583  // @}
584 
585  // @{
586  /// Literal nanometer value.
587  constexpr nanometer operator""_nm (long double v)
588  { return nanometer{ static_cast<double>(v) }; }
589  constexpr nanometer operator""_nm (unsigned long long int v)
590  { return nanometer{ static_cast<double>(v) }; }
591  // @}
592 
593  // @{
594  /// Literal picometer value.
595  constexpr picometer operator""_pm (long double v)
596  { return picometer{ static_cast<double>(v) }; }
597  constexpr picometer operator""_pm (unsigned long long int v)
598  { return picometer{ static_cast<double>(v) }; }
599  // @}
600 
601  // @{
602  /// Literal femtometer value.
603  constexpr femtometer operator""_fm (long double v)
604  { return femtometer{ static_cast<double>(v) }; }
605  constexpr femtometer operator""_fm (unsigned long long int v)
606  { return femtometer{ static_cast<double>(v) }; }
607  // @}
608 
609  } // space_literals
610 
611 
612  // --- BEGIN Space intervals -------------------------------------------------
613 
614  namespace intervals {
615 
616  /// The most generic `units::Meter`-based interval.
617  template <typename R, typename T = double>
618  using scaled_meters
620 
621  //
622  // meters
623  //
624  /// Type of space interval stored in meters.
625  template <typename T = double>
627 
628  /// Type of space stored in meters, in double precision.
630 
631  //
632  // kilometers
633  //
634 
635  /// Type of space interval stored in kilometers.
636  template <typename T = double>
638 
639  /// Type of space interval stored in kilometers, in double precision.
641 
642  //
643  // centimeters
644  //
645 
646  /// Type of space interval stored in centimeters.
647  template <typename T = double>
649 
650  /// Type of space interval stored in centimeters, in double precision.
652 
653  //
654  // millimeters
655  //
656 
657  /// Type of space interval stored in millimeters.
658  template <typename T = double>
660 
661  /// Type of space interval stored in millimeters, in double precision.
663 
664  //
665  // micrometers
666  //
667 
668  /// Type of space interval stored in micrometers.
669  template <typename T = double>
671 
672  /// Type of space interval stored in micrometers, in double precision.
674 
675  //
676  // nanometers
677  //
678 
679  /// Type of space interval stored in nanometers.
680  template <typename T = double>
682 
683  /// Type of space interval stored in nanometers, in double precision.
685 
686  //
687  // picometers
688  //
689 
690  /// Type of space interval stored in picometers.
691  template <typename T = double>
693 
694  /// Type of space interval stored in picometers, in double precision.
696 
697  //
698  // femtometers
699  //
700 
701  /// Type of space interval stored in femtometers.
702  template <typename T = double>
704 
705  /// Type of space interval stored in femtometers, in double precision.
707 
708 
709  } // namespace intervals
710 
711  // --- END Space intervals ---------------------------------------------------
712 
713 
714  // --- BEGIN Space points ----------------------------------------------------
715 
716  namespace points {
717 
718  /// The most generic `units::Meter`-based point.
719  template <typename R, typename T = double, typename Cat = NoCategory>
720  using scaled_meter
722 
723  //
724  // meter
725  //
726  /// Type of space point stored in meters.
727  template <typename T = double, typename Cat = NoCategory>
729 
730  /// Type of space point stored in meters, in double precision.
731  using meter = meter_as<>;
732 
733  //
734  // kilometer
735  //
736 
737  /// Type of space point stored in kilometers.
738  template <typename T = double, typename Cat = NoCategory>
740 
741  /// Type of space point stored in kilometers, in double precision.
743 
744  //
745  // centimeter
746  //
747 
748  /// Type of space point stored in centimeters.
749  template <typename T = double, typename Cat = NoCategory>
751 
752  /// Type of space point stored in centimeters, in double precision.
754 
755  //
756  // millimeter
757  //
758 
759  /// Type of space point stored in millimeters.
760  template <typename T = double, typename Cat = NoCategory>
762 
763  /// Type of space point stored in millimeters, in double precision.
765 
766  //
767  // micrometer
768  //
769 
770  /// Type of space point stored in micrometers.
771  template <typename T = double, typename Cat = NoCategory>
773 
774  /// Type of space point stored in micrometers, in double precision.
776 
777  //
778  // nanometer
779  //
780 
781  /// Type of space point stored in nanometers.
782  template <typename T = double, typename Cat = NoCategory>
784 
785  /// Type of space point stored in nanometers, in double precision.
787 
788  //
789  // picometer
790  //
791 
792  /// Type of space point stored in picometers.
793  template <typename T = double, typename Cat = NoCategory>
795 
796  /// Type of space point stored in picometers, in double precision.
798 
799  //
800  // femtometer
801  //
802 
803  /// Type of space point stored in femtometers.
804  template <typename T = double, typename Cat = NoCategory>
806 
807  /// Type of space point stored in femtometers, in double precision.
809 
810 
811  } // namespace points
812 
813  // --- END Space points -------------------------------------------------------
814 
815 
816  /// @}
817  // -- END Space --------------------------------------------------------------
818 
819 
820 
821 } // namespace util::quantities
822 
823 //------------------------------------------------------------------------------
824 
825 
826 #endif // LARDATAALG_UTILITIES_QUANTITIES_SPACETIME_H
picosecond_as<> picosecond
Type of time stored in picoseconds, in double precision.
Definition: spacetime.h:153
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
millimeter_as<> millimeter
Type of space stored in millimeters, in double precision.
Definition: spacetime.h:451
kilometer_as<> kilometer
Type of space stored in kilometers, in double precision.
Definition: spacetime.h:417
millisecond_as<> millisecond
Type of time stored in milliseconds, in double precision.
Definition: spacetime.h:102
femtometer_as<> femtometer
Type of space stored in femtometers, in double precision.
Definition: spacetime.h:519
concepts::Interval< util::quantities::scaled_meter< R, T >> scaled_meters
The most generic units::Meter-based interval.
Definition: spacetime.h:619
Defines point and interval variables based on quantities.
BEGIN_PROLOG units
A value measured in the specified unit.
Definition: quantities.h:566
concepts::Interval< util::quantities::scaled_second< R, T >> scaled_seconds
The most generic units::Second-based interval.
Definition: spacetime.h:227
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
meter_as<> meter
Type of space stored in meters, in double precision.
Definition: spacetime.h:400
Numeric variable proxies with embedded unit of measurement.
nanosecond_as<> nanosecond
Type of time stored in nanoseconds, in double precision.
Definition: spacetime.h:136
picometer_as<> picometer
Type of space stored in picometers, in double precision.
Definition: spacetime.h:502
then echo fcl name
micrometer_as<> micrometer
Type of space stored in micrometers, in double precision.
Definition: spacetime.h:468
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
nanometer_as<> nanometer
Type of space stored in nanometers, in double precision.
Definition: spacetime.h:485
centimeter_as<> centimeter
Type of space stored in centimeters, in double precision.
Definition: spacetime.h:434