LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OverriddenClusterParamsAlg.h
Go to the documentation of this file.
1 
10 #ifndef OVERRIDDENCLUSTERPARAMSALG_H
11 #define OVERRIDDENCLUSTERPARAMSALG_H
12 
13 // C/C++ standard library
14 #include <bitset>
15 #include <type_traits> // std::is_base_of<>
16 #include <utility> // std::forward<>
17 #include <vector>
18 
19 // LArSoft libraries
21 
22 namespace cluster {
23  namespace details {
30  class MultiValue {
31  public:
33 
34  union {
36  float float_value;
37  size_t size_t_value;
38  };
39 
44 
46  template <typename T>
48 
50  template <typename T>
51  operator T() const;
52 
53  }; // MultiValue
54 
55  } // namespace details
56 
68  template <typename AlgoBase>
71  "OverriddenClusterParamsAlg template parameter must derive"
72  " from ClusterParamsAlgBase");
73 
74  public:
75  using Algo_t = AlgoBase;
77  using Measure_t = typename AlgoBase::Measure_t;
78 
93  NParameters
94  };
95 
97  template <typename... Args>
98  explicit OverriddenClusterParamsAlg(Args&&... args)
99  : algo(std::forward<Args>(args)...), values(NParameters)
100  {}
101 
112  {
113  overridden_set.set((size_t)param);
114  values[(size_t)param] = value;
115  return *this;
116  } // OverrideParameter()
117 
125  {
126  overridden_set.set((size_t)param);
127  return *this;
128  }
129 
131  bool isOverridden(ParameterType_t param) const { return overridden_set.test((size_t)param); }
132 
138 
143  void Clear() override { algo.Clear(); }
144 
152  std::vector<recob::Hit const*> const& hits) override
153  {
154  algo.SetHitsFromPointers(gser, hits);
155  }
156 
163  void SetHits(util::GeometryUtilities const& gser, std::vector<recob::Hit> const& hits) override
164  {
165  algo.SetHits(gser, hits);
166  }
167 
169  void SetVerbose(int level = 1) override
170  {
172  algo.SetVerbose(level);
173  }
174 
177 
179 
185  {
186  return ReturnValue(cpStartCharge, &Algo_t::StartCharge, gser);
187  }
189  {
190  return ReturnValue(cpEndCharge, &Algo_t::EndCharge, gser);
191  }
193 
195 
204  Measure_t StartAngle() override { return ReturnValue(cpStartAngle, &Algo_t::StartAngle); }
205 
206  Measure_t EndAngle() override { return ReturnValue(cpEndAngle, &Algo_t::EndAngle); }
208 
210 
216  {
217  return ReturnValue(cpStartOpeningAngle, &Algo_t::StartOpeningAngle);
218  }
220  {
221  return ReturnValue(cpEndOpeningAngle, &Algo_t::EndOpeningAngle);
222  }
224 
227 
233  Measure_t Integral() override { return ReturnValue(cpIntegral, &Algo_t::Integral); }
234 
242  {
243  return ReturnValue(cpIntegralStdDev, &Algo_t::IntegralStdDev);
244  }
245 
252  Measure_t SummedADC() override { return ReturnValue(cpSummedADC, &Algo_t::SummedADC); }
253 
261  {
262  return ReturnValue(cpSummedADCStdDev, &Algo_t::SummedADCStdDev);
263  }
264 
266 
268  size_t NHits() override { return ReturnValue(cpNHits, &Algo_t::NHits); }
269 
275  float MultipleHitDensity() override
276  {
277  return ReturnValue(cpMultipleHitDensity, &Algo_t::MultipleHitDensity);
278  }
279 
285  float Width(util::GeometryUtilities const& gser) override
286  {
287  return ReturnValue(cpWidth, &Algo_t::Width, gser);
288  }
289 
291 
293 
294  protected:
295  using ValueFunction_t = float (Algo_t::*)();
296  using MeasureFunction_t = Measure_t (Algo_t::*)();
297 
299 
300  std::vector<details::MultiValue> values;
301  std::bitset<NParameters> overridden_set;
302 
303  template <typename Func, typename... Args>
304  auto ReturnValue(ParameterType_t param, Func func, Args&&... args)
305  -> decltype((algo.*func)(args...))
306  {
307  if (isOverridden(param)) {
308  // convert here to the return type of the function
309  // (even if we are not using that function, it still defines the type)
310  return values[(size_t)param];
311  }
312  else
313  return (algo.*func)(args...);
314  } // ReturnValue()
315 
316  }; // class OverriddenClusterParamsAlg
317 
318 } // namespace cluster
319 
320 //==============================================================================
321 //=== Template implementation
322 //==============================================================================
323 
324 namespace cluster {
325 
326  namespace details {
327 
328  // specialization: size_t
329  template <>
331  {
333  return *this;
334  }
335 
336  template <>
337  MultiValue::operator size_t() const
338  {
339  return size_t_value;
340  }
341 
342  // specialization: float
343  template <>
345  {
346  float_value = value;
347  return *this;
348  }
349 
350  template <>
351  MultiValue::operator float() const
352  {
353  return float_value;
354  }
355 
356  // specialization: Measure_t
357  template <>
359  {
361  return *this;
362  }
363 
364  template <>
365  MultiValue::operator MultiValue::Measure_t() const
366  {
367  return measure_value;
368  }
369 
370  } // namespace details
371 } // namespace cluster
372 
373 #endif // OVERRIDDENCLUSTERPARAMSALG_H
float Width(util::GeometryUtilities const &gser) override
Computes the width of the cluster.
void SetHits(util::GeometryUtilities const &gser, std::vector< recob::Hit > const &hits) override
Sets the list of input hits.
Measure_t EndCharge(util::GeometryUtilities const &gser) override
Computes the charge on the first and last wire of the track.
std::bitset< NParameters > overridden_set
bits for overriding
bool isOverridden(ParameterType_t param) const
Returns whether the specified parameter is currently overridden.
Measure_t StartCharge(util::GeometryUtilities const &gser) override
Computes the charge on the first and last wire of the track.
std::vector< details::MultiValue > values
the overridden values
Class holding a value of one among some selected types...
Measure_t Integral() override
Computes the total charge of the cluster from Hit::Integral()
virtual void SetVerbose(int level=1)
Set the verbosity level.
Measure_t StartOpeningAngle() override
Computes the opening angle at the start or end of the cluster.
void SetHitsFromPointers(util::GeometryUtilities const &gser, std::vector< recob::Hit const * > const &hits) override
Sets the list of input hits.
STL namespace.
Cluster finding and building.
Measure_t StartAngle() override
Computes the angle of the cluster.
Algo_t algo
an instance of the wrapped algorithm class
Measure_t EndAngle() override
Computes the angle of the cluster.
Algorithm collection class computing cluster parameters.
auto ReturnValue(ParameterType_t param, Func func, Args &&...args) -> decltype((algo.*func)(args...))
Measure_t EndOpeningAngle() override
Computes the opening angle at the start or end of the cluster.
float MultipleHitDensity() override
Fraction of wires in the cluster with more than one hit.
void hits()
Definition: readHits.C:15
size_t NHits() override
Returns the number of hits in the cluster.
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
double value
Definition: spectrum.C:18
Measure_t IntegralStdDev() override
Computes the standard deviation on the charge of the cluster hits.
This_t & ReleaseParameter(ParameterType_t param)
Cancels the override of the specified cluster parameter.
cluster::details::Measure_t< float > Measure_t
MultiValue & operator=(T)
Sets the value from a value of type T; undefined by default.
OverriddenClusterParamsAlg(Args &&...args)
Constructor; just forwards the arguments to the base class.
Interface for a algorithm class computing cluster parameters.
Measure_t SummedADC() override
Computes the total charge of the cluster from Hit::SummedADC()
void SetVerbose(int level=1) override
Set the verbosity level;.
Algorithm collection class computing cluster parameters.
Measure_t SummedADCStdDev() override
Computes the standard deviation on the charge of the cluster hits.
void Clear() override
Restores the class to post-configuration, pre-initialization state.
This_t & OverrideParameter(ParameterType_t param, Measure_t value)
Overrides the specified cluster parameter.