LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
DumpWires_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
10 #include "lardata/Utilities/StatCollector.h" // lar::util::MinMaxCollector<>
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 <ios> // std::fixed
30 #include <iomanip> // std::setprecision(), std::setw()
31 
32 
33 namespace {
34 
35  // Copied from geo::PlaneGeo, local so far
36  std::string ViewName(geo::View_t view) {
37  switch (view) {
38  case geo::kU: return "U";
39  case geo::kV: return "V";
40  case geo::kZ: return "Z";
41  // case geo::kY: return "Y";
42  // case geo::kX: return "X";
43  case geo::k3D: return "3D";
44  case geo::kUnknown: return "?";
45  default:
46  return "<UNSUPPORTED (" + std::to_string((int) view) + ")>";
47  } // switch
48  } // ViewName()
49 
50 } // local namespace
51 
52 
53 
54 namespace caldata {
55 
72  class DumpWires : public art::EDAnalyzer {
73  public:
74 
75  struct Config {
76  using Name = fhicl::Name;
78 
80  Name("CalWireModuleLabel"),
81  Comment("tag of producer used to create the recob::Wire collection"),
82  "caldata" /* default */
83  };
84 
86  Name("OutputCategory"),
87  Comment("the messagefacility category used for the output"),
88  "DumpWires" /* default */
89  };
90 
92  Name("DigitsPerLine"),
93  Comment("number of digits printed per line (0: don't print digits)"),
94  20 /* default */
95  };
96 
97  }; // Config
98 
100 
101 
103  explicit DumpWires(Parameters const& config);
104 
106  virtual void analyze (art::Event const& evt) override;
107 
108  private:
109 
111  std::string fOutputCategory;
112  unsigned int fDigitsPerLine;
113 
115  template <typename Stream>
116  void PrintWire(
117  Stream&& out, recob::Wire const& wire,
118  std::string indent = " ", std::string firstIndent = " "
119  ) const;
120 
121  }; // class DumpWires
122 
123 } // namespace caldata
124 
125 
126 //------------------------------------------------------------------------------
127 //--- Implementation
128 //------------------------------------------------------------------------------
130  : EDAnalyzer (config)
132  , fOutputCategory (config().OutputCategory())
133  , fDigitsPerLine (config().DigitsPerLine())
134  {}
135 
136 
137 //------------------------------------------------------------------------------
139 
140  auto const& Wires
141  = *(evt.getValidHandle<std::vector<recob::Wire>>(fCalWireModuleLabel));
142 
143  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
144  << " contains " << Wires.size() << " '" << fCalWireModuleLabel.encode()
145  << "' wires";
146 
147  for (recob::Wire const& wire: Wires) {
148 
150 
151  } // for wire
152 
153 } // caldata::DumpWires::analyze()
154 
155 
156 //------------------------------------------------------------------------------
157 template <typename Stream>
159  Stream&& out, recob::Wire const& wire,
160  std::string indent /* = " " */, std::string firstIndent /* = " " */
161 ) const {
162 
163  using RegionsOfInterest_t = recob::Wire::RegionsOfInterest_t;
164 
165  RegionsOfInterest_t const & RoIs = wire.SignalROI();
166 
167  //
168  // print a header for the wire
169  //
170  out << firstIndent << "channel #" << wire.Channel() << " on view "
171  << ViewName(wire.View()) << "; " << wire.NSignal() << " time ticks";
172  if (wire.NSignal() != RoIs.size())
173  out << " [!!! EXPECTED " << RoIs.size() << "]";
174  if (RoIs.n_ranges() == 0) {
175  out << " with nothing in them";
176  return;
177  }
178  out << " with " << RoIs.n_ranges() << " regions of interest:";
179 
180  //
181  // print the list of regions of interest
182  //
183  for (RegionsOfInterest_t::datarange_t const& RoI: RoIs.get_ranges()) {
184  out << "\n" << indent
185  << " from " << RoI.offset << " for " << RoI.size() << " ticks";
186  } // for
187 
188  //
189  // print the content of the wire
190  //
191  if (fDigitsPerLine > 0) {
192 
193  std::vector<RegionsOfInterest_t::value_type> DigitBuffer(fDigitsPerLine),
194  LastBuffer;
195 
196  unsigned int repeat_count = 0; // additional lines like the last one
197  unsigned int index = 0;
199  out << "\n" << indent
200  << " content of the wire (" << fDigitsPerLine << " ticks per line):";
201  auto iTick = RoIs.cbegin(), tend = RoIs.cend();
202  while (iTick != tend) {
203  // the next line will show at most fDigitsPerLine ticks
204  unsigned int line_size
205  = std::min(fDigitsPerLine, (unsigned int) RoIs.size() - index);
206  if (line_size == 0) break; // no more ticks
207 
208  // fill the new buffer (iTick will move forward)
209  DigitBuffer.resize(line_size);
210  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
211  while ((iBuf != bend) && (iTick != tend))
212  Extrema.add(*(iBuf++) = *(iTick++));
213  index += line_size;
214 
215  // if the new buffer is the same as the old one, just mark it
216  if (DigitBuffer == LastBuffer) {
217  repeat_count += 1;
218  continue;
219  }
220 
221  // if there are previous repeats, write that on screen
222  // before the new, different line
223  if (repeat_count > 0) {
224  out << "\n" << indent
225  << " [ ... repeated " << repeat_count << " more times, "
226  << (repeat_count * LastBuffer.size()) << " ticks ]";
227  repeat_count = 0;
228  }
229 
230  // dump the new line of ticks
231  out << "\n" << indent
232  << " " << std::fixed << std::setprecision(3);
233  for (auto digit: DigitBuffer) out << std::setw(8) << digit;
234 
235  // quick way to assign DigitBuffer to LastBuffer
236  // (we don't care we lose the former)
237  std::swap(LastBuffer, DigitBuffer);
238 
239  } // while
240  if (repeat_count > 0) {
241  out << "\n" << indent
242  << " [ ... repeated " << repeat_count << " more times to the end ]";
243  }
244  if (Extrema.min() < Extrema.max()) {
245  out << "\n" << indent
246  << " range of " << index
247  << " samples: [" << Extrema.min() << ";" << Extrema.max() << "]";
248  }
249  } // if dumping the ticks
250 
251 } // caldata::DumpWires::PrintWire()
252 
253 //------------------------------------------------------------------------------
255 
256 //------------------------------------------------------------------------------
Data_t max() const
Returns the accumulated maximum, or a very small number if no values.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
This_t & add(Data_t value)
Include a single value in the statistics.
Prints the content of all the wires on screen.
size_t NSignal() const
Returns the number of time ticks, or samples, in the channel.
Definition: Wire.h:162
fhicl::Atom< std::string > OutputCategory
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Planes which measure V.
Definition: geo_types.h:77
Unknown view.
Definition: geo_types.h:83
art::InputTag fCalWireModuleLabel
Input tag for wires.
Planes which measure Z direction.
Definition: geo_types.h:79
lar::sparse_vector< float > RegionsOfInterest_t
a region of interest is a pair (TDC offset, readings)
Definition: Wire.h:83
creation of calibrated signals on wires
Classes gathering simple statistics.
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:82
geo::View_t View() const
Returns the view the channel belongs to.
Definition: Wire.h:163
Keeps track of the minimum and maximum value we observed.
Planes which measure U.
Definition: geo_types.h:76
Data_t min() const
Returns the accumulated minimum, or a very large number if no values.
fhicl::Atom< art::InputTag > CalWireModuleLabel
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
std::string fOutputCategory
Category for LogVerbatim output.
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:164
std::string encode() const
Definition: InputTag.cc:36
std::string indent(std::size_t const i)
void PrintWire(Stream &&out, recob::Wire const &wire, std::string indent=" ", std::string firstIndent=" ") const
Dumps a single recob:Wire to the specified output stream.
unsigned int fDigitsPerLine
Ticks/digits per line in the output.
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Definition: Wire.h:161
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Definition of data types for geometry description.
DumpWires(Parameters const &config)
Constructor.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
Encapsulate the construction of a single detector plane.
Int_t min
Definition: plot.C:26
Class holding the deconvoluted signals from a channel.
Definition: Wire.h:80
virtual void analyze(art::Event const &evt) override
Does the printing.
Declaration of basic channel signal object.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
fhicl::Atom< unsigned int > DigitsPerLine
EventID id() const
Definition: Event.h:56