LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 <limits>
15 #include <string>
16 #include <utility> // std::forward()
17 #include <iosfwd> // std::ostream
18 
19 
20 namespace recob {
21 
31  class PointCharge {
32 
33  public:
34 
35  using Charge_t = float;
36 
38  static constexpr Charge_t InvalidCharge
39  = std::numeric_limits<Charge_t>::lowest();
40 
41 
42  //--- BEGIN Constructors ---------------------------------------------------
45 
48 
54  constexpr PointCharge(Charge_t charge): fCharge(charge) {}
55 
57  //--- END Constructors -----------------------------------------------------
58 
59 
60  //--- BEGIN Accessors ------------------------------------------------------
63 
65  constexpr Charge_t charge() const { return fCharge; }
66 
68  //--- END Accessors --------------------------------------------------------
69 
70 
71  //--- BEGIN Status ---------------------------------------------------------
74 
76  constexpr bool hasCharge() const { return charge() != InvalidCharge; }
77 
79  //--- END Status -----------------------------------------------------------
80 
81 
82  //--- BEGIN Printing operations --------------------------------------------
85 
87  static constexpr unsigned int DefaultVerbosity = 1U;
88 
90  static constexpr unsigned int MaxVerbosity = 1U;
91 
106  template <typename Stream>
107  void dump(
108  Stream&& out, unsigned int verbosity,
109  std::string indent, std::string firstIndent
110  ) const;
111 
112  // variants for the implementation of default values
113  template <typename Stream>
114  void dump
115  (Stream&& out, unsigned int verbosity, std::string indent = "") const
116  { dump(std::forward<Stream>(out), verbosity, indent, indent); }
117  template <typename Stream>
118  void dump(Stream&& out, std::string indent, std::string firstIndent) const
119  { dump(std::forward<Stream>(out), DefaultVerbosity, indent, firstIndent); }
120  template <typename Stream>
121  void dump(Stream&& out, std::string indent = "") const
122  { dump(std::forward<Stream>(out), indent, indent); }
123 
125  //--- END Printing operations ----------------------------------------------
126 
127  private:
128  float fCharge;
129 
130  }; // class PointCharge
131 
132 
134  inline std::ostream& operator<<
135  (std::ostream& out, recob::PointCharge const& charge)
136  { charge.dump(out); return out; }
137 
138 
139 } // namespace recob
140 
141 
142 
143 //------------------------------------------------------------------------------
144 //--- template implementation
145 //---
146 template <typename Stream>
148  Stream&& out, unsigned int verbosity,
149  std::string indent, std::string firstIndent
150  ) const
151 {
152  if (verbosity <= 0U) return;
153 
154  //----------------------------------------------------------------------------
155  out << firstIndent
156  << "charge: ";
157  if (hasCharge()) out << charge();
158  else out << "none";
159 
160 // if (verbosity <= 1U) return;
161  //----------------------------------------------------------------------------
162  // if the following check fails,
163  // consistency between `dump()` and `MaxVerbosity` needs to be restored
164  static_assert(MaxVerbosity == 1U, "Please update the code!");
165 
166 } // recob::PointCharge::dump()
167 
168 
169 //------------------------------------------------------------------------------
170 
171 #endif // LARDATAOBJ_RECOBASE_CHARGE_H
Reconstruction base classes.
constexpr PointCharge(Charge_t charge)
Constructor: sets all the data.
Definition: PointCharge.h:54
static constexpr Charge_t InvalidCharge
Value used for default-constructed ("invalid") charge.
Definition: PointCharge.h:39
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:147
void dump(Stream &&out, std::string indent="") const
Default verbosity for dumping operations.
Definition: PointCharge.h:121
constexpr PointCharge()
Default constructor (for ROOT only).
Definition: PointCharge.h:47
constexpr bool hasCharge() const
Returns whether the reconstructed charge value is valid.
Definition: PointCharge.h:76
std::string indent(std::size_t const i)
static constexpr unsigned int DefaultVerbosity
Default verbosity for dumping operations.
Definition: PointCharge.h:87
float fCharge
Reconstructed charge.
Definition: PointCharge.h:128
static constexpr unsigned int MaxVerbosity
Maximum available verbosity for dumping operations.
Definition: PointCharge.h:90
float Charge_t
Type for the amount of reconstructed charge.
Definition: PointCharge.h:35
void dump(Stream &&out, std::string indent, std::string firstIndent) const
Default verbosity for dumping operations.
Definition: PointCharge.h:118
constexpr Charge_t charge() const
Returns the stored value of the reconstructed charge.
Definition: PointCharge.h:65
Charge reconstructed in the active volume.
Definition: PointCharge.h:31