DumpRawDigits_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpRawDigits_module.cc
3  * @brief Dumps on screen the content of the raw digits
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date January 14th, 2015
6  */
7 
8 // LArSoft includes
9 #include "lardataalg/Utilities/StatCollector.h" // lar::util::MinMaxCollector<>
11 #include "lardataobj/RawData/raw.h" // raw::Uncompress()
12 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
13 
14 // art libraries
20 
21 // support libraries
22 #include "fhiclcpp/types/Atom.h"
23 #include "fhiclcpp/types/Name.h"
24 #include "fhiclcpp/types/Comment.h"
26 
27 // C//C++ standard libraries
28 #include <string>
29 #include <algorithm> // std::min(), std::copy_n()
30 #include <iomanip> // std::setprecision(), std::setw()
31 
32 
33 namespace detsim {
34 
35  /**
36  * @brief Prints the content of all the raw digits on screen.
37  *
38  * This analyser prints the content of all the raw digits into the
39  * `LogVerbatim` stream.
40  *
41  * Configuration parameters
42  * =========================
43  *
44  * - *DetSimModuleLabel* (string, default: `"daq"`): label of the
45  * producer used to create the `raw::RawDigits` collection
46  * - *OutputCategory* (string, default: `"DumpDigits"`): the category used
47  * for the output (useful for filtering)
48  * - *DigitsPerLine* (integer, default: `20`): the dump of digits and ticks
49  * will put this many of them for each line
50  * - *Pedestal* (integer, default: `0`): digit values are written relative
51  * to this number
52  *
53  */
55 
56  /// Type to represent a digit.
57  using Digit_t = raw::RawDigit::ADCvector_t::value_type;
58 
59  /// Type to represent a pedestal.
61 
62  public:
63 
64  struct Config {
65  using Name = fhicl::Name;
67 
69  Name("DetSimModuleLabel"),
70  Comment("tag of producer used to create the raw::RawDigit collection"),
71  "daq" /* default */
72  };
73 
75  Name("OutputCategory"),
76  Comment("the messagefacility category used for the output"),
77  "DumpDigits" /* default */
78  };
79 
81  Name("DigitsPerLine"),
82  Comment("number of digits printed per line (0: don't print digits)"),
83  20 /* default */
84  };
85 
87  Name("Pedestal"),
88  Comment("digit values are written relative to this number"),
89  0 /* default */
90  };
91 
92  }; // Config
93 
95 
96 
97  /// Constructor.
98  explicit DumpRawDigits(Parameters const& config);
99 
100  /// Prints an introduction.
101  virtual void beginJob() override;
102 
103  /// Does the printing.
104  virtual void analyze (art::Event const& evt) override;
105 
106  private:
107 
108  art::InputTag fDetSimModuleLabel; ///< Tag for digits data product.
109  std::string fOutputCategory; ///< Category for `LogVerbatim` output.
110  unsigned int fDigitsPerLine; ///< Ticks/digits per line in the output.
111  Pedestal_t fPedestal; ///< ADC pedestal, will be subtracted from digits.
112 
113  /// Dumps a single `recob:Wire` to the specified output stream.
114  template <typename Stream>
115  void PrintRawDigit(
116  Stream&& out, raw::RawDigit const& digits,
117  std::string indent = " ", std::string firstIndent = " "
118  ) const;
119 
120  }; // class DumpRawDigits
121 
122 } // namespace detsim
123 
124 
125 //------------------------------------------------------------------------------
126 //--- Implementation
127 //------------------------------------------------------------------------------
129  : EDAnalyzer (config)
131  , fOutputCategory (config().OutputCategory())
132  , fDigitsPerLine (config().DigitsPerLine())
133  , fPedestal (config().Pedestal())
134  {}
135 
136 
137 //------------------------------------------------------------------------------
139 
140  if (fPedestal != 0) {
141  mf::LogVerbatim(fOutputCategory) << "A pedestal of " << fPedestal
142  << " will be subtracted from all raw digits";
143  } // if pedestal
144 
145 } // detsim::DumpRawDigits::beginJob()
146 
147 
148 //------------------------------------------------------------------------------
150 
151  auto const& RawDigits
152  = *(evt.getValidHandle<std::vector<raw::RawDigit>>(fDetSimModuleLabel));
153 
154  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
155  << " contains " << RawDigits.size() << " '" << fDetSimModuleLabel.encode()
156  << "' waveforms";
157  for (raw::RawDigit const& digits: RawDigits) {
158 
160 
161  } // for digits
162 
163 } // caldata::DumpWires::analyze()
164 
165 
166 //------------------------------------------------------------------------------
167 template <typename Stream>
169  Stream&& out, raw::RawDigit const& digits,
170  std::string indent /* = " " */, std::string firstIndent /* = " " */
171 ) const {
172 
173  //
174  // uncompress the digits
175  //
176  raw::RawDigit::ADCvector_t ADCs(digits.Samples());
177  raw::Uncompress(digits.ADCs(), ADCs, digits.Compression());
178 
179  //
180  // print a header for the raw digits
181  //
182  out << firstIndent
183  << " #" << digits.Channel() << ": " << ADCs.size() << " time ticks";
184  if (digits.Samples() != ADCs.size())
185  out << " [!!! EXPECTED " << digits.Samples() << "] ";
186  out
187  << " (" << digits.NADC() << " after compression); compression type: ";
188  switch (digits.Compression()) {
189  case raw::kNone: out << "no compression"; break;
190  case raw::kHuffman: out << "Huffman encoding" ; break;
191  case raw::kZeroSuppression: out << "zero suppression"; break;
192  case raw::kZeroHuffman: out << "zero suppression + Huffman encoding";
193  break;
194  case raw::kDynamicDec: out << "dynamic decimation"; break;
195  default:
196  out << "unknown (#" << ((int) digits.Compression()) << ")"; break;
197  } // switch
198 
199  // print the content of the channel
200  if (fDigitsPerLine > 0) {
201  std::vector<Digit_t> DigitBuffer(fDigitsPerLine), LastBuffer;
202 
203  unsigned int repeat_count = 0; // additional lines like the last one
204  unsigned int index = 0;
206  out << "\n" << indent
207  << "content of the channel (" << fDigitsPerLine << " ticks per line):";
208  auto iTick = ADCs.cbegin(), tend = ADCs.cend(); // const iterators
209  while (iTick != tend) {
210  // the next line will show at most fDigitsPerLine ticks
211  unsigned int line_size
212  = std::min(fDigitsPerLine, (unsigned int) ADCs.size() - index);
213  if (line_size == 0) break; // no more ticks
214 
215  // fill the new buffer (iTick will move forward)
216  DigitBuffer.resize(line_size);
217  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
218  while ((iBuf != bend) && (iTick != tend))
219  Extrema.add(*(iBuf++) = (*(iTick++) - fPedestal));
220  index += line_size;
221 
222  // if the new buffer is the same as the old one, just mark it
223  if (DigitBuffer == LastBuffer) {
224  repeat_count += 1;
225  continue;
226  }
227 
228  // if there are previous repeats, write that on screen
229  // before the new, different line
230  if (repeat_count > 0) {
231  out << "\n" << indent
232  << " [ ... repeated " << repeat_count << " more times, "
233  << (repeat_count * LastBuffer.size()) << " ticks ]";
234  repeat_count = 0;
235  }
236 
237  // dump the new line of ticks
238  out << "\n" << indent << " ";
239  for (auto digit: DigitBuffer)
240  out << " " << std::setw(4) << digit;
241 
242  // quick way to assign DigitBuffer to LastBuffer
243  // (we don't care we lose the former)
244  std::swap(LastBuffer, DigitBuffer);
245 
246  } // while
247  if (repeat_count > 0) {
248  out << "\n" << indent
249  << " [ ... repeated " << repeat_count << " more times to the end ]";
250  }
251  if (Extrema.min() < Extrema.max()) {
252  out << "\n" << indent
253  << " range of " << index
254  << " samples: [" << Extrema.min() << ";" << Extrema.max() << "]";
255  }
256  } // if dumping the ticks
257 
258 } // detsim::DumpRawDigits::analyze()
259 
260 
261 //------------------------------------------------------------------------------
263 
264 //------------------------------------------------------------------------------
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:210
Digit_t Pedestal_t
Type to represent a pedestal.
std::vector< raw::RawDigit > RawDigits
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:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
art::InputTag fDetSimModuleLabel
Tag for digits data product.
virtual void analyze(art::Event const &evt) override
Does the printing.
std::string string
Definition: nybbler.cc:12
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:212
ChannelGroupService::Name Name
Detector simulation of raw signals on wires.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
fhicl::Atom< unsigned int > DigitsPerLine
Zero Suppression followed by Huffman Encoding.
Definition: RawTypes.h:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
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:67
void swap(Handle< T > &a, Handle< T > &b)
static Config * config
Definition: config.cpp:1054
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:207
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
virtual void beginJob() override
Prints an introduction.
Prints the content of all the raw digits on screen.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
#define Comment
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
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:7
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
fhicl::Atom< Pedestal_t > Pedestal
Dynamic decimation.
Definition: RawTypes.h:13
EventID id() const
Definition: Event.cc:34