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
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;
52 
54  Name ("PCAxisModuleLabel"),
55  Comment("label of the producer used to create the recob::PCAxis collection to be dumped")
56  };
58  Name ("OutputCategory"),
59  Comment("the category used for the output (useful for filtering) [\"DumpPCAxes\"]"),
60  "DumpPCAxes" /* 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 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
101 
102 // support libraries
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  //----------------------------------------------------------------------------
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();
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 
222 
223 } // namespace recob
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
DumpPCAxes(Parameters const &config)
Default constructor.
Reconstruction base classes.
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
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fPrintHexFloats
whether to print floats in base 16
Configuration parameters.
ChannelGroupService::Name Name
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string encode() const
Definition: InputTag.cc:97
fhicl::Atom< bool > PrintHexFloats
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
static Config * config
Definition: config.cpp:1054
Simple class managing a repetitive output task.
art::InputTag fInputTag
input tag of the PCAxis product
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
Prints the content of all the PCA axis object on screen.
fhicl::Atom< art::InputTag > PCAxisModuleLabel
Functions dumping principal component axis objects.
#define Comment
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:7
std::string nl(std::size_t i=1)
std::string fOutputCategory
category for LogInfo output