LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
DumpOpDetWaveforms_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
9 #include "lardata/Utilities/StatCollector.h" // lar::util::MinMaxCollector
11 
12 // art libraries
18 
19 // support libraries
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/types/Name.h"
23 #include "fhiclcpp/types/Comment.h"
24 
25 // C//C++ standard libraries
26 #include <string>
27 #include <algorithm> // std::min()
28 #include <ios> // std::fixed
29 #include <iomanip> // std::setprecision(), std::setw()
30 #include <utility> // std::forward(), std::swap()
31 
32 
33 namespace detsim {
34 
55  public:
56 
57  struct Config {
58 
59  using Name = fhicl::Name;
61 
63  Name("OpDetWaveformsTag"),
64  Comment("input tag of the raw::OpDetWaveform collection to be dumped")
65  };
66 
68  Name("OutputCategory"),
69  Comment("name of the category used for the output"),
70  "DumpOpDetWaveforms"
71  };
72 
74  Name("DigitsPerLine"),
75  Comment
76  ("the dump of ADC readings will put this many of them for each line"),
77  20U
78  };
79 
81  Name("Pedestal"),
82  Comment("ADC readings are written relative to this number"),
83  0
84  };
85 
86  }; // struct Config
87 
89 
90 
91  explicit DumpOpDetWaveforms(Parameters const& config);
92 
93 
95  void analyze (const art::Event& evt);
96 
97 
99  template <typename Stream>
100  void DumpWaveform(
101  Stream&& out, raw::OpDetWaveform const& waveform,
102  std::string indent, std::string indentFirst
103  ) const;
104 
105  template <typename Stream>
107  Stream&& out, raw::OpDetWaveform const& waveform, std::string indent = ""
108  ) const
109  { DumpWaveform(std::forward<Stream>(out), waveform, indent, indent); }
110 
111 
112  private:
113 
115  std::string fOutputCategory;
116  unsigned int fDigitsPerLine;
118 
119  }; // class DumpOpDetWaveforms
120 
121 } // namespace detsim
122 
123 
124 namespace detsim {
125 
126  //-------------------------------------------------
128  : EDAnalyzer (config)
130  , fOutputCategory (config().OutputCategory())
131  , fDigitsPerLine (config().DigitsPerLine())
132  , fPedestal (config().Pedestal())
133  {}
134 
135 
136  //-------------------------------------------------
138 
139  // fetch the data to be dumped on screen
140  auto Waveforms =
141  event.getValidHandle<std::vector<raw::OpDetWaveform>>(fOpDetWaveformsTag);
142 
144  << "The event " << event.id() << " contains data for "
145  << Waveforms->size() << " optical detector channels";
146  if (fPedestal != 0) {
147  mf::LogVerbatim(fOutputCategory) << "A pedestal of " << fPedestal
148  << " counts will be subtracted from all ADC readings.";
149  } // if pedestal
150 
151  for (raw::OpDetWaveform const& waveform: *Waveforms) {
152 
154 
155  } // for waveforms
156 
157  } // DumpOpDetWaveforms::analyze()
158 
159 
160  //----------------------------------------------------------------------------
161  template <typename Stream>
163  Stream&& out, raw::OpDetWaveform const& waveform,
164  std::string indent, std::string indentFirst
165  ) const
166  {
167  auto const& data = waveform;
168  using Count_t = raw::ADC_Count_t;
169 
170  // print a header for the raw digits
171  out << indentFirst
172  << "on channel #" << waveform.ChannelNumber() << " (time stamp: "
173  << waveform.TimeStamp() << "): " << data.size() << " time ticks";
174 
175  // print the content of the channel
176  if (fDigitsPerLine == 0) return;
177 
178  std::vector<Count_t> DigitBuffer(fDigitsPerLine), LastBuffer;
179 
180  unsigned int repeat_count = 0; // additional lines like the last one
181  unsigned int index = 0;
182 
184  out << "\n" << indent
185  << " content of the channel (" << fDigitsPerLine << " ticks per line):";
186  auto iTick = data.cbegin(), tend = data.cend(); // const iterators
187  while (iTick != tend) {
188  // the next line will show at most fDigitsPerLine ticks
189  unsigned int line_size
190  = std::min(fDigitsPerLine, (unsigned int) data.size() - index);
191  if (line_size == 0) break; // no more ticks
192 
193  // fill the new buffer (iTick will move forward)
194  DigitBuffer.resize(line_size);
195  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
196  while ((iBuf != bend) && (iTick != tend))
197  Extrema.add(*(iBuf++) = *(iTick++) - fPedestal);
198  index += line_size;
199 
200  // if the new buffer is the same as the old one, just mark it
201  if (DigitBuffer == LastBuffer) {
202  repeat_count += 1;
203  continue;
204  }
205 
206  // if there are previous repeats, write that on screen
207  // before the new, different line
208  if (repeat_count > 0) {
209  out << "\n" << indent
210  << " [ ... repeated " << repeat_count << " more times ]";
211  repeat_count = 0;
212  }
213 
214  // dump the new line of ticks
215  out << "\n" << indent << " ";
216  for (auto digit: DigitBuffer)
217  out << " " << std::setw(4) << digit;
218 
219  // quick way to assign DigitBuffer to LastBuffer
220  // (we don't care we lose the former)
221  std::swap(LastBuffer, DigitBuffer);
222 
223  } // while
224  if (repeat_count > 0) {
225  out << "\n" << indent
226  << " [ ... repeated " << repeat_count << " more times to the end]";
227  }
228  if (Extrema.min() != Extrema.max()) {
229  out << "\n" << indent
230  << " range of " << data.size()
231  << " samples: [" << Extrema.min() << ";" << Extrema.max() << "]";
232  }
233 
234  } // DumpOpDetWaveforms::DumpWaveform()
235 
236 
237  //----------------------------------------------------------------------------
239 
240  //----------------------------------------------------------------------------
241 
242 } // namespace detsim
Data_t max() const
Returns the accumulated maximum, or a very small number if no values.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fhicl::Atom< raw::ADC_Count_t > Pedestal
void DumpWaveform(Stream &&out, raw::OpDetWaveform const &waveform, std::string indent="") const
This_t & add(Data_t value)
Include a single value in the statistics.
Channel_t ChannelNumber() const
Definition: OpDetWaveform.h:72
TimeStamp_t TimeStamp() const
Definition: OpDetWaveform.h:73
Detector simulation of raw signals on wires.
DumpOpDetWaveforms(Parameters const &config)
std::string fOutputCategory
Category for mf::LogInfo output.
Prints the content of all optical detector waveforms on screen.
Classes gathering simple statistics.
Keeps track of the minimum and maximum value we observed.
Data_t min() const
Returns the accumulated minimum, or a very large number if no values.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
fhicl::Atom< art::InputTag > OpDetWaveformsTag
std::string indent(std::size_t const i)
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
raw::ADC_Count_t fPedestal
ADC pedestal (subtracted from readings).
void DumpWaveform(Stream &&out, raw::OpDetWaveform const &waveform, std::string indent, std::string indentFirst) const
Dumps the content of a single waveform into the specified output stream.
Int_t min
Definition: plot.C:26
void analyze(const art::Event &evt)
Does the printing.
art::InputTag fOpDetWaveformsTag
Input tag of data product to dump.
unsigned int fDigitsPerLine
ADC readings per line in the output.
short ADC_Count_t
Definition: OpDetWaveform.h:22
Event finding and building.