LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PointCharge.h
Go to the documentation of this file.
1 
10 #ifndef LARDATAOBJ_RECOBASE_CHARGE_H
11 #define LARDATAOBJ_RECOBASE_CHARGE_H
12 
13 // C/C++ standard libraries
14 #include <iosfwd> // std::ostream
15 #include <limits>
16 #include <string>
17 #include <utility> // std::forward()
18 
19 namespace recob {
20 
30  class PointCharge {
31 
32  public:
33  using Charge_t = float;
34 
36  static constexpr Charge_t InvalidCharge = std::numeric_limits<Charge_t>::lowest();
37 
38  //--- BEGIN Constructors ---------------------------------------------------
41 
43  constexpr PointCharge() : fCharge(InvalidCharge) {}
44 
50  constexpr PointCharge(Charge_t charge) : fCharge(charge) {}
51 
53  //--- END Constructors -----------------------------------------------------
54 
55  //--- BEGIN Accessors ------------------------------------------------------
58 
60  constexpr Charge_t charge() const { return fCharge; }
61 
63  //--- END Accessors --------------------------------------------------------
64 
65  //--- BEGIN Status ---------------------------------------------------------
68 
70  constexpr bool hasCharge() const { return charge() != InvalidCharge; }
71 
73  //--- END Status -----------------------------------------------------------
74 
75  //--- BEGIN Printing operations --------------------------------------------
78 
80  static constexpr unsigned int DefaultVerbosity = 1U;
81 
83  static constexpr unsigned int MaxVerbosity = 1U;
84 
99  template <typename Stream>
100  void dump(Stream&& out,
101  unsigned int verbosity,
102  std::string indent,
103  std::string firstIndent) const;
104 
105  // variants for the implementation of default values
106  template <typename Stream>
107  void dump(Stream&& out, unsigned int verbosity, std::string indent = "") const
108  {
109  dump(std::forward<Stream>(out), verbosity, indent, indent);
110  }
111  template <typename Stream>
112  void dump(Stream&& out, std::string indent, std::string firstIndent) const
113  {
114  dump(std::forward<Stream>(out), DefaultVerbosity, indent, firstIndent);
115  }
116  template <typename Stream>
117  void dump(Stream&& out, std::string indent = "") const
118  {
119  dump(std::forward<Stream>(out), indent, indent);
120  }
121 
123  //--- END Printing operations ----------------------------------------------
124 
125  private:
126  float fCharge;
127 
128  }; // class PointCharge
129 
131  inline std::ostream& operator<<(std::ostream& out, recob::PointCharge const& charge)
132  {
133  charge.dump(out);
134  return out;
135  }
136 
137 } // namespace recob
138 
139 //------------------------------------------------------------------------------
140 //--- template implementation
141 //---
142 template <typename Stream>
143 void recob::PointCharge::dump(Stream&& out,
144  unsigned int verbosity,
145  std::string indent,
146  std::string firstIndent) const
147 {
148  if (verbosity <= 0U) return;
149 
150  //----------------------------------------------------------------------------
151  out << firstIndent << "charge: ";
152  if (hasCharge())
153  out << charge();
154  else
155  out << "none";
156 
157  // if (verbosity <= 1U) return;
158  //----------------------------------------------------------------------------
159  // if the following check fails,
160  // consistency between `dump()` and `MaxVerbosity` needs to be restored
161  static_assert(MaxVerbosity == 1U, "Please update the code!");
162 
163 } // recob::PointCharge::dump()
164 
165 //------------------------------------------------------------------------------
166 
167 #endif // LARDATAOBJ_RECOBASE_CHARGE_H
Reconstruction base classes.
constexpr PointCharge(Charge_t charge)
Constructor: sets all the data.
Definition: PointCharge.h:50
static constexpr Charge_t InvalidCharge
Value used for default-constructed ("invalid") charge.
Definition: PointCharge.h:36
void dump(Stream &&out, unsigned int verbosity, std::string indent, std::string firstIndent) const
Dump the content of this object into an output stream.
Definition: PointCharge.h:143
void dump(Stream &&out, std::string indent="") const
Default verbosity for dumping operations.
Definition: PointCharge.h:117
constexpr PointCharge()
Default constructor (for ROOT only).
Definition: PointCharge.h:43
constexpr bool hasCharge() const
Returns whether the reconstructed charge value is valid.
Definition: PointCharge.h:70
std::string indent(std::size_t const i)
static constexpr unsigned int DefaultVerbosity
Default verbosity for dumping operations.
Definition: PointCharge.h:80
float fCharge
Reconstructed charge.
Definition: PointCharge.h:126
static constexpr unsigned int MaxVerbosity
Maximum available verbosity for dumping operations.
Definition: PointCharge.h:83
float Charge_t
Type for the amount of reconstructed charge.
Definition: PointCharge.h:33
void dump(Stream &&out, std::string indent, std::string firstIndent) const
Default verbosity for dumping operations.
Definition: PointCharge.h:112
constexpr Charge_t charge() const
Returns the stored value of the reconstructed charge.
Definition: PointCharge.h:60
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168
void dump(Stream &&out, unsigned int verbosity, std::string indent="") const
Default verbosity for dumping operations.
Definition: PointCharge.h:107
Charge reconstructed in the active volume.
Definition: PointCharge.h:30