LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
DumpSpacePoints_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
9 #include "lardata/ArtDataHelper/Dumpers/NewLine.h" // recob::dumper::makeNewLine()
13 
14 // art libraries
18 
19 // support libraries
20 #include "fhiclcpp/ParameterSet.h"
21 #include "fhiclcpp/types/Atom.h" // also pulls in fhicl::Name and fhicl::Comment
22 
23 // C//C++ standard libraries
24 #include <string>
25 
26 // ... and more in the implementation part
27 
28 namespace recob {
29 
48  public:
49 
51  struct Config {
52  using Name = fhicl::Name;
54 
56  Name ("SpacePointModuleLabel"),
57  Comment("label of the producer used to create the recob::SpacePoint collection to be dumped")
58  };
60  Name ("OutputCategory"),
61  Comment("the category used for the output (useful for filtering) [\"DumpSpacePoints\"]"),
62  "DumpSpacePoints" /* default value */
63  };
65  Name ("PrintHexFloats"),
66  Comment("print floating point numbers in base 16 [false]"),
67  false /* default value */
68  };
69 
70  }; // struct Config
71 
73 
75  explicit DumpSpacePoints(Parameters const& config);
76 
78  virtual void analyze (const art::Event& evt) override;
79 
80  private:
81 
83  std::string fOutputCategory;
85 
86  }; // class DumpSpacePoints
87 
88 } // namespace recob
89 
90 
91 //==============================================================================
92 //=== Implementation section
93 //==============================================================================
94 
95 // LArSoft includes
98 
99 // art libraries
103 
104 // support libraries
106 
107 // C//C++ standard libraries
108 #include <vector>
109 #include <array>
110 
111 
112 namespace {
113 
114  //----------------------------------------------------------------------------
115  class SpacePointDumper {
116  public:
117  using PrintOptions_t = recob::dumper::SpacePointPrintOptions_t;
118 
119 
121  SpacePointDumper(
122  std::vector<recob::SpacePoint> const& point_list,
123  PrintOptions_t const& printOptions = {}
124  )
125  : points(point_list)
126  , options(printOptions)
127  {}
128 
129 
131  void SetHits(art::FindMany<recob::Hit> const* hit_query)
132  { hits = hit_query; }
133 
134 
136  template <typename Stream>
137  void DumpSpacePoint(Stream&& out, size_t iPoint) const
138  { DumpSpacePoint(std::forward<Stream>(out), iPoint, options); }
139 
141  template <typename Stream>
142  void DumpSpacePoint
143  (Stream&& out, size_t iPoint, std::string indentstr) const
144  {
145  PrintOptions_t localOptions(options);
146  localOptions.indent.indent = indentstr;
147  DumpSpacePoint(std::forward<Stream>(out), iPoint, localOptions);
148  }
149 
151  template <typename Stream>
152  void DumpSpacePoint
153  (Stream&& out, size_t iPoint, PrintOptions_t const& localOptions) const
154  {
155  recob::SpacePoint const& point = points.at(iPoint);
156 
157  //
158  // intro
159  //
160  auto first_nl = recob::dumper::makeNewLine(out, localOptions.indent);
161  first_nl()
162  << "[#" << iPoint << "] ";
163 
164  PrintOptions_t indentedOptions(localOptions);
165  indentedOptions.indent.appendIndentation(" ");
167  (std::forward<Stream>(out), point, indentedOptions);
168 
169  //
170  // hits
171  //
172  if (hits) {
173  std::vector<recob::Hit const*> myHits = hits->at(iPoint);
174  if (myHits.empty()) {
175  out << "; no associated hits";
176  }
177  else {
178  auto nl = recob::dumper::makeNewLine(out, indentedOptions.indent);
179  out
180  << "; " << myHits.size() << " hits:";
181  for (recob::Hit const* hit: myHits) {
182  nl()
183  << " on " << hit->WireID()
184  << ", peak at tick " << hit->PeakTime() << ", "
185  << hit->PeakAmplitude() << " ADC, RMS: " << hit->RMS()
186  << " (channel: "
187  << hit->Channel() << ")";
188  } // for hits
189  } // if we have hits
190  } // if we have hit information
191 
192  //
193  // done
194  //
195 
196  } // DumpSpacePoints()
197 
198 
200  template <typename Stream>
201  void DumpAllSpacePoints(Stream&& out, std::string indentstr = "") const
202  {
203  auto localOptions = options;
204  localOptions.indent.appendIndentation(indentstr);
205  size_t const nPoints = points.size();
206  for (size_t iPoint = 0; iPoint < nPoints; ++iPoint)
207  DumpSpacePoint(std::forward<Stream>(out), iPoint, localOptions);
208  } // DumpAllSpacePoints()
209 
210 
211 
212  protected:
213  std::vector<recob::SpacePoint> const& points;
214  PrintOptions_t options;
215 
217  art::FindMany<recob::Hit> const* hits = nullptr;
218 
219  }; // SpacePointDumper
220 
221 
222  //----------------------------------------------------------------------------
223 
224 
225 } // local namespace
226 
227 
228 
229 namespace recob {
230 
231  //----------------------------------------------------------------------------
233  : EDAnalyzer(config)
234  , fInputTag(config().SpacePointModuleLabel())
235  , fOutputCategory(config().OutputCategory())
236  , fPrintHexFloats(config().PrintHexFloats())
237  {}
238 
239 
240  //----------------------------------------------------------------------------
242 
243  //
244  // collect all the available information
245  //
246  // fetch the data to be dumped on screen
247  auto SpacePoints
248  = evt.getValidHandle<std::vector<recob::SpacePoint>>(fInputTag);
249 
250  art::FindMany<recob::Hit> const PointHits(SpacePoints, evt, fInputTag);
251 
252  size_t const nPoints = SpacePoints->size();
254  << "The event contains " << nPoints << " space points from '"
255  << fInputTag.encode() << "'";
256 
257  // prepare the dumper
258  SpacePointDumper dumper(*SpacePoints);
259  if (PointHits.isValid()) dumper.SetHits(&PointHits);
260  else mf::LogWarning("DumpSpacePoints") << "hit information not avaialble";
261 
262  dumper.DumpAllSpacePoints(mf::LogVerbatim(fOutputCategory), " ");
263 
264  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
265 
266  } // DumpSpacePoints::analyze()
267 
269 
270 } // namespace recob
DumpSpacePoints(Parameters const &config)
Default constructor.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
bool fPrintHexFloats
whether to print floats in base 16
Reconstruction base classes.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
Prints the content of all the space points on screen.
Functions dumping space points.
std::string fOutputCategory
category for LogInfo output
fhicl::Atom< std::string > OutputCategory
virtual void analyze(const art::Event &evt) override
Does the printing.
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
auto DumpSpacePoint(Stream &&out, recob::SpacePoint const &sp, SpacePointPrintOptions_t const &options={}) -> std::enable_if_t < std::is_same< NewLine< std::decay_t< Stream >>, std::decay_t< NewLineRef >>::value >
Dumps the content of the specified space point into a stream.
std::string encode() const
Definition: InputTag.cc:36
Simple class managing a repetitive output task.
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Detector simulation of raw signals on wires.
fhicl::Atom< art::InputTag > SpacePointModuleLabel
art::InputTag fInputTag
input tag of the SpacePoint product
Helper to support output of real numbers in base 16.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
NewLine< Stream > makeNewLine(Stream &stream, std::string indent, bool followLine=false)
Convenience function to create a temporary NewLine.
Definition: NewLine.h:146
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::string nl(std::size_t i=1)
Collection of available printing style options.