All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpDetWaveformMeta.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/IcarusObj/OpDetWaveformMeta.h
3  * @brief Derivative information from `raw::OpDetWaveform` data.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 29, 2021
6  *
7  */
8 
9 #ifndef ICARUSCODE_ICARUSOBJ_OPDETWAVEFORMMETA_H
10 #define ICARUSCODE_ICARUSOBJ_OPDETWAVEFORMMETA_H
11 
12 
13 // LArSoft libraries
16 
17 // C/C++ standard libraries
18 #include <limits>
19 
20 
21 // -----------------------------------------------------------------------------
22 namespace sbn { struct OpDetWaveformMeta; }
23 /**
24  * @brief Derivative information from `raw::OpDetWaveform` data.
25  *
26  * This objects stores some of the information from `raw::OpDetWaveform`,
27  * with the notable exception of the content of the waveform.
28  * In particular, it reports the time range covered by one waveform, and it may
29  * store whether the range includes the beam gate opening time.
30  *
31  * Times are in the same scale as for `raw::OpDetWaveform`, that is the
32  * @ref DetectorClocksElectronicsStartTime "electronics time scale".
33  * The exact type of that time is `detinfo::timescales::electronics_time`.
34  */
36 
37  // this is the same type used in LArSoft tracking flags: ROOT dictionaries
38  // are already provided in there
39 
40  using Flags_t = ::util::flags::FlagSet<32U>; ///< Type of flag interface.
41 
42  /// Magic value denoting the absence of time information.
43  static constexpr double NoTime = std::numeric_limits<double>::lowest();
44  static constexpr raw::Channel_t NoChannel
45  = std::numeric_limits<raw::Channel_t>::max();
46 
47  /// Namespace for bits in the flags.
48  struct bits {
49 
50  using Flag_t = Flags_t::Flag_t; ///< Type for a single flag.
51 
52  /// Whether this time interval includes the nominal beam gate opening.
53  static constexpr Flag_t WithBeamGate { 0 };
54 
55  /// Whether this time interval includes the hardware trigger time.
56  static constexpr Flag_t WithTrigger { 1 };
57 
58  /// The first flag available for future use.
59  static constexpr Flag_t NFlags { 2 };
60 
61  }; // struct bits
62 
63 
64  // --- BEGIN -- Data members -------------------------------------------------
65 
66  raw::Channel_t channel = NoChannel; ///< ID of the PMT channel.
67 
68  std::size_t nSamples = 0; ///< Number of samples in the waveform.
69 
70  /// Time of the first sample in the waveform [us]
71  double startTime = NoTime;
72  /// Time at the end of the last sample in the waveform [us]
73  double endTime = NoTime;
74 
75  Flags_t flags; ///< All flags (may be set, unset or undefined); see `bits`.
76 
77  // --- END ---- Data members -------------------------------------------------
78 
79 
80  // --- BEGIN -- raw::OpDetWaveform interface replica -------------------------
81  /**
82  * @name `raw::OpDetWaveform` interface replica
83  *
84  * Partial mirror of `raw::OpDetWaveform` interface is provided here to
85  * facilitate static polymorphism ("metaprogramming").
86  * This version reflects the interface as found in LArSoft 9.36.00.
87  *
88  * These methods are supposed to return a value equivalent to the one from
89  * the original waveform.
90  *
91  * @note At this time `TimeStamp()` returns directly `startTime`, implicitly
92  * assuming that `raw::OpDetWaveform::TimeStamp()` time scale matches the
93  * @ref DetectorClocksElectronicsStartTime "electronics time scale".
94  * If this assumption is broken, an additional data member needs to be added.
95  */
96  /// @{
97 
98  /// Returns the channnel ID of the PMT waveform.
99  raw::Channel_t ChannelNumber() const { return channel; }
100 
101  /// Returns the timestamp at the start of the waveform.
103 
104  /// @}
105  // --- END ---- raw::OpDetWaveform interface replica -------------------------
106 
107 
108  // --- BEGIN -- Short bit managing interface ---------------------------------
109 
110  /**
111  * @name Bit query
112  *
113  * Note that each bit may be in an undefined state.
114  * The definition of a bit may be tested directly; for example:
115  * `info.flags.isDefined(bits::WithBeamGate)` returns whether `info` has the
116  * beam gate bit defined.
117  *
118  */
119  /// @{
120 
121  /// Returns whether the time interval includes for sure the beam opening time.
122  bool withBeamGate() const; // inline
123 
124  /// Returns whether the time interval for sure does not include the beam
125  /// opening time.
126  bool withoutBeamGate() const; // inline
127 
128  /// Returns whether the time interval includes for sure the trigger time.
129  bool withTrigger() const; // inline
130 
131  /// Returns whether the time interval for sure does not include the trigger
132  /// time.
133  bool withoutTrigger() const; // inline
134 
135  /// @}
136 
137 
138 }; // sbn::OpDetWaveformMeta
139 
140 
141 // -----------------------------------------------------------------------------
142 // --- inline implementation
143 // -----------------------------------------------------------------------------
146 }
147 
149  return
150  flags.isDefined(bits::WithBeamGate) && flags.isUnset(bits::WithBeamGate);
151 }
152 
154  return flags.isDefined(bits::WithTrigger) && flags.isSet(bits::WithTrigger);
155 }
156 
158  return flags.isDefined(bits::WithTrigger) && flags.isUnset(bits::WithTrigger);
159 }
160 
161 
162 // -----------------------------------------------------------------------------
163 
164 
165 #endif // ICARUSCODE_ICARUSOBJ_OPDETWAVEFORMMETA_H
raw::TimeStamp_t TimeStamp() const
Returns the timestamp at the start of the waveform.
constexpr bool isSet(Flag_t flag) const
Returns if the specified flag is set.
static constexpr Flag_t NFlags
The first flag available for future use.
static constexpr double NoTime
Magic value denoting the absence of time information.
Flags_t::Flag_t Flag_t
Type for a single flag.
double TimeStamp_t
us since 1970, based on TimeService
Derivative information from raw::OpDetWaveform data.
static constexpr raw::Channel_t NoChannel
double endTime
Time at the end of the last sample in the waveform [us].
Class holding flags.
raw::Channel_t ChannelNumber() const
Returns the channnel ID of the PMT waveform.
bool withBeamGate() const
Returns whether the time interval includes for sure the beam opening time.
typename Mask_t::Flag_t Flag_t
Type identifying a single flag.
Definition: FlagSet.h:60
bool withTrigger() const
Returns whether the time interval includes for sure the trigger time.
Namespace for bits in the flags.
static constexpr Flag_t WithBeamGate
Whether this time interval includes the nominal beam gate opening.
Flags_t flags
All flags (may be set, unset or undefined); see bits.
static constexpr Flag_t WithTrigger
Whether this time interval includes the hardware trigger time.
raw::Channel_t channel
ID of the PMT channel.
constexpr bool isDefined(Flag_t flag) const
Returns whether the flag is defined.
double startTime
Time of the first sample in the waveform [us].
std::size_t nSamples
Number of samples in the waveform.