All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DumpVertices_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpVertices_module.cc
3  * @brief Dumps on screen the content of vertices
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date September 29th, 2015
6  */
7 
8 // LArSoft includes
10 
11 // art libraries
12 #include "canvas/Utilities/InputTag.h"
13 #include "art/Framework/Core/EDAnalyzer.h"
14 #include "art/Framework/Principal/Event.h"
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 
26  /**
27  * @brief Prints the content of all the vertices on screen
28  *
29  * This analyser prints the content of all the vertices into the
30  * LogInfo/LogVerbatim stream.
31  *
32  * Configuration parameters
33  * =========================
34  *
35  * - *VertexModuleLabel* (art::InputTag, mandatory): label of the
36  * producer used to create the recob::Vertex collection to be dumped
37  * - *OutputCategory* (string, default: `"DumpVertices"`): the category used
38  * for the output (useful for filtering)
39  * - *PrintHexFloats* (boolean, default: `false`): print all the floating
40  * point numbers in base 16
41  *
42  */
43  class DumpVertices: public art::EDAnalyzer {
44  public:
45 
46  /// Default constructor
47  explicit DumpVertices(fhicl::ParameterSet const& pset);
48 
49  /// Does the printing
50  virtual void analyze (const art::Event& evt) override;
51 
52  private:
53 
54  art::InputTag fInputTag; ///< input tag of the Vertex product
55  std::string fOutputCategory; ///< category for LogInfo output
56  bool fPrintHexFloats; ///< whether to print floats in base 16
57 
58  }; // class DumpVertices
59 
60 } // namespace recob
61 
62 
63 //==============================================================================
64 //=== Implementation section
65 //==============================================================================
66 
67 // LArSoft includes
70 
71 // art libraries
72 #include "art/Framework/Core/ModuleMacros.h"
73 #include "art/Framework/Principal/Handle.h"
74 
75 // support libraries
76 #include "messagefacility/MessageLogger/MessageLogger.h"
77 
78 // C//C++ standard libraries
79 
80 
81 namespace {
82 
83  //----------------------------------------------------------------------------
84  class VertexDumper {
85  public:
86 
87  /// Collection of available printing style options
88  struct PrintOptions_t {
89  bool hexFloats = false; ///< print all floating point numbers in base 16
90  }; // PrintOptions_t
91 
92 
93  /// Constructor; will dump vertices from the specified list
94  VertexDumper(std::vector<recob::Vertex> const& vertex_list)
95  : VertexDumper(vertex_list, {})
96  {}
97 
98  /// Constructor; will dump vertices from the specified list, using options.
99  VertexDumper(
100  std::vector<recob::Vertex> const& vertex_list,
101  PrintOptions_t print_options
102  )
103  : vertices(vertex_list)
104  , options(print_options)
105  {}
106 
107 
108  /// Dump a vertex specified by its index in the input list
109  template <typename Stream>
110  void DumpVertex
111  (Stream&& out, size_t iVertex, std::string indentstr = "") const
112  {
113  lar::OptionalHexFloat hexfloat(options.hexFloats);
114 
115  recob::Vertex const& vertex = vertices.at(iVertex);
116 
117  //
118  // intro
119  //
120  out << "\n" << indentstr
121  << "[#" << iVertex << "]";
122 
123  std::array<double, 3> vtx_pos;
124  vertex.XYZ(vtx_pos.data());
125  out << " ID=" << vertex.ID() << " at ("
126  << hexfloat(vtx_pos[0]) << "," << hexfloat(vtx_pos[1])
127  << "," << hexfloat(vtx_pos[2])
128  << ")";
129 
130  //
131  // done
132  //
133 
134  } // DumpVertex()
135 
136 
137  /// Dumps all vertices in the input list
138  template <typename Stream>
139  void DumpAllVertices(Stream&& out, std::string indentstr = "") const
140  {
141  indentstr += " ";
142  size_t const nVertices = vertices.size();
143  for (size_t iVertex = 0; iVertex < nVertices; ++iVertex)
144  DumpVertex(out, iVertex, indentstr);
145  } // DumpAllVertices()
146 
147 
148 
149  protected:
150  std::vector<recob::Vertex> const& vertices; ///< input list
151 
152  PrintOptions_t options; ///< printing and formatting options
153 
154  }; // VertexDumper
155 
156 
157  //----------------------------------------------------------------------------
158 
159 
160 } // local namespace
161 
162 
163 
164 namespace recob {
165 
166  //----------------------------------------------------------------------------
167  DumpVertices::DumpVertices(fhicl::ParameterSet const& pset)
168  : EDAnalyzer(pset)
169  , fInputTag (pset.get<art::InputTag>("VertexModuleLabel"))
170  , fOutputCategory(pset.get<std::string> ("OutputCategory", "DumpVertices"))
171  , fPrintHexFloats(pset.get<bool> ("PrintHexFloats", false))
172  {}
173 
174 
175  //----------------------------------------------------------------------------
176  void DumpVertices::analyze(const art::Event& evt) {
177 
178  //
179  // collect all the available information
180  //
181  // fetch the data to be dumped on screen
182  auto Vertices = evt.getValidHandle<std::vector<recob::Vertex>>(fInputTag);
183 
184  size_t const nVertices = Vertices->size();
185  mf::LogVerbatim(fOutputCategory) << "Event " << evt.id()
186  << " contains " << nVertices << " vertices from '"
187  << fInputTag.encode() << "'";
188 
189  // prepare the dumper
190  VertexDumper::PrintOptions_t options;
191  options.hexFloats = fPrintHexFloats;
192  VertexDumper dumper(*Vertices, options);
193 
194  dumper.DumpAllVertices(mf::LogVerbatim(fOutputCategory), " ");
195 
196  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
197 
198  } // DumpVertices::analyze()
199 
200  DEFINE_ART_MODULE(DumpVertices)
201 
202 } // namespace recob
process_name vertex
Definition: cheaterreco.fcl:51
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
Definition: Vertex.cxx:36
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
DumpVertices(fhicl::ParameterSet const &pset)
Default constructor.
static constexpr bool
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
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
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
TCEvent evt
Definition: DataStructs.cxx:8
bnb BNB Stream
virtual void analyze(const art::Event &evt) override
Does the printing.