The Gaudi Framework  v37r0 (b608885e)
Accumulators.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2021 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 
12 #pragma once
13 
14 #include <Gaudi/MonitoringHub.h>
15 
16 #include <chrono>
17 
18 namespace Gaudi::Accumulators {
19  template <class Rep, class Period>
21  template <class Rep1, class Rep2, class Period>
23 } // namespace Gaudi::Accumulators
24 
207 #include "boost/format.hpp"
208 #include <atomic>
209 #include <cmath>
210 #include <iostream>
211 #include <limits>
212 #include <nlohmann/json.hpp>
213 #include <sstream>
214 #include <tuple>
215 #include <type_traits>
216 #include <utility>
217 
219 #include "GaudiKernel/MsgStream.h"
220 #include "GaudiKernel/detected.h"
221 
222 // Json serialization for std::chrono::duration
223 namespace nlohmann {
224  template <class Rep, class Period>
225  struct adl_serializer<std::chrono::duration<Rep, Period>> {
226  static void to_json( json& j, const std::chrono::duration<Rep, Period>& d ) { j = d.count(); }
228  d = std::chrono::duration<Rep, Period>{ j.get<Rep>() };
229  }
230  };
231 } // namespace nlohmann
232 
233 namespace Gaudi::Accumulators {
234 
236  enum class atomicity { none, full };
237 
239  template <class T>
240  auto sqrt( T d );
241 
245  template <typename T, T N>
246  struct Constant {
247  template <typename U>
248  constexpr T operator()( U&& ) const noexcept {
249  return N;
250  }
251  };
252 
256  struct Identity {
257  template <typename U>
258  constexpr decltype( auto ) operator()( U&& v ) const noexcept {
259  return std::forward<U>( v );
260  }
261  };
262 
266  struct Square {
267  template <typename U>
268  constexpr decltype( auto ) operator()( U&& v ) const noexcept {
269  return v * v;
270  }
271  };
272 
276  template <typename T, typename = int>
277  using has_fetch_add_ = decltype( std::declval<T&>().fetch_add( 0 ) );
278  template <typename T>
279  inline constexpr bool has_fetch_add_v = Gaudi::cpp17::is_detected_v<has_fetch_add_, T>;
280 
284  template <typename Arithmetic, typename Result = double>
285  using fp_result_type = std::conditional_t<std::is_integral_v<Arithmetic>, Result, Arithmetic>;
286 
290  template <typename Arithmetic, atomicity Atomicity>
292 
296  template <typename Arithmetic>
297  struct BaseValueHandler<Arithmetic, atomicity::none> {
298  using OutputType = Arithmetic;
299  using InternalType = Arithmetic;
300  static constexpr OutputType getValue( const InternalType& v ) noexcept { return v; };
301  static Arithmetic exchange( InternalType& v, Arithmetic newv ) noexcept { return std::exchange( v, newv ); }
302  };
303 
307  template <typename Arithmetic>
308  struct BaseValueHandler<Arithmetic, atomicity::full> {
309  using OutputType = Arithmetic;
311  static constexpr OutputType getValue( const InternalType& v ) noexcept {
312  return v.load( std::memory_order_relaxed );
313  };
314  static Arithmetic exchange( InternalType& v, Arithmetic newv ) noexcept { return v.exchange( newv ); }
315  };
316 
321  template <typename Arithmetic, atomicity Atomicity>
322  struct Adder;
323 
327  template <typename Arithmetic>
328  struct Adder<Arithmetic, atomicity::none> : BaseValueHandler<Arithmetic, atomicity::none> {
331  static constexpr OutputType DefaultValue() { return Arithmetic{}; }
332  static void merge( InternalType& a, Arithmetic b ) noexcept { a += b; };
333  };
334 
338  template <typename Arithmetic>
339  struct Adder<Arithmetic, atomicity::full> : BaseValueHandler<Arithmetic, atomicity::full> {
342  static constexpr OutputType DefaultValue() { return Arithmetic{}; }
343  static void merge( InternalType& a, Arithmetic b ) noexcept {
344  if ( DefaultValue() == b ) return; // avoid atomic operation if b is "0"
345  if constexpr ( has_fetch_add_v<InternalType> ) {
346  a.fetch_add( b, std::memory_order_relaxed );
347  } else {
349  while ( !a.compare_exchange_weak( current, current + b ) )
350  ;
351  }
352  };
353  };
354 
359  template <typename Arithmetic, atomicity Atomicity, typename Compare, Arithmetic ( *Initial )()>
360  struct Extremum;
361 
365  template <typename Arithmetic, typename Compare, Arithmetic ( *Initial )()>
366  struct Extremum<Arithmetic, atomicity::none, Compare, Initial> : BaseValueHandler<Arithmetic, atomicity::none> {
369  static constexpr OutputType DefaultValue() { return Initial(); }
370  static void merge( InternalType& a, Arithmetic b ) noexcept {
371  if ( Compare{}( b, a ) ) a = b;
372  };
373  };
374 
378  template <typename Arithmetic, typename Compare, Arithmetic ( *Initial )()>
379  struct Extremum<Arithmetic, atomicity::full, Compare, Initial> : BaseValueHandler<Arithmetic, atomicity::full> {
382  static constexpr OutputType DefaultValue() { return Initial(); }
383  static void merge( InternalType& a, Arithmetic b ) noexcept {
384  Arithmetic prev_value = BaseValueHandler<Arithmetic, atomicity::full>::getValue( a );
385  while ( Compare{}( b, prev_value ) && !a.compare_exchange_weak( prev_value, b ) )
386  ;
387  };
388  };
389 
394  template <typename Arithmetic, atomicity Atomicity = atomicity::full>
396 
401  template <typename Arithmetic, atomicity Atomicity = atomicity::full>
403 
410  explicit construct_empty_t() = default;
411  };
413 
431  template <typename InputTypeT, typename InnerType, 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>
436  friend class GenericAccumulator;
437 
438  public:
439  using InputType = InputTypeT;
440 #if __cplusplus >= 201703L
441  using OutputType = std::decay_t<std::invoke_result_t<OutputTransform, InnerType>>;
442 #else
443  using OutputType = std::decay_t<std::result_of_t<OutputTransform( InnerType )>>;
444 #endif
445  using InternalType = InnerType;
448  ValueHandler::merge( m_value, InputTransform{}( by ) );
449  return *this;
450  }
451  GenericAccumulator() = default;
453  template <atomicity ato, typename VH>
456  : GenericAccumulator() {}
457  template <typename... Args>
458  GenericAccumulator( std::in_place_t, Args&&... args ) : m_value( std::forward<Args>( args )... ) {}
459  GenericAccumulator( const GenericAccumulator& other ) : m_value( ValueHandler::getValue( other.m_value ) ) {}
461  m_value = ValueHandler::getValue( other.m_value );
462  return *this;
463  }
464  OutputType value() const { return OutputTransform{}( ValueHandler::getValue( m_value ) ); }
465  void reset() { reset( ValueHandler::DefaultValue() ); }
466  template <atomicity ato, typename VH>
468  ValueHandler::merge( m_value, VH::exchange( other.m_value, VH::DefaultValue() ) );
469  }
470  template <atomicity ato, typename VH>
472  ValueHandler::merge( m_value, other.m_value );
473  }
474 
475  protected:
476  GenericAccumulator( InnerType in ) : m_value( std::move( in ) ) {}
477  auto rawValue() const { return ValueHandler::getValue( m_value ); }
478  void reset( InnerType in ) { m_value = std::move( in ); }
479  static InnerType extractJSONData( const nlohmann::json& j, const JSONStringEntriesType& entries ) {
480  return j.at( entries ).get<InnerType>();
481  }
482 
483  private:
484  typename ValueHandler::InternalType m_value{ ValueHandler::DefaultValue() };
485  };
486 
492  template <typename Arithmetic, atomicity Atomicity, typename InputTypeT = Arithmetic,
493  template <atomicity, typename> class... Bases>
494  class AccumulatorSet : public Bases<Atomicity, Arithmetic>... {
495  public:
496  using InputType = InputTypeT;
500  constexpr AccumulatorSet() = default;
502  template <atomicity ato>
504  : AccumulatorSet() {}
506  ( Bases<Atomicity, Arithmetic>::operator+=( by ), ... );
507  return *this;
508  }
509  OutputType value() const { return std::make_tuple( Bases<Atomicity, Arithmetic>::value()... ); }
511  template <atomicity Ato>
513  ( Bases<Atomicity, Arithmetic>::mergeAndReset( static_cast<Bases<Ato, Arithmetic>&>( other ) ), ... );
514  }
515  template <atomicity Ato>
517  ( Bases<Atomicity, Arithmetic>::operator+( static_cast<Bases<Ato, Arithmetic>&&>( other ) ), ... );
518  }
519 
520  protected:
522  void reset( const InternalType& t ) {
523  std::apply( [this]( const auto&... i ) { ( this->Bases<Atomicity, Arithmetic>::reset( i ), ... ); }, t );
524  }
526  return extractJSONDataHelper( j, entries, std::index_sequence_for<Bases<Atomicity, Arithmetic>...>{} );
527  }
528 
529  private:
530  template <size_t... Is>
532  std::index_sequence<Is...> ) {
533  return extractJSONDataHelper( j, std::get<Is>( entries )... );
534  }
535  static InternalType
537  typename Bases<Atomicity, Arithmetic>::JSONStringEntriesType... entries ) {
538  return { Bases<Atomicity, Arithmetic>::extractJSONData( j, entries )... };
539  }
540  };
541 
546  template <atomicity Atomicity, typename Arithmetic = double>
548  : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Maximum<Arithmetic, Atomicity>> {
549  using GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity,
551  Arithmetic max() const { return this->value(); }
552  };
553 
558  template <atomicity Atomicity, typename Arithmetic = double>
560  : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Minimum<Arithmetic, Atomicity>> {
561  using GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity,
563  Arithmetic min() const { return this->value(); }
564  };
565 
572  template <atomicity Atomicity, typename Arithmetic = double>
573  struct CountAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, Constant<unsigned long, 1UL>> {
576  ( *this ) += Arithmetic{};
577  return *this;
578  }
580  auto copy = *this;
581  ++( *this );
582  return copy;
583  }
584  unsigned long nEntries() const { return this->value(); }
585  };
586 
591  template <atomicity Atomicity, typename Arithmetic = double>
592  struct SumAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity> {
594  Arithmetic sum() const { return this->value(); }
595  };
596 
602  template <atomicity Atomicity, typename Arithmetic = unsigned long>
603  struct IntegralAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity> {
604  static_assert( std::is_integral_v<Arithmetic>,
605  "Invalid Arithmetic type for IntegralAccumulator. It must be an integral type" );
606 
609  ( *this ) += 1;
610  return *this;
611  }
613  auto copy = *this;
614  ++( *this );
615  return copy;
616  }
617  Arithmetic nEntries() const { return this->value(); }
618  Arithmetic sum() const { return this->value(); }
619  };
620 
625  template <atomicity Atomicity, typename Arithmetic = double>
626  struct SquareAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Square> {
628  Arithmetic sum2() const { return this->value(); };
629  };
630 
632  struct TrueTo1 {
633  unsigned int operator()( bool v ) const { return v; }
634  };
635 
641  template <atomicity Atomicity, typename Arithmetic>
642  struct TrueAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, TrueTo1> {
644  unsigned long nTrueEntries() const { return this->value(); };
645  };
646 
648  struct FalseTo1 {
649  unsigned int operator()( bool v ) const { return !v; }
650  };
651 
657  template <atomicity Atomicity, typename Arithmetic>
658  struct FalseAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, FalseTo1> {
660  unsigned long nFalseEntries() const { return this->value(); };
661  };
662 
668  template <atomicity Atomicity, typename Arithmetic>
669  struct BinomialAccumulator : AccumulatorSet<bool, Atomicity, bool, TrueAccumulator, FalseAccumulator> {
671  unsigned long nEntries() const { return this->nTrueEntries() + this->nFalseEntries(); };
672 
673  template <typename Result = fp_result_type<Arithmetic>>
674  auto efficiency() const {
675  auto nbEntries = nEntries();
676  if ( 1 > nbEntries ) return Result{ -1 };
677  return static_cast<Result>( this->nTrueEntries() ) / nbEntries;
678  }
679  auto eff() const { return efficiency(); }
680 
681  template <typename Result = fp_result_type<Arithmetic>>
682  auto efficiencyErr() const {
683  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
684  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
686  using std::sqrt;
687  auto nbEntries = nEntries();
688  if ( 1 > nbEntries ) return Result{ -1 };
689  return sqrt( static_cast<Result>( this->nTrueEntries() * this->nFalseEntries() ) / nbEntries ) / nbEntries;
690  }
691  auto effErr() const { return efficiencyErr(); }
693  struct binomial_t {
694  unsigned long nPass;
695  unsigned long nTotal;
696  };
697  BinomialAccumulator& operator+=( binomial_t b ) {
698  assert( b.nPass <= b.nTotal );
699  TrueAccumulator<atomicity::none, bool> t{ std::in_place, b.nPass };
701  FalseAccumulator<atomicity::none, bool> f{ std::in_place, b.nTotal - b.nPass };
703  return *this;
704  }
705  };
706 
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" );
720  SumAcc>::AccumulatorSet;
721  template <typename Result = fp_result_type<Arithmetic>>
722  auto mean() const {
723  auto n = this->nEntries();
724  Result sum = this->sum();
725  return ( n > 0 ) ? static_cast<Result>( sum / n ) : Result{};
726  }
727  };
728 
733  template <atomicity Atomicity, typename Arithmetic>
735 
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" );
749  SquareAcc>::AccumulatorSet;
750  template <typename Result = fp_result_type<Arithmetic>>
751  auto biased_sample_variance() const {
752  auto n = this->nEntries();
753  Result sum = this->sum();
754  return ( n > 0 ) ? static_cast<Result>( ( this->sum2() - sum * ( sum / n ) ) / n ) : Result{};
755  }
756 
757  template <typename Result = fp_result_type<Arithmetic>>
759  auto n = this->nEntries();
760  Result sum = this->sum();
761  return ( n > 1 ) ? static_cast<Result>( ( this->sum2() - sum * ( sum / n ) ) / ( n - 1 ) ) : Result{};
762  }
763 
764  template <typename Result = fp_result_type<Arithmetic>>
765  auto standard_deviation() const {
766  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
767  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
769  using std::sqrt;
770  Result v = biased_sample_variance();
771  return ( Result{ 0 } > v ) ? Result{} : static_cast<Result>( sqrt( v ) );
772  }
773  [[deprecated( "The name 'rms' has changed to standard_deviation" )]] Arithmetic rms() const {
774  return standard_deviation();
775  }
776 
777  template <typename Result = fp_result_type<Arithmetic>>
778  auto meanErr() const {
779  auto n = this->nEntries();
780  if ( 0 == n ) return Result{};
781  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
782  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
784  using std::sqrt;
785  Result v = biased_sample_variance();
786  return ( Result{ 0 } > v ) ? Result{} : static_cast<Result>( sqrt( v / n ) );
787  }
788  };
789 
794  template <atomicity Atomicity, typename Arithmetic>
796 
801  template <atomicity Atomicity, typename Arithmetic>
804 
811  template <template <atomicity Ato, typename... Int> class ContainedAccumulator, atomicity Atomicity, typename... Args>
812  class Buffer : public ContainedAccumulator<atomicity::none, Args...> {
813  using prime_type = ContainedAccumulator<Atomicity, Args...>;
814  using base_type = ContainedAccumulator<atomicity::none, Args...>;
815 
816  public:
817  Buffer() = delete;
818  Buffer( prime_type& p ) : base_type( construct_empty, p ), m_prime( p ) {}
819  Buffer( const Buffer& ) = delete;
820  void operator=( const Buffer& ) = delete;
821  Buffer( Buffer&& other ) : base_type( other ), m_prime( other.m_prime ) { other.reset(); }
822  void push() { m_prime.mergeAndReset( static_cast<base_type&>( *this ) ); }
823  ~Buffer() { push(); }
824 
825  private:
827  };
828 
834  PrintableCounter() = default;
836  virtual ~PrintableCounter() = default;
837  // add tag to printout
838  template <typename stream>
839  stream& printImpl( stream& s, std::string_view tag ) const {
840  s << boost::format{ " | %|-48.48s|%|50t|" } % ( std::string{ '\"' }.append( tag ).append( "\"" ) );
841  return print( s, true );
842  }
844  virtual std::ostream& print( std::ostream&, bool tableFormat = false ) const = 0;
845  virtual MsgStream& print( MsgStream&, bool tableFormat = true ) const = 0;
847  virtual std::ostream& print( std::ostream& o, std::string_view tag ) const { return printImpl( o, tag ); }
848  virtual MsgStream& print( MsgStream& o, std::string_view tag ) const { return printImpl( o, tag ); }
851  virtual bool toBePrinted() const { return true; }
854  std::ostringstream ost;
855  print( ost );
856  return ost.str();
857  }
858  };
859 
863  inline std::ostream& operator<<( std::ostream& s, const PrintableCounter& counter ) { return counter.print( s ); }
864  inline MsgStream& operator<<( MsgStream& s, const PrintableCounter& counter ) { return counter.print( s ); }
871  template <atomicity Atomicity, template <atomicity Ato, typename... Int> class Accumulator, typename... Args>
872  class BufferableCounter : public PrintableCounter, public Accumulator<Atomicity, Args...> {
873  public:
874  using Accumulator<Atomicity, Args...>::Accumulator;
875  BufferableCounter() = default;
876  template <typename OWNER>
877  BufferableCounter( OWNER* o, std::string const& name ) : BufferableCounter( o, name, *this ) {}
878  Buffer<Accumulator, Atomicity, Args...> buffer() { return { *this }; }
882  if ( m_monitoringHub ) { m_monitoringHub->removeEntity( *this ); }
883  }
884 
885  inline static const std::string typeString{ "counter" };
886 
887  protected:
888  template <typename OWNER, typename SELF, typename... CARGS>
889  BufferableCounter( OWNER* o, std::string const& name, SELF& self, CARGS... args )
890  : Accumulator<Atomicity, Args...>( args... ), m_monitoringHub( &o->serviceLocator()->monitoringHub() ) {
891  m_monitoringHub->registerEntity( o->name(), name, self.typeString, self );
892  }
893 
894  private:
895  Monitoring::Hub* m_monitoringHub{ nullptr };
896  };
897 
902  template <atomicity Atomicity = atomicity::full, typename Arithmetic = unsigned long>
903  struct Counter : BufferableCounter<Atomicity, IntegralAccumulator, Arithmetic> {
904  inline static const std::string typeString{ std::string{ "counter:Counter:" } + typeid( Arithmetic ).name() };
906  template <typename OWNER>
907  Counter( OWNER* o, std::string const& name )
908  : BufferableCounter<Atomicity, IntegralAccumulator, Arithmetic>( o, name, *this ) {}
909  Counter& operator++() { return ( *this ) += 1; }
910  Counter& operator+=( const Arithmetic v ) {
912  return *this;
913  }
915 
916  template <typename stream>
917  stream& printImpl( stream& o, bool tableFormat ) const {
918  // Avoid printing empty counters in non DEBUG mode
919  auto fmt = ( tableFormat ? "|%|10d| |" : "#=%|-7lu|" );
920  return o << boost::format{ fmt } % this->nEntries();
921  }
922 
923  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
924  return printImpl( o, tableFormat );
925  }
926  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
927  bool toBePrinted() const override { return this->nEntries() > 0; }
928  friend void reset( Counter& c ) { c.reset(); }
929  friend void mergeAndReset( Counter& c, Counter& o ) { c.mergeAndReset( o ); }
930  friend void to_json( nlohmann::json& j, Counter const& c ) {
931  j = { { "type", c.typeString }, { "empty", c.nEntries() == 0 }, { "nEntries", c.nEntries() } };
932  }
933  static Counter fromJSON( const nlohmann::json& j ) {
935  }
936  };
937 
942  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
943  struct AveragingCounter : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic> {
944  inline static const std::string typeString{ std::string{ "counter:AveragingCounter:" } +
945  typeid( Arithmetic ).name() };
947  template <typename OWNER>
948  AveragingCounter( OWNER* o, std::string const& name )
949  : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic>( o, name, *this ) {}
951 
952  template <typename stream>
953  stream& printImpl( stream& o, bool tableFormat ) const {
954  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |" : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g|" );
955  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean();
956  }
957 
958  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
959  return printImpl( o, tableFormat );
960  }
961  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
962 
963  bool toBePrinted() const override { return this->nEntries() > 0; }
964  friend void reset( AveragingCounter& c ) { return c.reset(); }
965  friend void mergeAndReset( AveragingCounter& c, AveragingCounter& o ) { c.mergeAndReset( o ); }
966  friend void to_json( nlohmann::json& j, AveragingCounter const& c ) {
967  j = { { "type", c.typeString },
968  { "empty", c.nEntries() == 0 },
969  { "nEntries", c.nEntries() },
970  { "sum", c.sum() },
971  { "mean", c.mean() } };
972  }
974  return AveragingAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { "nEntries", "sum" } );
975  }
976  };
977  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
979 
984  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
985  struct SigmaCounter : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic> {
986  inline static const std::string typeString{ std::string{ "counter:SigmaCounter:" } + typeid( Arithmetic ).name() };
988  template <typename OWNER>
989  SigmaCounter( OWNER* o, std::string const& name )
990  : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic>( o, name, *this ) {}
992 
993  template <typename stream>
994  stream& printImpl( stream& o, bool tableFormat ) const {
995  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |"
996  : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g|" );
997  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean() % this->standard_deviation();
998  }
999 
1000  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1001  return printImpl( o, tableFormat );
1002  }
1003  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1004  bool toBePrinted() const override { return this->nEntries() > 0; }
1005  friend void reset( SigmaCounter& c ) { c.reset(); }
1006  friend void mergeAndReset( SigmaCounter& c, SigmaCounter& o ) { c.mergeAndReset( o ); }
1007  friend void to_json( nlohmann::json& j, SigmaCounter const& c ) {
1008  j = { { "type", c.typeString },
1009  { "empty", c.nEntries() == 0 },
1010  { "nEntries", c.nEntries() },
1011  { "sum", c.sum() },
1012  { "mean", c.mean() },
1013  { "sum2", c.sum2() },
1014  { "standard_deviation", c.standard_deviation() } };
1015  }
1017  return SigmaAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { { "nEntries", "sum" }, "sum2" } );
1018  }
1019  };
1020 
1025  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
1026  struct StatCounter : BufferableCounter<Atomicity, StatAccumulator, Arithmetic> {
1027  inline static const std::string typeString{ std::string{ "counter:StatCounter:" } + typeid( Arithmetic ).name() };
1029  template <typename OWNER>
1030  StatCounter( OWNER* o, std::string const& name )
1031  : BufferableCounter<Atomicity, StatAccumulator, Arithmetic>( o, name, *this ) {}
1033 
1034  template <typename stream>
1035  stream& printImpl( stream& o, bool tableFormat ) const {
1036  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |"
1037  : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" );
1038  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean() % this->standard_deviation() %
1039  this->min() % this->max();
1040  }
1041 
1042  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1043  return printImpl( o, tableFormat );
1044  }
1045  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1046  bool toBePrinted() const override { return this->nEntries() > 0; }
1047  friend void reset( StatCounter& c ) { c.reset(); }
1048  friend void mergeAndReset( StatCounter& c, StatCounter& o ) { c.mergeAndReset( o ); }
1049  friend void to_json( nlohmann::json& j, StatCounter const& c ) {
1050  j = { { "type", c.typeString },
1051  { "empty", c.nEntries() == 0 },
1052  { "nEntries", c.nEntries() },
1053  { "sum", c.sum() },
1054  { "mean", c.mean() },
1055  { "sum2", c.sum2() },
1056  { "standard_deviation", c.standard_deviation() },
1057  { "min", c.min() },
1058  { "max", c.max() } };
1059  }
1062  j, { { { "nEntries", "sum" }, "sum2" }, "min", "max" } );
1063  }
1064  };
1065 
1070  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
1071  struct BinomialCounter : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic> {
1072  inline static const std::string typeString{ std::string{ "counter:BinomialCounter:" } +
1073  typeid( Arithmetic ).name() };
1075  template <typename OWNER>
1076  BinomialCounter( OWNER* o, std::string const& name )
1077  : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic>( o, name, *this ) {}
1078 
1079  template <typename stream>
1080  stream& printImpl( stream& o, bool tableFormat ) const {
1081  auto fmt = ( tableFormat ? "|%|10d| |%|11.5g| |(%|#9.7g| +- %|-#8.7g|)%% |"
1082  : "#=%|-7lu| Sum=%|-11.5g| Eff=|(%|#9.7g| +- %|-#8.6g|)%%|" );
1083  return o << boost::format{ fmt } % this->nEntries() % this->nTrueEntries() % ( this->efficiency() * 100 ) %
1084  ( this->efficiencyErr() * 100 );
1085  }
1086 
1087  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1088  return printImpl( o, tableFormat );
1089  }
1090  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1091 
1092  template <typename stream>
1093  stream& printImpl( stream& o, std::string_view tag ) const {
1094  // override default print to add a '*' in from of the name
1095  o << boost::format{ " |*%|-48.48s|%|50t|" } % ( std::string{ "\"" }.append( tag ).append( "\"" ) );
1096  return print( o, true );
1097  }
1099  std::ostream& print( std::ostream& o, std::string_view tag ) const override { return printImpl( o, tag ); }
1100  MsgStream& print( MsgStream& o, std::string_view tag ) const override { return printImpl( o, tag ); }
1101  bool toBePrinted() const override { return this->nEntries() > 0; }
1102  friend void reset( BinomialCounter& c ) { c.reset(); }
1103  friend void mergeAndReset( BinomialCounter& c, BinomialCounter& o ) { c.mergeAndReset( o ); }
1104  friend void to_json( nlohmann::json& j, BinomialCounter const& c ) {
1105  j = { { "type", c.typeString },
1106  { "empty", c.nEntries() == 0 },
1107  { "nEntries", c.nTrueEntries() + c.nFalseEntries() },
1108  { "nTrueEntries", c.nTrueEntries() },
1109  { "nFalseEntries", c.nFalseEntries() },
1110  { "efficiency", c.efficiency() },
1111  { "efficiencyErr", c.efficiencyErr() } };
1112  }
1114  return BinomialAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { "nTrueEntries", "nFalseEntries" } );
1115  }
1116  };
1117 
1118  namespace details::MsgCounter {
1119  template <atomicity Atomicity>
1120  struct Handler : Adder<unsigned long, Atomicity> {
1122  static void merge( typename Base::InternalType& orig, bool b ) {
1123  if ( b ) Base::merge( orig, 1 );
1124  }
1125  };
1126  // note that Arithmetic type is unused in this case but needs to be there in case
1127  // we want to create AccumulatorSets with this Accumulator
1128  template <atomicity Atomicity, typename Arithmetic = double>
1130  } // namespace details::MsgCounter
1131 
1132  template <MSG::Level level, atomicity Atomicity = atomicity::full>
1134  public:
1135  inline static const std::string typeString{ "counter:MsgCounter" };
1136  template <typename OWNER>
1137  MsgCounter( OWNER* o, std::string const& ms, unsigned long nMax = 10 )
1138  : m_monitoringHub{ &o->serviceLocator()->monitoringHub() }, logger( o ), msg( ms ), max( nMax ) {
1139  m_monitoringHub->registerEntity( o->name(), ms, typeString, *this );
1140  }
1141  template <typename OWNER>
1142  MsgCounter( OWNER* o, std::string const& ms, int nMax ) : MsgCounter( o, ms, static_cast<unsigned long>( nMax ) ) {}
1144  ( *this ) += true;
1145  return *this;
1146  }
1147  MsgCounter& operator+=( const bool by ) {
1149  if ( by ) log();
1150  return *this;
1151  }
1152  MsgCounter( MsgCounter const& ) = delete;
1153  MsgCounter& operator=( MsgCounter const& ) = delete;
1155  if ( m_monitoringHub ) m_monitoringHub->removeEntity( *this );
1156  }
1157  template <typename stream>
1158  stream& printImpl( stream& o, bool tableFormat ) const {
1159  return o << boost::format{ tableFormat ? "|%|10d| |" : "#=%|-7lu|" } % this->value();
1160  }
1162  std::ostream& print( std::ostream& os, bool tableFormat ) const override { return printImpl( os, tableFormat ); }
1163  MsgStream& print( MsgStream& os, bool tableFormat ) const override { return printImpl( os, tableFormat ); }
1164  bool toBePrinted() const override { return this->value() > 0; }
1165  friend void reset( MsgCounter& c ) { c.reset(); }
1166  friend void mergeAndReset( MsgCounter& c, MsgCounter& o ) { c.mergeAndReset( o ); }
1167  friend void to_json( nlohmann::json& j, MsgCounter const& c ) {
1168  j = { { "type", c.typeString }, { "empty", c.value() == 0 },
1169  { "nEntries", c.value() }, { "level", level },
1170  { "max", c.max }, { "msg", c.msg } };
1171  }
1173  return { j.at( "msg" ).get<std::string>(), j.at( "max" ).get<unsigned long>(),
1174  j.at( "nEntries" ).get<unsigned long>() };
1175  }
1176 
1177  private:
1178  MsgCounter( std::string const& ms, unsigned long nMax, unsigned long count )
1179  : details::MsgCounter::MsgAccumulator<Atomicity>{ count }, msg( ms ), max( nMax ) {}
1180 
1182  const CommonMessagingBase* logger{ nullptr };
1184  unsigned long max;
1185  void log() {
1186  if ( this->value() <= max && logger ) {
1187  if ( this->value() == max ) {
1188  logger->msgStream( level ) << "Suppressing message: " << std::quoted( msg, '\'' ) << endmsg;
1189  } else {
1190  logger->msgStream( level ) << msg << endmsg;
1191  }
1192  }
1193  }
1194  };
1195 
1201  template <typename Counter, typename Container, typename Fun>
1202  void accumulate( Counter& counter, const Container& container, Fun f = Identity{} ) {
1203  auto b = counter.buffer();
1204  for ( const auto& elem : container ) b += f( elem );
1205  }
1206 
1207 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(std::string const &ms, unsigned long nMax, unsigned long count)
Definition: Accumulators.h:1178
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::full >::OutputType
Arithmetic OutputType
Definition: Accumulators.h:309
Gaudi::Accumulators::PrintableCounter
An empty ancester of all counters that knows how to print themselves.
Definition: Accumulators.h:833
Gaudi::Accumulators::BufferableCounter::buffer
Buffer< Accumulator, Atomicity, Args... > buffer()
Definition: Accumulators.h:878
Gaudi::Accumulators::PrintableCounter::printImpl
stream & printImpl(stream &s, std::string_view tag) const
Definition: Accumulators.h:839
Gaudi::Accumulators::sqrt
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::InternalType
unsigned long InternalType
Definition: Accumulators.h:445
Gaudi::Accumulators::BinomialCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1072
Gaudi::Accumulators::Buffer::m_prime
prime_type & m_prime
Definition: Accumulators.h:826
Gaudi::Accumulators::AccumulatorSet::extractJSONData
static InternalType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
Definition: Accumulators.h:525
std::make_tuple
T make_tuple(T... args)
Gaudi::Accumulators::MsgCounter::logger
const CommonMessagingBase * logger
Definition: Accumulators.h:1182
Gaudi::Accumulators::MsgCounter::mergeAndReset
friend void mergeAndReset(MsgCounter &c, MsgCounter &o)
Definition: Accumulators.h:1166
Gaudi::Accumulators::StatCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1035
Gaudi::Accumulators::CountAccumulator::operator++
CountAccumulator & operator++()
Definition: Accumulators.h:575
Gaudi::Accumulators::MsgCounter::log
void log()
Definition: Accumulators.h:1185
Write.stream
stream
Definition: Write.py:32
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::InternalType
Arithmetic InternalType
Definition: Accumulators.h:299
Gaudi::Accumulators::Buffer::prime_type
ContainedAccumulator< Atomicity, Args... > prime_type
Definition: Accumulators.h:813
std::string
STL class.
Gaudi::Accumulators::Buffer::push
void push()
Definition: Accumulators.h:822
Gaudi::Accumulators::TrueAccumulator
TrueAccumulator.
Definition: Accumulators.h:642
IOTest.N
N
Definition: IOTest.py:110
Gaudi::Accumulators::BinomialCounter::print
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
Definition: Accumulators.h:1099
Gaudi::Accumulators::BaseValueHandler
Base type for all functors used as ValuesHandler.
Definition: Accumulators.h:291
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(BufferableCounter const &)=delete
Gaudi::Accumulators::AccumulatorSet::operator+=
AccumulatorSet & operator+=(const InputType by)
Definition: Accumulators.h:505
Gaudi::Accumulators::SigmaCounter::reset
friend void reset(SigmaCounter &c)
Definition: Accumulators.h:1005
Gaudi::Accumulators::operator*
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.
Definition: Counters.h:40
Gaudi::Accumulators::GenericAccumulator::m_value
ValueHandler::InternalType m_value
Definition: Accumulators.h:484
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(MsgCounter const &)=delete
Gaudi::Accumulators::MsgCounter::m_monitoringHub
Monitoring::Hub * m_monitoringHub
Definition: Accumulators.h:1181
std::move
T move(T... args)
bug_34121.name
name
Definition: bug_34121.py:20
Gaudi::Accumulators::SigmaCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:985
Gaudi::Accumulators::Adder< Arithmetic, atomicity::full >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:342
Gaudi::Accumulators::AccumulatorSet::mergeAndReset
void mergeAndReset(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &other)
Definition: Accumulators.h:512
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::full >::getValue
static constexpr OutputType getValue(const InternalType &v) noexcept
Definition: Accumulators.h:311
Gaudi::Accumulators::PrintableCounter::toBePrinted
virtual bool toBePrinted() const
hint whether we should print that counter or not.
Definition: Accumulators.h:851
Gaudi::Accumulators::BufferableCounter::operator=
BufferableCounter & operator=(BufferableCounter const &)=delete
MonitoringHub.h
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(InnerType in)
Definition: Accumulators.h:476
Gaudi::Accumulators::StatCounter::mergeAndReset
friend void mergeAndReset(StatCounter &c, StatCounter &o)
Definition: Accumulators.h:1048
Gaudi::Accumulators::GenericAccumulator::rawValue
auto rawValue() const
Definition: Accumulators.h:477
Gaudi::Accumulators::AccumulatorSet
AccumulatorSet is an Accumulator that holds a set of Accumulators templated by same Arithmetic and At...
Definition: Accumulators.h:494
Gaudi::Accumulators::SumAccumulator
SumAccumulator.
Definition: Accumulators.h:592
Gaudi::Accumulators::Counter
A basic integral counter;.
Definition: Accumulators.h:903
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(OWNER *o, std::string const &ms, unsigned long nMax=10)
Definition: Accumulators.h:1137
Gaudi::Accumulators::AveragingCounter::AveragingCounter
AveragingCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:948
Gaudi::Accumulators::atomicity::full
@ full
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::exchange
static Arithmetic exchange(InternalType &v, Arithmetic newv) noexcept
Definition: Accumulators.h:301
Properties.long
long
(c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # # This software i...
Definition: Properties.py:15
gaudirun.s
string s
Definition: gaudirun.py:348
Gaudi::Accumulators::StatCounter::fromJSON
static StatCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1060
Gaudi::Accumulators::MsgCounter::print
MsgStream & print(MsgStream &os, bool tableFormat) const override
Definition: Accumulators.h:1163
Gaudi::Accumulators::SigmaCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1000
Gaudi::Accumulators::PrintableCounter::~PrintableCounter
virtual ~PrintableCounter()=default
destructor
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::getValue
static constexpr OutputType getValue(const InternalType &v) noexcept
Definition: Accumulators.h:300
Gaudi::Accumulators::PrintableCounter::toString
std::string toString() const
get a string representation
Definition: Accumulators.h:853
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter()=default
Gaudi::Accumulators::details::MsgCounter::Handler
Definition: Accumulators.h:1120
Gaudi::Accumulators::BinomialCounter::to_json
friend void to_json(nlohmann::json &j, BinomialCounter const &c)
Definition: Accumulators.h:1104
Gaudi::Accumulators::MsgCounter::msg
std::string msg
Definition: Accumulators.h:1183
Gaudi::Accumulators::IntegralAccumulator
IntegralAccumulator.
Definition: Accumulators.h:603
jsonFromLHCbLog.json
json
Definition: jsonFromLHCbLog.py:87
Gaudi::Accumulators::BinomialCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1101
Gaudi::Accumulators::AveragingCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:958
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::none, Compare, Initial >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:370
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(std::in_place_t, Args &&... args)
Definition: Accumulators.h:458
Gaudi::Accumulators::SquareAccumulator
SquareAccumulator.
Definition: Accumulators.h:626
std::chrono::duration
Gaudi::Accumulators::MsgCounter::reset
friend void reset(MsgCounter &c)
Definition: Accumulators.h:1165
Gaudi::Accumulators::GenericAccumulator::reset
void reset()
Definition: Accumulators.h:465
Gaudi::Accumulators::Counter::fromJSON
static Counter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:933
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::OutputType
Arithmetic OutputType
Definition: Accumulators.h:298
Gaudi::Accumulators::PrintableCounter::print
virtual MsgStream & print(MsgStream &, bool tableFormat=true) const =0
nlohmann
Definition: Accumulators.h:223
Gaudi::Accumulators::MsgCounter::operator++
MsgCounter & operator++()
Definition: Accumulators.h:1143
Gaudi::Accumulators::MsgCounter::~MsgCounter
~MsgCounter()
Definition: Accumulators.h:1154
CommonMessagingBase
Definition: CommonMessaging.h:68
Gaudi::Accumulators::MinAccumulator
MinAccumulator.
Definition: Accumulators.h:560
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition: Accumulators.h:943
Gaudi::Accumulators::PrintableCounter::PrintableCounter
PrintableCounter()=default
Gaudi::Accumulators::AccumulatorSet::reset
void reset()
Definition: Accumulators.h:510
Gaudi::Accumulators::Buffer::Buffer
Buffer(const Buffer &)=delete
Gaudi::Accumulators::Counter::mergeAndReset
friend void mergeAndReset(Counter &c, Counter &o)
Definition: Accumulators.h:929
Gaudi::Accumulators::BinomialCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1090
Gaudi::Accumulators::AccumulatorSet::AccumulatorSet
AccumulatorSet(construct_empty_t, const AccumulatorSet< Arithmetic, ato, InputType, Bases... > &)
constructor of an empty AccumulatorSet, copying the (non existent) config from another GenericAccumul...
Definition: Accumulators.h:503
Gaudi::Accumulators::BinomialCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1087
std::tuple
Gaudi::Accumulators::MinAccumulator::min
Arithmetic min() const
Definition: Accumulators.h:563
gaudirun.c
c
Definition: gaudirun.py:527
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
Gaudi::Accumulators::PrintableCounter::print
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
Definition: Accumulators.h:847
Gaudi::Accumulators::SigmaAccumulatorBase::meanErr
auto meanErr() const
Definition: Accumulators.h:778
class
#define class
Definition: HistogramPersistencySvc.cpp:54
Gaudi::Accumulators::BinomialAccumulator::operator+=
BinomialAccumulator & operator+=(binomial_t b)
Definition: Accumulators.h:697
Gaudi::Accumulators::BinomialCounter::BinomialCounter
BinomialCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:1076
Gaudi::Accumulators::AccumulatorSet::operator+
void operator+(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &&other)
Definition: Accumulators.h:516
Gaudi::Accumulators::MsgCounter::operator=
MsgCounter & operator=(MsgCounter const &)=delete
Gaudi::Accumulators::Counter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:917
Gaudi::Accumulators::TrueTo1
helper functor for the TrueAccumulator
Definition: Accumulators.h:632
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(OWNER *o, std::string const &ms, int nMax)
Definition: Accumulators.h:1142
Gaudi::Accumulators::AveragingAccumulatorBase
AveragingAccumulatorBase.
Definition: Accumulators.h:715
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::full >::exchange
static Arithmetic exchange(InternalType &v, Arithmetic newv) noexcept
Definition: Accumulators.h:314
Gaudi::Accumulators::Buffer::base_type
ContainedAccumulator< atomicity::none, Args... > base_type
Definition: Accumulators.h:814
Gaudi::Accumulators::SigmaCounter::SigmaCounter
SigmaCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:989
Gaudi::Accumulators::BinomialAccumulator::binomial_t
Definition: Accumulators.h:693
std::sqrt
T sqrt(T... args)
Gaudi::Accumulators::Counter::operator+=
Counter & operator+=(const Arithmetic v)
Definition: Accumulators.h:910
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:877
Gaudi::Accumulators::AccumulatorSet::extractJSONDataHelper
static InternalType extractJSONDataHelper(const nlohmann::json &j, typename Bases< Atomicity, Arithmetic >::JSONStringEntriesType... entries)
Definition: Accumulators.h:536
Gaudi::Accumulators::Square
A Square functor.
Definition: Accumulators.h:266
Gaudi::Accumulators::Counter::operator++
Counter & operator++()
Definition: Accumulators.h:909
Gaudi::Units::ms
constexpr double ms
Definition: SystemOfUnits.h:154
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::InputType
bool InputType
Definition: Accumulators.h:439
Gaudi::Accumulators::MsgCounter::operator+=
MsgCounter & operator+=(const bool by)
Definition: Accumulators.h:1147
Gaudi::Accumulators::Counter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:926
Gaudi::Accumulators::GenericAccumulator::operator+=
GenericAccumulator operator+=(const InputType by)
Definition: Accumulators.h:447
Gaudi::Accumulators::StatCounter::StatCounter
StatCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:1030
Gaudi::Accumulators::StatCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1042
bug_34121.t
t
Definition: bug_34121.py:30
Gaudi::Accumulators::BinomialAccumulator
BinomialAccumulator.
Definition: Accumulators.h:669
Gaudi::Accumulators::BinomialAccumulator::eff
auto eff() const
Definition: Accumulators.h:679
Gaudi::Accumulators::IntegralAccumulator::nEntries
Arithmetic nEntries() const
Definition: Accumulators.h:617
Gaudi::Accumulators::Extremum
An Extremum ValueHandler, to be reused for Minimum and Maximum operator(a, b) means if (Compare(b,...
Definition: Accumulators.h:360
Gaudi::Accumulators::IntegralAccumulator::operator++
IntegralAccumulator & operator++()
Definition: Accumulators.h:608
Gaudi::Accumulators::AveragingCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:953
Gaudi::Accumulators::Adder
An Adder ValueHandler operator(a, b) means a += b.
Definition: Accumulators.h:322
Gaudi::Accumulators::CountAccumulator::operator++
CountAccumulator operator++(int)
Definition: Accumulators.h:579
Gaudi::Accumulators::has_fetch_add_v
constexpr bool has_fetch_add_v
Definition: Accumulators.h:279
Gaudi::Accumulators::SigmaAccumulatorBase::unbiased_sample_variance
auto unbiased_sample_variance() const
Definition: Accumulators.h:758
details
Definition: AnyDataWrapper.h:18
Gaudi::Monitoring::reset
void reset(T &)
default (empty) implementation of reset method for types stored into an entity
Definition: MonitoringHub.h:75
Gaudi::Accumulators::BinomialAccumulator::efficiencyErr
auto efficiencyErr() const
Definition: Accumulators.h:682
ProduceConsume.j
j
Definition: ProduceConsume.py:101
std::ostream
STL class.
Gaudi::Accumulators::StatCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1045
nlohmann::adl_serializer< std::chrono::duration< Rep, Period > >::from_json
static void from_json(const json &j, std::chrono::duration< Rep, Period > &d)
Definition: Accumulators.h:227
Gaudi::Accumulators::Counter::reset
friend void reset(Counter &c)
Definition: Accumulators.h:928
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::full, Compare, Initial >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:382
Gaudi::Accumulators::BinomialCounter::printImpl
stream & printImpl(stream &o, std::string_view tag) const
Definition: Accumulators.h:1093
Gaudi::Accumulators::AccumulatorSet::InternalType
std::tuple< typename Bases< Atomicity, Arithmetic >::InternalType... > InternalType
Definition: Accumulators.h:498
Gaudi::Accumulators::AveragingAccumulatorBase::mean
auto mean() const
Definition: Accumulators.h:722
Gaudi::Accumulators::Buffer::Buffer
Buffer(prime_type &p)
Definition: Accumulators.h:818
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::none, Compare, Initial >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:369
Gaudi::Accumulators::Buffer::Buffer
Buffer(Buffer &&other)
Definition: Accumulators.h:821
Gaudi::Accumulators::StatCounter::reset
friend void reset(StatCounter &c)
Definition: Accumulators.h:1047
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
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...
Definition: Accumulators.h:454
Gaudi::Accumulators::GenericAccumulator< double, double, Atomicity, Identity, Identity, Maximum< double, Atomicity > >::GenericAccumulator
friend class GenericAccumulator
Definition: Accumulators.h:436
Gaudi::Accumulators::Counter::typeString
static const std::string typeString
Definition: Accumulators.h:904
Gaudi::Accumulators::AccumulatorSet::value
OutputType value() const
Definition: Accumulators.h:509
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::OutputType
std::decay_t< std::result_of_t< Identity(unsigned long)> > OutputType
Definition: Accumulators.h:443
Gaudi::Accumulators::GenericAccumulator::operator=
GenericAccumulator & operator=(const GenericAccumulator &other)
Definition: Accumulators.h:460
GaudiAlg.HistoUtils.nEntries
nEntries
Definition: HistoUtils.py:939
Gaudi::Accumulators::details::MsgCounter::MsgAccumulator
GenericAccumulator< bool, unsigned long, Atomicity, Identity, Identity, Handler< Atomicity > > MsgAccumulator
Definition: Accumulators.h:1129
Gaudi::Accumulators::BinomialCounter
A counter dealing with binomial data.
Definition: Accumulators.h:1071
AlgTools.Int
Int
Definition: AlgTools.py:21
Gaudi::Accumulators::details::MsgCounter::Handler::merge
static void merge(typename Base::InternalType &orig, bool b)
Definition: Accumulators.h:1122
Gaudi::Accumulators::Buffer::~Buffer
~Buffer()
Definition: Accumulators.h:823
Gaudi::Monitoring::Hub::registerEntity
void registerEntity(std::string c, std::string n, std::string t, T &ent)
Definition: MonitoringHub.h:174
Gaudi::Accumulators::Adder< Arithmetic, atomicity::none >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:332
Gaudi::Accumulators::AccumulatorSet::extractJSONDataHelper
static InternalType extractJSONDataHelper(const nlohmann::json &j, const JSONStringEntriesType &entries, std::index_sequence< Is... >)
Definition: Accumulators.h:531
Gaudi::Accumulators::BinomialAccumulator::binomial_t::nPass
unsigned long nPass
Definition: Accumulators.h:694
CommonMessaging.h
Gaudi::Accumulators::Buffer::operator=
void operator=(const Buffer &)=delete
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Gaudi::Accumulators::GenericAccumulator::mergeAndReset
void mergeAndReset(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &other)
Definition: Accumulators.h:467
Gaudi::Accumulators::MsgCounter::print
std::ostream & print(std::ostream &os, bool tableFormat) const override
prints the counter to a stream
Definition: Accumulators.h:1162
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Gaudi::Monitoring::Hub::removeEntity
void removeEntity(T &ent)
Definition: MonitoringHub.h:182
Gaudi::Accumulators::MsgCounter
Definition: Accumulators.h:1133
std::atomic
STL class.
Gaudi::Accumulators::AccumulatorSet< Arithmetic, Atomicity, CountAcc< Atomicity, Arithmetic >::InputType, CountAcc, SumAcc >::InputType
CountAcc< Atomicity, Arithmetic >::InputType InputType
Definition: Accumulators.h:496
Gaudi::Accumulators::FalseAccumulator::nFalseEntries
unsigned long nFalseEntries() const
Definition: Accumulators.h:660
Gaudi::Accumulators::BinomialAccumulator::efficiency
auto efficiency() const
Definition: Accumulators.h:674
min
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:212
Gaudi::Accumulators::AccumulatorSet::AccumulatorSet
constexpr AccumulatorSet()=default
Gaudi::Accumulators::GenericAccumulator
Generic Accumulator, templated by.
Definition: Accumulators.h:434
gaudirun.level
level
Definition: gaudirun.py:366
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(OWNER *o, std::string const &name, SELF &self, CARGS... args)
Definition: Accumulators.h:889
Gaudi::Accumulators::Constant
A functor always returning the value N.
Definition: Accumulators.h:246
MsgStream
Definition: MsgStream.h:34
Gaudi::Accumulators::BinomialCounter::mergeAndReset
friend void mergeAndReset(BinomialCounter &c, BinomialCounter &o)
Definition: Accumulators.h:1103
nlohmann::adl_serializer< std::chrono::duration< Rep, Period > >::to_json
static void to_json(json &j, const std::chrono::duration< Rep, Period > &d)
Definition: Accumulators.h:226
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:235
Gaudi::Accumulators::GenericAccumulator::value
OutputType value() const
Definition: Accumulators.h:464
std::string::append
T append(T... args)
Gaudi::Accumulators::GenericAccumulator::reset
void reset(InnerType in)
Definition: Accumulators.h:478
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:81
Gaudi::Accumulators::StatCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1046
Gaudi::Accumulators::BufferableCounter
An empty ancester of all counters that provides a buffer method that returns a buffer on itself Also ...
Definition: Accumulators.h:872
Gaudi::Accumulators::StatCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1027
std::ostringstream
STL class.
Gaudi::Accumulators::Identity
An Identity functor.
Definition: Accumulators.h:256
Gaudi::Accumulators::SigmaCounter::to_json
friend void to_json(nlohmann::json &j, SigmaCounter const &c)
Definition: Accumulators.h:1007
Gaudi::Accumulators::BinomialAccumulator::effErr
auto effErr() const
Definition: Accumulators.h:691
Gaudi::Accumulators
Definition: HistogramsTests.cpp:20
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator()=default
merge
int merge(const char *target, const char *source, bool fixup=false, bool dbg=true)
Definition: merge.C:430
Gaudi::Accumulators::MsgCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1158
Gaudi::Accumulators::Buffer::Buffer
Buffer()=delete
Gaudi::Accumulators::SigmaCounter::typeString
static const std::string typeString
Definition: Accumulators.h:986
Gaudi::Accumulators::fp_result_type
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
Definition: Accumulators.h:285
Gaudi::Accumulators::MaxAccumulator
MaxAccumulator.
Definition: Accumulators.h:548
Gaudi::Accumulators::MsgCounter::max
unsigned long max
Definition: Accumulators.h:1184
Gaudi::Accumulators::SigmaAccumulatorBase::rms
Arithmetic rms() const
Definition: Accumulators.h:773
Gaudi::Accumulators::CountAccumulator
CountAccumulator.
Definition: Accumulators.h:573
Gaudi::Accumulators::AccumulatorSet::AccumulatorSet
AccumulatorSet(const InternalType &t)
Definition: Accumulators.h:521
Gaudi::Accumulators::AveragingCounter::to_json
friend void to_json(nlohmann::json &j, AveragingCounter const &c)
Definition: Accumulators.h:966
Gaudi::Accumulators::PrintableCounter::print
virtual MsgStream & print(MsgStream &o, std::string_view tag) const
Definition: Accumulators.h:848
gaudirun.args
args
Definition: gaudirun.py:338
Gaudi::Accumulators::GenericAccumulator::extractJSONData
static InnerType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
Definition: Accumulators.h:479
Gaudi::Accumulators::MsgCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1164
Gaudi::Accumulators::FalseAccumulator
FalseAccumulator.
Definition: Accumulators.h:658
Gaudi::Accumulators::MaxAccumulator::max
Arithmetic max() const
Definition: Accumulators.h:551
Gaudi::Accumulators::SigmaAccumulatorBase::standard_deviation
auto standard_deviation() const
Definition: Accumulators.h:765
Gaudi::Accumulators::construct_empty_t::construct_empty_t
construct_empty_t()=default
std
STL namespace.
Gaudi::Accumulators::construct_empty
constexpr construct_empty_t construct_empty
Definition: Accumulators.h:412
fmt
Definition: MessageSvcSink.cpp:25
Gaudi::Accumulators::FalseTo1
helper functor for the FalseAccumulator
Definition: Accumulators.h:648
Gaudi::Accumulators::BinomialCounter::fromJSON
static BinomialCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1113
detected.h
Gaudi::Accumulators::AccumulatorSet::reset
void reset(const InternalType &t)
Definition: Accumulators.h:522
Gaudi::Accumulators::SigmaAccumulatorBase
SigmaAccumulatorBase.
Definition: Accumulators.h:744
Gaudi::Accumulators::Buffer
Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-sa...
Definition: Accumulators.h:812
Gaudi::Accumulators::CountAccumulator::nEntries
unsigned long nEntries() const
Definition: Accumulators.h:584
Gaudi::Accumulators::GenericAccumulator::operator+
void operator+(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &&other)
Definition: Accumulators.h:471
Gaudi::Accumulators::SigmaCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:994
std::chrono::duration::count
T count(T... args)
Gaudi::Accumulators::AveragingCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:963
Gaudi::Accumulators::atomicity
atomicity
Defines atomicity of the accumulators.
Definition: Accumulators.h:236
Gaudi::Accumulators::IntegralAccumulator::sum
Arithmetic sum() const
Definition: Accumulators.h:618
Properties.v
v
Definition: Properties.py:123
Gaudi::Accumulators::Adder< Arithmetic, atomicity::full >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:343
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(const GenericAccumulator &other)
Definition: Accumulators.h:459
Gaudi::Accumulators::Adder< Arithmetic, atomicity::none >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:331
Gaudi::Accumulators::StatCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:1026
Gaudi::Accumulators::construct_empty_t
constant used to disambiguate construction of an empty Accumulator versus the copy constructor.
Definition: Accumulators.h:409
std::ostringstream::str
T str(T... args)
Gaudi::Accumulators::AveragingCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:961
Gaudi::Accumulators::BinomialAccumulator::nEntries
unsigned long nEntries() const
Definition: Accumulators.h:671
Gaudi::Accumulators::BinomialCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1080
plotSpeedupsPyRoot.counter
counter
Definition: plotSpeedupsPyRoot.py:175
Gaudi::Accumulators::SigmaCounter::fromJSON
static SigmaCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1016
Gaudi::Accumulators::SigmaAccumulatorBase::biased_sample_variance
auto biased_sample_variance() const
Definition: Accumulators.h:751
Gaudi::Accumulators::TrueAccumulator::nTrueEntries
unsigned long nTrueEntries() const
Definition: Accumulators.h:644
Gaudi::Accumulators::BinomialCounter::reset
friend void reset(BinomialCounter &c)
Definition: Accumulators.h:1102
Gaudi::Accumulators::PrintableCounter::print
virtual std::ostream & print(std::ostream &, bool tableFormat=false) const =0
prints the counter to a stream
Gaudi::Monitoring::Hub
Central entity in a Gaudi application that manages monitoring objects (i.e.
Definition: MonitoringHub.h:85
GaudiAlg.HistoUtils.mean
mean
Definition: HistoUtils.py:904
Gaudi::Accumulators::FalseTo1::operator()
unsigned int operator()(bool v) const
Definition: Accumulators.h:649
Gaudi::Accumulators::Counter::Counter
Counter(OWNER *o, std::string const &name)
Definition: Accumulators.h:907
Gaudi::Accumulators::atomicity::none
@ none
Gaudi::Accumulators::IntegralAccumulator::operator++
IntegralAccumulator operator++(int)
Definition: Accumulators.h:612
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::full, Compare, Initial >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:383
Gaudi::Accumulators::TrueTo1::operator()
unsigned int operator()(bool v) const
Definition: Accumulators.h:633
Gaudi::Accumulators::MsgCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1135
Gaudi::Accumulators::BinomialCounter::print
MsgStream & print(MsgStream &o, std::string_view tag) const override
Definition: Accumulators.h:1100
Gaudi::Accumulators::AveragingCounter::mergeAndReset
friend void mergeAndReset(AveragingCounter &c, AveragingCounter &o)
Definition: Accumulators.h:965
Gaudi::Accumulators::SigmaCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1004
Gaudi::Accumulators::StatCounter::to_json
friend void to_json(nlohmann::json &j, StatCounter const &c)
Definition: Accumulators.h:1049
Gaudi::Accumulators::SumAccumulator::sum
Arithmetic sum() const
Definition: Accumulators.h:594
Gaudi::Accumulators::MsgCounter::fromJSON
static MsgCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1172
Gaudi::Accumulators::AveragingCounter::fromJSON
static AveragingCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:973
Gaudi::Accumulators::Counter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:927
Gaudi::Accumulators::Constant::operator()
constexpr T operator()(U &&) const noexcept
Definition: Accumulators.h:248
Gaudi::Accumulators::accumulate
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...
Definition: Accumulators.h:1202
std::numeric_limits
Gaudi::operator+
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:443
Gaudi::Accumulators::AveragingCounter::typeString
static const std::string typeString
Definition: Accumulators.h:944
Gaudi::Monitoring::mergeAndReset
void mergeAndReset(T &, T &)
default (empty) implementation of mergeAndReset method for types stored into an entity
Definition: MonitoringHub.h:79
Gaudi::Accumulators::Counter::to_json
friend void to_json(nlohmann::json &j, Counter const &c)
Definition: Accumulators.h:930
Gaudi::Accumulators::operator<<
std::ostream & operator<<(std::ostream &s, const PrintableCounter &counter)
external printout operator to a stream type
Definition: Accumulators.h:863
Gaudi::Accumulators::SigmaCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1003
Gaudi::Accumulators::MsgCounter::to_json
friend void to_json(nlohmann::json &j, MsgCounter const &c)
Definition: Accumulators.h:1167
Gaudi::Accumulators::SigmaCounter::mergeAndReset
friend void mergeAndReset(SigmaCounter &c, SigmaCounter &o)
Definition: Accumulators.h:1006
Gaudi::Accumulators::BufferableCounter::~BufferableCounter
~BufferableCounter()
Definition: Accumulators.h:881
MsgStream.h
Gaudi::Accumulators::AveragingCounter::reset
friend void reset(AveragingCounter &c)
Definition: Accumulators.h:964
Gaudi::Accumulators::Counter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:923
Gaudi::Accumulators::BinomialAccumulator::binomial_t::nTotal
unsigned long nTotal
Definition: Accumulators.h:695
Gaudi::Accumulators::has_fetch_add_
decltype(std::declval< T & >().fetch_add(0)) has_fetch_add_
type_traits for checking the presence of fetch_add
Definition: Accumulators.h:277
Gaudi::Accumulators::SquareAccumulator::sum2
Arithmetic sum2() const
Definition: Accumulators.h:628