LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpVertices_module.cc
Go to the documentation of this file.
1 
8 // LArSoft includes
10 
11 // art libraries
15 
16 // support libraries
17 #include "fhiclcpp/ParameterSet.h"
18 
19 // C//C++ standard libraries
20 #include <string>
21 
22 // ... and more in the implementation part
23 
24 namespace recob {
25 
43  class DumpVertices : public art::EDAnalyzer {
44  public:
46  explicit DumpVertices(fhicl::ParameterSet const& pset);
47 
49  virtual void analyze(const art::Event& evt) override;
50 
51  private:
53  std::string fOutputCategory;
55 
56  }; // class DumpVertices
57 
58 } // namespace recob
59 
60 //==============================================================================
61 //=== Implementation section
62 //==============================================================================
63 
64 // LArSoft includes
67 
68 // art libraries
71 
72 // support libraries
74 
75 // C//C++ standard libraries
76 
77 namespace {
78 
79  //----------------------------------------------------------------------------
80  class VertexDumper {
81  public:
83  struct PrintOptions_t {
84  bool hexFloats = false;
85  }; // PrintOptions_t
86 
88  VertexDumper(std::vector<recob::Vertex> const& vertex_list) : VertexDumper(vertex_list, {}) {}
89 
91  VertexDumper(std::vector<recob::Vertex> const& vertex_list, PrintOptions_t print_options)
92  : vertices(vertex_list), options(print_options)
93  {}
94 
96  template <typename Stream>
97  void DumpVertex(Stream&& out, size_t iVertex, std::string indentstr = "") const
98  {
99  lar::OptionalHexFloat hexfloat(options.hexFloats);
100 
101  recob::Vertex const& vertex = vertices.at(iVertex);
102 
103  //
104  // intro
105  //
106  out << "\n" << indentstr << "[#" << iVertex << "]";
107 
108  std::array<double, 3> vtx_pos;
109  vertex.XYZ(vtx_pos.data());
110  out << " ID=" << vertex.ID() << " at (" << hexfloat(vtx_pos[0]) << "," << hexfloat(vtx_pos[1])
111  << "," << hexfloat(vtx_pos[2]) << ")";
112 
113  //
114  // done
115  //
116 
117  } // DumpVertex()
118 
120  template <typename Stream>
121  void DumpAllVertices(Stream&& out, std::string indentstr = "") const
122  {
123  indentstr += " ";
124  size_t const nVertices = vertices.size();
125  for (size_t iVertex = 0; iVertex < nVertices; ++iVertex)
126  DumpVertex(out, iVertex, indentstr);
127  } // DumpAllVertices()
128 
129  protected:
130  std::vector<recob::Vertex> const& vertices;
131 
132  PrintOptions_t options;
133 
134  }; // VertexDumper
135 
136  //----------------------------------------------------------------------------
137 
138 } // local namespace
139 
140 namespace recob {
141 
142  //----------------------------------------------------------------------------
144  : EDAnalyzer(pset)
145  , fInputTag(pset.get<art::InputTag>("VertexModuleLabel"))
146  , fOutputCategory(pset.get<std::string>("OutputCategory", "DumpVertices"))
147  , fPrintHexFloats(pset.get<bool>("PrintHexFloats", false))
148  {}
149 
150  //----------------------------------------------------------------------------
152  {
153 
154  //
155  // collect all the available information
156  //
157  // fetch the data to be dumped on screen
158  auto Vertices = evt.getValidHandle<std::vector<recob::Vertex>>(fInputTag);
159 
160  size_t const nVertices = Vertices->size();
161  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id() << " contains " << nVertices
162  << " vertices from '" << fInputTag.encode() << "'";
163 
164  // prepare the dumper
165  VertexDumper::PrintOptions_t options;
166  options.hexFloats = fPrintHexFloats;
167  VertexDumper dumper(*Vertices, options);
168 
169  dumper.DumpAllVertices(mf::LogVerbatim(fOutputCategory), " ");
170 
171  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
172 
173  } // DumpVertices::analyze()
174 
176 
177 } // namespace recob
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
Definition: Vertex.cxx:34
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Reconstruction base classes.
DumpVertices(fhicl::ParameterSet const &pset)
Default constructor.
STL namespace.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
std::string encode() const
Definition: InputTag.cc:97
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
std::string fOutputCategory
category for LogInfo output
art::InputTag fInputTag
input tag of the Vertex product
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Prints the content of all the vertices on screen.
Helper for formatting floats in base 16.
Definition: hexfloat.h:109
bool fPrintHexFloats
whether to print floats in base 16
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
Helper to support output of real numbers in base 16.
int ID() const
Return vertex id.
Definition: Vertex.h:101
Definition: MVAAlg.h:12
TCEvent evt
Definition: DataStructs.cxx:8
EventID id() const
Definition: Event.cc:23
virtual void analyze(const art::Event &evt) override
Does the printing.
vertex reconstruction