DumpSpacePoints_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpSpacePoints_module.cc
3  * @brief Dumps on screen the content of space points
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 18th, 2015
6  */
7 
8 // LArSoft includes
9 #include "lardata/ArtDataHelper/Dumpers/NewLine.h" // recob::dumper::makeNewLine()
12 
13 // art libraries
17 
18 // support libraries
19 #include "fhiclcpp/types/Atom.h" // also pulls in fhicl::Name and fhicl::Comment
20 
21 // C//C++ standard libraries
22 #include <string>
23 
24 // ... and more in the implementation part
25 
26 namespace recob {
27 
28  /**
29  * @brief Prints the content of all the space points on screen
30  *
31  * This analyser prints the content of all the space points into the
32  * LogInfo/LogVerbatim stream.
33  *
34  * Configuration parameters
35  * =========================
36  *
37  * - *SpacePointModuleLabel* (art::InputTag, mandatory): label of the
38  * producer used to create the recob::SpacePoint collection to be dumped
39  * - *OutputCategory* (string, default: "DumpSpacePoints"): the category used
40  * for the output (useful for filtering)
41  * - *PrintHexFloats* (boolean, default: `false`): print all the floating
42  * point numbers in base 16
43  *
44  */
46  public:
47 
48  /// Configuration parameters
49  struct Config {
50  using Name = fhicl::Name;
52 
54  Name ("SpacePointModuleLabel"),
55  Comment("label of the producer used to create the recob::SpacePoint collection to be dumped")
56  };
58  Name ("OutputCategory"),
59  Comment("the category used for the output (useful for filtering) [\"DumpSpacePoints\"]"),
60  "DumpSpacePoints" /* default value */
61  };
63  Name ("PrintHexFloats"),
64  Comment("print floating point numbers in base 16 [false]"),
65  false /* default value */
66  };
67 
68  }; // struct Config
69 
71 
72  /// Default constructor
73  explicit DumpSpacePoints(Parameters const& config);
74 
75  /// Does the printing
76  virtual void analyze (const art::Event& evt) override;
77 
78  private:
79 
80  art::InputTag fInputTag; ///< input tag of the SpacePoint product
81  std::string fOutputCategory; ///< category for LogInfo output
82  bool fPrintHexFloats; ///< whether to print floats in base 16
83 
84  }; // class DumpSpacePoints
85 
86 } // namespace recob
87 
88 
89 //==============================================================================
90 //=== Implementation section
91 //==============================================================================
92 
93 // LArSoft includes
96 
97 // art libraries
99 #include "canvas/Persistency/Common/FindMany.h"
101 
102 // support libraries
104 
105 // C//C++ standard libraries
106 
107 
108 namespace {
109 
110  //----------------------------------------------------------------------------
111  class SpacePointDumper {
112  public:
113  using PrintOptions_t = recob::dumper::SpacePointPrintOptions_t;
114 
115 
116  /// Constructor; will dump space points from the specified list
117  SpacePointDumper(
118  std::vector<recob::SpacePoint> const& point_list,
119  PrintOptions_t const& printOptions = {}
120  )
121  : points(point_list)
122  , options(printOptions)
123  {}
124 
125 
126  /// Sets the hits associated to each space point
127  void SetHits(art::FindMany<recob::Hit> const* hit_query)
128  { hits = hit_query; }
129 
130 
131  /// Dump a space point specified by its index in the input list
132  template <typename Stream>
133  void DumpSpacePoint(Stream&& out, size_t iPoint) const
134  { DumpSpacePoint(std::forward<Stream>(out), iPoint, options); }
135 
136  /// Dump a space point specified by its index in the input list
137  template <typename Stream>
138  void DumpSpacePoint
139  (Stream&& out, size_t iPoint, std::string indentstr) const
140  {
141  PrintOptions_t localOptions(options);
142  localOptions.indent.indent = indentstr;
143  DumpSpacePoint(std::forward<Stream>(out), iPoint, localOptions);
144  }
145 
146  /// Dump a space point specified by its index in the input list
147  template <typename Stream>
148  void DumpSpacePoint
149  (Stream&& out, size_t iPoint, PrintOptions_t const& localOptions) const
150  {
151  recob::SpacePoint const& point = points.at(iPoint);
152 
153  //
154  // intro
155  //
156  auto first_nl = recob::dumper::makeNewLine(out, localOptions.indent);
157  first_nl()
158  << "[#" << iPoint << "] ";
159 
160  PrintOptions_t indentedOptions(localOptions);
161  indentedOptions.indent.appendIndentation(" ");
163  (std::forward<Stream>(out), point, indentedOptions);
164 
165  //
166  // hits
167  //
168  if (hits) {
169  std::vector<recob::Hit const*> myHits = hits->at(iPoint);
170  if (myHits.empty()) {
171  out << "; no associated hits";
172  }
173  else {
174  auto nl = recob::dumper::makeNewLine(out, indentedOptions.indent);
175  out
176  << "; " << myHits.size() << " hits:";
177  for (recob::Hit const* hit: myHits) {
178  nl()
179  << " on " << hit->WireID()
180  << ", peak at tick " << hit->PeakTime() << ", "
181  << hit->PeakAmplitude() << " ADC, RMS: " << hit->RMS()
182  << " (channel: "
183  << hit->Channel() << ")";
184  } // for hits
185  } // if we have hits
186  } // if we have hit information
187 
188  //
189  // done
190  //
191 
192  } // DumpSpacePoints()
193 
194 
195  /// Dumps all space points in the input list
196  template <typename Stream>
197  void DumpAllSpacePoints(Stream&& out, std::string indentstr = "") const
198  {
199  auto localOptions = options;
200  localOptions.indent.appendIndentation(indentstr);
201  size_t const nPoints = points.size();
202  for (size_t iPoint = 0; iPoint < nPoints; ++iPoint)
203  DumpSpacePoint(std::forward<Stream>(out), iPoint, localOptions);
204  } // DumpAllSpacePoints()
205 
206 
207 
208  protected:
209  std::vector<recob::SpacePoint> const& points; ///< input list
210  PrintOptions_t options; ///< formatting and indentation options
211 
212  /// Associated hits (expected same order as for space points)
213  art::FindMany<recob::Hit> const* hits = nullptr;
214 
215  }; // SpacePointDumper
216 
217 
218  //----------------------------------------------------------------------------
219 
220 
221 } // local namespace
222 
223 
224 
225 namespace recob {
226 
227  //----------------------------------------------------------------------------
229  : EDAnalyzer(config)
230  , fInputTag(config().SpacePointModuleLabel())
231  , fOutputCategory(config().OutputCategory())
232  , fPrintHexFloats(config().PrintHexFloats())
233  {}
234 
235 
236  //----------------------------------------------------------------------------
238 
239  //
240  // collect all the available information
241  //
242  // fetch the data to be dumped on screen
243  auto SpacePoints
244  = evt.getValidHandle<std::vector<recob::SpacePoint>>(fInputTag);
245 
246  art::FindMany<recob::Hit> const PointHits(SpacePoints, evt, fInputTag);
247 
248  size_t const nPoints = SpacePoints->size();
250  << "The event contains " << nPoints << " space points from '"
251  << fInputTag.encode() << "'";
252 
253  // prepare the dumper
254  SpacePointDumper dumper(*SpacePoints);
255  if (PointHits.isValid()) dumper.SetHits(&PointHits);
256  else mf::LogWarning("DumpSpacePoints") << "hit information not avaialble";
257 
258  dumper.DumpAllSpacePoints(mf::LogVerbatim(fOutputCategory), " ");
259 
260  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
261 
262  } // DumpSpacePoints::analyze()
263 
265 
266 } // 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.
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Prints the content of all the space points on screen.
ChannelGroupService::Name Name
Functions dumping space points.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string encode() const
Definition: InputTag.cc:97
std::string fOutputCategory
category for LogInfo output
fhicl::Atom< std::string > OutputCategory
virtual void analyze(const art::Event &evt) override
Does the printing.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
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.
static Config * config
Definition: config.cpp:1054
Simple class managing a repetitive output task.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
Detector simulation of raw signals on wires.
fhicl::Atom< art::InputTag > SpacePointModuleLabel
Declaration of signal hit object.
#define Comment
art::InputTag fInputTag
input tag of the SpacePoint product
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:48
TCEvent evt
Definition: DataStructs.cxx:7
std::string nl(std::size_t i=1)
Collection of available printing style options.