LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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/ParameterSet.h"
17 
18 // C//C++ standard libraries
19 #include <string>
20 
21 // ... and more in the implementation part
22 
23 namespace recob {
24 
42  class DumpPCAxes: public art::EDAnalyzer {
43  public:
44 
46  struct Config {
47  using Name = fhicl::Name;
49 
51  Name ("PCAxisModuleLabel"),
52  Comment("label of the producer used to create the recob::PCAxis collection to be dumped")
53  };
55  Name ("OutputCategory"),
56  Comment("the category used for the output (useful for filtering) [\"DumpPCAxes\"]"),
57  "DumpPCAxes" /* default value */
58  };
60  Name ("PrintHexFloats"),
61  Comment("print floating point numbers in base 16 [false]"),
62  false /* default value */
63  };
64 
65  }; // struct Config
66 
68 
70  explicit DumpPCAxes(Parameters const& config);
71 
73  virtual void analyze (const art::Event& evt) override;
74 
75  private:
76 
78  std::string fOutputCategory;
80 
81  }; // class DumpPCAxes
82 
83 } // namespace recob
84 
85 
86 //==============================================================================
87 //=== Implementation section
88 //==============================================================================
89 
90 // LArSoft includes
92 #include "lardata/ArtDataHelper/Dumpers/NewLine.h" // recob::dumper::makeNewLine()
93 #include "lardata/ArtDataHelper/Dumpers/PCAxisDumpers.h" // recob::dumper::DumpPCAxis()
94 
95 // art libraries
98 
99 // support libraries
101 
102 // C//C++ standard libraries
103 #include <vector>
104 
105 
106 namespace {
107 
108  //----------------------------------------------------------------------------
109  class PCAxisDumper {
110  public:
111 
113  struct PrintOptions_t {
114  bool hexFloats = false;
115  }; // PrintOptions_t
116 
117 
119  PCAxisDumper(std::vector<recob::PCAxis> const& pca_list)
120  : PCAxisDumper(pca_list, {})
121  {}
122 
124  PCAxisDumper
125  (std::vector<recob::PCAxis> const& pca_list, PrintOptions_t print_options)
126  : pcas(pca_list)
127  , options(print_options)
128  {}
129 
130 
132  template <typename Stream>
133  void DumpPCAxis
134  (Stream&& out, size_t iPCA, std::string indentstr = "") const
135  {
136  recob::PCAxis const& pca = pcas.at(iPCA);
137 
138  //
139  // intro
140  //
141  auto first_nl = recob::dumper::makeNewLine(out, indentstr);
142  first_nl()
143  << "[#" << iPCA << "] ";
144 
146  (out, indentstr + " ", true /* follow */);
147  recob::dumper::DumpPCAxis(out, pca, nl);
148 
149  //
150  // done
151  //
152 
153  } // DumpPCAxis()
154 
155 
157  template <typename Stream>
158  void DumpAllPCAxes(Stream&& out, std::string indentstr = "") const
159  {
160  indentstr += " ";
161  size_t const nPCAs = pcas.size();
162  for (size_t iPCA = 0; iPCA < nPCAs; ++iPCA)
163  DumpPCAxis(std::forward<Stream>(out), iPCA, indentstr);
164  } // DumpAllPCAxes()
165 
166 
167 
168  protected:
169  std::vector<recob::PCAxis> const& pcas;
170 
171  PrintOptions_t options;
172 
173  }; // PCAxisDumper
174 
175 
176  //----------------------------------------------------------------------------
177 
178 
179 } // local namespace
180 
181 
182 
183 namespace recob {
184 
185  //----------------------------------------------------------------------------
187  : EDAnalyzer(config)
188  , fInputTag(config().PCAxisModuleLabel())
189  , fOutputCategory(config().OutputCategory())
190  , fPrintHexFloats(config().PrintHexFloats())
191  {}
192 
193 
194  //----------------------------------------------------------------------------
196 
197  //
198  // collect all the available information
199  //
200  // fetch the data to be dumped on screen
201  auto PCAxes = evt.getValidHandle<std::vector<recob::PCAxis>>(fInputTag);
202 
203  size_t const nPCAs = PCAxes->size();
205  << "The event contains " << nPCAs << " PC axes from '"
206  << fInputTag.encode() << "'";
207 
208  // prepare the dumper
209  PCAxisDumper::PrintOptions_t options;
210  options.hexFloats = fPrintHexFloats;
211  PCAxisDumper dumper(*PCAxes, options);
212 
213  dumper.DumpAllPCAxes(mf::LogVerbatim(fOutputCategory), " ");
214 
215  mf::LogVerbatim(fOutputCategory) << "\n"; // two empty lines
216 
217  } // DumpPCAxes::analyze()
218 
220 
221 } // 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
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fPrintHexFloats
whether to print floats in base 16
Configuration parameters.
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:42
std::string encode() const
Definition: InputTag.cc:36
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
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Functions dumping principal component axis objects.
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:5
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::string nl(std::size_t i=1)
std::string fOutputCategory
category for LogInfo output