LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpPCAxes_module.cc
Go to the documentation of this file.
1 
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 
45  class DumpPCAxes : public art::EDAnalyzer {
46  public:
48  struct Config {
49  using Name = fhicl::Name;
51 
53  Name("PCAxisModuleLabel"),
54  Comment("label of the producer used to create the recob::PCAxis collection to be dumped")};
56  Name("OutputCategory"),
57  Comment("the category used for the output (useful for filtering) [\"DumpPCAxes\"]"),
58  "DumpPCAxes" /* default value */
59  };
61  Name("PrintHexFloats"),
62  Comment("print floating point numbers in base 16 [false]"),
63  false /* default value */
64  };
65 
66  }; // struct Config
67 
69 
71  explicit DumpPCAxes(Parameters const& config);
72 
74  virtual void analyze(const art::Event& evt) override;
75 
76  private:
78  std::string fOutputCategory;
80 
81  }; // class DumpPCAxes
82 
83 } // namespace recob
84 
85 //==============================================================================
86 //=== Implementation section
87 //==============================================================================
88 
89 // LArSoft includes
90 #include "lardata/ArtDataHelper/Dumpers/NewLine.h" // recob::dumper::makeNewLine()
91 #include "lardata/ArtDataHelper/Dumpers/PCAxisDumpers.h" // recob::dumper::DumpPCAxis()
93 
94 // art libraries
97 
98 // support libraries
100 
101 // C//C++ standard libraries
102 
103 namespace {
104 
105  //----------------------------------------------------------------------------
106  class PCAxisDumper {
107  public:
109  struct PrintOptions_t {
110  bool hexFloats = false;
111  }; // PrintOptions_t
112 
114  PCAxisDumper(std::vector<recob::PCAxis> const& pca_list) : PCAxisDumper(pca_list, {}) {}
115 
117  PCAxisDumper(std::vector<recob::PCAxis> const& pca_list, PrintOptions_t print_options)
118  : pcas(pca_list), options(print_options)
119  {}
120 
122  template <typename Stream>
123  void DumpPCAxis(Stream&& out, size_t iPCA, std::string indentstr = "") const
124  {
125  recob::PCAxis const& pca = pcas.at(iPCA);
126 
127  //
128  // intro
129  //
130  auto first_nl = recob::dumper::makeNewLine(out, indentstr);
131  first_nl() << "[#" << iPCA << "] ";
132 
133  auto nl = recob::dumper::makeNewLine(out, indentstr + " ", true /* follow */);
134  recob::dumper::DumpPCAxis(out, pca, nl);
135 
136  //
137  // done
138  //
139 
140  } // DumpPCAxis()
141 
143  template <typename Stream>
144  void DumpAllPCAxes(Stream&& out, std::string indentstr = "") const
145  {
146  indentstr += " ";
147  size_t const nPCAs = pcas.size();
148  for (size_t iPCA = 0; iPCA < nPCAs; ++iPCA)
149  DumpPCAxis(std::forward<Stream>(out), iPCA, indentstr);
150  } // DumpAllPCAxes()
151 
152  protected:
153  std::vector<recob::PCAxis> const& pcas;
154 
155  PrintOptions_t options;
156 
157  }; // PCAxisDumper
158 
159  //----------------------------------------------------------------------------
160 
161 } // local namespace
162 
163 namespace recob {
164 
165  //----------------------------------------------------------------------------
167  : EDAnalyzer(config)
168  , fInputTag(config().PCAxisModuleLabel())
169  , fOutputCategory(config().OutputCategory())
170  , fPrintHexFloats(config().PrintHexFloats())
171  {}
172 
173  //----------------------------------------------------------------------------
175  {
176 
177  //
178  // collect all the available information
179  //
180  // fetch the data to be dumped on screen
181  auto PCAxes = evt.getValidHandle<std::vector<recob::PCAxis>>(fInputTag);
182 
183  size_t const nPCAs = PCAxes->size();
184  mf::LogInfo(fOutputCategory) << "The event contains " << nPCAs << " PC axes from '"
185  << fInputTag.encode() << "'";
186 
187  // prepare the dumper
188  PCAxisDumper::PrintOptions_t options;
189  options.hexFloats = fPrintHexFloats;
190  PCAxisDumper dumper(*PCAxes, options);
191 
192  dumper.DumpAllPCAxes(mf::LogVerbatim(fOutputCategory), " ");
193 
194  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
195 
196  } // DumpPCAxes::analyze()
197 
199 
200 } // 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:68
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fPrintHexFloats
whether to print floats in base 16
Configuration parameters.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
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:65
Simple class managing a repetitive output task.
art::InputTag fInputTag
input tag of the PCAxis product
Prints the content of all the PCA axis object on screen.
fhicl::Atom< art::InputTag > PCAxisModuleLabel
Functions dumping principal component axis objects.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
NewLine< Stream > makeNewLine(Stream &stream, std::string indent, bool followLine=false)
Convenience function to create a temporary NewLine.
Definition: NewLine.h:148
TCEvent evt
Definition: DataStructs.cxx:8
std::string nl(std::size_t i=1)
std::string fOutputCategory
category for LogInfo output