LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpRawDigits_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
9 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
10 #include "lardataalg/Utilities/StatCollector.h" // lar::util::MinMaxCollector<>
12 #include "lardataobj/RawData/raw.h" // raw::Uncompress()
13 
14 // art libraries
20 
21 // support libraries
22 #include "fhiclcpp/types/Atom.h"
23 #include "fhiclcpp/types/Comment.h"
24 #include "fhiclcpp/types/Name.h"
26 
27 // C//C++ standard libraries
28 #include <algorithm> // std::min(), std::copy_n()
29 #include <iomanip> // std::setprecision(), std::setw()
30 #include <string>
31 
32 namespace detsim {
33 
53  class DumpRawDigits : public art::EDAnalyzer {
54 
56  using Digit_t = raw::RawDigit::ADCvector_t::value_type;
57 
60 
61  public:
62  struct Config {
63  using Name = fhicl::Name;
65 
67  Name("DetSimModuleLabel"),
68  Comment("tag of producer used to create the raw::RawDigit collection"),
69  "daq" /* default */
70  };
71 
73  Name("OutputCategory"),
74  Comment("the messagefacility category used for the output"),
75  "DumpDigits" /* default */
76  };
77 
79  Name("DigitsPerLine"),
80  Comment("number of digits printed per line (0: don't print digits)"),
81  20 /* default */
82  };
83 
85  Name("Pedestal"),
86  Comment("digit values are written relative to this number"),
87  0 /* default */
88  };
89 
90  }; // Config
91 
93 
95  explicit DumpRawDigits(Parameters const& config);
96 
98  virtual void beginJob() override;
99 
101  virtual void analyze(art::Event const& evt) override;
102 
103  private:
105  std::string fOutputCategory;
106  unsigned int fDigitsPerLine;
108 
110  template <typename Stream>
111  void PrintRawDigit(Stream&& out,
112  raw::RawDigit const& digits,
113  std::string indent = " ",
114  std::string firstIndent = " ") const;
115 
116  }; // class DumpRawDigits
117 
118 } // namespace detsim
119 
120 //------------------------------------------------------------------------------
121 //--- Implementation
122 //------------------------------------------------------------------------------
124  : EDAnalyzer(config)
126  , fOutputCategory(config().OutputCategory())
127  , fDigitsPerLine(config().DigitsPerLine())
128  , fPedestal(config().Pedestal())
129 {}
130 
131 //------------------------------------------------------------------------------
133 {
134 
135  if (fPedestal != 0) {
137  << "A pedestal of " << fPedestal << " will be subtracted from all raw digits";
138  } // if pedestal
139 
140 } // detsim::DumpRawDigits::beginJob()
141 
142 //------------------------------------------------------------------------------
144 {
145 
146  auto const& RawDigits = *(evt.getValidHandle<std::vector<raw::RawDigit>>(fDetSimModuleLabel));
147 
148  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id() << " contains " << RawDigits.size()
149  << " '" << fDetSimModuleLabel.encode() << "' waveforms";
150  for (raw::RawDigit const& digits : RawDigits) {
151 
153 
154  } // for digits
155 
156 } // caldata::DumpWires::analyze()
157 
158 //------------------------------------------------------------------------------
159 template <typename Stream>
161  raw::RawDigit const& digits,
162  std::string indent /* = " " */,
163  std::string firstIndent /* = " " */
164 ) const
165 {
166 
167  //
168  // uncompress the digits
169  //
170  raw::RawDigit::ADCvector_t ADCs(digits.Samples());
171  raw::Uncompress(digits.ADCs(), ADCs, digits.Compression());
172 
173  //
174  // print a header for the raw digits
175  //
176  out << firstIndent << " #" << digits.Channel() << ": " << ADCs.size() << " time ticks";
177  if (digits.Samples() != ADCs.size()) out << " [!!! EXPECTED " << digits.Samples() << "] ";
178  out << " (" << digits.NADC() << " after compression); compression type: ";
179  switch (digits.Compression()) {
180  case raw::kNone: out << "no compression"; break;
181  case raw::kHuffman: out << "Huffman encoding"; break;
182  case raw::kZeroSuppression: out << "zero suppression"; break;
183  case raw::kZeroHuffman: out << "zero suppression + Huffman encoding"; break;
184  case raw::kDynamicDec: out << "dynamic decimation"; break;
185  default: out << "unknown (#" << ((int)digits.Compression()) << ")"; break;
186  } // switch
187 
188  // print the content of the channel
189  if (fDigitsPerLine > 0) {
190  std::vector<Digit_t> DigitBuffer(fDigitsPerLine), LastBuffer;
191 
192  unsigned int repeat_count = 0; // additional lines like the last one
193  unsigned int index = 0;
195  out << "\n" << indent << "content of the channel (" << fDigitsPerLine << " ticks per line):";
196  auto iTick = ADCs.cbegin(), tend = ADCs.cend(); // const iterators
197  while (iTick != tend) {
198  // the next line will show at most fDigitsPerLine ticks
199  unsigned int line_size = std::min(fDigitsPerLine, (unsigned int)ADCs.size() - index);
200  if (line_size == 0) break; // no more ticks
201 
202  // fill the new buffer (iTick will move forward)
203  DigitBuffer.resize(line_size);
204  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
205  while ((iBuf != bend) && (iTick != tend))
206  Extrema.add(*(iBuf++) = (*(iTick++) - fPedestal));
207  index += line_size;
208 
209  // if the new buffer is the same as the old one, just mark it
210  if (DigitBuffer == LastBuffer) {
211  repeat_count += 1;
212  continue;
213  }
214 
215  // if there are previous repeats, write that on screen
216  // before the new, different line
217  if (repeat_count > 0) {
218  out << "\n"
219  << indent << " [ ... repeated " << repeat_count << " more times, "
220  << (repeat_count * LastBuffer.size()) << " ticks ]";
221  repeat_count = 0;
222  }
223 
224  // dump the new line of ticks
225  out << "\n" << indent << " ";
226  for (auto digit : DigitBuffer)
227  out << " " << std::setw(4) << digit;
228 
229  // quick way to assign DigitBuffer to LastBuffer
230  // (we don't care we lose the former)
231  std::swap(LastBuffer, DigitBuffer);
232 
233  } // while
234  if (repeat_count > 0) {
235  out << "\n" << indent << " [ ... repeated " << repeat_count << " more times to the end ]";
236  }
237  if (Extrema.min() < Extrema.max()) {
238  out << "\n"
239  << indent << " range of " << index << " samples: [" << Extrema.min() << ";"
240  << Extrema.max() << "]";
241  }
242  } // if dumping the ticks
243 
244 } // detsim::DumpRawDigits::analyze()
245 
246 //------------------------------------------------------------------------------
248 
249 //------------------------------------------------------------------------------
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.
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:217
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:213
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
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Classes gathering simple statistics.
no compression
Definition: RawTypes.h:9
std::string encode() const
Definition: InputTag.cc:97
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:65
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:201
virtual void beginJob() override
Prints an introduction.
Prints the content of all the raw digits on screen.
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:229
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
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.
TCEvent evt
Definition: DataStructs.cxx:8
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:744
fhicl::Atom< Pedestal_t > Pedestal
Dynamic decimation.
Definition: RawTypes.h:13
EventID id() const
Definition: Event.cc:23