LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
DumpRawDigits_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
9 #include "lardata/Utilities/StatCollector.h" // lar::util::MinMaxCollector<>
11 #include "lardataobj/RawData/raw.h" // raw::Uncompress()
12 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
13 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::View_t
14 
15 // art libraries
21 
22 // support libraries
23 #include "fhiclcpp/types/Atom.h"
24 #include "fhiclcpp/types/Name.h"
25 #include "fhiclcpp/types/Comment.h"
27 
28 // C//C++ standard libraries
29 #include <string>
30 #include <algorithm> // std::min(), std::copy_n()
31 #include <ios> // std::fixed
32 #include <iomanip> // std::setprecision(), std::setw()
33 
34 
35 namespace detsim {
36 
57 
59  using Digit_t = raw::RawDigit::ADCvector_t::value_type;
60 
63 
64  public:
65 
66  struct Config {
67  using Name = fhicl::Name;
69 
71  Name("DetSimModuleLabel"),
72  Comment("tag of producer used to create the raw::RawDigit collection"),
73  "daq" /* default */
74  };
75 
77  Name("OutputCategory"),
78  Comment("the messagefacility category used for the output"),
79  "DumpDigits" /* default */
80  };
81 
83  Name("DigitsPerLine"),
84  Comment("number of digits printed per line (0: don't print digits)"),
85  20 /* default */
86  };
87 
89  Name("Pedestal"),
90  Comment("digit values are written relative to this number"),
91  0 /* default */
92  };
93 
94  }; // Config
95 
97 
98 
100  explicit DumpRawDigits(Parameters const& config);
101 
103  virtual void beginJob() override;
104 
106  virtual void analyze (art::Event const& evt) override;
107 
108  private:
109 
111  std::string fOutputCategory;
112  unsigned int fDigitsPerLine;
114 
116  template <typename Stream>
117  void PrintRawDigit(
118  Stream&& out, raw::RawDigit const& digits,
119  std::string indent = " ", std::string firstIndent = " "
120  ) const;
121 
122  }; // class DumpRawDigits
123 
124 } // namespace detsim
125 
126 
127 //------------------------------------------------------------------------------
128 //--- Implementation
129 //------------------------------------------------------------------------------
131  : EDAnalyzer (config)
133  , fOutputCategory (config().OutputCategory())
134  , fDigitsPerLine (config().DigitsPerLine())
135  , fPedestal (config().Pedestal())
136  {}
137 
138 
139 //------------------------------------------------------------------------------
141 
142  if (fPedestal != 0) {
143  mf::LogVerbatim(fOutputCategory) << "A pedestal of " << fPedestal
144  << " will be subtracted from all raw digits";
145  } // if pedestal
146 
147 } // detsim::DumpRawDigits::beginJob()
148 
149 
150 //------------------------------------------------------------------------------
152 
153  auto const& RawDigits
154  = *(evt.getValidHandle<std::vector<raw::RawDigit>>(fDetSimModuleLabel));
155 
156  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
157  << " contains " << RawDigits.size() << " '" << fDetSimModuleLabel.encode()
158  << "' waveforms";
159  for (raw::RawDigit const& digits: RawDigits) {
160 
162 
163  } // for digits
164 
165 } // caldata::DumpWires::analyze()
166 
167 
168 //------------------------------------------------------------------------------
169 template <typename Stream>
171  Stream&& out, raw::RawDigit const& digits,
172  std::string indent /* = " " */, std::string firstIndent /* = " " */
173 ) const {
174 
175  //
176  // uncompress the digits
177  //
178  raw::RawDigit::ADCvector_t ADCs(digits.Samples());
179  raw::Uncompress(digits.ADCs(), ADCs, digits.Compression());
180 
181  //
182  // print a header for the raw digits
183  //
184  out << firstIndent
185  << " #" << digits.Channel() << ": " << ADCs.size() << " time ticks";
186  if (digits.Samples() != ADCs.size())
187  out << " [!!! EXPECTED " << digits.Samples() << "] ";
188  out
189  << " (" << digits.NADC() << " after compression); compression type: ";
190  switch (digits.Compression()) {
191  case raw::kNone: out << "no compression"; break;
192  case raw::kHuffman: out << "Huffman encoding" ; break;
193  case raw::kZeroSuppression: out << "zero suppression"; break;
194  case raw::kZeroHuffman: out << "zero suppression + Huffman encoding";
195  break;
196  case raw::kDynamicDec: out << "dynamic decimation"; break;
197  default:
198  out << "unknown (#" << ((int) digits.Compression()) << ")"; break;
199  } // switch
200 
201  // print the content of the channel
202  if (fDigitsPerLine > 0) {
203  std::vector<Digit_t> DigitBuffer(fDigitsPerLine), LastBuffer;
204 
205  unsigned int repeat_count = 0; // additional lines like the last one
206  unsigned int index = 0;
208  out << "\n" << indent
209  << "content of the channel (" << fDigitsPerLine << " ticks per line):";
210  auto iTick = ADCs.cbegin(), tend = ADCs.cend(); // const iterators
211  while (iTick != tend) {
212  // the next line will show at most fDigitsPerLine ticks
213  unsigned int line_size
214  = std::min(fDigitsPerLine, (unsigned int) ADCs.size() - index);
215  if (line_size == 0) break; // no more ticks
216 
217  // fill the new buffer (iTick will move forward)
218  DigitBuffer.resize(line_size);
219  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
220  while ((iBuf != bend) && (iTick != tend))
221  Extrema.add(*(iBuf++) = (*(iTick++) - fPedestal));
222  index += line_size;
223 
224  // if the new buffer is the same as the old one, just mark it
225  if (DigitBuffer == LastBuffer) {
226  repeat_count += 1;
227  continue;
228  }
229 
230  // if there are previous repeats, write that on screen
231  // before the new, different line
232  if (repeat_count > 0) {
233  out << "\n" << indent
234  << " [ ... repeated " << repeat_count << " more times, "
235  << (repeat_count * LastBuffer.size()) << " ticks ]";
236  repeat_count = 0;
237  }
238 
239  // dump the new line of ticks
240  out << "\n" << indent << " ";
241  for (auto digit: DigitBuffer)
242  out << " " << std::setw(4) << digit;
243 
244  // quick way to assign DigitBuffer to LastBuffer
245  // (we don't care we lose the former)
246  std::swap(LastBuffer, DigitBuffer);
247 
248  } // while
249  if (repeat_count > 0) {
250  out << "\n" << indent
251  << " [ ... repeated " << repeat_count << " more times to the end ]";
252  }
253  if (Extrema.min() < Extrema.max()) {
254  out << "\n" << indent
255  << " range of " << index
256  << " samples: [" << Extrema.min() << ";" << Extrema.max() << "]";
257  }
258  } // if dumping the ticks
259 
260 } // detsim::DumpRawDigits::analyze()
261 
262 
263 //------------------------------------------------------------------------------
265 
266 //------------------------------------------------------------------------------
Data_t max() const
Returns the accumulated maximum, or a very small number if no values.
Huffman Encoding.
Definition: RawTypes.h:10
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:209
Digit_t Pedestal_t
Type to represent a pedestal.
This_t & add(Data_t value)
Include a single value in the statistics.
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:68
art::InputTag fDetSimModuleLabel
Tag for digits data product.
virtual void analyze(art::Event const &evt) override
Does the printing.
fhicl::Atom< art::InputTag > DetSimModuleLabel
std::string fOutputCategory
Category for LogVerbatim output.
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:211
Detector simulation of raw signals on wires.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:72
fhicl::Atom< unsigned int > DigitsPerLine
Definition of basic raw digits.
Zero Suppression followed by Huffman Encoding.
Definition: RawTypes.h:12
Classes gathering simple statistics.
no compression
Definition: RawTypes.h:9
unsigned short Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:212
raw::RawDigit::ADCvector_t::value_type Digit_t
Type to represent a digit.
unsigned int fDigitsPerLine
Ticks/digits per line in the output.
DumpRawDigits(Parameters const &config)
Constructor.
Zero Suppression algorithm.
Definition: RawTypes.h:11
Keeps track of the minimum and maximum value we observed.
Pedestal_t fPedestal
ADC pedestal, will be subtracted from digits.
Data_t min() const
Returns the accumulated minimum, or a very large number if no values.
fhicl::Atom< std::string > OutputCategory
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
std::string encode() const
Definition: InputTag.cc:36
Collect all the RawData header files together.
std::string indent(std::size_t const i)
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:206
virtual void beginJob() override
Prints an introduction.
Prints the content of all the raw digits on screen.
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Definition of data types for geometry description.
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:215
Int_t min
Definition: plot.C:26
void PrintRawDigit(Stream &&out, raw::RawDigit const &digits, std::string indent=" ", std::string firstIndent=" ") const
Dumps a single recob:Wire to the specified output stream.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:756
fhicl::Atom< Pedestal_t > Pedestal
Dynamic decimation.
Definition: RawTypes.h:13
EventID id() const
Definition: Event.h:56