DetectorTimingTypes.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/DetectorInfo/DetectorTimingTypes.h
3  * @brief Data types for `detinfo::DetectorTimings`.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date May 31, 2019
6  *
7  */
8 
9 #ifndef LARDATAALG_DETECTORINFO_DETECTORTIMINGTYPES_H
10 #define LARDATAALG_DETECTORINFO_DETECTORTIMINGTYPES_H
11 
12 // LArSoft libraries
16 
17 
18 /// Namespace including different time scales as defined in LArSoft.
20 
21 
22  /**
23  * @brief A collection of traits for a time scale.
24  * @tparam Cat category the traits belong to
25  *
26  * The included traits are documented in
27  * `details::timescale_traits_base`.
28  *
29  *
30  * Writing traits for a category
31  * ==============================
32  *
33  * Traits are specified by specializing the `timescale_traits` class
34  * for the category. The easiest way is to derive the specialized class
35  * from `details::timescale_traits_base<Cat>` and add the necessary
36  * customization:
37  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
38  * namespace detinfo::timescales {
39  * template <>
40  * struct timescale_traits<MyCat>: details::timescale_traits_base<MyCat>
41  * {
42  * // more customization as needed
43  * };
44  * } // namespace detinfo::timescales
45  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46  *
47  *
48  * Category compatibility
49  * -----------------------
50  *
51  * Among the traits, one offers whether a specified category is "compatible"
52  * with this one. The easiest way to implement that is to define a set of
53  * compatible categories, and then an object which returns whether a
54  * category is among them. This object should override
55  * `category_compatible_with` member of each relevant category trait.
56  * A way to achieve that is to define a specific trait base class:
57  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
58  * struct TimeOnePointOneCategory: util::quantities::concepts::CategoryBase
59  * { static std::string name() { return "time 1.1"; } };
60  *
61  * struct TimeOnePointTwoCategory: util::quantities::concepts::CategoryBase
62  * { static std::string name() { return "time 1.2"; } };
63  *
64  * template <typename TimeOneCat>
65  * struct timeone_traits_base
66  * : detinfo::timescales::details::timescale_traits_base<TimeOneCat>
67  * {
68  * template <typename OC>
69  * static constexpr bool category_compatible_with = util::is_any_of_v
70  * <OC, TimeOnePointOneCategory, TimeOnePointTwoCategory>;
71  * };
72  *
73  * namespace detinfo::timescales {
74  * template <>
75  * struct timescale_traits<::TimeOnePointOneCategory>
76  * : ::timeone_traits_base<::TimeOnePointOneCategory>
77  * {};
78  *
79  * template <>
80  * struct timescale_traits<::TimeOnePointTwoCategory>
81  * : ::timeone_traits_base<::TimeOnePointTwoCategory>
82  * {};
83  *
84  * } // namespace detinfo::timescales
85  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86  *
87  */
88  template <typename Cat>
90 
91 
92  /// Type of time interval (natively in microseconds).
93  /// Intentionally cross-category.
95 
96 
97  namespace details {
98 
99  template <typename Cat, typename = void>
100  struct category_of_t { using type = Cat; };
101 
102  template <typename Cat>
103  struct category_of_t<Cat, std::void_t<typename Cat::category_t>>
104  { using type = typename Cat::category_t; };
105 
106  template <typename Cat>
108 
109  /// A template traits for time scale of category `Cat`.
110  template <typename Cat, typename TimeUnit = util::quantities::microsecond>
112 
113  /// The category this time scale belongs to.
114  using category_t = Cat;
115 
116  /// Type of a time interval in this scale.
118 
119  /// Type of a point on this time scale.
122 
123  /// Type of frequency for this time scale.
124  using frequency_t
125  = decltype(1.0 / std::declval<typename time_interval_t::quantity_t>());
126 
127  /// An interval on this time scale expressed in its ticks (integral).
129  <util::quantities::tick, category_t>;
130 
131  /// An interval on this time scale expressed in its ticks (real).
134 
135  /// A point on this time scale expressed in its ticks.
138 
139  /// A point on this time scale expressed in its ticks (real).
142 
143  /// Name of this time scale.
144  static std::string name() { return category_t::name(); }
145 
146  /// Returns whether the category `OC` is the same as this one.
147  template <typename OC>
148  static constexpr bool same_category_as
149  = std::is_same_v<category_of<OC>, category_t>;
150 
151  /// Returns whether the category `OC` is compatible with this one.
152  template <typename OC>
153  static constexpr bool category_compatible_with
154  = same_category_as<category_of<OC>>;
155 
156  }; // timescale_traits_base<>
157 
158 
159  } // namespace details
160 
161 
162  //----------------------------------------------------------------------------
163  /// Category for electronics time scale.
165  static std::string name() { return { "electronics time" }; }
166  }; // struct ElectronicsTimeCategory
167 
168 
169  /**
170  * @brief Timing types for electronics time scale.
171  *
172  * This object collects data types meant to represent a time on the
173  * @ref DetectorClocksElectronicsTime "electronics time axis", starting at the
174  * @ref DetectorClocksElectronicsStartTime "electronics start time".
175  *
176  * It exposes the interface documented in `details::timescale_traits_base`.
177  */
178  template <>
180  : public details::timescale_traits_base<ElectronicsTimeCategory>
181  {};
182 
183 
184  // ---------------------------------------------------------------------------
185 
186  /// Category for TPC electronics time scale.
188  static std::string name() { return { "TPC electronics time" }; }
189  }; // struct TPCelectronicsTimeCategory
190 
191 
192  /**
193  * @brief Timing types for TPC electronics time scale.
194  *
195  * This object collects data types meant to represent a time on the
196  * @ref DetectorClocksTPCelectronicsTime "TPC electronics time axis", starting
197  * at the
198  * @ref DetectorClocksTPCelectronicsStartTime "TPC electronics start time".
199  *
200  * It exposes the interface documented in `details::timescale_traits_base`.
201  *
202  * This time is natively expressed in microseconds.
203  */
204  template <>
206  : public details::timescale_traits_base<TPCelectronicsTimeCategory>
207  {};
208 
209 
210  // ---------------------------------------------------------------------------
211 
212  /// Category for electronics time scale.
214  static std::string name() { return { "optical electronics time" }; }
215  }; // struct OpticalTimeCategory
216 
217 
218  /**
219  * @brief Timing types for optical detector time scale.
220  *
221  * This object collects data types meant to represent a time on the
222  * @ref DetectorClocksOpticalElectronicsTime "optical detector electronics time axis",
223  * starting at the
224  * @ref DetectorClocksOpticalElectronicsStartTime "optical detector electronics start time".
225  *
226  * @note Unfortunately, that time is not defined, so the functions that need
227  * it pin it down to the start of the electronics time scale.
228  *
229  * This traits expose the interface documented in
230  * `details::timescale_traits_base`.
231  *
232  * This time is natively expressed in microseconds.
233  */
234  template <>
236  : public details::timescale_traits_base<OpticalTimeCategory>
237  {};
238 
239 
240  // ---------------------------------------------------------------------------
241 
242  /// Category for trigger time scale.
244  static std::string name() { return { "hardware trigger time" }; }
245  }; // struct TriggerTimeCategory
246 
247 
248  /**
249  * @brief Timing types for trigger electronics time scale.
250  *
251  * This object collects data types meant to represent a time on the
252  * @ref DetectorClocksTriggerTime "trigger time axis", starting at the
253  * @ref DetectorClocksHardwareTrigger "hardware trigger time".
254  *
255  * This traits expose the interface documented in
256  * `details::timescale_traits_base`.
257  *
258  * This time is natively expressed in microseconds.
259  */
260  template <>
262  : public details::timescale_traits_base<TriggerTimeCategory>
263  {};
264 
265 
266  // ---------------------------------------------------------------------------
267 
268  /// Category for electronics time scale.
270  static std::string name() { return { "simulation time" }; }
271  }; // struct SimulationTimeCategory
272 
273 
274  /**
275  * @brief Timing types for simulation time scale.
276  *
277  * This object collects data types meant to represent a time on the
278  * @ref DetectorClocksSimulationTime "simulation time axis", starting at the
279  * @ref DetectorClocksGeant4TimeStart "GEANT4 time start".
280  *
281  * This traits expose the interface documented in
282  * `details::timescale_traits_base`.
283  *
284  * This time is natively expressed in nanoseconds.
285  */
286  template <>
289  <SimulationTimeCategory, util::quantities::nanosecond>
290  {};
291 
292 
293  // ---------------------------------------------------------------------------
294 
295  // --- BEGIN -- Continuous times ---------------------------------------------
296  /// @name Continuous times
297  /// @{
298 
299  /**
300  * @brief A point in time on the electronics time scale.
301  *
302  * This object is nothing special, but it is meant to represent a time on
303  * the @ref DetectorClocksElectronicsTime "electronics time axis", starting
304  * at the @ref DetectorClocksElectronicsStartTime "electronics start time".
305  *
306  * This time is natively expressed in microseconds.
307  */
308  using electronics_time
310 
311 
312  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
313  /**
314  * @brief A point in time on the TPC electronics time scale.
315  *
316  * This object is meant to represent a time on the
317  * @ref DetectorClocksTPCelectronicsTime "TPC electronics time axis",
318  * starting at the
319  * @ref DetectorClocksTPCelectronicsStartTime "TPC electronics start time".
320  *
321  * This time is natively expressed in microseconds.
322  */
323  using TPCelectronics_time
325 
326 
327  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
328  /**
329  * @brief A point in time on the optical detector electronics time scale.
330  *
331  * This object is meant to represent a time on the
332  * @ref DetectorClocksOpticalElectronicsTime "optical detector electronics time axis",
333  * starting at the
334  * @ref DetectorClocksOpticalElectronicsStartTime "optical detector electronics start time".
335  *
336  * @note Unfortunately, that time is not defined, so the functions that need
337  * it pin it down to the start of the electronics time scale.
338  *
339  * This time is natively expressed in microseconds.
340  */
341  using optical_time
343 
344 
345  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
346  /**
347  * @brief A point in time on the trigger time scale.
348  *
349  * This object is nothing special, but it is meant to represent a time on
350  * the @ref DetectorClocksTriggerTime "trigger time axis", starting
351  * at the @ref DetectorClocksHardwareTrigger "hardware trigger time".
352  *
353  * This time is natively expressed in microseconds.
354  */
356 
357 
358  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
359  /**
360  * @brief A point in time on the simulation time scale.
361  *
362  * This object is meant to represent a time on the
363  * @ref DetectorClocksSimulationTime "simulation time axis", starting at the
364  * @ref DetectorClocksGeant4TimeStart "GEANT4 time start".
365  *
366  * This time is natively expressed in nanoseconds.
367  */
368  using simulation_time
370 
371 
372  /// @}
373  // --- END -- Continuous times ---------------------------------------------
374 
375 
376  // --- BEGIN -- Tick-based times -------------------------------------------
377  /// @name Tick-based times
378  /// @{
379 
380  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
381  /// A point on the electronics time scale expressed in its ticks.
382  using electronics_tick
384 
385  /// A point on the electronics time scale expressed in its ticks (real).
386  using electronics_tick_d
388 
389  /// An interval on the electronics time scale expressed in its ticks.
392 
393  /// An interval on the electronics time scale expressed in its ticks (real).
396 
397 
398  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
399 
400  /// A point on the TPC electronics time scale expressed in its ticks.
401  using TPCelectronics_tick
403 
404  /// A point on the TPC electronics time scale expressed in its ticks (real).
407 
408  /// An interval on the TPC electronics time scale expressed in its ticks.
411 
412  /// An interval on the TPC electronics time scale expressed in its ticks
413  /// (real).
416 
417 
418  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
419 
420  /// A point on the optical detector electronics time scale expressed in its
421  /// ticks.
423 
424  /// A point on the optical detector electronics time scale expressed in its
425  /// ticks (real).
427 
428  /// An interval on the optical detector electronics time scale expressed in
429  /// its ticks.
430  using optical_time_ticks
432 
433  /// An interval on the optical detector electronics time scale expressed in
434  /// its ticks (real).
437 
438 
439  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
440 
441  /// A point on the trigger time scale expressed in its ticks.
443 
444  /// A point on the trigger time scale expressed in its ticks (real).
446 
447  /// An interval on the trigger time scale expressed in its ticks.
448  using trigger_time_ticks
450 
451  /// An interval on the trigger time scale expressed in its ticks (real).
454 
455 
456  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
457  /// Evaluates to whether the specified time `T` is tick-based.
458  template <typename T>
459  struct is_tick_type;
460 
461  /// Whether the specified time `T` is tick-based.
462  template <typename T>
463  constexpr bool is_tick_v = is_tick_type<T>();
464 
465 
466  /// @}
467  // --- END -- Tick-based times ---------------------------------------------
468 
469 
470 } // namespace detinfo::timescales
471 
472 
473 //------------------------------------------------------------------------------
474 
475 /// Namespace including different time scales as defined in LArSoft.
476 namespace detinfo::timescales {
477 
478  // ---------------------------------------------------------------------------
479  namespace details {
480 
481  // -------------------------------------------------------------------------
482  template <typename T, typename = void>
483  struct is_tick_type_impl: std::false_type {};
484 
485 
486  template <typename Q>
487  struct is_tick_type_impl<Q, std::enable_if_t<
488  std::is_same_v<typename Q::baseunit_t, util::quantities::units::Tick>
489  >>
490  : std::true_type
491  {};
492 
493 
494  // -------------------------------------------------------------------------
495 
496  // Generally undefined; suggested to derive from `timescale_traits_base`.
497  template <typename, typename = void>
499 
500  // Specialization for quantities: same traits as quantity category.
501  template <typename WC>
503  <WC, std::enable_if_t
504  <util::quantities::concepts::is_interval_or_point_v<WC>>
505  >
506  : public timescale_traits<typename WC::category_t>
507  {};
508 
509 
510  // -------------------------------------------------------------------------
511 
512  } // namespace details
513 
514 
515  // ---------------------------------------------------------------------------
516 
517  // For customization, pick on `details::custom_timescale_traits`.
518  template <typename Cat>
519  struct timescale_traits: public details::custom_timescale_traits<Cat> {};
520 
521 
522  // ---------------------------------------------------------------------------
523  template <typename T>
525 
526  // ---------------------------------------------------------------------------
527 
528 
529 } // namespace detinfo::timescales
530 
531 
532 //------------------------------------------------------------------------------
533 
534 
535 #endif // LARDATAALG_DETECTORINFO_DETECTORTIMINGTYPES_H
static QCString name
Definition: declinfo.cpp:673
timescale_traits< TriggerTimeCategory >::tick_d_t trigger_tick_d
A point on the trigger time scale expressed in its ticks (real).
Dimensioned variables representing frequency quantities.
timescale_traits< ElectronicsTimeCategory >::tick_t electronics_tick
A point on the electronics time scale expressed in its ticks.
std::string string
Definition: nybbler.cc:12
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
decltype(1.0/std::declval< typename time_interval_t::quantity_t >()) frequency_t
Type of frequency for this time scale.
timescale_traits< TriggerTimeCategory >::tick_t trigger_tick
A point on the trigger time scale expressed in its ticks.
Category for electronics time scale.
util::quantities::intervals::microseconds time_interval
STL namespace.
A collection of traits for a time scale.
timescale_traits< TriggerTimeCategory >::tick_interval_d_t trigger_time_ticks_d
An interval on the trigger time scale expressed in its ticks (real).
Category for electronics time scale.
timescale_traits< OpticalTimeCategory >::tick_interval_d_t optical_time_ticks_d
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
timescale_traits< TPCelectronicsTimeCategory >::tick_d_t TPCelectronics_tick_d
A point on the TPC electronics time scale expressed in its ticks (real).
tick_as< double > tick_d
Tick number, represented by double.
Definition: electronics.h:87
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
timescale_traits< TriggerTimeCategory >::tick_interval_t trigger_time_ticks
An interval on the trigger time scale expressed in its ticks.
timescale_traits< ElectronicsTimeCategory >::tick_interval_t electronics_time_ticks
An interval on the electronics time scale expressed in its ticks.
timescale_traits< ElectronicsTimeCategory >::tick_interval_d_t electronics_time_ticks_d
An interval on the electronics time scale expressed in its ticks (real).
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
timescale_traits< TPCelectronicsTimeCategory >::tick_interval_t TPCelectronics_time_ticks
An interval on the TPC electronics time scale expressed in its ticks.
constexpr bool is_tick_v
Whether the specified time T is tick-based.
Evaluates to whether the specified time T is tick-based.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
timescale_traits< OpticalTimeCategory >::time_point_t optical_time
A point in time on the optical detector electronics time scale.
timescale_traits< ElectronicsTimeCategory >::tick_d_t electronics_tick_d
A point on the electronics time scale expressed in its ticks (real).
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Category for trigger time scale.
A template traits for time scale of category Cat.
timescale_traits< TPCelectronicsTimeCategory >::tick_interval_d_t TPCelectronics_time_ticks_d
Category for electronics time scale.
Category for TPC electronics time scale.
Dimensioned variables related to electronics.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
An non-mandatory base class for interval and point categories.
Definition: intervals.h:52
Dimensioned variables representing space or time quantities.
typename category_of_t< Cat >::type category_of
timescale_traits< OpticalTimeCategory >::tick_d_t optical_tick_d
timescale_traits< TPCelectronicsTimeCategory >::time_point_t TPCelectronics_time
A point in time on the TPC electronics time scale.
Namespace including different time scales as defined in LArSoft.
timescale_traits< TPCelectronicsTimeCategory >::tick_t TPCelectronics_tick
A point on the TPC electronics time scale expressed in its ticks.
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.
static std::string name()
Name of this time scale.