All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DumpPCAxes_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpPCAxes_module.cc
3  * @brief Dumps on screen the content of Principal Component Axis objects
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 18th, 2015
6  */
7 
8 // LArSoft includes
9 
10 // art libraries
11 #include "canvas/Utilities/InputTag.h"
12 #include "art/Framework/Core/EDAnalyzer.h"
13 #include "art/Framework/Principal/Event.h"
14 
15 // support libraries
16 #include "fhiclcpp/types/Atom.h"
17 #include "fhiclcpp/types/Comment.h"
18 #include "fhiclcpp/types/Name.h"
19 #include "fhiclcpp/types/Table.h"
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 PCA axis object on screen
30  *
31  * This analyser prints the content of all the principal component axis object
32  * into the LogInfo/LogVerbatim stream.
33  *
34  * Configuration parameters
35  * =========================
36  *
37  * - *PCAxisModuleLabel* (art::InputTag, mandatory): label of the
38  * producer used to create the recob::PCAxis collection to be dumped
39  * - *OutputCategory* (string, default: `"DumpPCAxes"`): 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  */
45  class DumpPCAxes: public art::EDAnalyzer {
46  public:
47 
48  /// Configuration parameters
49  struct Config {
50  using Name = fhicl::Name;
51  using Comment = fhicl::Comment;
52 
53  fhicl::Atom<art::InputTag> PCAxisModuleLabel {
54  Name ("PCAxisModuleLabel"),
55  Comment("label of the producer used to create the recob::PCAxis collection to be dumped")
56  };
57  fhicl::Atom<std::string> OutputCategory {
58  Name ("OutputCategory"),
59  Comment("the category used for the output (useful for filtering) [\"DumpPCAxes\"]"),
60  "DumpPCAxes" /* default value */
61  };
62  fhicl::Atom<bool> PrintHexFloats {
63  Name ("PrintHexFloats"),
64  Comment("print floating point numbers in base 16 [false]"),
65  false /* default value */
66  };
67 
68  }; // struct Config
69 
70  using Parameters = art::EDAnalyzer::Table<Config>;
71 
72  /// Default constructor
73  explicit DumpPCAxes(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 PCAxis product
81  std::string fOutputCategory; ///< category for LogInfo output
82  bool fPrintHexFloats; ///< whether to print floats in base 16
83 
84  }; // class DumpPCAxes
85 
86 } // namespace recob
87 
88 
89 //==============================================================================
90 //=== Implementation section
91 //==============================================================================
92 
93 // LArSoft includes
95 #include "lardata/ArtDataHelper/Dumpers/NewLine.h" // recob::dumper::makeNewLine()
96 #include "lardata/ArtDataHelper/Dumpers/PCAxisDumpers.h" // recob::dumper::DumpPCAxis()
97 
98 // art libraries
99 #include "art/Framework/Core/ModuleMacros.h"
100 #include "art/Framework/Principal/Handle.h"
101 
102 // support libraries
103 #include "messagefacility/MessageLogger/MessageLogger.h"
104 
105 // C//C++ standard libraries
106 
107 
108 namespace {
109 
110  //----------------------------------------------------------------------------
111  class PCAxisDumper {
112  public:
113 
114  /// Collection of available printing style options
115  struct PrintOptions_t {
116  bool hexFloats = false; ///< print all floating point numbers in base 16
117  }; // PrintOptions_t
118 
119 
120  /// Constructor; will dump space points from the specified list.
121  PCAxisDumper(std::vector<recob::PCAxis> const& pca_list)
122  : PCAxisDumper(pca_list, {})
123  {}
124 
125  /// Constructor; will dump space points from the specified list.
126  PCAxisDumper
127  (std::vector<recob::PCAxis> const& pca_list, PrintOptions_t print_options)
128  : pcas(pca_list)
129  , options(print_options)
130  {}
131 
132 
133  /// Dump a space point specified by its index in the input list
134  template <typename Stream>
135  void DumpPCAxis
136  (Stream&& out, size_t iPCA, std::string indentstr = "") const
137  {
138  recob::PCAxis const& pca = pcas.at(iPCA);
139 
140  //
141  // intro
142  //
143  auto first_nl = recob::dumper::makeNewLine(out, indentstr);
144  first_nl()
145  << "[#" << iPCA << "] ";
146 
148  (out, indentstr + " ", true /* follow */);
149  recob::dumper::DumpPCAxis(out, pca, nl);
150 
151  //
152  // done
153  //
154 
155  } // DumpPCAxis()
156 
157 
158  /// Dumps all space points in the input list
159  template <typename Stream>
160  void DumpAllPCAxes(Stream&& out, std::string indentstr = "") const
161  {
162  indentstr += " ";
163  size_t const nPCAs = pcas.size();
164  for (size_t iPCA = 0; iPCA < nPCAs; ++iPCA)
165  DumpPCAxis(std::forward<Stream>(out), iPCA, indentstr);
166  } // DumpAllPCAxes()
167 
168 
169 
170  protected:
171  std::vector<recob::PCAxis> const& pcas; ///< input list
172 
173  PrintOptions_t options; ///< printing and formatting options
174 
175  }; // PCAxisDumper
176 
177 
178  //----------------------------------------------------------------------------
179 
180 
181 } // local namespace
182 
183 
184 
185 namespace recob {
186 
187  //----------------------------------------------------------------------------
189  : EDAnalyzer(config)
190  , fInputTag(config().PCAxisModuleLabel())
191  , fOutputCategory(config().OutputCategory())
192  , fPrintHexFloats(config().PrintHexFloats())
193  {}
194 
195 
196  //----------------------------------------------------------------------------
197  void DumpPCAxes::analyze(const art::Event& evt) {
198 
199  //
200  // collect all the available information
201  //
202  // fetch the data to be dumped on screen
203  auto PCAxes = evt.getValidHandle<std::vector<recob::PCAxis>>(fInputTag);
204 
205  size_t const nPCAs = PCAxes->size();
206  mf::LogInfo(fOutputCategory)
207  << "The event contains " << nPCAs << " PC axes from '"
208  << fInputTag.encode() << "'";
209 
210  // prepare the dumper
211  PCAxisDumper::PrintOptions_t options;
212  options.hexFloats = fPrintHexFloats;
213  PCAxisDumper dumper(*PCAxes, options);
214 
215  dumper.DumpAllPCAxes(mf::LogVerbatim(fOutputCategory), " ");
216 
217  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
218 
219  } // DumpPCAxes::analyze()
220 
221  DEFINE_ART_MODULE(DumpPCAxes)
222 
223 } // namespace recob
DumpPCAxes(Parameters const &config)
Default constructor.
std::enable_if_t< std::is_same< recob::dumper::NewLine< std::decay_t< Stream > >, std::decay_t< NewLineRef > >::value > DumpPCAxis(Stream &&out, recob::PCAxis const &pca, NewLineRef &&nl)
Definition: PCAxisDumpers.h:76
bool fPrintHexFloats
whether to print floats in base 16
art::EDAnalyzer::Table< Config > Parameters
Configuration parameters.
fhicl::Atom< bool > PrintHexFloats
fhicl::Atom< std::string > OutputCategory
virtual void analyze(const art::Event &evt) override
Does the printing.
Simple class managing a repetitive output task.
art::InputTag fInputTag
input tag of the PCAxis product
BEGIN_PROLOG vertical distance to the surface Name
Prints the content of all the PCA axis object on screen.
fhicl::Atom< art::InputTag > PCAxisModuleLabel
Functions dumping principal component axis objects.
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
NewLine< Stream > makeNewLine(Stream &stream, std::string indent, bool followLine=false)
Convenience function to create a temporary NewLine.
Definition: NewLine.h:146
TCEvent evt
Definition: DataStructs.cxx:8
std::string fOutputCategory
category for LogInfo output
bnb BNB Stream