LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpWires_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
10 #include "lardataalg/Utilities/StatCollector.h" // lar::util::MinMaxCollector<>
12 
13 // art libraries
19 
20 // support libraries
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/types/Comment.h"
23 #include "fhiclcpp/types/Name.h"
25 
26 // C//C++ standard libraries
27 #include <iomanip> // std::setprecision(), std::setw()
28 #include <ios> // std::fixed
29 #include <string>
30 
31 namespace {
32 
33  // Copied from geo::PlaneGeo, local so far
34  std::string ViewName(geo::View_t view)
35  {
36  switch (view) {
37  case geo::kU: return "U";
38  case geo::kV: return "V";
39  case geo::kZ:
40  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: return "<UNSUPPORTED (" + std::to_string((int)view) + ")>";
46  } // switch
47  } // ViewName()
48 
49 } // local namespace
50 
51 namespace caldata {
52 
69  class DumpWires : public art::EDAnalyzer {
70  public:
71  struct Config {
72  using Name = fhicl::Name;
74 
76  Name("CalWireModuleLabel"),
77  Comment("tag of producer used to create the recob::Wire collection"),
78  "caldata" /* default */
79  };
80 
82  Name("OutputCategory"),
83  Comment("the messagefacility category used for the output"),
84  "DumpWires" /* default */
85  };
86 
88  Name("DigitsPerLine"),
89  Comment("number of digits printed per line (0: don't print digits)"),
90  20 /* default */
91  };
92 
93  }; // Config
94 
96 
98  explicit DumpWires(Parameters const& config);
99 
101  virtual void analyze(art::Event const& evt) override;
102 
103  private:
105  std::string fOutputCategory;
106  unsigned int fDigitsPerLine;
107 
109  template <typename Stream>
110  void PrintWire(Stream&& out,
111  recob::Wire const& wire,
112  std::string indent = " ",
113  std::string firstIndent = " ") const;
114 
115  }; // class DumpWires
116 
117 } // namespace caldata
118 
119 //------------------------------------------------------------------------------
120 //--- Implementation
121 //------------------------------------------------------------------------------
123  : EDAnalyzer(config)
125  , fOutputCategory(config().OutputCategory())
126  , fDigitsPerLine(config().DigitsPerLine())
127 {}
128 
129 //------------------------------------------------------------------------------
131 {
132 
133  auto const& Wires = *(evt.getValidHandle<std::vector<recob::Wire>>(fCalWireModuleLabel));
134 
135  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id() << " contains " << Wires.size() << " '"
136  << fCalWireModuleLabel.encode() << "' wires";
137 
138  for (recob::Wire const& wire : Wires) {
139 
141 
142  } // for wire
143 
144 } // caldata::DumpWires::analyze()
145 
146 //------------------------------------------------------------------------------
147 template <typename Stream>
149  recob::Wire const& wire,
150  std::string indent /* = " " */,
151  std::string firstIndent /* = " " */
152 ) const
153 {
154 
155  using RegionsOfInterest_t = recob::Wire::RegionsOfInterest_t;
156 
157  RegionsOfInterest_t const& RoIs = wire.SignalROI();
158 
159  //
160  // print a header for the wire
161  //
162  out << firstIndent << "channel #" << wire.Channel() << " on view " << ViewName(wire.View())
163  << "; " << wire.NSignal() << " time ticks";
164  if (wire.NSignal() != RoIs.size()) out << " [!!! EXPECTED " << RoIs.size() << "]";
165  if (RoIs.n_ranges() == 0) {
166  out << " with nothing in them";
167  return;
168  }
169  out << " with " << RoIs.n_ranges() << " regions of interest:";
170 
171  //
172  // print the list of regions of interest
173  //
174  for (RegionsOfInterest_t::datarange_t const& RoI : RoIs.get_ranges()) {
175  out << "\n" << indent << " from " << RoI.offset << " for " << RoI.size() << " ticks";
176  } // for
177 
178  //
179  // print the content of the wire
180  //
181  if (fDigitsPerLine > 0) {
182 
183  std::vector<RegionsOfInterest_t::value_type> DigitBuffer(fDigitsPerLine), LastBuffer;
184 
185  unsigned int repeat_count = 0; // additional lines like the last one
186  unsigned int index = 0;
188  out << "\n" << indent << " content of the wire (" << fDigitsPerLine << " ticks per line):";
189  auto iTick = RoIs.cbegin(), tend = RoIs.cend();
190  while (iTick != tend) {
191  // the next line will show at most fDigitsPerLine ticks
192  unsigned int line_size = std::min(fDigitsPerLine, (unsigned int)RoIs.size() - index);
193  if (line_size == 0) break; // no more ticks
194 
195  // fill the new buffer (iTick will move forward)
196  DigitBuffer.resize(line_size);
197  auto iBuf = DigitBuffer.begin(), bend = DigitBuffer.end();
198  while ((iBuf != bend) && (iTick != tend))
199  Extrema.add(*(iBuf++) = *(iTick++));
200  index += line_size;
201 
202  // if the new buffer is the same as the old one, just mark it
203  if (DigitBuffer == LastBuffer) {
204  repeat_count += 1;
205  continue;
206  }
207 
208  // if there are previous repeats, write that on screen
209  // before the new, different line
210  if (repeat_count > 0) {
211  out << "\n"
212  << indent << " [ ... repeated " << repeat_count << " more times, "
213  << (repeat_count * LastBuffer.size()) << " ticks ]";
214  repeat_count = 0;
215  }
216 
217  // dump the new line of ticks
218  out << "\n" << indent << " " << std::fixed << std::setprecision(3);
219  for (auto digit : DigitBuffer)
220  out << std::setw(8) << digit;
221 
222  // quick way to assign DigitBuffer to LastBuffer
223  // (we don't care we lose the former)
224  std::swap(LastBuffer, DigitBuffer);
225 
226  } // while
227  if (repeat_count > 0) {
228  out << "\n" << indent << " [ ... repeated " << repeat_count << " more times to the end ]";
229  }
230  if (Extrema.min() < Extrema.max()) {
231  out << "\n"
232  << indent << " range of " << index << " samples: [" << Extrema.min() << ";"
233  << Extrema.max() << "]";
234  }
235  } // if dumping the ticks
236 
237 } // caldata::DumpWires::PrintWire()
238 
239 //------------------------------------------------------------------------------
241 
242 //------------------------------------------------------------------------------
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.
fhicl::Atom< std::string > OutputCategory
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Planes which measure V.
Definition: geo_types.h:136
Unknown view.
Definition: geo_types.h:142
art::InputTag fCalWireModuleLabel
Input tag for wires.
Planes which measure Z direction.
Definition: geo_types.h:138
lar::sparse_vector< float > RegionsOfInterest_t
a region of interest is a pair (TDC offset, readings)
Definition: Wire.h:119
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
creation of calibrated signals on wires
Classes gathering simple statistics.
std::string encode() const
Definition: InputTag.cc:97
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:141
geo::View_t View() const
Returns the view the channel belongs to.
Definition: Wire.h:219
Keeps track of the minimum and maximum value we observed.
Planes which measure U.
Definition: geo_types.h:135
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:65
std::string fOutputCategory
Category for LogVerbatim output.
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:223
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
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:211
Definition of data types for geometry description.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
DumpWires(Parameters const &config)
Constructor.
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:116
virtual void analyze(art::Event const &evt) override
Does the printing.
Declaration of basic channel signal object.
TCEvent evt
Definition: DataStructs.cxx:8
fhicl::Atom< unsigned int > DigitsPerLine
EventID id() const
Definition: Event.cc:23
std::size_t NSignal() const
Returns the number of time ticks, or samples, in the channel.
Definition: Wire.h:215