| The Gaudi Framework v32r1 (f65d50dc)

Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
Gaudi::Accumulators Namespace Reference

Efficient counter implementations for Gaudi. More...

## Namespaces
| details

## Classes
class | AccumulatorSet
| AccumulatorSet is an Accumulator that holds a set of Accumulators templated by same Arithmetic and Atomicity and increase them altogether. More...
struct | Adder
| An Adder ValueHandler operator(a, b) means a += b. More...
struct | Adder< Arithmetic, atomicity::full >
| Adder specialization in the case of atomicity full. More...
struct | Adder< Arithmetic, atomicity::none >
| Adder specialization in the case of atomicity none. More...
struct | AveragingAccumulator
| AveragingAccumulator. More...
struct | AveragingCounter
| A counter aiming at computing sum and average. More...
struct | BaseValueHandler
| Base type for all functors used as ValuesHandler. More...
struct | BaseValueHandler< Arithmetic, atomicity::full >
| BaseValueHandler specialization in the case of atomicity full. More...
struct | BaseValueHandler< Arithmetic, atomicity::none >
| BaseValueHandler specialization in the case of atomicity none. More...
struct | BinomialAccumulator
| BinomialAccumulator. More...
struct | BinomialCounter
| A counter dealing with binomial data. More...
class | Buffer
| Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-safe Accumulator for all previous updates in one go. More...
struct | BufferableCounter
| An empty ancester of all counters that provides a buffer method that returns a buffer on itself. More...
struct | Constant
| A functor always returning the value N. More...
struct | CountAccumulator
| CountAccumulator. More...
struct | Counter
| A basic counter counting input values. More...
struct | Extremum
| An Extremum ValueHandler, to be reused for Minimum and Maximum operator(a, b) means if (Compare(b,a)) a = b In case of full atomicity, compare_exchange_weak is used. More...
struct | Extremum< Arithmetic, atomicity::full, Compare, Initial >
| Extremum specialization in the case of atomicity full. More...
struct | Extremum< Arithmetic, atomicity::none, Compare, Initial >
| Extremum specialization in the case of atomicity none. More...
struct | FalseAccumulator
| FalseAccumulator. More...
struct | FalseTo1
| helper functor for the FalseAccumulator More...
class | GenericAccumulator
| Generic Accumulator, templated by. More...
struct | Identity
| An Identity functor. More...
struct | MaxAccumulator
| MaxAccumulator. More...
struct | MinAccumulator
| MinAccumulator. More...
struct | PrintableCounter
| An empty ancester of all counters that knows how to print themselves. More...
struct | SigmaAccumulator
| SigmaAccumulator. More...
struct | SigmaCounter
| A counter aiming at computing average and sum2 / variance / standard deviation. More...
struct | Square
| A Square functor. More...
struct | SquareAccumulator
| SquareAccumulator. More...
struct | StatCounter
| A counter aiming at computing average and sum2 / variance / standard deviation. More...
struct | SumAccumulator
| SumAccumulator. More...
struct | TrueAccumulator
| TrueAccumulator. More...
struct | TrueTo1
| helper functor for the TrueAccumulator More...

## Typedefs
template<typename T , typename = int>
using | has_fetch_add_ = decltype(std::atomic< T >{}.fetch_add(0))
| type_traits for checking the presence of fetch_add in std::atomic<T> More...
template<typename Arithmetic , typename Result = double>
using | fp_result_type = std::conditional_t< std::is_integral_v< Arithmetic >, Result, Arithmetic >
| type_trait for the result type of a floating point operation on the type Arithmetic More...
template<typename Arithmetic , atomicity Atomicity = atomicity::full>
using | Minimum = Extremum< Arithmetic, Atomicity, std::less< Arithmetic >, std::numeric_limits< Arithmetic >::max >
| A Minimun ValueHandler operator(a, b) means a = min(a, b) In case of full atomicity, compare_exchange_weak is used. More...
template<typename Arithmetic , atomicity Atomicity = atomicity::full>
using | Maximum = Extremum< Arithmetic, Atomicity, std::greater< Arithmetic >, std::numeric_limits< Arithmetic >::lowest >
| An Maximum ValueHandler operator(a, b) means a = max(a, b) In case of full atomicity, compare_exchange_weak is used. More...
template<typename Arithmetic , atomicity Atomicity = atomicity::full>
using | StatAccumulator = AccumulatorSet< Arithmetic, Atomicity, SigmaAccumulator, MinAccumulator, MaxAccumulator >
| StatAccumulator. More...
template<typename Arithmetic = double, atomicity Atomicity = atomicity::full>
using | SummingCounter = AveragingCounter< Arithmetic, Atomicity >

## Enumerations
enum | atomicity { atomicity::none, atomicity::full }
| Defines atomicity of the accumulators. More...

## Functions
template<class Rep , class Period >
auto | sqrt (std::chrono::duration< Rep, Period > d)
| sqrt for std::chrono::duration More...
template<class Rep1 , class Rep2 , class Period >
auto | operator * (const std::chrono::duration< Rep1, Period > &lhs, const std::chrono::duration< Rep2, Period > &rhs)
| Multiplication of two std::chrono::duration objects with same Period. More...
template<class T >
auto | sqrt (T d)
| forward declaration of sqrt for custom types More...
std::ostream & | operator<< (std::ostream &s, const PrintableCounter &counter)
| external printout operator to a stream type More...
MsgStream & | operator<< (MsgStream &s, const PrintableCounter &counter)

## Variables
template<typename T >
constexpr bool | has_fetch_add_v = Gaudi::cpp17::is_detected_v<has_fetch_add_, T>

## Detailed Description

Efficient counter implementations for Gaudi.

A number of concepts and templated classes are defined:

## Concepts

- Accumulator : object accumulating some data in some way. examples : counters, sum of squares accumulator, minimum accumulator (keeps minimum of all values)
- Atomicity : the atomicity of an accumulator. Can be none or full. "none" means that the accumulator is not thread safe and should only be used locally within a thread. "full" means that the accumulator is thread safe, but that you pay the price of atomics inside. Note that this price may be reduced by the usage of the Buffer class, see below.
- InputTransform : a transformation to be applied to the input of an Accumulator. for example "elevation to power 2" for a sum of squares Accumulator, "identity" for a sum Accumulator or a minimum Accumulator, "constant 1" for a pure counter
- OutputTransform : a transformation to be applied to the value of an Accumulator when reading it. Usually identity. You can think of square root for an RMS Accumulator (accumulating squares internally)
- ValueHandler : the class handling the internal value of an Accumulator, and responsible for updating it with a new input. It defines the initial default value, the storage type used (depending on atomicity) and the actual update operation (sum, keep min or max typically).
- AccumulatorSet : an Accumulator defined as a set of Accumulators with same InputType and Atomicity. Updating it means updating all Accumulators of the set with the same value. E.g. a set with Counter and Sum will be able to compute some average
- Buffer : a wrapper around a thread safe Accumulator that allows to accumulate locally (in a non thread safe Accumulator) data before merging into the original one when Buffer is destructed. To be use when accumulators are updated in tight loops
- Counter : a higher level object that is an Accumulator and provides extra methods, most notably a way to print itself via operator<<, a print method and a buffer method to retrieve a Buffer on top of it.

## Classes and helper functions

- many classes are directly linked to concepts :
  - Constant, Identity, Square are InputTransforms / OutputTransforms
  - BaseValueHandler : a base class for ValueHandlers Adder, Minimum and Maximum
  - Adder, Extremum, Minimum, Maximum, Binomial are ValueHandlers
  - GenericAccumulator : implements a generic Accumulator. See class definition for details
  - AccumulatorSet binds together a set of Accumulators into a new accumulator
  - Buffer implements the local buffering of an Accumulator
- some classes implements the most common Accumulators :
  - MaxAccumulator : keeps the max, has a max() method
  - MinAccumulator : keeps the min, has a min() method
  - CountAccumulator : keeps count of number of values, has a nEntries() method
  - SumAccumulator : keeps the sum of all values, has a sum() method
  - SquareAccumulator : keeps the sum of all values squared, has a sum2() method
  - TrueAccumulator : keeps a count of the number of true values, has a nTrueEntries() method
  - FalseAccumulator : keeps a count of the number of false values, has a nFalseEntries() method
  - BinomialAccumulator : set of TrueAccumulator and FalseAccumulator. Has extra nEntries(), efficiency() and efficiencyErr() methods
  - AveragingAccumulator : set of CountAccumulator and SumAccumulator. Has an extra mean() method
  - SigmaAccumulator : set of AveragingAccumulator and SquareAccumulator. Has extra methods variance(), standard_deviation() and meanErr()
  - MsgCounter: keeps a count of number of values, and prints the first N times it is incremented at a specified logging level
  - StatAccumulator : set of SigmaAccumulator, MinAccumulator and MaxAccumulator
- some classes implement the most common Counters :
  - PrintableCounter is the interface to be used for abstract counters that can be printed
  - BufferableCounter is the base class for counters that can be buffered. It provides a buffer method returning a Buffer on the current counter
  - Counter, AveragingCounter, SigmaCounter, StatCounter, BinomialCounter : standard counters based on the corresponding accumulators
  - StatEntity : a counter meant to be backward compatible with the old one and actually being a set of StatAccumulator and BinomialAccumulator. StatEntity should not be used and should be dropped when ancient code has been ported to the other counters

## Notes

All Accumulators and Counters defined above are provided in their atomic and non atomic versions

Here is an example of the typical usage of these classes :

AveragingCounter<> avg;
avg += 3;
avg += 5;
avg += 6;
std::cout << avg << std::endl;
SigmaCounter<> sig;
sig += 3;
sig += 5;
sig += 6;
std::cout << sig << std::endl;
AveragingCounter<float, atomicity::full> avg2;
{
auto buf = avg2.buffer();
for ( int i = 0; i < 1000; i++ ) buf += i;
// single update of original counter when buf is destroyed
}
std::cout << avg2 << std::endl;
BinomialCounter<> bin;
bin += false;
bin += true;
bin += true;
bin += false;
bin += false;
std::cout << bin << std::endl;
StatEntity se;
se += 3;
se += 5;
se += 6;
std::cout << se << std::endl;

## Typedef Documentation

## ◆ fp_result_type

template<typename Arithmetic , typename Result = double>

using Gaudi::Accumulators::fp_result_type = typedef std::conditional_t<std::is_integral_v<Arithmetic>, Result, Arithmetic>

type_trait for the result type of a floating point operation on the type Arithmetic

Definition at line 198 of file Counters.h.

## ◆ has_fetch_add_

template<typename T , typename = int>

using Gaudi::Accumulators::has_fetch_add_ = typedef decltype( std::atomic<T>{}.fetch_add( 0 ) )

type_traits for checking the presence of fetch_add in std::atomic<T>

Definition at line 190 of file Counters.h.

## ◆ Maximum

template<typename Arithmetic , atomicity Atomicity = atomicity::full>

using Gaudi::Accumulators::Maximum = typedef Extremum<Arithmetic, Atomicity, std::greater<Arithmetic>, std::numeric_limits<Arithmetic>::lowest>

An Maximum ValueHandler operator(a, b) means a = max(a, b) In case of full atomicity, compare_exchange_weak is used.

Definition at line 315 of file Counters.h.

## ◆ Minimum

template<typename Arithmetic , atomicity Atomicity = atomicity::full>

using Gaudi::Accumulators::Minimum = typedef Extremum<Arithmetic, Atomicity, std::less<Arithmetic>, std::numeric_limits<Arithmetic>::max>

A Minimun ValueHandler operator(a, b) means a = min(a, b) In case of full atomicity, compare_exchange_weak is used.

Definition at line 308 of file Counters.h.

## ◆ StatAccumulator

template<typename Arithmetic , atomicity Atomicity = atomicity::full>

using Gaudi::Accumulators::StatAccumulator = typedef AccumulatorSet<Arithmetic, Atomicity, SigmaAccumulator, MinAccumulator, MaxAccumulator>

StatAccumulator.

A StatAccumulator is an Accumulator able to compute an average, variance/rms and min/max

See also
  Gaudi::Accumulators for detailed documentation

Definition at line 571 of file Counters.h.

## ◆ SummingCounter

template<typename Arithmetic = double, atomicity Atomicity = atomicity::full>

using Gaudi::Accumulators::SummingCounter = typedef AveragingCounter<Arithmetic, Atomicity>

Definition at line 710 of file Counters.h.

## Enumeration Type Documentation

## ◆ atomicity

enum Gaudi::Accumulators::atomicity
| strong

Defines atomicity of the accumulators.

Enumerator
none |
full |

Definition at line 149 of file Counters.h.

149 { none, full };
Gaudi::Accumulators::atomicity::none
Gaudi::Accumulators::atomicity::full

## Function Documentation

## ◆ operator *()

template<class Rep1 , class Rep2 , class Period >

auto Gaudi::Accumulators::operator * | ( | const std::chrono::duration< Rep1, Period > & | lhs,
|  | const std::chrono::duration< Rep2, Period > & | rhs
| ) |  |

Multiplication of two std::chrono::duration objects with same Period.

Definition at line 34 of file Counters.h.

34 {
35 return std::chrono::duration<std::common_type_t<Rep1, Rep2>, Period>( lhs.count() * rhs.count() );
36 }
std::chrono::duration
std::chrono::duration::count
T count(T... args)

## ◆ operator<<() [1/2]

std::ostream& Gaudi::Accumulators::operator<< | ( | std::ostream & | s,
|  | const PrintableCounter & | counter
| ) |  |
| inline

external printout operator to a stream type

Definition at line 635 of file Counters.h.

635 { return counter.print( s ); }
plotSpeedupsPyRoot.counter
int counter
Definition: plotSpeedupsPyRoot.py:147
gaudirun.s
string s
Definition: gaudirun.py:316

## ◆ operator<<() [2/2]

MsgStream& Gaudi::Accumulators::operator<< | ( | MsgStream & | s,
|  | const PrintableCounter & | counter
| ) |  |
| inline

Definition at line 636 of file Counters.h.

636 { return counter.print( s ); }
plotSpeedupsPyRoot.counter
int counter
Definition: plotSpeedupsPyRoot.py:147
gaudirun.s
string s
Definition: gaudirun.py:316

## ◆ sqrt() [1/2]

template<class Rep , class Period >

auto Gaudi::Accumulators::sqrt | ( | std::chrono::duration< Rep, Period > | d | ) |

sqrt for std::chrono::duration

Definition at line 28 of file Counters.h.

28 {
29 return std::chrono::duration<Rep, Period>( static_cast<Rep>( std::round( std::sqrt( d.count() ) ) ) );
30 }
std::chrono::duration
std::chrono::duration::count
T count(T... args)
std::sqrt
T sqrt(T... args)
std::round
T round(T... args)

## ◆ sqrt() [2/2]

template<class T >

auto Gaudi::Accumulators::sqrt | ( | T | d | ) |

forward declaration of sqrt for custom types

## Variable Documentation

## ◆ has_fetch_add_v

template<typename T >

constexpr bool Gaudi::Accumulators::has_fetch_add_v = Gaudi::cpp17::is_detected_v<has_fetch_add_, T>
| inline

Definition at line 192 of file Counters.h.