The Gaudi Framework  v39r3 (979e3109)
Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity > Struct Template Reference

An Adder ValueHandler, taking weight into account and computing a count plus the sum of the weights In case of full atomicity, fetch_add or compare_exchange_weak are used for each element, that is we do not have full atomicity accross the two elements. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/Accumulators/StaticHistogram.h>

Public Types

using RegularType = std::pair< unsigned long, Arithmetic >
 
using AtomicType = std::pair< std::atomic< unsigned long >, std::atomic< Arithmetic > >
 
using OutputType = RegularType
 
using InternalType = std::conditional_t< isAtomic, AtomicType, OutputType >
 

Static Public Member Functions

static constexpr OutputType getValue (const InternalType &v) noexcept
 
static RegularType exchange (InternalType &v, RegularType newv) noexcept
 
static constexpr OutputType DefaultValue ()
 
static void merge (InternalType &a, RegularType b) noexcept
 

Static Public Attributes

static constexpr bool isAtomic = Atomicity == atomicity::full
 

Detailed Description

template<typename Arithmetic, atomicity Atomicity>
struct Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >

An Adder ValueHandler, taking weight into account and computing a count plus the sum of the weights In case of full atomicity, fetch_add or compare_exchange_weak are used for each element, that is we do not have full atomicity accross the two elements.

Definition at line 123 of file StaticHistogram.h.

Member Typedef Documentation

◆ AtomicType

template<typename Arithmetic , atomicity Atomicity>
using Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::AtomicType = std::pair<std::atomic<unsigned long>, std::atomic<Arithmetic> >

Definition at line 125 of file StaticHistogram.h.

◆ InternalType

template<typename Arithmetic , atomicity Atomicity>
using Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::InternalType = std::conditional_t<isAtomic, AtomicType, OutputType>

Definition at line 128 of file StaticHistogram.h.

◆ OutputType

template<typename Arithmetic , atomicity Atomicity>
using Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::OutputType = RegularType

Definition at line 126 of file StaticHistogram.h.

◆ RegularType

template<typename Arithmetic , atomicity Atomicity>
using Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::RegularType = std::pair<unsigned long, Arithmetic>

Definition at line 124 of file StaticHistogram.h.

Member Function Documentation

◆ DefaultValue()

template<typename Arithmetic , atomicity Atomicity>
static constexpr OutputType Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::DefaultValue ( )
inlinestaticconstexpr

Definition at line 143 of file StaticHistogram.h.

143 { return { 0, Arithmetic{} }; }

◆ exchange()

template<typename Arithmetic , atomicity Atomicity>
static RegularType Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::exchange ( InternalType v,
RegularType  newv 
)
inlinestaticnoexcept

Definition at line 136 of file StaticHistogram.h.

136  {
137  if constexpr ( isAtomic ) {
138  return { v.first.exchange( newv.first ), v.second.exchange( newv.second ) };
139  } else {
140  return { std::exchange( v.first, newv.first ), std::exchange( v.second, newv.second ) };
141  }
142  }

◆ getValue()

template<typename Arithmetic , atomicity Atomicity>
static constexpr OutputType Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::getValue ( const InternalType v)
inlinestaticconstexprnoexcept

Definition at line 129 of file StaticHistogram.h.

129  {
130  if constexpr ( isAtomic ) {
131  return { v.first.load( std::memory_order_relaxed ), v.second.load( std::memory_order_relaxed ) };
132  } else {
133  return v;
134  }
135  }

◆ merge()

template<typename Arithmetic , atomicity Atomicity>
static void Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::merge ( InternalType a,
RegularType  b 
)
inlinestaticnoexcept

Definition at line 144 of file StaticHistogram.h.

144  {
145  if constexpr ( isAtomic ) {
146  fetch_add( a.first, b.first );
147  fetch_add( a.second, b.second );
148  } else {
149  a.first += b.first;
150  a.second += b.second;
151  }
152  }

Member Data Documentation

◆ isAtomic

template<typename Arithmetic , atomicity Atomicity>
constexpr bool Gaudi::Accumulators::WeightedAdder< Arithmetic, Atomicity >::isAtomic = Atomicity == atomicity::full
staticconstexpr

Definition at line 127 of file StaticHistogram.h.


The documentation for this struct was generated from the following file:
Gaudi::Accumulators::WeightedAdder::isAtomic
static constexpr bool isAtomic
Definition: StaticHistogram.h:127
Gaudi::Accumulators::fetch_add
void fetch_add(AtomicType &atVar, Arithmetic value)
generic fetch_add, also dealing with atomic types with no fetch_add member method
Definition: Accumulators.h:366
Properties.v
v
Definition: Properties.py:122