LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <vector>
15 #include <bitset>
16 #include <type_traits> // std::is_base_of<>
17 #include <utility> // std::forward<>
18 
19 // LArSoft libraries
22 
23 
24 
26 namespace cluster {
27 
28  namespace details {
41  class MultiValue {
42  public:
44 
45  // I can't believe I am writing this shit
46  union {
48  float float_value;
49  size_t size_t_value;
50  };
51 
56 
58  template <typename T>
60 
62  template <typename T>
63  operator T() const;
64 
65  }; // MultiValue
66 
67  } // namespace details
68 
69 
81  template <typename AlgoBase>
84  "OverriddenClusterParamsAlg template parameter must derive"
85  " from ClusterParamsAlgBase"
86  );
87  public:
88  using Algo_t = AlgoBase;
90  using Measure_t = typename AlgoBase::Measure_t;
91 
92  typedef enum {
106  NParameters
107  } ParameterType_t;
108 
110  template <typename... Args>
111  explicit OverriddenClusterParamsAlg(Args&&... args):
112  algo(std::forward<Args>(args)...),
113  values(NParameters)
114  {}
115 
117  virtual ~OverriddenClusterParamsAlg() = default;
118 
119 
129  This_t& OverrideParameter(ParameterType_t param, Measure_t value)
130  {
131  overridden_set.set((size_t) param);
132  values[(size_t) param] = value;
133  return *this;
134  } // OverrideParameter()
135 
136 
143  This_t& ReleaseParameter(ParameterType_t param)
144  { overridden_set.set((size_t) param); return *this; }
145 
146 
148  bool isOverridden(ParameterType_t param) const
149  { return overridden_set.test((size_t) param); }
150 
151 
157 
162  virtual void Clear() override { algo.Clear(); }
163 
164 
171  virtual void SetHits(std::vector<recob::Hit const*> const& hits) override
172  { algo.SetHits(hits); }
173 
180  virtual void SetHits(std::vector<recob::Hit> const& hits) override
181  { algo.SetHits(hits); }
182 
183 
185  virtual void SetVerbose(int level = 1) override
186  { ClusterParamsAlgBase::SetVerbose(level); algo.SetVerbose(level); }
187 
188 
191 
193 
198  virtual Measure_t StartCharge() override
199  { return ReturnValue(cpStartCharge, &Algo_t::StartCharge); }
200  virtual Measure_t EndCharge() override
201  { return ReturnValue(cpEndCharge, &Algo_t::EndCharge); }
203 
205 
214  virtual Measure_t StartAngle() override
215  { return ReturnValue(cpStartAngle, &Algo_t::StartAngle); }
216 
217  virtual Measure_t EndAngle() override
218  { return ReturnValue(cpEndAngle, &Algo_t::EndAngle); }
220 
222 
227  virtual Measure_t StartOpeningAngle() override
228  { return ReturnValue(cpStartOpeningAngle, &Algo_t::StartOpeningAngle); }
229  virtual Measure_t EndOpeningAngle() override
230  { return ReturnValue(cpEndOpeningAngle, &Algo_t::EndOpeningAngle); }
232 
233 
236 
242  virtual Measure_t Integral() override
243  { return ReturnValue(cpIntegral, &Algo_t::Integral); }
244 
251  virtual Measure_t IntegralStdDev() override
252  { return ReturnValue(cpIntegralStdDev, &Algo_t::IntegralStdDev); }
253 
260  virtual Measure_t SummedADC() override
261  { return ReturnValue(cpSummedADC, &Algo_t::SummedADC); }
262 
269  virtual Measure_t SummedADCStdDev() override
270  { return ReturnValue(cpSummedADCStdDev, &Algo_t::SummedADCStdDev); }
271 
273 
274 
276  virtual size_t NHits() override
277  { return ReturnValue(cpNHits, &Algo_t::NHits); }
278 
279 
285  virtual float MultipleHitDensity() override
286  { return ReturnValue(cpMultipleHitDensity, &Algo_t::MultipleHitDensity); }
287 
293  virtual float Width() override
294  { return ReturnValue(cpWidth, &Algo_t::Width); }
295 
297 
299 
300  protected:
301 
302  using ValueFunction_t = float (Algo_t::*) ();
303  using MeasureFunction_t = Measure_t (Algo_t::*) ();
304 
306 
307  std::vector<details::MultiValue> values;
308  std::bitset<NParameters> overridden_set;
309 
310  template <typename Func>
311  auto ReturnValue(ParameterType_t param, Func func)
312  -> decltype((algo.*func)())
313  {
314  if (isOverridden(param)) {
315  // convert here to the return type of the function
316  // (even if we are not using that function, it still defines the type)
317  return values[(size_t) param];
318  }
319  else
320  return (algo.*func)();
321  } // ReturnValue()
322 
323  }; // class OverriddenClusterParamsAlg
324 
325 } // namespace cluster
326 
327 
328 
329 //==============================================================================
330 //=== Template implementation
331 //==============================================================================
332 
333 namespace cluster {
334 
335  namespace details {
336 
337  // specialization: size_t
338  template <>
340  { size_t_value = value; return *this; }
341 
342  template <>
343  MultiValue::operator size_t () const { return size_t_value; }
344 
345  // specialization: float
346  template <>
348  { float_value = value; return *this; }
349 
350  template <>
351  MultiValue::operator float () const { return float_value; }
352 
353  // specialization: Measure_t
354  template <>
356  { measure_value = value; return *this; }
357 
358  template <>
359  MultiValue::operator MultiValue::Measure_t () const
360  { return measure_value; }
361 
362  } // namespace details
363 
364 } // namespace cluster
365 
366 #endif // OVERRIDDENCLUSTERPARAMSALG_H
367 
368 
virtual Measure_t EndAngle() override
Computes the angle of the cluster.
virtual void SetVerbose(int level=1) override
Set the verbosity level;.
std::bitset< NParameters > overridden_set
bits for overriding
bool isOverridden(ParameterType_t param) const
Returns whether the specified parameter is currently overridden.
virtual Measure_t StartOpeningAngle() override
Computes the opening angle at the start or end of the cluster.
virtual Measure_t SummedADCStdDev() override
Computes the standard deviation on the charge of the cluster hits.
virtual Measure_t IntegralStdDev() override
Computes the standard deviation on the charge of the cluster hits.
std::vector< details::MultiValue > values
the overridden values
Class holding a value of one among some selected types...
virtual void SetVerbose(int level=1)
Set the verbosity level.
virtual void Clear() override
Restores the class to post-configuration, pre-initialization state.
STL namespace.
Cluster finding and building.
virtual float Width() override
Computes the width of the cluster.
Algo_t algo
an instance of the wrapped algorithm class
virtual Measure_t StartCharge() override
Computes the charge on the first and last wire of the track.
Algorithm collection class computing cluster parameters.
virtual Measure_t StartAngle() override
Computes the angle of the cluster.
auto ReturnValue(ParameterType_t param, Func func) -> decltype((algo.*func)())
void hits()
Definition: readHits.C:15
virtual Measure_t SummedADC() override
Computes the total charge of the cluster from Hit::SummedADC()
virtual void SetHits(std::vector< recob::Hit > const &hits) override
Sets the list of input hits.
This_t & ReleaseParameter(ParameterType_t param)
Cancels the override of the specified cluster parameter.
virtual void SetHits(std::vector< recob::Hit const * > const &hits) override
Sets the list of input hits.
cluster::details::Measure_t< float > Measure_t
MultiValue & operator=(T)
Sets the value from a value of type T; undefined by default.
std::string value(boost::any const &)
OverriddenClusterParamsAlg(Args &&...args)
Constructor; just forwards the arguments to the base class.
Interface for a algorithm class computing cluster parameters.
virtual size_t NHits() override
Returns the number of hits in the cluster.
virtual Measure_t EndCharge() override
Computes the charge on the first and last wire of the track.
virtual Measure_t EndOpeningAngle() override
Computes the opening angle at the start or end of the cluster.
virtual float MultipleHitDensity() override
Fraction of wires in the cluster with more than one hit.
virtual Measure_t Integral() override
Computes the total charge of the cluster from Hit::Integral()
Algorithm collection class computing cluster parameters.
This_t & OverrideParameter(ParameterType_t param, Measure_t value)
Overrides the specified cluster parameter.