Go to the documentation of this file.
19 template <
class Rep,
class Period>
21 template <
class Rep1,
class Rep2,
class Period>
207 #include "boost/format.hpp"
212 #include <nlohmann/json.hpp>
215 #include <type_traits>
224 template <
class Rep,
class Period>
225 struct adl_serializer<
std::chrono::duration<Rep, Period>> {
245 template <
typename T, T N>
247 template <
typename U>
257 template <
typename U>
258 constexpr decltype(
auto ) operator()( U&&
v )
const noexcept {
259 return std::forward<U>(
v );
267 template <
typename U>
268 constexpr decltype(
auto ) operator()( U&&
v )
const noexcept {
276 template <
typename T,
typename =
int>
278 template <
typename T>
279 inline constexpr
bool has_fetch_add_v = Gaudi::cpp17::is_detected_v<has_fetch_add_, T>;
284 template <
typename Arithmetic,
typename Result =
double>
285 using fp_result_type = std::conditional_t<std::is_integral_v<Arithmetic>, Result, Arithmetic>;
290 template <
typename Arithmetic, atomicity Atomicity>
296 template <
typename Arithmetic>
307 template <
typename Arithmetic>
312 return v.load( std::memory_order_relaxed );
321 template <
typename Arithmetic, atomicity Atomicity>
327 template <
typename Arithmetic>
338 template <
typename Arithmetic>
344 if ( DefaultValue() == b )
return;
345 if constexpr ( has_fetch_add_v<InternalType> ) {
346 a.fetch_add( b, std::memory_order_relaxed );
349 while ( !a.compare_exchange_weak( current, current + b ) )
359 template <
typename Arithmetic, atomicity Atomicity,
typename Compare, Arithmetic ( *Initial )()>
365 template <
typename Arithmetic,
typename Compare, Arithmetic ( *Initial )()>
371 if ( Compare{}( b, a ) ) a = b;
378 template <
typename Arithmetic,
typename Compare, Arithmetic ( *Initial )()>
385 while ( Compare{}( b, prev_value ) && !a.compare_exchange_weak( prev_value, b ) )
394 template <
typename Arithmetic, atomicity Atomicity = atomicity::full>
401 template <
typename Arithmetic, atomicity Atomicity = atomicity::full>
432 typename InputTransform = Identity,
typename OutputTransform = Identity,
433 typename ValueHandler = Adder<InnerType, Atomicity>>
435 template <
typename,
typename, atomicity,
typename,
typename,
typename>
440 #if __cplusplus >= 201703L
441 using OutputType = std::decay_t<std::invoke_result_t<OutputTransform, InnerType>>;
443 using OutputType = std::decay_t<std::result_of_t<OutputTransform( InnerType )>>;
453 template <atomicity ato,
typename VH>
457 template <
typename... Args>
466 template <atomicity ato,
typename VH>
470 template <atomicity ato,
typename VH>
480 return j.at( entries ).get<InnerType>();
484 typename ValueHandler::InternalType
m_value{ ValueHandler::DefaultValue() };
492 template <
typename Arithmetic,
atomicity Atomicity,
typename InputTypeT = Arithmetic,
493 template <atomicity,
typename>
class... Bases>
502 template <atomicity ato>
506 ( Bases<Atomicity, Arithmetic>::operator+=( by ), ... );
510 void reset() { ( Bases<Atomicity, Arithmetic>::reset(), ... ); }
511 template <atomicity Ato>
513 ( Bases<Atomicity, Arithmetic>::mergeAndReset(
static_cast<Bases<Ato, Arithmetic>&&
>( other ) ), ... );
515 template <atomicity Ato>
523 std::apply( [
this](
const auto&... i ) { ( this->Bases<Atomicity, Arithmetic>::reset( i ), ... ); },
t );
530 template <
size_t... Is>
532 std::index_sequence<Is...> ) {
537 typename Bases<Atomicity, Arithmetic>::JSONStringEntriesType... entries ) {
538 return { Bases<Atomicity, Arithmetic>::extractJSONData(
j, entries )... };
546 template <atomicity Atomicity,
typename Arithmetic =
double>
548 :
GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Maximum<Arithmetic, Atomicity>> {
558 template <atomicity Atomicity,
typename Arithmetic =
double>
560 :
GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Minimum<Arithmetic, Atomicity>> {
572 template <atomicity Atomicity,
typename Arithmetic =
double>
576 ( *this ) += Arithmetic{};
591 template <atomicity Atomicity,
typename Arithmetic =
double>
602 template <atomicity Atomicity,
typename Arithmetic =
unsigned long>
604 static_assert( std::is_integral_v<Arithmetic>,
605 "Invalid Arithmetic type for IntegralAccumulator. It must be an integral type" );
625 template <atomicity Atomicity,
typename Arithmetic =
double>
641 template <atomicity Atomicity,
typename Arithmetic>
657 template <atomicity Atomicity,
typename Arithmetic>
668 template <atomicity Atomicity,
typename Arithmetic>
673 template <
typename Result = fp_result_type<Arithmetic>>
676 if ( 1 > nbEntries )
return Result{ -1 };
677 return static_cast<Result
>( this->
nTrueEntries() ) / nbEntries;
681 template <
typename Result = fp_result_type<Arithmetic>>
688 if ( 1 > nbEntries )
return Result{ -1 };
689 return sqrt(
static_cast<Result
>( this->
nTrueEntries() * this->nFalseEntries() ) / nbEntries ) / nbEntries;
698 assert( b.nPass <= b.nTotal );
712 template <atomicity Atomicity,
typename Arithmetic,
template <atomicity,
typename>
typename CountAcc,
713 template <atomicity,
typename>
typename SumAcc>
715 :
AccumulatorSet<Arithmetic, Atomicity, typename CountAcc<Atomicity, Arithmetic>::InputType, CountAcc, SumAcc> {
716 static_assert( std::is_same_v<
typename CountAcc<Atomicity, Arithmetic>::InputType,
717 typename SumAcc<Atomicity, Arithmetic>::InputType>,
718 "Incompatible Counters in definition of AveragingAccumulator. Both should have identical Input" );
721 template <
typename Result = fp_result_type<Arithmetic>>
724 Result sum = this->sum();
725 return (
n > 0 ) ?
static_cast<Result
>( sum /
n ) : Result{};
733 template <atomicity Atomicity,
typename Arithmetic>
741 template <atomicity Atomicity,
typename Arithmetic,
template <atomicity,
typename>
typename AvgAcc,
742 template <atomicity,
typename>
typename SquareAcc>
744 :
AccumulatorSet<Arithmetic, Atomicity, typename AvgAcc<Atomicity, Arithmetic>::InputType, AvgAcc, SquareAcc> {
745 static_assert( std::is_same_v<
typename AvgAcc<Atomicity, Arithmetic>::InputType,
746 typename SquareAcc<Atomicity, Arithmetic>::InputType>,
747 "Incompatible Counters in definition of SigmaAccumulator. Both should have identical Input" );
750 template <
typename Result = fp_result_type<Arithmetic>>
753 Result sum = this->sum();
754 return (
n > 0 ) ?
static_cast<Result
>( ( this->sum2() - sum * ( sum /
n ) ) /
n ) : Result{};
757 template <
typename Result = fp_result_type<Arithmetic>>
760 Result sum = this->sum();
761 return (
n > 1 ) ?
static_cast<Result
>( ( this->sum2() - sum * ( sum /
n ) ) / (
n - 1 ) ) : Result{};
764 template <
typename Result = fp_result_type<Arithmetic>>
771 return ( Result{ 0 } >
v ) ? Result{} :
static_cast<Result
>(
sqrt(
v ) );
773 [[deprecated(
"The name 'rms' has changed to standard_deviation" )]] Arithmetic
rms()
const {
777 template <
typename Result = fp_result_type<Arithmetic>>
780 if ( 0 ==
n )
return Result{};
786 return ( Result{ 0 } >
v ) ? Result{} :
static_cast<Result
>(
sqrt(
v /
n ) );
794 template <atomicity Atomicity,
typename Arithmetic>
801 template <atomicity Atomicity,
typename Arithmetic>
811 template <
template <
atomicity Ato,
typename...
Int>
class ContainedAccumulator,
atomicity Atomicity, typename... Args>
812 class Buffer :
public ContainedAccumulator<atomicity::none, Args...> {
838 template <
typename stream>
873 template <
atomicity Atomicity,
template <
atomicity Ato,
typename...
Int>
class Accumulator, typename... Args>
876 using Accumulator<Atomicity, Args...>::Accumulator;
878 template <
typename OWNER>
884 if ( m_monitoringHub ) { m_monitoringHub->removeEntity( *
this ); }
890 template <
typename OWNER,
typename SELF,
typename... CARGS>
892 : Accumulator<Atomicity, Args...>(
args... ), m_monitoringHub( &o->serviceLocator()->monitoringHub() ) {
893 m_monitoringHub->registerEntity( o->name(),
name,
self.typeString,
self );
904 template <atomicity Atomicity = atomicity::full,
typename Arithmetic =
unsigned long>
908 template <
typename OWNER>
918 template <
typename stream>
921 auto fmt = ( tableFormat ?
"|%|10d| |" :
"#=%|-7lu|" );
942 template <
typename Arithmetic =
double, atomicity Atomicity = atomicity::full>
945 typeid( Arithmetic ).
name() };
947 template <
typename OWNER>
952 template <
typename stream>
954 auto fmt = ( tableFormat ?
"|%|10d| |%|11.7g| |%|#11.5g| |" :
"#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g|" );
968 {
"sum", this->sum() },
969 {
"mean", this->
mean() } };
975 template <
typename Arithmetic =
double, atomicity Atomicity = atomicity::full>
982 template <
typename Arithmetic =
double, atomicity Atomicity = atomicity::full>
986 template <
typename OWNER>
991 template <
typename stream>
993 auto fmt = ( tableFormat ?
"|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |"
994 :
"#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g|" );
1005 {
"empty", this->
nEntries() == 0 },
1007 {
"sum", this->sum() },
1008 {
"mean", this->
mean() },
1009 {
"sum2", this->sum2() },
1021 template <
typename Arithmetic =
double, atomicity Atomicity = atomicity::full>
1025 template <
typename OWNER>
1030 template <
typename stream>
1032 auto fmt = ( tableFormat ?
"|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |"
1033 :
"#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" );
1035 this->
min() % this->
max();
1045 {
"empty", this->
nEntries() == 0 },
1047 {
"sum", this->sum() },
1048 {
"mean", this->
mean() },
1049 {
"sum2", this->sum2() },
1050 {
"standard_deviation", this->standard_deviation() },
1051 {
"min", this->
min() },
1052 {
"max", this->
max() } };
1056 j, { { {
"nEntries",
"sum" },
"sum2" },
"min",
"max" } );
1064 template <
typename Arithmetic =
double, atomicity Atomicity = atomicity::full>
1067 typeid( Arithmetic ).
name() };
1069 template <
typename OWNER>
1073 template <
typename stream>
1075 auto fmt = ( tableFormat ?
"|%|10d| |%|11.5g| |(%|#9.7g| +- %|-#8.7g|)%% |"
1076 :
"#=%|-7lu| Sum=%|-11.5g| Eff=|(%|#9.7g| +- %|-#8.6g|)%%|" );
1086 template <
typename stream>
1090 return print( o,
true );
1098 {
"empty", this->
nEntries() == 0 },
1099 {
"nEntries", this->
nTrueEntries() + this->nFalseEntries() },
1101 {
"nFalseEntries", this->nFalseEntries() },
1110 namespace details::MsgCounter {
1111 template <atomicity Atomicity>
1114 static void merge(
typename Base::InternalType& orig,
bool b ) {
1120 template <atomicity Atomicity,
typename Arithmetic =
double>
1124 template <MSG::Level level, atomicity Atomicity = atomicity::full>
1128 template <
typename OWNER>
1133 template <
typename OWNER>
1149 template <
typename stream>
1151 return o <<
boost::format{ tableFormat ?
"|%|10d| |" :
"#=%|-7lu|" } % this->
value();
1159 {
"empty", this->
value() == 0 },
1160 {
"nEntries", this->
value() },
1166 return {
j.at(
"msg" ).get<
std::string>(),
j.at(
"max" ).get<
unsigned long>(),
1167 j.at(
"nEntries" ).get<
unsigned long>() };
1180 if ( this->
value() == max ) {
1194 template <
typename Counter,
typename Container,
typename Fun>
1197 for (
const auto& elem : container ) b += f( elem );
MsgCounter(std::string const &ms, unsigned long nMax, unsigned long count)
An empty ancester of all counters that knows how to print themselves.
Buffer< Accumulator, Atomicity, Args... > buffer()
stream & printImpl(stream &s, std::string_view tag) const
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
unsigned long InternalType
static const std::string typeString
static InternalType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
const CommonMessagingBase * logger
stream & printImpl(stream &o, bool tableFormat) const
CountAccumulator & operator++()
ContainedAccumulator< Atomicity, Args... > prime_type
std::ostream & print(std::ostream &o, std::string_view tag) const override
prints the counter to a stream in table format, with the given tag
Base type for all functors used as ValuesHandler.
BufferableCounter(BufferableCounter const &)=delete
AccumulatorSet & operator+=(const InputType by)
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.
ValueHandler::InternalType m_value
MsgCounter(MsgCounter const &)=delete
Monitoring::Hub * m_monitoringHub
A counter aiming at computing average and sum2 / variance / standard deviation.
static constexpr OutputType DefaultValue()
static constexpr OutputType getValue(const InternalType &v) noexcept
virtual bool toBePrinted() const
hint whether we should print that counter or not.
BufferableCounter & operator=(BufferableCounter const &)=delete
GenericAccumulator(InnerType in)
AccumulatorSet is an Accumulator that holds a set of Accumulators templated by same Arithmetic and At...
MsgCounter(OWNER *o, std::string const &ms, unsigned long nMax=10)
AveragingCounter(OWNER *o, std::string const &name)
static Arithmetic exchange(InternalType &v, Arithmetic newv) noexcept
long
(c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # # This software i...
static StatCounter fromJSON(const nlohmann::json &j)
MsgStream & print(MsgStream &os, bool tableFormat) const override
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
virtual ~PrintableCounter()=default
destructor
static constexpr OutputType getValue(const InternalType &v) noexcept
std::string toString() const
get a string representation
BufferableCounter()=default
bool toBePrinted() const override
hint whether we should print that counter or not.
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
static void merge(InternalType &a, Arithmetic b) noexcept
GenericAccumulator(std::in_place_t, Args &&... args)
static Counter fromJSON(const nlohmann::json &j)
virtual MsgStream & print(MsgStream &, bool tableFormat=true) const =0
MsgCounter & operator++()
A counter aiming at computing sum and average.
PrintableCounter()=default
Buffer(const Buffer &)=delete
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
AccumulatorSet(construct_empty_t, const AccumulatorSet< Arithmetic, ato, InputType, Bases... > &)
constructor of an empty AccumulatorSet, copying the (non existent) config from another GenericAccumul...
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
virtual std::ostream & print(std::ostream &o, std::string_view tag) const
prints the counter to a stream in table format, with the given tag
BinomialAccumulator & operator+=(binomial_t b)
BinomialCounter(OWNER *o, std::string const &name)
void operator+(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &&other)
MsgCounter & operator=(MsgCounter const &)=delete
stream & printImpl(stream &o, bool tableFormat) const
helper functor for the TrueAccumulator
MsgCounter(OWNER *o, std::string const &ms, int nMax)
AveragingAccumulatorBase.
static Arithmetic exchange(InternalType &v, Arithmetic newv) noexcept
ContainedAccumulator< atomicity::none, Args... > base_type
SigmaCounter(OWNER *o, std::string const &name)
Counter & operator+=(const Arithmetic v)
BufferableCounter(OWNER *o, std::string const &name)
static InternalType extractJSONDataHelper(const nlohmann::json &j, typename Bases< Atomicity, Arithmetic >::JSONStringEntriesType... entries)
MsgCounter & operator+=(const bool by)
void mergeAndReset(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &&other)
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
GenericAccumulator operator+=(const InputType by)
StatCounter(OWNER *o, std::string const &name)
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Arithmetic nEntries() const
An Extremum ValueHandler, to be reused for Minimum and Maximum operator(a, b) means if (Compare(b,...
IntegralAccumulator & operator++()
stream & printImpl(stream &o, bool tableFormat) const
An Adder ValueHandler operator(a, b) means a += b.
CountAccumulator operator++(int)
constexpr bool has_fetch_add_v
auto unbiased_sample_variance() const
auto efficiencyErr() const
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
virtual nlohmann::json toJSON() const =0
Basic JSON export for Gaudi::Monitoring::Hub support.
static void from_json(const json &j, std::chrono::duration< Rep, Period > &d)
static constexpr OutputType DefaultValue()
stream & printImpl(stream &o, std::string_view tag) const
std::tuple< typename Bases< Atomicity, Arithmetic >::InternalType... > InternalType
static constexpr OutputType DefaultValue()
GenericAccumulator(construct_empty_t, const GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &)
constructor of an empty GenericAccumulator, copying the (non existent) config from another GenericAcc...
friend class GenericAccumulator
static const std::string typeString
std::decay_t< std::result_of_t< Identity(unsigned long)> > OutputType
GenericAccumulator & operator=(const GenericAccumulator &other)
GenericAccumulator< bool, unsigned long, Atomicity, Identity, Identity, Handler< Atomicity > > MsgAccumulator
A counter dealing with binomial data.
static void merge(typename Base::InternalType &orig, bool b)
void registerEntity(std::string c, std::string n, std::string t, T &ent)
static void merge(InternalType &a, Arithmetic b) noexcept
static InternalType extractJSONDataHelper(const nlohmann::json &j, const JSONStringEntriesType &entries, std::index_sequence< Is... >)
void operator=(const Buffer &)=delete
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
std::ostream & print(std::ostream &os, bool tableFormat) const override
prints the counter to a stream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void removeEntity(T &ent)
CountAcc< Atomicity, Arithmetic >::InputType InputType
unsigned long nFalseEntries() const
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
constexpr AccumulatorSet()=default
Generic Accumulator, templated by.
BufferableCounter(OWNER *o, std::string const &name, SELF &self, CARGS... args)
A functor always returning the value N.
static void to_json(json &j, const std::chrono::duration< Rep, Period > &d)
MsgStream & msgStream() const
Return an uninitialized MsgStream.
bool toBePrinted() const override
hint whether we should print that counter or not.
An empty ancester of all counters that provides a buffer method that returns a buffer on itself Also ...
static const std::string typeString
GenericAccumulator()=default
int merge(const char *target, const char *source, bool fixup=false, bool dbg=true)
stream & printImpl(stream &o, bool tableFormat) const
static const std::string typeString
std::conditional_t< std::is_integral_v< Arithmetic >, Result, Arithmetic > fp_result_type
type_trait for the result type of a floating point operation on the type Arithmetic
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
AccumulatorSet(const InternalType &t)
virtual MsgStream & print(MsgStream &o, std::string_view tag) const
static InnerType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
bool toBePrinted() const override
hint whether we should print that counter or not.
auto standard_deviation() const
construct_empty_t()=default
constexpr construct_empty_t construct_empty
void mergeAndReset(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &&other)
helper functor for the FalseAccumulator
static BinomialCounter fromJSON(const nlohmann::json &j)
void reset(const InternalType &t)
Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-sa...
unsigned long nEntries() const
void operator+(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &&other)
stream & printImpl(stream &o, bool tableFormat) const
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
bool toBePrinted() const override
hint whether we should print that counter or not.
atomicity
Defines atomicity of the accumulators.
static void merge(InternalType &a, Arithmetic b) noexcept
GenericAccumulator(const GenericAccumulator &other)
static constexpr OutputType DefaultValue()
A counter aiming at computing average and sum2 / variance / standard deviation.
constant used to disambiguate construction of an empty Accumulator versus the copy constructor.
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
unsigned long nEntries() const
stream & printImpl(stream &o, bool tableFormat) const
static SigmaCounter fromJSON(const nlohmann::json &j)
auto biased_sample_variance() const
unsigned long nTrueEntries() const
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
virtual std::ostream & print(std::ostream &, bool tableFormat=false) const =0
prints the counter to a stream
Central entity in a Gaudi application that manages monitoring objects (i.e.
unsigned int operator()(bool v) const
Counter(OWNER *o, std::string const &name)
IntegralAccumulator operator++(int)
static void merge(InternalType &a, Arithmetic b) noexcept
unsigned int operator()(bool v) const
static const std::string typeString
MsgStream & print(MsgStream &o, std::string_view tag) const override
bool toBePrinted() const override
hint whether we should print that counter or not.
static MsgCounter fromJSON(const nlohmann::json &j)
static AveragingCounter fromJSON(const nlohmann::json &j)
bool toBePrinted() const override
hint whether we should print that counter or not.
constexpr T operator()(U &&) const noexcept
void accumulate(Counter &counter, const Container &container, Fun f=Identity{})
A helper function for accumulating data from a container into a counter This is internally using buff...
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
static const std::string typeString
std::ostream & operator<<(std::ostream &s, const PrintableCounter &counter)
external printout operator to a stream type
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
decltype(std::declval< T & >().fetch_add(0)) has_fetch_add_
type_traits for checking the presence of fetch_add
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.