Classes | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
dump::raw::OpDetWaveformDumper Class Reference

Prints the content of optical detector waveforms on screen. More...

#include <OpDetWaveform.h>

Inheritance diagram for dump::raw::OpDetWaveformDumper:
dump::DumperBase

Classes

struct  TickLabelMaker
 Time label: tick number relative to the waveform. More...
 
struct  TimeLabelMaker
 Base functor for printing time according to tick number. More...
 

Public Member Functions

 OpDetWaveformDumper (raw::ADC_Count_t pedestal=0, unsigned int digitsPerLine=0U)
 Constructor: sets waveform dump parameters. More...
 
void setTimeLabelMaker (TimeLabelMaker const *timeLabelMaker)
 Chooses which time label maker to use. More...
 
template<typename Stream >
void dump (Stream &&stream, raw::OpDetWaveform const &waveform)
 Dumps the content of a waveform into the specified output stream. More...
 
template<typename Stream >
void operator() (Stream &&stream, raw::OpDetWaveform const &waveform)
 An alias of dump(). More...
 
- Public Member Functions inherited from dump::DumperBase
 DumperBase ()
 Default constructor: no indentation. More...
 
 DumperBase (std::string const &indent, std::string const &firstIndent)
 Constructor: sets indentation. More...
 
 DumperBase (std::string const &indent)
 Constructor: sets indentation. More...
 
template<typename Stream >
decltype(auto) indenter (Stream &&out) const
 Returns an Indenter object tied to this dumper and out stream. More...
 
std::string const & indent () const
 Returns the indentation string currently configured for all lines. More...
 
std::string const & firstIndent () const
 Returns the indentation string currently configured for the first line. More...
 
void setIndent (std::string const &indent, std::string const &firstIndent)
 Sets indentation strings to the specified values. More...
 
void setIndent (std::string const &indent)
 Sets both indentation strings to the same specified value. More...
 
template<typename Stream >
Stream & indented (Stream &&out, bool first=false) const
 Writes the indentation into a stream, and returns it for further output. More...
 
template<typename Stream >
Stream & firstIndented (Stream &&out) const
 
template<typename Stream >
Stream & newline (Stream &&out) const
 

Static Public Member Functions

static std::string padRight (std::string const &s, unsigned int width, std::string padding=" ")
 Pads the specified string to the right, truncating its right if needed. More...
 
static unsigned int digitsOf (unsigned int n)
 Pads the specified string to the right, truncating its right if needed. More...
 

Private Attributes

raw::ADC_Count_t fPedestal
 ADC pedestal (subtracted from readings). More...
 
unsigned int fDigitsPerLine
 ADC readings per line in the output. More...
 
TimeLabelMaker const * fTimeLabelMaker = nullptr
 The functor to be used to extract the time label. More...
 

Additional Inherited Members

- Protected Member Functions inherited from dump::DumperBase
IndentSettingsindentSettings ()
 
IndentSettings const & indentSettings () const
 
IndentSettingssaveIndentSettings ()
 Stacks a copy of the current settings, and returns the "new" ones. More...
 
IndentSettingsrestoreIndentSettings ()
 Restores and returns the last saved settings. More...
 

Detailed Description

Prints the content of optical detector waveforms on screen.

Example of usage:

dump.setIndent(" ");
for (raw::OpDetWaveform const& waveform: waveforms)
dump(mf::LogVerbatim("dumper"), waveform);

Definition at line 45 of file OpDetWaveform.h.

Constructor & Destructor Documentation

dump::raw::OpDetWaveformDumper::OpDetWaveformDumper ( raw::ADC_Count_t  pedestal = 0,
unsigned int  digitsPerLine = 0U 
)
inline

Constructor: sets waveform dump parameters.

Parameters
pedestal(default: 0) the pedestal to be automatically added to all digits
digitsPerLine(default: 0) how many ADC digits to print per line; 0 disables the digit printing completely

Note that no indentation is set. If some is desired, set it with setIndent() after construction.

Definition at line 92 of file OpDetWaveform.h.

93  : fPedestal(pedestal), fDigitsPerLine(digitsPerLine)
94  {}
raw::ADC_Count_t fPedestal
ADC pedestal (subtracted from readings).
unsigned int fDigitsPerLine
ADC readings per line in the output.

Member Function Documentation

unsigned int dump::raw::OpDetWaveformDumper::digitsOf ( unsigned int  n)
static

Pads the specified string to the right, truncating its right if needed.

Definition at line 299 of file OpDetWaveform.h.

299  {
300  unsigned int digits = 1U;
301  while (n >= 10) {
302  ++digits;
303  n /= 10;
304  }
305  return digits;
306 } // dump::raw::OpDetWaveformDumper::digitsOf()
std::void_t< T > n
template<typename Stream >
void dump::raw::OpDetWaveformDumper::dump ( Stream &&  stream,
raw::OpDetWaveform const &  waveform 
)

Dumps the content of a waveform into the specified output stream.

Template Parameters
Streamtype of stream to dump data into
Parameters
streamstream to dump data into
waveformthe object to be dumped

Indentation is regulated via base class methods (see setIndent()).

Definition at line 151 of file OpDetWaveform.h.

152 {
153  static std::string const headerSep = " | ";
154 
155  auto const& data = waveform;
156  using Count_t = raw::ADC_Count_t;
157 
158  auto out = indenter(std::forward<Stream>(stream));
159 
160  // print a header for the raw digits
161  out.start()
162  << "on channel #" << waveform.ChannelNumber() << " (time stamp: "
163  << waveform.TimeStamp() << "): " << data.size() << " time ticks";
164 
165  // print the content of the channel
166  if (fDigitsPerLine == 0) return;
167 
168  // save and change indentation
169  saveIndentSettings().set(indent() + " ");
170 
171  unsigned int repeat_count = 0U; // additional lines like the last one
172  unsigned int index = 0U;
173  unsigned int firstLineTick = 0U;
174 
175  // local function for printing and resetting the repeat count
176  auto flushRepeatCount
177  = [this, &out, &waveform, &firstLineTick](unsigned int& count)
178  -> decltype(auto)
179  {
180  if (count > 0) {
181  out.newline();
182  if (fTimeLabelMaker) {
183  out
184  << padRight("", fTimeLabelMaker->labelWidth(waveform, firstLineTick))
185  << headerSep
186  ;
187  }
188  out << " [ ... repeated " << count << " more times ]";
189  count = 0;
190  }
191  return out;
192  };
193 
194  std::vector<Count_t> DigitBuffer(fDigitsPerLine), LastBuffer;
195 
197  out.newline()
198  << "content of the channel (" << fDigitsPerLine << " ticks per line):";
199  auto iTick = data.cbegin(), tend = data.cend(); // const iterators
200  while (iTick != tend) {
201  // the next line will show at most fDigitsPerLine ticks
202  unsigned int line_size
203  = std::min(fDigitsPerLine, (unsigned int) data.size() - index);
204  if (line_size == 0) break; // no more ticks
205 
206  // fill the new buffer (iTick will move forward)
207  DigitBuffer.resize(line_size);
208  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
209  while ((iBuf != bend) && (iTick != tend))
210  Extrema.add(*(iBuf++) = *(iTick++) - fPedestal);
211  firstLineTick = index;
212  index += line_size;
213 
214  // if the new buffer is the same as the old one, just mark it
215  if (DigitBuffer == LastBuffer) {
216  repeat_count += 1;
217  continue;
218  }
219 
220  // if there are previous repeats, write that on screen
221  // before the new, different line
222  flushRepeatCount(repeat_count);
223 
224  // dump the new line of ticks
225  out.newline();
226  if (fTimeLabelMaker) {
227  out << padRight(
228  fTimeLabelMaker->label(waveform, firstLineTick),
229  fTimeLabelMaker->labelWidth(waveform, firstLineTick)
230  )
231  << headerSep
232  ;
233  }
234  for (auto digit: DigitBuffer)
235  out << " " << std::setw(4) << digit;
236 
237 
238  // quick way to assign DigitBuffer to LastBuffer
239  // (we don't care we lose the former)
240  std::swap(LastBuffer, DigitBuffer);
241 
242  } // while
243  flushRepeatCount(repeat_count);
244  if (Extrema.min() != Extrema.max()) {
245  out.newline()
246  << " range of " << data.size()
247  << " samples: [" << Extrema.min() << ";" << Extrema.max() << "] (span: "
248  << (Extrema.max() - Extrema.min());
249  if (fPedestal != 0) {
250  out << ", absolute: ["
251  << (Extrema.min() + fPedestal) << ";"
252  << (Extrema.max() + fPedestal) << "]";
253  }
254  out << ")";
255  }
256 
258 
259 } // dump::raw::OpDetWaveformDumper::dump()
Data_t max() const
Returns the accumulated maximum, or a very small number if no values.
This_t & add(Data_t value)
Include a single value in the statistics.
std::string string
Definition: nybbler.cc:12
IndentSettings & restoreIndentSettings()
Restores and returns the last saved settings.
Definition: DumperBase.h:220
void set(std::string const &newIndent, std::string const &newFirstIndent)
Definition: DumperBase.h:45
static std::string padRight(std::string const &s, unsigned int width, std::string padding=" ")
Pads the specified string to the right, truncating its right if needed.
virtual unsigned int labelWidth(raw::OpDetWaveform const &waveform, unsigned int tick) const
Length of padded label. For best results, it should be a constant.
Definition: OpDetWaveform.h:59
Keeps track of the minimum and maximum value we observed.
TimeLabelMaker const * fTimeLabelMaker
The functor to be used to extract the time label.
Data_t min() const
Returns the accumulated minimum, or a very large number if no values.
void swap(Handle< T > &a, Handle< T > &b)
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:96
decltype(auto) indenter(Stream &&out) const
Returns an Indenter object tied to this dumper and out stream.
Definition: DumperBase.h:202
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
raw::ADC_Count_t fPedestal
ADC pedestal (subtracted from readings).
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
IndentSettings & saveIndentSettings()
Stacks a copy of the current settings, and returns the "new" ones.
Definition: DumperBase.h:212
virtual std::string label(raw::OpDetWaveform const &waveform, unsigned int tick) const =0
Returns the label to be written for the specified tick number.
unsigned int fDigitsPerLine
ADC readings per line in the output.
short ADC_Count_t
Definition: OpDetWaveform.h:21
template<typename Stream >
void dump::raw::OpDetWaveformDumper::operator() ( Stream &&  stream,
raw::OpDetWaveform const &  waveform 
)
inline

An alias of dump().

Definition at line 122 of file OpDetWaveform.h.

123  { dump(stream, waveform); }
void dump(Stream &&stream, raw::OpDetWaveform const &waveform)
Dumps the content of a waveform into the specified output stream.
std::string dump::raw::OpDetWaveformDumper::padRight ( std::string const &  s,
unsigned int  width,
std::string  padding = " " 
)
static

Pads the specified string to the right, truncating its right if needed.

Definition at line 264 of file OpDetWaveform.h.

265 {
266 
267  if (s.length() > width) { // too long already?
268  // truncate on the right
269  return { s, 0U, width }; // { string, start index, character count }
270  }
271 
272  std::string padded;
273  padded.reserve(width);
274 
275  // this is how many full padding strings we need to prepend
276  unsigned int nPadding
277  = (s.length() >= width)? 0U: (width - s.length()) / padding.length();
278 
279  // if there is need for some more partial padding beyond that:
280  if (nPadding * padding.length() + s.length() < width) {
281  // immediately prepend from the rightmost part of the padding string
282  padded.append(
283  padding.end() - (width - (nPadding * padding.length() + s.length())),
284  padding.end()
285  );
286  }
287 
288  // add the rest of the padding and the string, and then we are done
289  while (nPadding-- > 0) padded += padding;
290  padded += s;
291 
292  assert(padded.length() == width);
293 
294  return padded;
295 } // dump::raw::OpDetWaveformDumper::padRight()
uint length() const
Definition: qcstring.h:195
std::string string
Definition: nybbler.cc:12
static QCString * s
Definition: config.cpp:1042
void dump::raw::OpDetWaveformDumper::setTimeLabelMaker ( TimeLabelMaker const *  timeLabelMaker)
inline

Chooses which time label maker to use.

Parameters
timeLabelMakera pointer to the external time label maker

A time label maker is an object derived from TimeLabelMaker which can convert a waveform and tick into a string representing that tick within the waveform. If never specified or if nullptr, no time label will be printed at all.

Definition at line 105 of file OpDetWaveform.h.

106  { fTimeLabelMaker = timeLabelMaker; }
TimeLabelMaker const * fTimeLabelMaker
The functor to be used to extract the time label.

Member Data Documentation

unsigned int dump::raw::OpDetWaveformDumper::fDigitsPerLine
private

ADC readings per line in the output.

Definition at line 136 of file OpDetWaveform.h.

raw::ADC_Count_t dump::raw::OpDetWaveformDumper::fPedestal
private

ADC pedestal (subtracted from readings).

Definition at line 135 of file OpDetWaveform.h.

TimeLabelMaker const* dump::raw::OpDetWaveformDumper::fTimeLabelMaker = nullptr
private

The functor to be used to extract the time label.

Definition at line 139 of file OpDetWaveform.h.


The documentation for this class was generated from the following file: