LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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:
45 
47  explicit DumpVertices(fhicl::ParameterSet const& pset);
48 
50  virtual void analyze (const art::Event& evt) override;
51 
52  private:
53 
55  std::string fOutputCategory;
57 
58  }; // class DumpVertices
59 
60 } // namespace recob
61 
62 
63 //==============================================================================
64 //=== Implementation section
65 //==============================================================================
66 
67 // LArSoft includes
70 
71 // art libraries
74 
75 // support libraries
77 
78 // C//C++ standard libraries
79 #include <vector>
80 
81 
82 namespace {
83 
84  //----------------------------------------------------------------------------
85  class VertexDumper {
86  public:
87 
89  struct PrintOptions_t {
90  bool hexFloats = false;
91  }; // PrintOptions_t
92 
93 
95  VertexDumper(std::vector<recob::Vertex> const& vertex_list)
96  : VertexDumper(vertex_list, {})
97  {}
98 
100  VertexDumper(
101  std::vector<recob::Vertex> const& vertex_list,
102  PrintOptions_t print_options
103  )
104  : vertices(vertex_list)
105  , options(print_options)
106  {}
107 
108 
110  template <typename Stream>
111  void DumpVertex
112  (Stream&& out, size_t iVertex, std::string indentstr = "") const
113  {
114  lar::OptionalHexFloat hexfloat(options.hexFloats);
115 
116  recob::Vertex const& vertex = vertices.at(iVertex);
117 
118  //
119  // intro
120  //
121  out << "\n" << indentstr
122  << "[#" << iVertex << "]";
123 
124  std::array<double, 3> vtx_pos;
125  vertex.XYZ(vtx_pos.data());
126  out << " ID=" << vertex.ID() << " at ("
127  << hexfloat(vtx_pos[0]) << "," << hexfloat(vtx_pos[1])
128  << "," << hexfloat(vtx_pos[2])
129  << ")";
130 
131  //
132  // done
133  //
134 
135  } // DumpVertex()
136 
137 
139  template <typename Stream>
140  void DumpAllVertices(Stream&& out, std::string indentstr = "") const
141  {
142  indentstr += " ";
143  size_t const nVertices = vertices.size();
144  for (size_t iVertex = 0; iVertex < nVertices; ++iVertex)
145  DumpVertex(out, iVertex, indentstr);
146  } // DumpAllVertices()
147 
148 
149 
150  protected:
151  std::vector<recob::Vertex> const& vertices;
152 
153  PrintOptions_t options;
154 
155  }; // VertexDumper
156 
157 
158  //----------------------------------------------------------------------------
159 
160 
161 } // local namespace
162 
163 
164 
165 namespace recob {
166 
167  //----------------------------------------------------------------------------
169  : EDAnalyzer(pset)
170  , fInputTag (pset.get<art::InputTag>("VertexModuleLabel"))
171  , fOutputCategory(pset.get<std::string> ("OutputCategory", "DumpVertices"))
172  , fPrintHexFloats(pset.get<bool> ("PrintHexFloats", false))
173  {}
174 
175 
176  //----------------------------------------------------------------------------
178 
179  //
180  // collect all the available information
181  //
182  // fetch the data to be dumped on screen
183  auto Vertices = evt.getValidHandle<std::vector<recob::Vertex>>(fInputTag);
184 
185  size_t const nVertices = Vertices->size();
186  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
187  << " contains " << nVertices << " vertices from '"
188  << fInputTag.encode() << "'";
189 
190  // prepare the dumper
191  VertexDumper::PrintOptions_t options;
192  options.hexFloats = fPrintHexFloats;
193  VertexDumper dumper(*Vertices, options);
194 
195  dumper.DumpAllVertices(mf::LogVerbatim(fOutputCategory), " ");
196 
197  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
198 
199  } // DumpVertices::analyze()
200 
202 
203 } // 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:37
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Reconstruction base classes.
DumpVertices(fhicl::ParameterSet const &pset)
Default constructor.
STL namespace.
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:42
std::string encode() const
Definition: InputTag.cc:36
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Prints the content of all the vertices on screen.
Helper for formatting floats in base 16.
Definition: hexfloat.h:105
bool fPrintHexFloats
whether to print floats in base 16
Helper to support output of real numbers in base 16.
int ID() const
Return vertex id.
Definition: Vertex.h:99
HLT enums.
TCEvent evt
Definition: DataStructs.cxx:5
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
EventID id() const
Definition: Event.h:56
virtual void analyze(const art::Event &evt) override
Does the printing.
vertex reconstruction