All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BeamBits.h
Go to the documentation of this file.
1 /**
2  * @file sbnobj/Common/Trigger/BeamBits.h
3  * @brief Definitions of the trigger bits for SBN.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date May 19, 2021
6  *
7  * This is a header-only library.
8  *
9  * @todo This header should be moved into the proper place
10  * (proposal: `sbnobj/Common/Trigger` in `sbnobj`)
11  */
12 
13 #ifndef SBNOBJ_COMMON_TRIGGER_BEAMBITS_H
14 #define SBNOBJ_COMMON_TRIGGER_BEAMBITS_H
15 
16 
17 // C/C++ standard libraries
18 #include <stdexcept> // std::runtime_error
19 #include <string>
20 #include <vector>
21 #include <initializer_list>
22 #include <type_traits> // std::underlying_type_t
23 
24 
25 // -----------------------------------------------------------------------------
26 /**
27  * @brief Set of values to identify a beam.
28  *
29  * The constants are used to identify the gate during which a trigger is
30  * acquired, in the `raw::Trigger::TriggerBits()` bit mask.
31  */
32 namespace sbn {
33 
34  /**
35  * @brief Simple utilities to deal with bit enumerators.
36  *
37  * A few simple concepts:
38  * * a bit is identified by its position (integral number: `0`, `1`, `2`...)
39  * * representation of a bit is via a enumerator (`enum class`)
40  * * bits may be associated with a name (`name()`)
41  * * to test bits, `mask()`, `value()` and `hasBitSet()` help with the
42  * conversions between `enum class` and the underlying integral type
43  *
44  */
45  namespace bits {
46 
47  // --- BEGIN -- Generic bit functions --------------------------------------
48  /// @name Generic bit functions
49  /// @{
50 
51  /// Type for bit masks.
52  /// @note This is a glorified integral type.
53  template <typename EnumType>
54  struct mask_t {
55  using bits_t = EnumType; ///< Enumeration type of the bits.
56  using maskbits_t = std::underlying_type_t<EnumType>; ///< Bit data type.
58  operator maskbits_t() const { return bits; }
59  }; // mask_t
60 
61  /// Converts a integral type into a mask.
62  template <typename EnumType>
63  mask_t<EnumType> makeMask
64  (typename mask_t<EnumType>::maskbits_t bits) noexcept;
65 
66 
67  /// Returns the value of specified `bit` (conversion like `enum` to `int`).
68  template <typename EnumType>
69  constexpr auto value(EnumType bit);
70 
71  /// Returns a mask with all specified bits set.
72  template <typename EnumType, typename... OtherBits>
73  constexpr mask_t<EnumType> mask(EnumType bit, OtherBits... otherBits);
74 
75  /// Returns whether the specified `bit` is set in `bitMask`.
76  template <typename EnumType>
77  constexpr bool hasBitSet(mask_t<EnumType> bitMask, EnumType bit);
78 
79  /// Returns the name of the specified `bit`. Delegates to `bitName()`.
80  template <typename EnumType>
81  std::string name(EnumType bit);
82 
83  /// Returns a list of the names of all the bits set in `mask`.
84  /// Mask is interpreted as made of only bits of type `EnumType`.
85  template <typename EnumType>
86  std::vector<std::string> names(mask_t<EnumType> mask);
87 
88  /// @}
89  // --- END ---- Generic bit functions --------------------------------------
90 
91 
92  // --- BEGIN -- Beam bits --------------------------------------------------
93  /// @name Beam bits
94  /// @{
95 
96  /// Type of beam or beam gate or other trigger source.
97  enum class triggerSource: unsigned int {
98  Unknown, ///< Type of beam unknown.
99  BNB, ///< Type of beam: BNB.
100  NuMI, ///< Type of beam: NuMI.
101  OffbeamBNB, ///< Type of Offbeam: BNB.
102  OffbeamNuMI, ///< Type of Offbeam: NuMI.
103  Calib, ///< Type of source: calibration trigger.
104  // ==> add here if more are needed <==
105  NBits ///< Number of bits currently supported.
106  }; // triggerSource
107 
108  /// Type of mask with `triggerSource` bits.
110 
111 
112  /// Location or locations generating a trigger.
113  enum class triggerLocation: unsigned int {
114  CryoEast, ///< A trigger happened in the east cryostat.
115  CryoWest, ///< A trigger happened in the west cryostat.
116  TPCEE, ///< A trigger happened in the east cryostat, east TPC.
117  TPCEW, ///< A trigger happened in the east cryostat, west TPC.
118  TPCWE, ///< A trigger happened in the west cryostat, east TPC.
119  TPCWW, ///< A trigger happened in the west cryostat, west TPC.
120  // ==> add here if more are needed <==
121  NBits ///< Number of bits currently supported.
122  }; // triggerLocation
123 
124  /// Type of mask with `triggerLocation` bits.
126 
127  /// Type representing the type(s) of this trigger.
128  enum class triggerType: unsigned int {
129  Majority, ///< A minimum number of close-by PMT pairs above threshold was reached.
130  MinimumBias, ///< Data collected at gate opening with no further requirement imposed.
131  // ==> add here if more are needed <==
132  NBits ///< Number of bits currently supported.
133  }; // triggerType
134 
135  /// Type of mask with `triggerType` bits.
137 
138  /// Trigger window mode
139  enum class triggerWindowMode: unsigned int {
140  Separated, ///< Separated, non-overlapping contigous window
141  Overlapping, ///< Overlaping windows
142  //==> add here if more are needed <==
143  NBits ///< Number of Bits currently supported
144  };
145 
146 
147 
148  /// Enabled gates in the trigger configuration. See register 0X00050008 in docdb SBN-doc-23778-v1
149  enum class gateSelection: unsigned int {
150  GateBNB, ///<Enable receiving BNB early warning signal (gatedBES) to open BNB gates
151  DriftGateBNB, ///<Enable BNB early-early warning signal ($1D) for light out-of-time in BNB gates
152  GateNuMI, ///<Enable NuMI early warning signal (MIBS$74) to open NuMI gates
153  DriftGateNuMI, ///<Enable receiving NuMI early-early warning signal ($AD) for light out-of-time in NuMI gates
154  GateOffbeamBNB, ///<Enable Offbeam gate for BNB
155  DriftGateOffbeamBNB, ///<Enable Offbeam drift gate BNB (for light out-of-time in offbeam gates)
156  GateOffbeamNuMI, ///<Enable Offbeam gate for NuMI
157  DriftGateOffbeamNuMI, ///<Enable Offbeam drift gate NuMI (for light out-of-time in offbeam gates)
158  GateCalibration, ///<Enable Calibration gate
159  DriftGateCalibration, ///<Enable Calibration drift gate (for light out-of-time in calibration gates)
160  MinbiasGateBNB, ///<Enable MinBias triggers for the BNB stream
161  MinbiasGateNuMI, ///<Enable MinBias triggers for the NuMI stream
162  MinbiasGateOffbeamBNB, ///<Enabke MinBias triggers for the Offbeam BNB stream
163  MinbiasGateOffbeamNuMI, ///<Enable MinBias triggers for the Offbeam NuMI stream
164  MinbiasGateCalibration, ///<Enable MinBias triggers for the Calibration stream
165  MinbiasDriftGateBNB, ///<Enable light out-of-time for MinBias triggers in BNB stream
166  MinbiasDriftGateNuMI, ///<Enable light out-of-time for MinBias triggers in NuMI stream
167  MinbiasDriftGateOffbeamBNB, ///<Enable light out-of-time for MinBias triggers in Offbeam BNB stream
168  MinbiasDriftGateOffbeamNuMI, ///<Enable light out-of-time for MinBias triggers in Offbeam NuMI stream
169  MinbiasDriftGateCalibration, ///<Enable light out-of-time for MinBias triggers in Calibration stream
170  // ==> add here if more are needed <==
171  NBits
172  }; // gateSelection
173 
175 
176  /// Returns a mnemonic short name of the beam type.
177  std::string bitName(triggerSource bit);
178  /// Returns a mnemonic short name of the trigger location.
179  std::string bitName(triggerLocation bit);
180  /// Returns a mnemonic short name of the trigger type.
181  std::string bitName(triggerType bit);
182  /// Returns a mnemonic short name for the trigger window mode.
183  std::string bitName(triggerWindowMode bit);
184  /// Returns a mnemonic short name for the trigger window mode.
185  std::string bitName(gateSelection bit);
186 
187  /// @}
188  // --- END ---- Beam bits --------------------------------------------------
189 
190  } // namespace bits
191 
192  using bits::triggerSource; // import symbol
194  using bits::triggerType;
195  using bits::triggerTypeMask;
196  using bits::triggerLocation;
199  using bits::gateSelection;
200 
201 } // namespace sbn
202 
203 
204 // -----------------------------------------------------------------------------
205 // --- inline and template implementation
206 // -----------------------------------------------------------------------------
207 template <typename EnumType>
208 auto sbn::bits::makeMask (typename mask_t<EnumType>::maskbits_t bits) noexcept
209  -> mask_t<EnumType>
210  { return { bits }; }
211 
212 
213 // -----------------------------------------------------------------------------
214 template <typename EnumType>
215 constexpr auto sbn::bits::value(EnumType bit)
216  { return static_cast<std::underlying_type_t<EnumType>>(bit); }
217 
218 
219 // -----------------------------------------------------------------------------
220 template <typename EnumType, typename... OtherBits>
221 constexpr auto sbn::bits::mask(EnumType bit, OtherBits... otherBits)
222  -> mask_t<EnumType>
223 {
224  unsigned int m { 1U << value(bit) };
225  if constexpr(sizeof...(OtherBits) > 0U) m |= mask(otherBits...);
226  return { m };
227 } // sbn::mask()
228 
229 
230 // -----------------------------------------------------------------------------
231 template <typename EnumType>
232 constexpr bool sbn::bits::hasBitSet(mask_t<EnumType> bitMask, EnumType bit)
233  { return bitMask & mask(bit); }
234 
235 
236 // -----------------------------------------------------------------------------
237 template <typename EnumType>
238 std::string sbn::bits::name(EnumType bit)
239  { return bitName(bit); }
240 
241 
242 // -----------------------------------------------------------------------------
243 template <typename EnumType>
244 std::vector<std::string> sbn::bits::names(mask_t<EnumType> mask) {
245  static_assert(value(EnumType::NBits) >= 0);
246 
247  using namespace std::string_literals;
248 
249  constexpr std::size_t MaxBits = sizeof(mask) * 8U;
250  constexpr std::size_t NSupportedBits = value(EnumType::NBits);
251 
252  std::vector<std::string> names;
253  for (std::size_t bit = 0U; bit < MaxBits; ++bit) {
254  auto const typedBit = static_cast<EnumType>(bit);
255  if (!hasBitSet(mask, typedBit)) continue;
256  names.push_back((bit > NSupportedBits)
257  ? "<unsupported ["s + std::to_string(bit) + "]>"s: name(typedBit)
258  );
259  } // for
260  return names;
261 
262 } // sbn::bits::names()
263 
264 
265 // -----------------------------------------------------------------------------
266 /// @todo Move into an implementation file once this header in the final location.
267 inline std::string sbn::bits::bitName(triggerSource bit) {
268 
269  using namespace std::string_literals;
270  switch (bit) {
271  case triggerSource::Unknown: return "unknown"s;
272  case triggerSource::BNB: return "BNB"s;
273  case triggerSource::NuMI: return "NuMI"s;
274  case triggerSource::OffbeamBNB: return "OffbeamBNB"s;
275  case triggerSource::OffbeamNuMI: return "OffbeamNuMI"s;
276  case triggerSource::Calib: return "Calib"s;
277  case triggerSource::NBits: return "<invalid>"s;
278  } // switch
279  throw std::runtime_error("sbn::bits::bitName(triggerSource{ "s
280  + std::to_string(value(bit)) + " }): unknown bit"s);
281 } // sbn::bitName()
282 
283 // -----------------------------------------------------------------------------
284 
285 inline std::string sbn::bits::bitName(triggerLocation bit) {
286 
287  using namespace std::string_literals;
288  switch (bit) {
289  case triggerLocation::CryoEast: return "Cryo E"s;
290  case triggerLocation::CryoWest: return "Cryo W"s;
291  case triggerLocation::TPCEE: return "TPC EE"s;
292  case triggerLocation::TPCEW: return "TPC EW"s;
293  case triggerLocation::TPCWE: return "TPC WE"s;
294  case triggerLocation::TPCWW: return "TPC WW"s;
295  case triggerLocation::NBits: return "<invalid>"s;
296  } // switch
297  throw std::runtime_error("sbn::bits::bitName(triggerLocation{ "s
298  + std::to_string(value(bit)) + " }): unknown bit"s);
299 } // sbn::bitName(triggerLocation)
300 
301 // -----------------------------------------------------------------------------
302 inline std::string sbn::bits::bitName(triggerType bit) {
303 
304  using namespace std::string_literals;
305  switch (bit) {
306  case triggerType::Majority: return "majority"s;
307  case triggerType::MinimumBias: return "minimum bias"s;
308  case triggerType::NBits: return "<invalid>"s;
309  } // switch
310  throw std::runtime_error("sbn::bits::bitName(triggerType{ "s
311  + std::to_string(value(bit)) + " }): unknown bit"s);
312 } // sbn::bitName(triggerType)
313 
314 inline std::string sbn::bits::bitName(triggerWindowMode bit) {
315 
316  using namespace std::string_literals;
317  switch (bit) {
318  case sbn::bits::triggerWindowMode::Separated: return "Separated Window"s;
319  case sbn::bits::triggerWindowMode::Overlapping: return "Overlapping Window"s;
320  case sbn::bits::triggerWindowMode::NBits: return "<invalid>"s;
321  } // switch
322  throw std::runtime_error("sbn::bits::bitName(triggerWindowMode{ "s
323  + std::to_string(value(bit)) + " }): unknown bit"s);
324 } // triggerWindowMode
325 
326 
327 inline std::string sbn::bits::bitName(gateSelection bit) {
328 
329  using namespace std::string_literals;
330  switch (bit) {
331  case gateSelection::GateBNB: return "GateBNB"s;
332  case gateSelection::DriftGateBNB: return "DriftGateBNB"s;
333  case gateSelection::GateNuMI: return "GateNuMI"s;
334  case gateSelection::DriftGateNuMI: return "DriftGateNuMI"s;
335  case gateSelection::GateOffbeamBNB: return "GateOffbeamBNB"s;
336  case gateSelection::DriftGateOffbeamBNB: return "DriftGateOffbeamBNB"s;
337  case gateSelection::GateOffbeamNuMI: return "GateOffbeamNuMI"s;
338  case gateSelection::DriftGateOffbeamNuMI: return "DriftGateOffbeamNuMI"s;
339  case gateSelection::GateCalibration: return "GateCalibration"s;
340  case gateSelection::DriftGateCalibration: return "DriftGateCalibration"s;
341  case gateSelection::MinbiasGateBNB: return "MinbiasGateBNB"s;
342  case gateSelection::MinbiasGateNuMI: return "MinbiasGateNuMI"s;
343  case gateSelection::MinbiasGateOffbeamBNB: return "MinbiasGateOffbeamBNB"s;
344  case gateSelection::MinbiasGateOffbeamNuMI: return "MinbiasGateOffbeamNuMI"s;
345  case gateSelection::MinbiasGateCalibration: return "MinbiasGateCalibration"s;
346  case gateSelection::MinbiasDriftGateBNB: return "MinbiasDriftGateBNB"s;
347  case gateSelection::MinbiasDriftGateNuMI: return "MinbiasDriftGateNuMI"s;
348  case gateSelection::MinbiasDriftGateOffbeamBNB: return "MinbiasDriftGateOffbeamBNB"s;
349  case gateSelection::MinbiasDriftGateOffbeamNuMI: return "MinbiasDriftGateOffbeamNuMI"s;
350  case gateSelection::MinbiasDriftGateCalibration: return "MinbiasDriftGateCalibration"s;
351  case gateSelection::NBits: return "NBits"s;
352  } // switch
353  throw std::runtime_error("sbn::bits::bitName(gateSelection{ "s
354  + std::to_string(value(bit)) + " }): unknown bit"s);
355 } // sbn::bitName()
356 
357 
358 namespace icarus::trigger {
359 
362 
363  static constexpr std::size_t kEast = sbn::bits::value<triggerLocation>(triggerLocation::CryoEast);
364  static constexpr std::size_t kWest = sbn::bits::value<triggerLocation>(triggerLocation::CryoWest);
365  static constexpr std::size_t kNTriggerLocation = sbn::bits::value<triggerLocation>(triggerLocation::NBits);
366 
367  static constexpr std::size_t kBNB = sbn::bits::value<triggerSource>(triggerSource::BNB);
368  static constexpr std::size_t kNuMI = sbn::bits::value<triggerSource>(triggerSource::NuMI);
369  static constexpr std::size_t kOffBeamBNB = sbn::bits::value<triggerSource>(triggerSource::OffbeamBNB);
370  static constexpr std::size_t kOffBeamNuMI = sbn::bits::value<triggerSource>(triggerSource::OffbeamNuMI);
371  static constexpr std::size_t kCalibration = sbn::bits::value<triggerSource>(triggerSource::Calib);
372  static constexpr std::size_t kNTriggerSource = sbn::bits::value<triggerSource>(triggerSource::NBits);
373 
374 }
375 
376 
377 // -----------------------------------------------------------------------------
378 
379 #endif // SBNOBJ_COMMON_TRIGGER_BEAMBITS_H
std::string name(EnumType bit)
Returns the name of the specified bit. Delegates to bitName().
Definition: BeamBits.h:238
Number of bits currently supported.
sbn::triggerSource triggerSource
Definition: BeamBits.h:361
static constexpr std::size_t kOffBeamNuMI
Definition: BeamBits.h:370
static constexpr std::size_t kWest
Definition: BeamBits.h:364
Enabke MinBias triggers for the Offbeam BNB stream.
Enable MinBias triggers for the Calibration stream.
constexpr bool hasBitSet(mask_t< EnumType > bitMask, EnumType bit)
Returns whether the specified bit is set in bitMask.
Definition: BeamBits.h:232
constexpr auto value(EnumType bit)
Returns the value of specified bit (conversion like enum to int).
Definition: BeamBits.h:215
Separated, non-overlapping contigous window.
mask_t< triggerLocation > triggerLocationMask
Type of mask with triggerLocation bits.
Definition: BeamBits.h:125
Enable Offbeam drift gate NuMI (for light out-of-time in offbeam gates)
gateSelection
Enabled gates in the trigger configuration. See register 0X00050008 in docdb SBN-doc-23778-v1.
Definition: BeamBits.h:149
std::underlying_type_t< EnumType > maskbits_t
Bit data type.
Definition: BeamBits.h:56
triggerWindowMode
Trigger window mode.
Definition: BeamBits.h:139
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
static constexpr std::size_t kBNB
Definition: BeamBits.h:367
Data collected at gate opening with no further requirement imposed.
static constexpr std::size_t kNTriggerSource
Definition: BeamBits.h:372
A minimum number of close-by PMT pairs above threshold was reached.
triggerLocation
Location or locations generating a trigger.
Definition: BeamBits.h:113
static constexpr std::size_t kNTriggerLocation
Definition: BeamBits.h:365
Enable NuMI early warning signal (MIBS$74) to open NuMI gates.
std::string bitName(triggerSource bit)
Returns a mnemonic short name of the beam type.
Definition: BeamBits.h:267
Enable light out-of-time for MinBias triggers in NuMI stream.
Enable light out-of-time for MinBias triggers in BNB stream.
Enable light out-of-time for MinBias triggers in Offbeam NuMI stream.
Type of beam unknown.
static constexpr std::size_t kCalibration
Definition: BeamBits.h:371
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
sbn::triggerLocation triggerLocation
Definition: BeamBits.h:360
std::vector< std::string > names(mask_t< EnumType > mask)
Definition: BeamBits.h:244
A trigger happened in the east cryostat.
triggerType
Type representing the type(s) of this trigger.
Definition: BeamBits.h:128
Enable MinBias triggers for the Offbeam NuMI stream.
A trigger happened in the east cryostat, west TPC.
Enable Offbeam gate for BNB.
Type of source: calibration trigger.
A trigger happened in the west cryostat, west TPC.
static constexpr std::size_t kNuMI
Definition: BeamBits.h:368
static const std::vector< std::string > names
Enable Offbeam drift gate BNB (for light out-of-time in offbeam gates)
mask_t< EnumType > makeMask(typename mask_t< EnumType >::maskbits_t bits) noexcept
Converts a integral type into a mask.
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
Enable MinBias triggers for the BNB stream.
Enable Calibration drift gate (for light out-of-time in calibration gates)
static constexpr std::size_t kOffBeamBNB
Definition: BeamBits.h:369
A trigger happened in the east cryostat, east TPC.
mask_t< triggerSource > triggerSourceMask
Type of mask with triggerSource bits.
Definition: BeamBits.h:109
Enable Offbeam gate for NuMI.
Enable BNB early-early warning signal ($1D) for light out-of-time in BNB gates.
triggerSource
Type of beam or beam gate or other trigger source.
Definition: BeamBits.h:97
then echo fcl name
temporary value
EnumType bits_t
Enumeration type of the bits.
Definition: BeamBits.h:55
maskbits_t bits
Definition: BeamBits.h:57
Enable receiving NuMI early-early warning signal ($AD) for light out-of-time in NuMI gates...
mask_t< triggerType > triggerTypeMask
Type of mask with triggerType bits.
Definition: BeamBits.h:136
Type of beam: NuMI.
Enable MinBias triggers for the NuMI stream.
static constexpr std::size_t kEast
Definition: BeamBits.h:363
A trigger happened in the west cryostat.
Enable receiving BNB early warning signal (gatedBES) to open BNB gates.
Enable light out-of-time for MinBias triggers in Calibration stream.
Enable light out-of-time for MinBias triggers in Offbeam BNB stream.
A trigger happened in the west cryostat, east TPC.