SpacePointDumpers.h
Go to the documentation of this file.
1 /**
2  * @file SpacePointDumpers.h
3  * @brief Functions dumping space points
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 18th, 2015
6  * @see SpacePointDumpers.cc DumpSpacePoints_module.cc
7  */
8 
9 #ifndef LARDATA_RECOBASE_DUMPERS_SPACEPOINTDUMPERS_H
10 #define LARDATA_RECOBASE_DUMPERS_SPACEPOINTDUMPERS_H 1
11 
12 
13 // LArSoft libraries
15 
16 // C/C++ standard libraries
17 #include <utility> // std::forward<>()
18 #include <type_traits> // std::decay<>
19 
20 
21 // --- for the implementation ---
22 // LArSoft libraries
25 
26 
27 namespace recob {
28  namespace dumper {
29 
30  /// Collection of available printing style options
32  IndentOptions_t indent; ///< indentation string
33  bool hexFloats = false; ///< print all floating point numbers in base 16
34 
35  /**
36  * @brief Default constructor
37  *
38  * By default, the options are:
39  *
40  * * no indentation
41  * * same indentation for the first and the following lines
42  * * real numbers printed in base 10
43  *
44  */
45  SpacePointPrintOptions_t() = default;
46 
48  (IndentOptions_t indentOptions, bool bHexFloats)
49  : indent(indentOptions), hexFloats(bHexFloats)
50  {}
51 
52  }; // SpacePointPrintOptions_t
53 
54 
55  /**
56  * @brief Dumps the content of the specified space point into a stream
57  * @tparam Stream the type of the output stream
58  * @tparam NewLineRef NewLine reference type (to get a universal reference)
59  * @param out the output stream
60  * @param sp the space point to be dumped
61  * @param options indentation and formatting options
62  */
63  template
64  <typename Stream, typename NewLineRef = recob::dumper::NewLine<Stream>>
65  auto DumpSpacePoint(
66  Stream&& out,
67  recob::SpacePoint const& sp,
69  ) -> std::enable_if_t
70  <std::is_same<NewLine<std::decay_t<Stream>>, std::decay_t<NewLineRef>>::value>;
71 
72  } // namespace dumper
73 } // namespace recob
74 
75 
76 //==============================================================================
77 //=== template implementation
78 //===
79 //------------------------------------------------------------------------------
80 //--- recob::dumper::DumpSpacePoint
81 //---
82 template <typename Stream, typename NewLineRef>
84  Stream&& out,
85  recob::SpacePoint const& sp,
86  SpacePointPrintOptions_t const& options /* = {} */
87 ) -> std::enable_if_t<
88  std::is_same<
90  std::decay_t<NewLineRef>
91  >::value>
92 {
93  double const* pos = sp.XYZ();
94  double const* err = sp.ErrXYZ();
95 
96  NewLineRef nl(out, options.indent);
97  lar::OptionalHexFloat hexfloat(options.hexFloats);
98 
99  nl()
100  << "ID=" << sp.ID() << " at (" << hexfloat(pos[0])
101  << ", " << hexfloat(pos[1]) << ", " << hexfloat(pos[2])
102  << ") cm, chi^2/NDF=" << hexfloat(sp.Chisq());
103 
104  nl()
105  << "variances { x^2=" << hexfloat(err[0]) << " y^2=" << hexfloat(err[2])
106  << " z^2=" << hexfloat(err[5])
107  << " xy=" << hexfloat(err[1]) << " xz=" << hexfloat(err[3])
108  << " yz=" << hexfloat(err[4]) << " }";
109 
110 } // recob::dumper::DumpSpacePoint()
111 
112 //------------------------------------------------------------------------------
113 
114 #endif // LARDATA_RECOBASE_DUMPERS_SPACEPOINTDUMPERS_H
Starts a new line in a output stream.
Definition: NewLine.h:74
Reconstruction base classes.
IndentOptions_t indent
indentation string
auto DumpSpacePoint(Stream &&out, recob::SpacePoint const &sp, SpacePointPrintOptions_t const &options={}) -> std::enable_if_t < std::is_same< NewLine< std::decay_t< Stream >>, std::decay_t< NewLineRef >>::value >
Dumps the content of the specified space point into a stream.
Simple class managing a repetitive output task.
Structure collecting indentation options.
Definition: NewLine.h:20
void err(const char *fmt,...)
Definition: message.cpp:226
Helper for formatting floats in base 16.
Definition: hexfloat.h:105
SpacePointPrintOptions_t()=default
Default constructor.
Helper to support output of real numbers in base 16.
bool hexFloats
print all floating point numbers in base 16
std::string nl(std::size_t i=1)
Collection of available printing style options.