All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriggerConfiguration.h
Go to the documentation of this file.
1 
2 /**
3  * @file icaruscode/Decode/DataProducts/TriggerConfiguration.h (todo move to sbnobj)
4  * @brief Information from the configuration of the ICARUS trigger readout.
5  * @author Andrea Scarpelli (ascarpell@bnl.gov)
6  * @date March 23 2021
7  * @see icaruscode/Decode/DataProducts/TriggerConfiguration.cxx
8  */
9 
10 #ifndef ICARUSCODE_DECODE_DATAPRODUCT_TRIGGERCONFIGURATION_H
11 #define ICARUSCODE_DECODE_DATAPRODUCT_TRIGGERCONFIGURATION_H
12 
13 // C/C++ standard libraries
14 #include <iosfwd> // std::ostream
15 #include <string>
16 #include <array>
17 #include <cassert>
18 
20 
21 namespace icarus {
22 
23  struct TriggerConfiguration;
24 
25  /// Prints the configuration into a stream with default verbosity.
26  std::ostream& operator<<(std::ostream& out, icarus::TriggerConfiguration const& config);
27 
28 }
29 
30 
32 
33  struct CryoConfig {
34 
35  /// Majority Level for in-time activity
36  unsigned int majLevelInTime = 0U;
37 
38  /// Majority Level for out-of-time activity
39  unsigned int majLevelDrift = 0U;
40 
41  /// Window selection "Fixed" (0) or "Overlapping" (1)
42  unsigned int slidingWindow = 0U;
43 
44  #if __cplusplus < 202004L
45  //@{
46  /// Comparison: all fields need to have the same values.
47  bool operator== ( CryoConfig const& other) const noexcept;
48  bool operator!= ( CryoConfig const& other) const noexcept
49  { return ! this->operator== (other); }
50  //@}
51  #else
52  # error "With C++20 support, enable the default comparison operators"
53  // probably the compiler will be generating these anyway, so don't bother
54  // bool operator== (CryoConfig const& other) const = default;
55  // bool operator!= (CryoConfig const& other) const = default;
56  #endif
57 
58  };
59 
60  struct GateConfig {
61 
62  /// Return gate activation
63  bool hasGate = false;
64 
65  /// Return drift gate activation status (for out-of-time light)
66  bool hasDriftGate = false;
67 
68  /// Return MinBias triggers activation status
69  bool hasMinBiasGate = false;
70 
71  /// Return MinBias drift gate activation status (for out-of-time light)
72  bool hasMinBiasDriftGate = false;
73 
74  /// Duration of the gate for the in-time activity in ns
75  unsigned int gateWidth = 0U;
76 
77  /// Duration of the drift gate for the out-of-time activity in ns
78  unsigned int driftGateWidth = 0U;
79 
80  /// Prescale for the MinBias triggers (calculated with respect to the number of gates opened)
81  unsigned long prescaleMinBias=1U;
82 
83  /// Rate of gates opened outside the extraction (calculated with respect to the number of gates opened)
84  unsigned long offBeamGateRate = 1U;
85 
86  /// Early warning offset for the BNB (NuMI) GatedBES ($MIBS74) in ns; used for the beam gate.
87  unsigned long earlyWarningOffset = 0U;
88 
89  /// Early Early warning offset for the BNB (NuMI) $1D ($AE) in ns; used for the drift gate.
90  unsigned long earlyEarlyWarningOffset = 0U;
91 
92  /// Period of two consecutive pulses from the internal pulse generator (valid for calibration gate) in ns
93  unsigned int period = 0U;
94 
95  #if __cplusplus < 202004L
96  //@{
97  /// Comparison: all fields need to have the same values.
98  bool operator== ( GateConfig const& other) const noexcept;
99  bool operator!= ( GateConfig const& other) const noexcept
100  { return ! this->operator== (other); }
101  //@}
102  #else
103  # error "With C++20 support, enable the default comparison operators"
104  // probably the compiler will be generating these anyway, so don't bother
105  // bool operator== (GateConfig const& other) const = default;
106  // bool operator!= (GateConfig const& other) const = default;
107  #endif
108 
109  };
110 
111  // --- BEGIN -- Data members -------------------------------------------------
112 
113  // NOTE when adding data members, remember to add an element to the comparison
114 
115  /// Use the WR time reference
116  bool useWrTime = false;
117 
118  /// Add an offset between the npt and tai time as used in the wr reference (normally it is 1 or 2 leap seconds) in ns
119  unsigned int wrTimeOffset = 1'000'000'000;
120 
121  /// Veto (this delay has to be subtracted to the gate width ). Value is in ns
122  unsigned int vetoDelay = 0;
123 
124  /// Cryostat configuration
125  std::array<CryoConfig, icarus::trigger::kNTriggerLocation> cryoConfig;
126 
127  /// Majority trigger type (consider triggers from one cryostats, either cryostats, or both cryostats)
128  std::string majorityTriggerType;
129 
130  /// Force the run to be fully a MinBias, if runType=="MinBias". If runType=="Majority" does a majority run with some prescaled minbias triggers depending on the gate selection in use
131  std::string runType;
132 
133  /// TPCTriggerDelay: distance between the Global trigger time and the output for the TPC. NB: It is in units of 400 ns
134  unsigned int tpcTriggerDelay = 0;
135 
136  /// Gate Configuration
137  std::array<GateConfig, icarus::trigger::kNTriggerSource> gateConfig;
138 
139  // --- END ---- Data members -------------------------------------------------
140 
141  // --- BEGIN -- Derived quantities -------------------------------------------
142 
143  /**
144  * @brief returns the effective gate width corrected for the veto delay in us
145  * @param source is the value of the sbn::bits::triggerSource enum type corresponding to the type of gate
146  *
147  */
148  float getGateWidth( std::size_t source ) const {
149 
150  // We really want the vetoDelay to be shorter than the gateWidth
151  assert(!gateConfig[source].hasGate || (gateConfig[source].gateWidth >= vetoDelay));
152 
153  return gateConfig[source].hasGate ?
154  static_cast<float>( gateConfig[source].gateWidth - vetoDelay )/1000. : 0.;
155 
156  }
157 
158 
159  /**
160  * @brief returns the width of the drift gate used for out-of-time light activity in us
161  * @param source is the value of the sbn::bits::triggerSource enum type corresponding to the type of gate
162  *
163  */
164  float getDriftGateWidth( std::size_t source ) const {
165 
166  return gateConfig[source].hasDriftGate ?
167  static_cast<float>( gateConfig[source].driftGateWidth )/1000. : 0U;
168 
169  }
170 
171  /**
172  * @brief returns the prescale value used to open the offbeam gates with respect to the total number of
173  * beam gates seen
174  * @param source is the value of the sbn::bits::triggerSource enum type corresponding to the type of gate
175  *
176  */
177  unsigned int getOffBeamRate( std::size_t source ) const {
178 
179  return gateConfig[source].hasGate ? gateConfig[source].offBeamGateRate : 0U;
180 
181  }
182 
183  /**
184  * @brief returns the prescale value used to collect MinBias triggers with respect to the total number of
185  * gates seen of a particula type
186  * @param source is the value of the sbn::bits::triggerSource enum type corresponding to the type of gate
187  *
188  */
189  unsigned int getMinBiasPrescale( std::size_t source ) const {
190 
191  return gateConfig[source].hasGate ? gateConfig[source].prescaleMinBias : 0U;
192 
193  }
194 
195 
196  // --- END ---- Derived quantities -------------------------------------------
197 
198  #if __cplusplus < 202004L
199  //@{
200  /// Comparison: all fields need to have the same values.
201  bool operator== (TriggerConfiguration const& other) const noexcept;
202  bool operator!= (TriggerConfiguration const& other) const noexcept
203  { return ! this->operator== (other); }
204  //@}
205  #else
206  # error "With C++20 support, enable the default comparison operators"
207  // probably the compiler will be generating these anyway, so don't bother
208  // bool operator== (ICARUSTriggerConfiguration const& other) const = default;
209  // bool operator!= (ICARUSTriggerConfiguration const& other) const = default;
210  #endif
211 
212  // -- BEGIN -- Dump facility -------------------------------------------------
213 
214  /// Maximum supported verbosity level supported by `dump()`.
215  static constexpr unsigned int MaxDumpVerbosity = 2U;
216 
217  /// Default verbosity level for `dump()`.
218  static constexpr unsigned int DefaultDumpVerbosity = MaxDumpVerbosity;
219 
220 
221  /**
222  * @brief Dumps the content of the configuration into `out` stream.
223  * @param out stream to dump the information into
224  * @param indent indentation string
225  * @param firstIndent special indentation string for the first line
226  * @param verbosity (default: `DefaultDumpVerbosity`) level of verbosity
227  *
228  * The indentation string is prepended to each new line of the dump.
229  * The first line indentation string is prepended before the first line of
230  * the dump. The dump ends on a new empty line.
231  *
232  * The amount of information printed depends on the `verbosity` level:
233  *
234  * * `0`: Boardreader configuration
235  * * `1`: FPGA configuration
236  * * `2`: SPEXI configuration
237  *
238  */
239 
240  void dump(std::ostream& out,
241  std::string const& indent, std::string const& firstIndent,
242  unsigned int verbosity = MaxDumpVerbosity
243  ) const;
244 
245  /**
246  * @brief Dumps the content of the configuration into `out` stream.
247  * @param out stream to dump the information into
248  * @param indent indentation level
249  * @see `dump(std::ostream&, std::string const&, std::string const&, unsigned int) const`
250  *
251  * Version of `dump()` with same first indentation level as the rest, and
252  * default verbosity.
253  */
254  void dump(std::ostream& out, std::string const& indent = "") const
255  { dump(out, indent, indent); }
256 
257  /**
258  * @brief Dumps the content of the gate configuration into `out` stream.
259  * @param out stream to dump the information into
260  * @param gateConfig the gate to be dumped
261  * @param indent (default: none) indentation string
262  * @see `dump(std::ostream&, std::string const&, std::string const&, unsigned int) const`
263  *
264  * Version of `dump()` with the specified `verbosity` level and same first
265  * indentation level as the rest.
266  */
267  void dumpGateConfig(std::ostream& out,
269  std::string const& indent
270  ) const;
271 
272  void dump(std::ostream& out,
273  unsigned int verbosity,
274  std::string const& indent = ""
275  ) const
276  { dump(out, indent, indent, verbosity); }
277 
278  // -- END ---- Dump facility -------------------------------------------------
279 
280 
281 }; // sbn::ICARUSTriggerConfiguration
282 
283 //------------------------------------------------------------------------------
284 
285 // Equality operators are incompete: fix for C++20
286 
287 // Equality operator for icarus::TriggerConfiguration
288 inline bool icarus::TriggerConfiguration::operator==
289  (icarus::TriggerConfiguration const& other) const noexcept
290 {
291 
292  if ( useWrTime != other.useWrTime ) return false;
293  if ( wrTimeOffset != other.wrTimeOffset ) return false;
294  if ( vetoDelay != other.vetoDelay ) return false;
295  if ( majorityTriggerType != other.majorityTriggerType ) return false;
296  if ( runType != other.runType ) return false;
297  if ( tpcTriggerDelay != other.tpcTriggerDelay ) return false;
298 
299 
300  return true;
301 
302 }
303 
304 
305 // Equality operator for icarus::TriggerConfiguration::CryoConfiguration
306 inline bool icarus::TriggerConfiguration::CryoConfig::operator==
307  (icarus::TriggerConfiguration::CryoConfig const & other) const noexcept
308 {
309  if ( majLevelInTime != other.majLevelInTime ) return false;
310  if ( majLevelDrift != other.majLevelDrift ) return false;
311  if ( slidingWindow != other.slidingWindow ) return false;
312 
313  return true;
314 
315 }
316 
317 
318 // Equality operator for icarus::TriggerConfiguration::GateConfiguration
319 inline bool icarus::TriggerConfiguration::GateConfig::operator==
320  (icarus::TriggerConfiguration::GateConfig const & other) const noexcept
321  {
322  if( hasGate != other.hasGate ) return false;
323  if( hasDriftGate != other.hasDriftGate ) return false;
324  if( hasMinBiasGate != other.hasMinBiasGate ) return false;
325  if( gateWidth != other.gateWidth ) return false;
326  if( driftGateWidth != other.driftGateWidth ) return false;
327  if( prescaleMinBias != other.prescaleMinBias ) return false;
328  if( offBeamGateRate != other.offBeamGateRate ) return false;
329  if( earlyWarningOffset != other.earlyWarningOffset ) return false;
330  if( earlyEarlyWarningOffset != other.earlyEarlyWarningOffset ) return false;
331  if( period != other.period ) return false;
332 
333  return true;
334 
335  }
336 
337 
338 //------------------------------------------------------------------------------
339 inline std::ostream& icarus::operator<<(std::ostream& out, icarus::TriggerConfiguration const& config)
340  { config.dump(out); return out; }
341 
342 
343 //------------------------------------------------------------------------------
344 
345 
346 #endif // ICARUSCODE_DECODE_DATAPRODUCT_TRIGGERCONFIGURATION_H
Definitions of the trigger bits for SBN.
bool hasDriftGate
Return drift gate activation status (for out-of-time light)
unsigned int majLevelDrift
Majority Level for out-of-time activity.
stream1 can override from command line with o or output services user runType
bool operator!=(GateConfig const &other) const noexcept
bool operator!=(CryoConfig const &other) const noexcept
void dumpGateConfig(std::ostream &out, icarus::TriggerConfiguration::GateConfig const &gateConfig, std::string const &indent) const
Dumps the content of the gate configuration into out stream.
std::ostream & operator<<(std::ostream &out, IntegerRanges< T, CheckGrowing > const &ranges)
unsigned int majLevelInTime
Majority Level for in-time activity.
bool operator==(GateConfig const &other) const noexcept
Comparison: all fields need to have the same values.
unsigned int period
Period of two consecutive pulses from the internal pulse generator (valid for calibration gate) in ns...
void dump(std::ostream &out, std::string const &indent="") const
Dumps the content of the configuration into out stream.
unsigned int wrTimeOffset
Add an offset between the npt and tai time as used in the wr reference (normally it is 1 or 2 leap se...
bool operator==(CryoConfig const &other) const noexcept
Comparison: all fields need to have the same values.
bool hasMinBiasGate
Return MinBias triggers activation status.
void dump(std::ostream &out, unsigned int verbosity, std::string const &indent="") const
std::array< GateConfig, icarus::trigger::kNTriggerSource > gateConfig
Gate Configuration.
unsigned long prescaleMinBias
Prescale for the MinBias triggers (calculated with respect to the number of gates opened) ...
void dump(std::ostream &out, std::string const &indent, std::string const &firstIndent, unsigned int verbosity=MaxDumpVerbosity) const
Dumps the content of the configuration into out stream.
bool useWrTime
Use the WR time reference.
unsigned int slidingWindow
Window selection &quot;Fixed&quot; (0) or &quot;Overlapping&quot; (1)
bool hasMinBiasDriftGate
Return MinBias drift gate activation status (for out-of-time light)
unsigned int gateWidth
Duration of the gate for the in-time activity in ns.
static constexpr unsigned int MaxDumpVerbosity
Maximum supported verbosity level supported by dump().
static constexpr unsigned int DefaultDumpVerbosity
Default verbosity level for dump().
unsigned long earlyEarlyWarningOffset
Early Early warning offset for the BNB (NuMI) $1D ($AE) in ns; used for the drift gate...
unsigned long offBeamGateRate
Rate of gates opened outside the extraction (calculated with respect to the number of gates opened) ...
unsigned long earlyWarningOffset
Early warning offset for the BNB (NuMI) GatedBES ($MIBS74) in ns; used for the beam gate...
unsigned int driftGateWidth
Duration of the drift gate for the out-of-time activity in ns.