LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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...
 
template<typename Stream >
decltype(auto) indenter (Stream &&out) const
 Returns an Indenter object tied to this dumper and out stream. More...
 
Indentation.

Indentation strings are expected to be written by the dumping algorithms at the beginning of each output line to ensure the proper alignment of the dump. The indent() string should be written at the beginning of every new output line, with the exception of the first one, for which firstIndent() should be written instead.

Note that this infrastructure only keeps track of the strings needed to indent the output, but it does not provide any tool to apply the indentation.

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...
 

Protected Member Functions

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...
 

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...
 

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 43 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 89 of file OpDetWaveform.h.

90  : fPedestal(pedestal), fDigitsPerLine(digitsPerLine)
91  {}
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 278 of file OpDetWaveform.h.

Referenced by dump::raw::OpDetWaveformDumper::TickLabelMaker::labelWidth(), and operator()().

279 {
280  unsigned int digits = 1U;
281  while (n >= 10) {
282  ++digits;
283  n /= 10;
284  }
285  return digits;
286 } // dump::raw::OpDetWaveformDumper::digitsOf()
Char_t n[5]
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 148 of file OpDetWaveform.h.

References lar::util::MinMaxCollector< T >::add(), raw::OpDetWaveform::ChannelNumber(), fDigitsPerLine, fPedestal, fTimeLabelMaker, dump::DumperBase::indent(), dump::DumperBase::indenter(), dump::raw::OpDetWaveformDumper::TimeLabelMaker::label(), dump::raw::OpDetWaveformDumper::TimeLabelMaker::labelWidth(), lar::util::MinMaxCollector< T >::max(), lar::util::MinMaxCollector< T >::min(), padRight(), dump::DumperBase::restoreIndentSettings(), dump::DumperBase::saveIndentSettings(), dump::DumperBase::IndentSettings::set(), and raw::OpDetWaveform::TimeStamp().

Referenced by operator()(), and setTimeLabelMaker().

149 {
150  static std::string const headerSep = " | ";
151 
152  auto const& data = waveform;
153  using Count_t = raw::ADC_Count_t;
154 
155  auto out = indenter(std::forward<Stream>(stream));
156 
157  // print a header for the raw digits
158  out.start() << "on channel #" << waveform.ChannelNumber()
159  << " (time stamp: " << waveform.TimeStamp() << "): " << data.size() << " time ticks";
160 
161  // print the content of the channel
162  if (fDigitsPerLine == 0) return;
163 
164  // save and change indentation
165  saveIndentSettings().set(indent() + " ");
166 
167  unsigned int repeat_count = 0U; // additional lines like the last one
168  unsigned int index = 0U;
169  unsigned int firstLineTick = 0U;
170 
171  // local function for printing and resetting the repeat count
172  auto flushRepeatCount =
173  [this, &out, &waveform, &firstLineTick](unsigned int& count) -> decltype(auto) {
174  if (count > 0) {
175  out.newline();
176  if (fTimeLabelMaker) {
177  out << padRight("", fTimeLabelMaker->labelWidth(waveform, firstLineTick)) << headerSep;
178  }
179  out << " [ ... repeated " << count << " more times ]";
180  count = 0;
181  }
182  return out;
183  };
184 
185  std::vector<Count_t> DigitBuffer(fDigitsPerLine), LastBuffer;
186 
188  out.newline() << "content of the channel (" << fDigitsPerLine << " ticks per line):";
189  auto iTick = data.cbegin(), tend = data.cend(); // const iterators
190  while (iTick != tend) {
191  // the next line will show at most fDigitsPerLine ticks
192  unsigned int line_size = std::min(fDigitsPerLine, (unsigned int)data.size() - index);
193  if (line_size == 0) break; // no more ticks
194 
195  // fill the new buffer (iTick will move forward)
196  DigitBuffer.resize(line_size);
197  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
198  while ((iBuf != bend) && (iTick != tend))
199  Extrema.add(*(iBuf++) = *(iTick++) - fPedestal);
200  firstLineTick = index;
201  index += line_size;
202 
203  // if the new buffer is the same as the old one, just mark it
204  if (DigitBuffer == LastBuffer) {
205  repeat_count += 1;
206  continue;
207  }
208 
209  // if there are previous repeats, write that on screen
210  // before the new, different line
211  flushRepeatCount(repeat_count);
212 
213  // dump the new line of ticks
214  out.newline();
215  if (fTimeLabelMaker) {
216  out << padRight(fTimeLabelMaker->label(waveform, firstLineTick),
217  fTimeLabelMaker->labelWidth(waveform, firstLineTick))
218  << headerSep;
219  }
220  for (auto digit : DigitBuffer)
221  out << " " << std::setw(4) << digit;
222 
223  // quick way to assign DigitBuffer to LastBuffer
224  // (we don't care we lose the former)
225  std::swap(LastBuffer, DigitBuffer);
226 
227  } // while
228  flushRepeatCount(repeat_count);
229  if (Extrema.min() != Extrema.max()) {
230  out.newline() << " range of " << data.size() << " samples: [" << Extrema.min() << ";"
231  << Extrema.max() << "] (span: " << (Extrema.max() - Extrema.min());
232  if (fPedestal != 0) {
233  out << ", absolute: [" << (Extrema.min() + fPedestal) << ";" << (Extrema.max() + fPedestal)
234  << "]";
235  }
236  out << ")";
237  }
238 
240 
241 } // 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.
IndentSettings & restoreIndentSettings()
Restores and returns the last saved settings.
Definition: DumperBase.h:233
void set(std::string const &newIndent, std::string const &newFirstIndent)
Definition: DumperBase.h:43
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:54
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.
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
decltype(auto) indenter(Stream &&out) const
Returns an Indenter object tied to this dumper and out stream.
Definition: DumperBase.h:215
raw::ADC_Count_t fPedestal
ADC pedestal (subtracted from readings).
IndentSettings & saveIndentSettings()
Stacks a copy of the current settings, and returns the "new" ones.
Definition: DumperBase.h:225
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
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:20
std::string const& dump::DumperBase::firstIndent ( ) const
inlineinherited

Returns the indentation string currently configured for the first line.

Definition at line 98 of file DumperBase.h.

References dump::DumperBase::IndentSettings::firstIndent, and dump::DumperBase::indentSettings().

Referenced by dump::DumperBase::Indenter< Stream >::firstIndentString().

98 { return indentSettings().firstIndent; }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::string firstIndent
Indentation string for the first line.
Definition: DumperBase.h:41
template<typename Stream >
Stream& dump::DumperBase::firstIndented ( Stream &&  out) const
inlineinherited

Writes first line indentation into a stream, and returns it for further output.

Definition at line 120 of file DumperBase.h.

References dump::DumperBase::indented().

121  {
122  return indented(std::forward<Stream>(out), true);
123  }
Stream & indented(Stream &&out, bool first=false) const
Writes the indentation into a stream, and returns it for further output.
Definition: DumperBase.h:111
std::string const& dump::DumperBase::indent ( ) const
inlineinherited

Returns the indentation string currently configured for all lines.

Definition at line 95 of file DumperBase.h.

References dump::DumperBase::IndentSettings::indent, and dump::DumperBase::indentSettings().

Referenced by dump(), and dump::DumperBase::Indenter< Stream >::indentString().

95 { return indentSettings().indent; }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::string indent
Default indentation string.
Definition: DumperBase.h:40
template<typename Stream >
Stream& dump::DumperBase::indented ( Stream &&  out,
bool  first = false 
) const
inlineinherited

Writes the indentation into a stream, and returns it for further output.

Definition at line 111 of file DumperBase.h.

References dump::DumperBase::IndentSettings::firstIndent, and dump::DumperBase::IndentSettings::indent.

Referenced by dump::DumperBase::firstIndented(), dump::DumperBase::Indenter< Stream >::indent(), and dump::DumperBase::newline().

112  {
113  out << (first ? firstIndent() : indent());
114  return out;
115  }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:98
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
template<typename Stream >
decltype(auto) dump::DumperBase::indenter ( Stream &&  out) const
inlineinherited

Returns an Indenter object tied to this dumper and out stream.

Definition at line 215 of file DumperBase.h.

Referenced by dump().

216  {
217  return Indenter<Stream>(std::forward<Stream>(out), *this);
218  }
IndentSettings& dump::DumperBase::indentSettings ( )
inlineprotectedinherited

Definition at line 221 of file DumperBase.h.

Referenced by dump::DumperBase::firstIndent(), dump::DumperBase::indent(), dump::DumperBase::restoreIndentSettings(), dump::DumperBase::saveIndentSettings(), and dump::DumperBase::setIndent().

221 { return fIndentSettings.back(); }
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
IndentSettings const& dump::DumperBase::indentSettings ( ) const
inlineprotectedinherited

Definition at line 222 of file DumperBase.h.

222 { return fIndentSettings.back(); }
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
template<typename Stream >
Stream& dump::DumperBase::newline ( Stream &&  out) const
inlineinherited

Initiates a new output line, including indentation, and returns the stream for further output.

Definition at line 128 of file DumperBase.h.

References dump::DumperBase::indented().

129  {
130  return indented(std::forward<Stream>(out));
131  }
Stream & indented(Stream &&out, bool first=false) const
Writes the indentation into a stream, and returns it for further output.
Definition: DumperBase.h:111
template<typename Stream >
void dump::raw::OpDetWaveformDumper::operator() ( Stream &&  stream,
raw::OpDetWaveform const &  waveform 
)
inline

An alias of dump().

Definition at line 120 of file OpDetWaveform.h.

References digitsOf(), dump(), n, and padRight().

121  {
122  dump(stream, waveform);
123  }
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 244 of file OpDetWaveform.h.

Referenced by dump(), and operator()().

247 {
248 
249  if (s.length() > width) { // too long already?
250  // truncate on the right
251  return {s, 0U, width}; // { string, start index, character count }
252  }
253 
254  std::string padded;
255  padded.reserve(width);
256 
257  // this is how many full padding strings we need to prepend
258  unsigned int nPadding = (s.length() >= width) ? 0U : (width - s.length()) / padding.length();
259 
260  // if there is need for some more partial padding beyond that:
261  if (nPadding * padding.length() + s.length() < width) {
262  // immediately prepend from the rightmost part of the padding string
263  padded.append(padding.end() - (width - (nPadding * padding.length() + s.length())),
264  padding.end());
265  }
266 
267  // add the rest of the padding and the string, and then we are done
268  while (nPadding-- > 0)
269  padded += padding;
270  padded += s;
271 
272  assert(padded.length() == width);
273 
274  return padded;
275 } // dump::raw::OpDetWaveformDumper::padRight()
IndentSettings& dump::DumperBase::restoreIndentSettings ( )
inlineprotectedinherited

Restores and returns the last saved settings.

Definition at line 233 of file DumperBase.h.

References dump::DumperBase::indentSettings().

Referenced by dump().

234  {
235  if (fIndentSettings.size() > 1U) fIndentSettings.pop_back();
236  assert(!fIndentSettings.empty());
237  return indentSettings();
238  }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
IndentSettings& dump::DumperBase::saveIndentSettings ( )
inlineprotectedinherited

Stacks a copy of the current settings, and returns the "new" ones.

Definition at line 225 of file DumperBase.h.

References dump::DumperBase::indentSettings().

Referenced by dump().

226  {
227  auto oldSettings = indentSettings();
228  fIndentSettings.push_back(std::move(oldSettings));
229  return indentSettings();
230  }
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::vector< IndentSettings > fIndentSettings
All indentation settings.
Definition: DumperBase.h:57
void dump::DumperBase::setIndent ( std::string const &  indent,
std::string const &  firstIndent 
)
inlineinherited

Sets indentation strings to the specified values.

Definition at line 101 of file DumperBase.h.

References dump::DumperBase::IndentSettings::indent, and dump::DumperBase::indentSettings().

102  {
104  }
std::string const & firstIndent() const
Returns the indentation string currently configured for the first line.
Definition: DumperBase.h:98
IndentSettings & indentSettings()
Definition: DumperBase.h:221
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
void dump::DumperBase::setIndent ( std::string const &  indent)
inlineinherited

Sets both indentation strings to the same specified value.

Definition at line 107 of file DumperBase.h.

References dump::DumperBase::setIndent().

Referenced by dump::DumperBase::setIndent().

107 { setIndent(indent, indent); }
void setIndent(std::string const &indent, std::string const &firstIndent)
Sets indentation strings to the specified values.
Definition: DumperBase.h:101
std::string const & indent() const
Returns the indentation string currently configured for all lines.
Definition: DumperBase.h:95
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 102 of file OpDetWaveform.h.

References dump(), and fTimeLabelMaker.

103  {
104  fTimeLabelMaker = timeLabelMaker;
105  }
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 135 of file OpDetWaveform.h.

Referenced by dump().

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

ADC pedestal (subtracted from readings).

Definition at line 134 of file OpDetWaveform.h.

Referenced by dump().

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

The functor to be used to extract the time label.

Definition at line 138 of file OpDetWaveform.h.

Referenced by dump(), and setTimeLabelMaker().


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