All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
V1730Configuration.h
Go to the documentation of this file.
1 /**
2  * @file sbnobj/Common/PMT/Data/V1730Configuration.h
3  * @brief Information from the configuration of a V1730 PMT readout board.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date February 18, 2021
6  * @see sbnobj/Common/PMT/Data/V1730Configuration.cxx
7  */
8 
9 #ifndef SBNOBJ_COMMON_PMT_DATA_V1730CONFIGURATION_H
10 #define SBNOBJ_COMMON_PMT_DATA_V1730CONFIGURATION_H
11 
12 // SBN libraries
14 
15 // C/C++ standard libraries
16 #include <iosfwd> // std::ostream
17 #include <vector>
18 #include <string>
19 
20 
21 //------------------------------------------------------------------------------
22 namespace sbn {
23 
24  struct V1730Configuration;
25 
26  /// Prints the configuration into a stream with default verbosity.
27  std::ostream& operator<<
28  (std::ostream& out, sbn::V1730Configuration const& config);
29 
30 } // namespace sbn
31 
32 /**
33  * @brief Class containing configuration for a V1730 board.
34  *
35  * This is an informative class containing configuration of a V1730 board
36  * extracted from some other source (typically, DAQ) made readily available
37  * to the users.
38  *
39  * This class does not include any configuration extraction code.
40  *
41  * The class is default-constructible only, and its content needs to be added
42  * element by element.
43  *
44  */
46 
47  // --- BEGIN -- Data members -------------------------------------------------
48 
49  // NOTE when adding data members, remember to add an element to the comparison
50 
51  /// Name (mnemonic) of the board.
52  std::string boardName;
53 
54  /// Numeric ID of the board (`board_id`).
55  unsigned int boardID = std::numeric_limits<unsigned int>::max();
56 
57  /// DAQ fragment ID.
58  unsigned int fragmentID = std::numeric_limits<unsigned int>::max();
59 
60  /// Ticks in each buffer (`recordLength`).
61  unsigned int bufferLength = 0U;
62 
63  /// Fraction of the waveform _after_ the trigger signal (`postPercent`).
64  float postTriggerFrac = 0.0f;
65 
66  /// Number of channels (`nChannels`).
67  unsigned int nChannels = 0U;
68 
69  /// Whether fragment timestamp is synchronised with server NTP and with TTT.
70  bool useTimeTagForTimeStamp = false;
71 
72  /// Configuration of each channel.
73  std::vector<sbn::V1730channelConfiguration> channels;
74 
75  // NOTE when adding data members, remember to read the note above
76 
77  // --- END ---- Data members -------------------------------------------------
78 
79 
80  // --- BEGIN -- Derived quantities -------------------------------------------
81 
82  /// Ticks in the waveform before the trigger.
83  unsigned int preTriggerTicks() const;
84 
85  /// Ticks in the waveform after the trigger.
86  unsigned int postTriggerTicks() const;
87 
88  /// Duration of the waveform [us].
89  float bufferTime() const;
90 
91  /// Time in the waveform before the trigger [us].
92  float preTriggerTime() const;
93 
94  /// Time in the waveform after the trigger [us].
95  float postTriggerTime() const;
96 
97  // --- END ---- Derived quantities -------------------------------------------
98 
99 
100 #if __cplusplus < 202004L
101  //@{
102  /// Comparison: all fields need to have the same values.
103  bool operator== (V1730Configuration const& other) const;
104  bool operator!= (V1730Configuration const& other) const
105  { return ! this->operator== (other); }
106  //@}
107 #else
108 # error "With C++20 support, enable the default comparison operators"
109  // probably the compiler will be generating these anyway, so don't bother
110 // bool operator== (V1730Configuration const& other) const = default;
111 // bool operator!= (V1730Configuration const& other) const = default;
112 #endif
113 
114  // -- BEGIN -- Dump facility -------------------------------------------------
115  /// Maximum supported verbosity level supported by `dump()`.
116  static constexpr unsigned int MaxDumpVerbosity
118 
119  /// Default verbosity level for `dump()`.
120  static constexpr unsigned int DefaultDumpVerbosity = MaxDumpVerbosity;
121 
122 
123  /**
124  * @brief Dumps the content of the configuration into `out` stream.
125  * @param out stream to dump the information into
126  * @param indent indentation string
127  * @param firstIndent special indentation string for the first line
128  * @param verbosity (default: `DefaultDumpVerbosity`) level of verbosity
129  *
130  * The indentation string is prepended to each new line of the dump.
131  * The first line indentation string is prepended before the first line of
132  * the dump. The dump ends on a new empty line.
133  *
134  * The amount of information printed depends on the `verbosity` level:
135  *
136  * * `0`: name of the board, board and fragment ID, number of channels
137  * * `1`: waveform length and post-trigger fraction;
138  * also: information on each channel, one per line, as with
139  * `V1730channelConfiguration::dump() with verbosity one level smaller
140  * than the value of `verbosity` argument
141  * * `2`: also setting of fragment timestamp
142  *
143  */
144  void dump(std::ostream& out,
145  std::string const& indent, std::string const& firstIndent,
146  unsigned int verbosity = MaxDumpVerbosity
147  ) const;
148 
149  /**
150  * @brief Dumps the content of the configuration into `out` stream.
151  * @param out stream to dump the information into
152  * @param indent indentation level
153  * @see `dump(std::ostream&, std::string const&, std::string const&, unsigned int) const`
154  *
155  * Version of `dump()` with same first indentation level as the rest, and
156  * default verbosity.
157  */
158  void dump(std::ostream& out, std::string const& indent = "") const
159  { dump(out, indent, indent); }
160 
161  /**
162  * @brief Dumps the content of the configuration into `out` stream.
163  * @param out stream to dump the information into
164  * @param indent (default: none) indentation string
165  * @see `dump(std::ostream&, std::string const&, std::string const&, unsigned int) const`
166  *
167  * Version of `dump()` with the specified `verbosity` level and same first
168  * indentation level as the rest.
169  */
170  void dump(std::ostream& out,
171  unsigned int verbosity,
172  std::string const& indent = ""
173  ) const
174  { dump(out, indent, indent, verbosity); }
175 
176  // -- END ---- Dump facility -------------------------------------------------
177 
178 
179  /// Convert a number of ticks into a time interval in microseconds.
180  static float ticks2us(int ticks) { return ticks * 0.002f; }
181 
182 }; // sbn::V1730Configuration
183 
184 
185 
186 //------------------------------------------------------------------------------
187 //--- Inline implementation
188 //------------------------------------------------------------------------------
189 inline unsigned int sbn::V1730Configuration::preTriggerTicks() const
190  { return static_cast<unsigned int>((1.0f - postTriggerFrac) * bufferLength); }
191 
192 
193 //------------------------------------------------------------------------------
194 inline unsigned int sbn::V1730Configuration::postTriggerTicks() const
195  { return static_cast<unsigned int>(postTriggerFrac * bufferLength); }
196 
197 
198 //------------------------------------------------------------------------------
200  { return ticks2us(bufferLength); }
201 
202 
203 //------------------------------------------------------------------------------
205  { return ticks2us(preTriggerTicks()); }
206 
207 
208 //------------------------------------------------------------------------------
210  { return ticks2us(postTriggerTicks()); }
211 
212 
213 //------------------------------------------------------------------------------
214 inline bool sbn::V1730Configuration::operator==
215  (sbn::V1730Configuration const& other) const
216 {
217 
218  if (boardName != other.boardName ) return false;
219  if (boardID != other.boardID ) return false;
220  if (fragmentID != other.fragmentID ) return false;
221  if (bufferLength != other.bufferLength ) return false;
222  if (postTriggerFrac != other.postTriggerFrac ) return false;
223  if (useTimeTagForTimeStamp != other.useTimeTagForTimeStamp) return false;
224  if (nChannels != other.nChannels ) return false;
225  if (channels != other.channels ) return false;
226 
227  return true;
228 } // sbn::V1730Configuration::operator==()
229 
230 
231 //------------------------------------------------------------------------------
232 inline std::ostream& sbn::operator<<
233  (std::ostream& out, sbn::V1730Configuration const& config)
234  { config.dump(out); return out; }
235 
236 
237 //------------------------------------------------------------------------------
238 
239 #endif // SBNOBJ_COMMON_PMT_DATA_V1730CONFIGURATION_H
std::string boardName
Name (mnemonic) of the board.
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.
unsigned int preTriggerTicks() const
Ticks in the waveform before the trigger.
bool operator==(V1730Configuration const &other) const
Comparison: all fields need to have the same values.
unsigned int nChannels
Number of channels (nChannels).
unsigned int boardID
Numeric ID of the board (board_id).
bool operator!=(V1730Configuration const &other) const
unsigned int postTriggerTicks() const
Ticks in the waveform after the trigger.
tick ticks
Alias for common language habits.
Definition: electronics.h:78
unsigned int fragmentID
DAQ fragment ID.
unsigned int bufferLength
Ticks in each buffer (recordLength).
static float ticks2us(int ticks)
Convert a number of ticks into a time interval in microseconds.
float bufferTime() const
Duration of the waveform [us].
Information from the configuration of a V1730 PMT readout board.
void dump(std::ostream &out, std::string const &indent="") const
Dumps the content of the configuration into out stream.
static constexpr unsigned int MaxDumpVerbosity
Maximum supported verbosity level supported by dump().
bool useTimeTagForTimeStamp
Whether fragment timestamp is synchronised with server NTP and with TTT.
static constexpr unsigned int MaxDumpVerbosity
Maximum supported verbosity level supported by dump().
float postTriggerFrac
Fraction of the waveform after the trigger signal (postPercent).
float postTriggerTime() const
Time in the waveform after the trigger [us].
static constexpr unsigned int DefaultDumpVerbosity
Default verbosity level for dump().
std::vector< sbn::V1730channelConfiguration > channels
Configuration of each channel.
void dump(std::ostream &out, unsigned int verbosity, std::string const &indent="") const
Dumps the content of the configuration into out stream.
float preTriggerTime() const
Time in the waveform before the trigger [us].
Class containing configuration for a V1730 board.