Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
lar::util::details::WeightTracker< W > Class Template Reference

#include <StatCollector.h>

Inheritance diagram for lar::util::details::WeightTracker< W >:
lar::util::StatCollector< T, W > lar::util::StatCollector2D< T, W >

Public Types

using Weight_t = W
 type of the weight More...
 

Public Member Functions

void add (Weight_t weight)
 Adds the specified weight to the statistics. More...
 
void clear ()
 Resets the count. More...
 
int N () const
 Returns the number of entries added. More...
 
Weight_t Weights () const
 Returns the sum of the weights. More...
 
Weight_t AverageWeight () const
 Returns the arithmetic average of the weights. More...
 

Static Public Member Functions

template<typename V >
static constexpr V sqr (V const &v)
 Returns the square of the specified value. More...
 

Protected Attributes

int n = 0
 number of added entries More...
 
Weight_t w = Weight_t(0)
 total weight More...
 

Detailed Description

template<typename W>
class lar::util::details::WeightTracker< W >

Class tracking the number of entries and their total weight

Template Parameters
Wtype of the weight

Definition at line 48 of file StatCollector.h.

Member Typedef Documentation

template<typename W>
using lar::util::details::WeightTracker< W >::Weight_t = W

type of the weight

Definition at line 50 of file StatCollector.h.

Member Function Documentation

template<typename W>
void lar::util::details::WeightTracker< W >::add ( Weight_t  weight)
inline

Adds the specified weight to the statistics.

Definition at line 53 of file StatCollector.h.

53 { ++n; w += weight; }
weight
Definition: test.py:257
int n
number of added entries
Definition: StatCollector.h:77
template<typename W >
lar::util::details::WeightTracker< W >::Weight_t lar::util::details::WeightTracker< W >::AverageWeight ( ) const

Returns the arithmetic average of the weights.

Returns
the weight average
Exceptions
std::range_errorif no entry was added

Definition at line 841 of file StatCollector.h.

842 {
843  if (N() == 0)
844  throw std::range_error("WeightTracker<>::AverageWeight(): divide by 0");
845  return Weights() / N();
846 } // details::WeightTracker<W>::AverageWeight()
Weight_t Weights() const
Returns the sum of the weights.
Definition: StatCollector.h:62
int N() const
Returns the number of entries added.
Definition: StatCollector.h:59
template<typename W>
void lar::util::details::WeightTracker< W >::clear ( )
inline

Resets the count.

Definition at line 56 of file StatCollector.h.

56 { n= 0; w = Weight_t(0); }
int n
number of added entries
Definition: StatCollector.h:77
W Weight_t
type of the weight
Definition: StatCollector.h:50
template<typename W>
int lar::util::details::WeightTracker< W >::N ( void  ) const
inline

Returns the number of entries added.

Definition at line 59 of file StatCollector.h.

59 { return n; }
int n
number of added entries
Definition: StatCollector.h:77
template<typename W>
template<typename V >
static constexpr V lar::util::details::WeightTracker< W >::sqr ( V const &  v)
inlinestatic

Returns the square of the specified value.

Definition at line 74 of file StatCollector.h.

74 { return v*v; }
template<typename W>
Weight_t lar::util::details::WeightTracker< W >::Weights ( ) const
inline

Returns the sum of the weights.

Definition at line 62 of file StatCollector.h.

62 { return w; }

Member Data Documentation

template<typename W>
int lar::util::details::WeightTracker< W >::n = 0
protected

number of added entries

Definition at line 77 of file StatCollector.h.

template<typename W>
Weight_t lar::util::details::WeightTracker< W >::w = Weight_t(0)
protected

total weight

Definition at line 78 of file StatCollector.h.


The documentation for this class was generated from the following file: