The Gaudi Framework  v37r1 (a7f61348)
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 constexpr ( !std::is_floating_point_v<Arithmetic> ) { // avoid comparisons for floating points
345  if ( DefaultValue() == b ) return; // avoid atomic operation if b is "0"
346  }
347  if constexpr ( has_fetch_add_v<InternalType> ) {
348  a.fetch_add( b, std::memory_order_relaxed );
349  } else {
351  while ( !a.compare_exchange_weak( current, current + b ) )
352  ;
353  }
354  };
355  };
356 
361  template <typename Arithmetic, atomicity Atomicity, typename Compare, Arithmetic ( *Initial )()>
362  struct Extremum;
363 
367  template <typename Arithmetic, typename Compare, Arithmetic ( *Initial )()>
368  struct Extremum<Arithmetic, atomicity::none, Compare, Initial> : BaseValueHandler<Arithmetic, atomicity::none> {
371  static constexpr OutputType DefaultValue() { return Initial(); }
372  static void merge( InternalType& a, Arithmetic b ) noexcept {
373  if ( Compare{}( b, a ) ) a = b;
374  };
375  };
376 
380  template <typename Arithmetic, typename Compare, Arithmetic ( *Initial )()>
381  struct Extremum<Arithmetic, atomicity::full, Compare, Initial> : BaseValueHandler<Arithmetic, atomicity::full> {
384  static constexpr OutputType DefaultValue() { return Initial(); }
385  static void merge( InternalType& a, Arithmetic b ) noexcept {
386  Arithmetic prev_value = BaseValueHandler<Arithmetic, atomicity::full>::getValue( a );
387  while ( Compare{}( b, prev_value ) && !a.compare_exchange_weak( prev_value, b ) )
388  ;
389  };
390  };
391 
396  template <typename Arithmetic, atomicity Atomicity = atomicity::full>
398 
403  template <typename Arithmetic, atomicity Atomicity = atomicity::full>
405 
412  explicit construct_empty_t() = default;
413  };
415 
433  template <typename InputTypeT, typename InnerType, atomicity Atomicity = atomicity::full,
434  typename InputTransform = Identity, typename OutputTransform = Identity,
435  typename ValueHandler = Adder<InnerType, Atomicity>>
437  template <typename, typename, atomicity, typename, typename, typename>
438  friend class GenericAccumulator;
439 
440  public:
441  using InputType = InputTypeT;
442 #if __cplusplus >= 201703L
443  using OutputType = std::decay_t<std::invoke_result_t<OutputTransform, InnerType>>;
444 #else
445  using OutputType = std::decay_t<std::result_of_t<OutputTransform( InnerType )>>;
446 #endif
447  using InternalType = InnerType;
450  ValueHandler::merge( m_value, InputTransform{}( by ) );
451  return *this;
452  }
453  GenericAccumulator() = default;
455  template <atomicity ato, typename VH>
458  : GenericAccumulator() {}
459  template <typename... Args>
460  GenericAccumulator( std::in_place_t, Args&&... args ) : m_value( std::forward<Args>( args )... ) {}
461  GenericAccumulator( const GenericAccumulator& other ) : m_value( ValueHandler::getValue( other.m_value ) ) {}
463  m_value = ValueHandler::getValue( other.m_value );
464  return *this;
465  }
466  OutputType value() const { return OutputTransform{}( ValueHandler::getValue( m_value ) ); }
467  void reset() { reset( ValueHandler::DefaultValue() ); }
468  template <atomicity ato, typename VH>
470  ValueHandler::merge( m_value, VH::exchange( other.m_value, VH::DefaultValue() ) );
471  }
472  template <atomicity ato, typename VH>
474  ValueHandler::merge( m_value, other.m_value );
475  }
476 
477  protected:
478  GenericAccumulator( InnerType in ) : m_value( std::move( in ) ) {}
479  auto rawValue() const { return ValueHandler::getValue( m_value ); }
480  void reset( InnerType in ) { m_value = std::move( in ); }
481  static InnerType extractJSONData( const nlohmann::json& j, const JSONStringEntriesType& entries ) {
482  return j.at( entries ).get<InnerType>();
483  }
484 
485  private:
486  typename ValueHandler::InternalType m_value{ ValueHandler::DefaultValue() };
487  };
488 
494  template <typename Arithmetic, atomicity Atomicity, typename InputTypeT = Arithmetic,
495  template <atomicity, typename> class... Bases>
496  class AccumulatorSet : public Bases<Atomicity, Arithmetic>... {
497  public:
498  using InputType = InputTypeT;
502  constexpr AccumulatorSet() = default;
504  template <atomicity ato>
506  : AccumulatorSet() {}
508  ( Bases<Atomicity, Arithmetic>::operator+=( by ), ... );
509  return *this;
510  }
511  OutputType value() const { return std::make_tuple( Bases<Atomicity, Arithmetic>::value()... ); }
513  template <atomicity Ato>
515  ( Bases<Atomicity, Arithmetic>::mergeAndReset( static_cast<Bases<Ato, Arithmetic>&>( other ) ), ... );
516  }
517  template <atomicity Ato>
519  ( Bases<Atomicity, Arithmetic>::operator+( static_cast<Bases<Ato, Arithmetic>&&>( other ) ), ... );
520  }
521 
522  protected:
524  void reset( const InternalType& t ) {
525  std::apply( [this]( const auto&... i ) { ( this->Bases<Atomicity, Arithmetic>::reset( i ), ... ); }, t );
526  }
528  return extractJSONDataHelper( j, entries, std::index_sequence_for<Bases<Atomicity, Arithmetic>...>{} );
529  }
530 
531  private:
532  template <size_t... Is>
534  std::index_sequence<Is...> ) {
535  return extractJSONDataHelper( j, std::get<Is>( entries )... );
536  }
537  static InternalType
539  typename Bases<Atomicity, Arithmetic>::JSONStringEntriesType... entries ) {
540  return { Bases<Atomicity, Arithmetic>::extractJSONData( j, entries )... };
541  }
542  };
543 
548  template <atomicity Atomicity, typename Arithmetic = double>
550  : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Maximum<Arithmetic, Atomicity>> {
551  using GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity,
553  Arithmetic max() const { return this->value(); }
554  };
555 
560  template <atomicity Atomicity, typename Arithmetic = double>
562  : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Minimum<Arithmetic, Atomicity>> {
563  using GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity,
565  Arithmetic min() const { return this->value(); }
566  };
567 
574  template <atomicity Atomicity, typename Arithmetic = double>
575  struct CountAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, Constant<unsigned long, 1UL>> {
578  ( *this ) += Arithmetic{};
579  return *this;
580  }
582  auto copy = *this;
583  ++( *this );
584  return copy;
585  }
586  unsigned long nEntries() const { return this->value(); }
587  };
588 
593  template <atomicity Atomicity, typename Arithmetic = double>
594  struct SumAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity> {
596  Arithmetic sum() const { return this->value(); }
597  };
598 
604  template <atomicity Atomicity, typename Arithmetic = unsigned long>
605  struct IntegralAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity> {
606  static_assert( std::is_integral_v<Arithmetic>,
607  "Invalid Arithmetic type for IntegralAccumulator. It must be an integral type" );
608 
611  ( *this ) += 1;
612  return *this;
613  }
615  auto copy = *this;
616  ++( *this );
617  return copy;
618  }
619  Arithmetic nEntries() const { return this->value(); }
620  Arithmetic sum() const { return this->value(); }
621  };
622 
627  template <atomicity Atomicity, typename Arithmetic = double>
628  struct SquareAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Square> {
630  Arithmetic sum2() const { return this->value(); };
631  };
632 
634  struct TrueTo1 {
635  unsigned int operator()( bool v ) const { return v; }
636  };
637 
643  template <atomicity Atomicity, typename Arithmetic>
644  struct TrueAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, TrueTo1> {
646  unsigned long nTrueEntries() const { return this->value(); };
647  };
648 
650  struct FalseTo1 {
651  unsigned int operator()( bool v ) const { return !v; }
652  };
653 
659  template <atomicity Atomicity, typename Arithmetic>
660  struct FalseAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, FalseTo1> {
662  unsigned long nFalseEntries() const { return this->value(); };
663  };
664 
670  template <atomicity Atomicity, typename Arithmetic>
671  struct BinomialAccumulator : AccumulatorSet<bool, Atomicity, bool, TrueAccumulator, FalseAccumulator> {
673  unsigned long nEntries() const { return this->nTrueEntries() + this->nFalseEntries(); };
674 
675  template <typename Result = fp_result_type<Arithmetic>>
676  auto efficiency() const {
677  auto nbEntries = nEntries();
678  if ( 1 > nbEntries ) return Result{ -1 };
679  return static_cast<Result>( this->nTrueEntries() ) / nbEntries;
680  }
681  auto eff() const { return efficiency(); }
682 
683  template <typename Result = fp_result_type<Arithmetic>>
684  auto efficiencyErr() const {
685  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
686  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
688  using std::sqrt;
689  auto nbEntries = nEntries();
690  if ( 1 > nbEntries ) return Result{ -1 };
691  return sqrt( static_cast<Result>( this->nTrueEntries() * this->nFalseEntries() ) / nbEntries ) / nbEntries;
692  }
693  auto effErr() const { return efficiencyErr(); }
695  struct binomial_t {
696  unsigned long nPass;
697  unsigned long nTotal;
698  };
699  BinomialAccumulator& operator+=( binomial_t b ) {
700  assert( b.nPass <= b.nTotal );
701  TrueAccumulator<atomicity::none, bool> t{ std::in_place, b.nPass };
703  FalseAccumulator<atomicity::none, bool> f{ std::in_place, b.nTotal - b.nPass };
705  return *this;
706  }
707  };
708 
714  template <atomicity Atomicity, typename Arithmetic, template <atomicity, typename> typename CountAcc,
715  template <atomicity, typename> typename SumAcc>
717  : AccumulatorSet<Arithmetic, Atomicity, typename CountAcc<Atomicity, Arithmetic>::InputType, CountAcc, SumAcc> {
718  static_assert( std::is_same_v<typename CountAcc<Atomicity, Arithmetic>::InputType,
719  typename SumAcc<Atomicity, Arithmetic>::InputType>,
720  "Incompatible Counters in definition of AveragingAccumulator. Both should have identical Input" );
722  SumAcc>::AccumulatorSet;
723  template <typename Result = fp_result_type<Arithmetic>>
724  auto mean() const {
725  auto n = this->nEntries();
726  Result sum = this->sum();
727  return ( n > 0 ) ? static_cast<Result>( sum / n ) : Result{};
728  }
729  };
730 
735  template <atomicity Atomicity, typename Arithmetic>
737 
743  template <atomicity Atomicity, typename Arithmetic, template <atomicity, typename> typename AvgAcc,
744  template <atomicity, typename> typename SquareAcc>
746  : AccumulatorSet<Arithmetic, Atomicity, typename AvgAcc<Atomicity, Arithmetic>::InputType, AvgAcc, SquareAcc> {
747  static_assert( std::is_same_v<typename AvgAcc<Atomicity, Arithmetic>::InputType,
748  typename SquareAcc<Atomicity, Arithmetic>::InputType>,
749  "Incompatible Counters in definition of SigmaAccumulator. Both should have identical Input" );
751  SquareAcc>::AccumulatorSet;
752  template <typename Result = fp_result_type<Arithmetic>>
753  auto biased_sample_variance() const {
754  auto n = this->nEntries();
755  Result sum = this->sum();
756  return ( n > 0 ) ? static_cast<Result>( ( this->sum2() - sum * ( sum / n ) ) / n ) : Result{};
757  }
758 
759  template <typename Result = fp_result_type<Arithmetic>>
761  auto n = this->nEntries();
762  Result sum = this->sum();
763  return ( n > 1 ) ? static_cast<Result>( ( this->sum2() - sum * ( sum / n ) ) / ( n - 1 ) ) : Result{};
764  }
765 
766  template <typename Result = fp_result_type<Arithmetic>>
767  auto standard_deviation() const {
768  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
769  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
771  using std::sqrt;
772  Result v = biased_sample_variance();
773  return ( Result{ 0 } > v ) ? Result{} : static_cast<Result>( sqrt( v ) );
774  }
775  [[deprecated( "The name 'rms' has changed to standard_deviation" )]] Arithmetic rms() const {
776  return standard_deviation();
777  }
778 
779  template <typename Result = fp_result_type<Arithmetic>>
780  auto meanErr() const {
781  auto n = this->nEntries();
782  if ( 0 == n ) return Result{};
783  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
784  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
786  using std::sqrt;
787  Result v = biased_sample_variance();
788  return ( Result{ 0 } > v ) ? Result{} : static_cast<Result>( sqrt( v / n ) );
789  }
790  };
791 
796  template <atomicity Atomicity, typename Arithmetic>
798 
803  template <atomicity Atomicity, typename Arithmetic>
806 
813  template <template <atomicity Ato, typename... Int> class ContainedAccumulator, atomicity Atomicity, typename... Args>
814  class Buffer : public ContainedAccumulator<atomicity::none, Args...> {
815  using prime_type = ContainedAccumulator<Atomicity, Args...>;
816  using base_type = ContainedAccumulator<atomicity::none, Args...>;
817 
818  public:
819  Buffer() = delete;
820  Buffer( prime_type& p ) : base_type( construct_empty, p ), m_prime( p ) {}
821  Buffer( const Buffer& ) = delete;
822  void operator=( const Buffer& ) = delete;
823  Buffer( Buffer&& other ) : base_type( other ), m_prime( other.m_prime ) { other.reset(); }
824  void push() { m_prime.mergeAndReset( static_cast<base_type&>( *this ) ); }
825  ~Buffer() { push(); }
826 
827  private:
829  };
830 
836  PrintableCounter() = default;
838  virtual ~PrintableCounter() = default;
839  // add tag to printout
840  template <typename stream>
841  stream& printImpl( stream& s, std::string_view tag ) const {
842  s << boost::format{ " | %|-48.48s|%|50t|" } % ( std::string{ '\"' }.append( tag ).append( "\"" ) );
843  return print( s, true );
844  }
846  virtual std::ostream& print( std::ostream&, bool tableFormat = false ) const = 0;
847  virtual MsgStream& print( MsgStream&, bool tableFormat = true ) const = 0;
849  virtual std::ostream& print( std::ostream& o, std::string_view tag ) const { return printImpl( o, tag ); }
850  virtual MsgStream& print( MsgStream& o, std::string_view tag ) const { return printImpl( o, tag ); }
853  virtual bool toBePrinted() const { return true; }
856  std::ostringstream ost;
857  print( ost );
858  return ost.str();
859  }
860  };
861 
865  inline std::ostream& operator<<( std::ostream& s, const PrintableCounter& counter ) { return counter.print( s ); }
866  inline MsgStream& operator<<( MsgStream& s, const PrintableCounter& counter ) { return counter.print( s ); }
873  template <atomicity Atomicity, template <atomicity Ato, typename... Int> class Accumulator, typename... Args>
874  class BufferableCounter : public PrintableCounter, public Accumulator<Atomicity, Args...> {
875  public:
876  using Accumulator<Atomicity, Args...>::Accumulator;
877  BufferableCounter() = default;
878  template <typename OWNER>
879  BufferableCounter( OWNER* o, std::string const& name ) : BufferableCounter( o, name, *this ) {}
880  Buffer<Accumulator, Atomicity, Args...> buffer() { return { *this }; }
884  if ( m_monitoringHub ) { m_monitoringHub->removeEntity( *this ); }
885  }
886 
887  inline static const std::string typeString{ "counter" };
888 
889  protected:
890  template <typename OWNER, typename SELF, typename... CARGS>
891  BufferableCounter( OWNER* o, std::string const& name, SELF& self, CARGS... args )
892  : Accumulator<Atomicity, Args...>( args... ), m_monitoringHub( &o->serviceLocator()->monitoringHub() ) {
893  m_monitoringHub->registerEntity( o->name(), name, self.typeString, self );
894  }
895 
896  private:
897  Monitoring::Hub* m_monitoringHub{ nullptr };
898  };
899 
904  template <atomicity Atomicity = atomicity::full, typename Arithmetic = unsigned long>
905  struct Counter : BufferableCounter<Atomicity, IntegralAccumulator, Arithmetic> {
906  inline static const std::string typeString{ std::string{ "counter:Counter:" } + typeid( Arithmetic ).name() };
908  template <typename OWNER>
909  Counter( OWNER* o, std::string const& name )
910  : BufferableCounter<Atomicity, IntegralAccumulator, Arithmetic>( o, name, *this ) {}
911  Counter& operator++() { return ( *this ) += 1; }
912  Counter& operator+=( const Arithmetic v ) {
914  return *this;
915  }
917 
918  template <typename stream>
919  stream& printImpl( stream& o, bool tableFormat ) const {
920  // Avoid printing empty counters in non DEBUG mode
921  auto fmt = ( tableFormat ? "|%|10d| |" : "#=%|-7lu|" );
922  return o << boost::format{ fmt } % this->nEntries();
923  }
924 
925  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
926  return printImpl( o, tableFormat );
927  }
928  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
929  bool toBePrinted() const override { return this->nEntries() > 0; }
930  friend void reset( Counter& c ) { c.reset(); }
931  friend void mergeAndReset( Counter& c, Counter& o ) { c.mergeAndReset( o ); }
932  friend void to_json( nlohmann::json& j, Counter const& c ) {
933  j = { { "type", c.typeString }, { "empty", c.nEntries() == 0 }, { "nEntries", c.nEntries() } };
934  }
935  static Counter fromJSON( const nlohmann::json& j ) {
937  }
938  };
939 
944  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
945  struct AveragingCounter : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic> {
946  inline static const std::string typeString{ std::string{ "counter:AveragingCounter:" } +
947  typeid( Arithmetic ).name() };
949  template <typename OWNER>
950  AveragingCounter( OWNER* o, std::string const& name )
951  : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic>( o, name, *this ) {}
953 
954  template <typename stream>
955  stream& printImpl( stream& o, bool tableFormat ) const {
956  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |" : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g|" );
957  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean();
958  }
959 
960  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
961  return printImpl( o, tableFormat );
962  }
963  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
964 
965  bool toBePrinted() const override { return this->nEntries() > 0; }
966  friend void reset( AveragingCounter& c ) { return c.reset(); }
967  friend void mergeAndReset( AveragingCounter& c, AveragingCounter& o ) { c.mergeAndReset( o ); }
968  friend void to_json( nlohmann::json& j, AveragingCounter const& c ) {
969  j = { { "type", c.typeString },
970  { "empty", c.nEntries() == 0 },
971  { "nEntries", c.nEntries() },
972  { "sum", c.sum() },
973  { "mean", c.mean() } };
974  }
976  return AveragingAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { "nEntries", "sum" } );
977  }
978  };
979  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
981 
986  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
987  struct SigmaCounter : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic> {
988  inline static const std::string typeString{ std::string{ "counter:SigmaCounter:" } + typeid( Arithmetic ).name() };
990  template <typename OWNER>
991  SigmaCounter( OWNER* o, std::string const& name )
992  : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic>( o, name, *this ) {}
994 
995  template <typename stream>
996  stream& printImpl( stream& o, bool tableFormat ) const {
997  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |"
998  : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g|" );
999  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean() % this->standard_deviation();
1000  }
1001 
1002  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1003  return printImpl( o, tableFormat );
1004  }
1005  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1006  bool toBePrinted() const override { return this->nEntries() > 0; }
1007  friend void reset( SigmaCounter& c ) { c.reset(); }
1008  friend void mergeAndReset( SigmaCounter& c, SigmaCounter& o ) { c.mergeAndReset( o ); }
1009  friend void to_json( nlohmann::json& j, SigmaCounter const& c ) {
1010  j = { { "type", c.typeString },
1011  { "empty", c.nEntries() == 0 },
1012  { "nEntries", c.nEntries() },
1013  { "sum", c.sum() },
1014  { "mean", c.mean() },
1015  { "sum2", c.sum2() },
1016  { "standard_deviation", c.standard_deviation() } };
1017  }
1019  return SigmaAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { { "nEntries", "sum" }, "sum2" } );
1020  }
1021  };
1022 
1027  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
1028  struct StatCounter : BufferableCounter<Atomicity, StatAccumulator, Arithmetic> {
1029  inline static const std::string typeString{ std::string{ "counter:StatCounter:" } + typeid( Arithmetic ).name() };
1031  template <typename OWNER>
1032  StatCounter( OWNER* o, std::string const& name )
1033  : BufferableCounter<Atomicity, StatAccumulator, Arithmetic>( o, name, *this ) {}
1035 
1036  template <typename stream>
1037  stream& printImpl( stream& o, bool tableFormat ) const {
1038  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |"
1039  : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" );
1040  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean() % this->standard_deviation() %
1041  this->min() % this->max();
1042  }
1043 
1044  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1045  return printImpl( o, tableFormat );
1046  }
1047  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1048  bool toBePrinted() const override { return this->nEntries() > 0; }
1049  friend void reset( StatCounter& c ) { c.reset(); }
1050  friend void mergeAndReset( StatCounter& c, StatCounter& o ) { c.mergeAndReset( o ); }
1051  friend void to_json( nlohmann::json& j, StatCounter const& c ) {
1052  j = { { "type", c.typeString },
1053  { "empty", c.nEntries() == 0 },
1054  { "nEntries", c.nEntries() },
1055  { "sum", c.sum() },
1056  { "mean", c.mean() },
1057  { "sum2", c.sum2() },
1058  { "standard_deviation", c.standard_deviation() },
1059  { "min", c.min() },
1060  { "max", c.max() } };
1061  }
1064  j, { { { "nEntries", "sum" }, "sum2" }, "min", "max" } );
1065  }
1066  };
1067 
1072  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
1073  struct BinomialCounter : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic> {
1074  inline static const std::string typeString{ std::string{ "counter:BinomialCounter:" } +
1075  typeid( Arithmetic ).name() };
1077  template <typename OWNER>
1078  BinomialCounter( OWNER* o, std::string const& name )
1079  : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic>( o, name, *this ) {}
1080 
1081  template <typename stream>
1082  stream& printImpl( stream& o, bool tableFormat ) const {
1083  auto fmt = ( tableFormat ? "|%|10d| |%|11.5g| |(%|#9.7g| +- %|-#8.7g|)%% |"
1084  : "#=%|-7lu| Sum=%|-11.5g| Eff=|(%|#9.7g| +- %|-#8.6g|)%%|" );
1085  return o << boost::format{ fmt } % this->nEntries() % this->nTrueEntries() % ( this->efficiency() * 100 ) %
1086  ( this->efficiencyErr() * 100 );
1087  }
1088 
1089  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1090  return printImpl( o, tableFormat );
1091  }
1092  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1093 
1094  template <typename stream>
1095  stream& printImpl( stream& o, std::string_view tag ) const {
1096  // override default print to add a '*' in from of the name
1097  o << boost::format{ " |*%|-48.48s|%|50t|" } % ( std::string{ "\"" }.append( tag ).append( "\"" ) );
1098  return print( o, true );
1099  }
1101  std::ostream& print( std::ostream& o, std::string_view tag ) const override { return printImpl( o, tag ); }
1102  MsgStream& print( MsgStream& o, std::string_view tag ) const override { return printImpl( o, tag ); }
1103  bool toBePrinted() const override { return this->nEntries() > 0; }
1104  friend void reset( BinomialCounter& c ) { c.reset(); }
1105  friend void mergeAndReset( BinomialCounter& c, BinomialCounter& o ) { c.mergeAndReset( o ); }
1106  friend void to_json( nlohmann::json& j, BinomialCounter const& c ) {
1107  j = { { "type", c.typeString },
1108  { "empty", c.nEntries() == 0 },
1109  { "nEntries", c.nTrueEntries() + c.nFalseEntries() },
1110  { "nTrueEntries", c.nTrueEntries() },
1111  { "nFalseEntries", c.nFalseEntries() },
1112  { "efficiency", c.efficiency() },
1113  { "efficiencyErr", c.efficiencyErr() } };
1114  }
1116  return BinomialAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { "nTrueEntries", "nFalseEntries" } );
1117  }
1118  };
1119 
1120  namespace details::MsgCounter {
1121  template <atomicity Atomicity>
1122  struct Handler : Adder<unsigned long, Atomicity> {
1124  static void merge( typename Base::InternalType& orig, bool b ) {
1125  if ( b ) Base::merge( orig, 1 );
1126  }
1127  };
1128  // note that Arithmetic type is unused in this case but needs to be there in case
1129  // we want to create AccumulatorSets with this Accumulator
1130  template <atomicity Atomicity, typename Arithmetic = double>
1132  } // namespace details::MsgCounter
1133 
1134  template <MSG::Level level, atomicity Atomicity = atomicity::full>
1136  public:
1137  inline static const std::string typeString{ "counter:MsgCounter" };
1138  template <typename OWNER>
1139  MsgCounter( OWNER* o, std::string const& ms, unsigned long nMax = 10 )
1140  : m_monitoringHub{ &o->serviceLocator()->monitoringHub() }, logger( o ), msg( ms ), max( nMax ) {
1141  m_monitoringHub->registerEntity( o->name(), ms, typeString, *this );
1142  }
1143  template <typename OWNER>
1144  MsgCounter( OWNER* o, std::string const& ms, int nMax ) : MsgCounter( o, ms, static_cast<unsigned long>( nMax ) ) {}
1146  ( *this ) += true;
1147  return *this;
1148  }
1149  MsgCounter& operator+=( const bool by ) {
1151  if ( by ) log();
1152  return *this;
1153  }
1154  MsgCounter( MsgCounter const& ) = delete;
1155  MsgCounter& operator=( MsgCounter const& ) = delete;
1157  if ( m_monitoringHub ) m_monitoringHub->removeEntity( *this );
1158  }
1159  template <typename stream>
1160  stream& printImpl( stream& o, bool tableFormat ) const {
1161  return o << boost::format{ tableFormat ? "|%|10d| |" : "#=%|-7lu|" } % this->value();
1162  }
1164  std::ostream& print( std::ostream& os, bool tableFormat ) const override { return printImpl( os, tableFormat ); }
1165  MsgStream& print( MsgStream& os, bool tableFormat ) const override { return printImpl( os, tableFormat ); }
1166  bool toBePrinted() const override { return this->value() > 0; }
1167  friend void reset( MsgCounter& c ) { c.reset(); }
1168  friend void mergeAndReset( MsgCounter& c, MsgCounter& o ) { c.mergeAndReset( o ); }
1169  friend void to_json( nlohmann::json& j, MsgCounter const& c ) {
1170  j = { { "type", c.typeString }, { "empty", c.value() == 0 },
1171  { "nEntries", c.value() }, { "level", level },
1172  { "max", c.max }, { "msg", c.msg } };
1173  }
1175  return { j.at( "msg" ).get<std::string>(), j.at( "max" ).get<unsigned long>(),
1176  j.at( "nEntries" ).get<unsigned long>() };
1177  }
1178 
1179  private:
1180  MsgCounter( std::string const& ms, unsigned long nMax, unsigned long count )
1181  : details::MsgCounter::MsgAccumulator<Atomicity>{ count }, msg( ms ), max( nMax ) {}
1182 
1184  const CommonMessagingBase* logger{ nullptr };
1186  unsigned long max;
1187  void log() {
1188  if ( this->value() <= max && logger ) {
1189  if ( this->value() == max ) {
1190  logger->msgStream( level ) << "Suppressing message: " << std::quoted( msg, '\'' ) << endmsg;
1191  } else {
1192  logger->msgStream( level ) << msg << endmsg;
1193  }
1194  }
1195  }
1196  };
1197 
1203  template <typename Counter, typename Container, typename Fun>
1204  void accumulate( Counter& counter, const Container& container, Fun f = Identity{} ) {
1205  auto b = counter.buffer();
1206  for ( const auto& elem : container ) b += f( elem );
1207  }
1208 
1209 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(std::string const &ms, unsigned long nMax, unsigned long count)
Definition: Accumulators.h:1180
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:835
Gaudi::Accumulators::BufferableCounter::buffer
Buffer< Accumulator, Atomicity, Args... > buffer()
Definition: Accumulators.h:880
Gaudi::Accumulators::PrintableCounter::printImpl
stream & printImpl(stream &s, std::string_view tag) const
Definition: Accumulators.h:841
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:447
Gaudi::Accumulators::BinomialCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1074
Gaudi::Accumulators::Buffer::m_prime
prime_type & m_prime
Definition: Accumulators.h:828
Gaudi::Accumulators::AccumulatorSet::extractJSONData
static InternalType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
Definition: Accumulators.h:527
std::make_tuple
T make_tuple(T... args)
Gaudi::Accumulators::MsgCounter::logger
const CommonMessagingBase * logger
Definition: Accumulators.h:1184
Gaudi::Accumulators::MsgCounter::mergeAndReset
friend void mergeAndReset(MsgCounter &c, MsgCounter &o)
Definition: Accumulators.h:1168
Gaudi::Accumulators::StatCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1037
Gaudi::Accumulators::CountAccumulator::operator++
CountAccumulator & operator++()
Definition: Accumulators.h:577
Gaudi::Accumulators::MsgCounter::log
void log()
Definition: Accumulators.h:1187
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:815
std::string
STL class.
Gaudi::Accumulators::Buffer::push
void push()
Definition: Accumulators.h:824
Gaudi::Accumulators::TrueAccumulator
TrueAccumulator.
Definition: Accumulators.h:644
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:1101
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:507
Gaudi::Accumulators::SigmaCounter::reset
friend void reset(SigmaCounter &c)
Definition: Accumulators.h:1007
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:486
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(MsgCounter const &)=delete
Gaudi::Accumulators::MsgCounter::m_monitoringHub
Monitoring::Hub * m_monitoringHub
Definition: Accumulators.h:1183
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:987
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:514
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:853
Gaudi::Accumulators::BufferableCounter::operator=
BufferableCounter & operator=(BufferableCounter const &)=delete
MonitoringHub.h
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(InnerType in)
Definition: Accumulators.h:478
Gaudi::Accumulators::StatCounter::mergeAndReset
friend void mergeAndReset(StatCounter &c, StatCounter &o)
Definition: Accumulators.h:1050
Gaudi::Accumulators::GenericAccumulator::rawValue
auto rawValue() const
Definition: Accumulators.h:479
Gaudi::Accumulators::AccumulatorSet
AccumulatorSet is an Accumulator that holds a set of Accumulators templated by same Arithmetic and At...
Definition: Accumulators.h:496
Gaudi::Accumulators::SumAccumulator
SumAccumulator.
Definition: Accumulators.h:594
Gaudi::Accumulators::Counter
A basic integral counter;.
Definition: Accumulators.h:905
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(OWNER *o, std::string const &ms, unsigned long nMax=10)
Definition: Accumulators.h:1139
Gaudi::Accumulators::AveragingCounter::AveragingCounter
AveragingCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:950
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:1062
Gaudi::Accumulators::MsgCounter::print
MsgStream & print(MsgStream &os, bool tableFormat) const override
Definition: Accumulators.h:1165
Gaudi::Accumulators::SigmaCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1002
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:855
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter()=default
Gaudi::Accumulators::details::MsgCounter::Handler
Definition: Accumulators.h:1122
Gaudi::Accumulators::BinomialCounter::to_json
friend void to_json(nlohmann::json &j, BinomialCounter const &c)
Definition: Accumulators.h:1106
Gaudi::Accumulators::MsgCounter::msg
std::string msg
Definition: Accumulators.h:1185
Gaudi::Accumulators::IntegralAccumulator
IntegralAccumulator.
Definition: Accumulators.h:605
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:1103
Gaudi::Accumulators::AveragingCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:960
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::none, Compare, Initial >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:372
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(std::in_place_t, Args &&... args)
Definition: Accumulators.h:460
Gaudi::Accumulators::SquareAccumulator
SquareAccumulator.
Definition: Accumulators.h:628
std::chrono::duration
Gaudi::Accumulators::MsgCounter::reset
friend void reset(MsgCounter &c)
Definition: Accumulators.h:1167
Gaudi::Accumulators::GenericAccumulator::reset
void reset()
Definition: Accumulators.h:467
Gaudi::Accumulators::Counter::fromJSON
static Counter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:935
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:1145
Gaudi::Accumulators::MsgCounter::~MsgCounter
~MsgCounter()
Definition: Accumulators.h:1156
CommonMessagingBase
Definition: CommonMessaging.h:68
Gaudi::Accumulators::MinAccumulator
MinAccumulator.
Definition: Accumulators.h:562
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition: Accumulators.h:945
Gaudi::Accumulators::PrintableCounter::PrintableCounter
PrintableCounter()=default
Gaudi::Accumulators::AccumulatorSet::reset
void reset()
Definition: Accumulators.h:512
Gaudi::Accumulators::Buffer::Buffer
Buffer(const Buffer &)=delete
Gaudi::Accumulators::Counter::mergeAndReset
friend void mergeAndReset(Counter &c, Counter &o)
Definition: Accumulators.h:931
Gaudi::Accumulators::BinomialCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1092
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:505
Gaudi::Accumulators::BinomialCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1089
std::tuple
Gaudi::Accumulators::MinAccumulator::min
Arithmetic min() const
Definition: Accumulators.h:565
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:849
Gaudi::Accumulators::SigmaAccumulatorBase::meanErr
auto meanErr() const
Definition: Accumulators.h:780
class
#define class
Definition: HistogramPersistencySvc.cpp:54
Gaudi::Accumulators::BinomialAccumulator::operator+=
BinomialAccumulator & operator+=(binomial_t b)
Definition: Accumulators.h:699
Gaudi::Accumulators::BinomialCounter::BinomialCounter
BinomialCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:1078
Gaudi::Accumulators::AccumulatorSet::operator+
void operator+(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &&other)
Definition: Accumulators.h:518
Gaudi::Accumulators::MsgCounter::operator=
MsgCounter & operator=(MsgCounter const &)=delete
Gaudi::Accumulators::Counter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:919
Gaudi::Accumulators::TrueTo1
helper functor for the TrueAccumulator
Definition: Accumulators.h:634
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(OWNER *o, std::string const &ms, int nMax)
Definition: Accumulators.h:1144
Gaudi::Accumulators::AveragingAccumulatorBase
AveragingAccumulatorBase.
Definition: Accumulators.h:717
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:816
Gaudi::Accumulators::SigmaCounter::SigmaCounter
SigmaCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:991
Gaudi::Accumulators::BinomialAccumulator::binomial_t
Definition: Accumulators.h:695
std::sqrt
T sqrt(T... args)
Gaudi::Accumulators::Counter::operator+=
Counter & operator+=(const Arithmetic v)
Definition: Accumulators.h:912
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:879
Gaudi::Accumulators::AccumulatorSet::extractJSONDataHelper
static InternalType extractJSONDataHelper(const nlohmann::json &j, typename Bases< Atomicity, Arithmetic >::JSONStringEntriesType... entries)
Definition: Accumulators.h:538
Gaudi::Accumulators::Square
A Square functor.
Definition: Accumulators.h:266
Gaudi::Accumulators::Counter::operator++
Counter & operator++()
Definition: Accumulators.h:911
Gaudi::Units::ms
constexpr double ms
Definition: SystemOfUnits.h:154
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::InputType
bool InputType
Definition: Accumulators.h:441
Gaudi::Accumulators::MsgCounter::operator+=
MsgCounter & operator+=(const bool by)
Definition: Accumulators.h:1149
Gaudi::Accumulators::Counter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:928
Gaudi::Accumulators::GenericAccumulator::operator+=
GenericAccumulator operator+=(const InputType by)
Definition: Accumulators.h:449
Gaudi::Accumulators::StatCounter::StatCounter
StatCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:1032
Gaudi::Accumulators::StatCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1044
bug_34121.t
t
Definition: bug_34121.py:30
Gaudi::Accumulators::BinomialAccumulator
BinomialAccumulator.
Definition: Accumulators.h:671
Gaudi::Accumulators::BinomialAccumulator::eff
auto eff() const
Definition: Accumulators.h:681
Gaudi::Accumulators::IntegralAccumulator::nEntries
Arithmetic nEntries() const
Definition: Accumulators.h:619
Gaudi::Accumulators::Extremum
An Extremum ValueHandler, to be reused for Minimum and Maximum operator(a, b) means if (Compare(b,...
Definition: Accumulators.h:362
Gaudi::Accumulators::IntegralAccumulator::operator++
IntegralAccumulator & operator++()
Definition: Accumulators.h:610
Gaudi::Accumulators::AveragingCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:955
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:581
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:760
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:684
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:1047
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:930
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::full, Compare, Initial >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:384
Gaudi::Accumulators::BinomialCounter::printImpl
stream & printImpl(stream &o, std::string_view tag) const
Definition: Accumulators.h:1095
Gaudi::Accumulators::AccumulatorSet::InternalType
std::tuple< typename Bases< Atomicity, Arithmetic >::InternalType... > InternalType
Definition: Accumulators.h:500
Gaudi::Accumulators::AveragingAccumulatorBase::mean
auto mean() const
Definition: Accumulators.h:724
Gaudi::Accumulators::Buffer::Buffer
Buffer(prime_type &p)
Definition: Accumulators.h:820
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::none, Compare, Initial >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:371
Gaudi::Accumulators::Buffer::Buffer
Buffer(Buffer &&other)
Definition: Accumulators.h:823
Gaudi::Accumulators::StatCounter::reset
friend void reset(StatCounter &c)
Definition: Accumulators.h:1049
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:456
Gaudi::Accumulators::GenericAccumulator< double, double, Atomicity, Identity, Identity, Maximum< double, Atomicity > >::GenericAccumulator
friend class GenericAccumulator
Definition: Accumulators.h:438
Gaudi::Accumulators::Counter::typeString
static const std::string typeString
Definition: Accumulators.h:906
Gaudi::Accumulators::AccumulatorSet::value
OutputType value() const
Definition: Accumulators.h:511
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::OutputType
std::decay_t< std::result_of_t< Identity(unsigned long)> > OutputType
Definition: Accumulators.h:445
Gaudi::Accumulators::GenericAccumulator::operator=
GenericAccumulator & operator=(const GenericAccumulator &other)
Definition: Accumulators.h:462
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:1131
Gaudi::Accumulators::BinomialCounter
A counter dealing with binomial data.
Definition: Accumulators.h:1073
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:1124
Gaudi::Accumulators::Buffer::~Buffer
~Buffer()
Definition: Accumulators.h:825
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:533
Gaudi::Accumulators::BinomialAccumulator::binomial_t::nPass
unsigned long nPass
Definition: Accumulators.h:696
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:469
Gaudi::Accumulators::MsgCounter::print
std::ostream & print(std::ostream &os, bool tableFormat) const override
prints the counter to a stream
Definition: Accumulators.h:1164
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:1135
std::atomic
STL class.
Gaudi::Accumulators::AccumulatorSet< Arithmetic, Atomicity, CountAcc< Atomicity, Arithmetic >::InputType, CountAcc, SumAcc >::InputType
CountAcc< Atomicity, Arithmetic >::InputType InputType
Definition: Accumulators.h:498
Gaudi::Accumulators::FalseAccumulator::nFalseEntries
unsigned long nFalseEntries() const
Definition: Accumulators.h:662
Gaudi::Accumulators::BinomialAccumulator::efficiency
auto efficiency() const
Definition: Accumulators.h:676
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:436
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:891
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:1105
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:466
std::string::append
T append(T... args)
Gaudi::Accumulators::GenericAccumulator::reset
void reset(InnerType in)
Definition: Accumulators.h:480
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:1048
Gaudi::Accumulators::BufferableCounter
An empty ancester of all counters that provides a buffer method that returns a buffer on itself Also ...
Definition: Accumulators.h:874
Gaudi::Accumulators::StatCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1029
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:1009
Gaudi::Accumulators::BinomialAccumulator::effErr
auto effErr() const
Definition: Accumulators.h:693
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:1160
Gaudi::Accumulators::Buffer::Buffer
Buffer()=delete
Gaudi::Accumulators::SigmaCounter::typeString
static const std::string typeString
Definition: Accumulators.h:988
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:550
Gaudi::Accumulators::MsgCounter::max
unsigned long max
Definition: Accumulators.h:1186
Gaudi::Accumulators::SigmaAccumulatorBase::rms
Arithmetic rms() const
Definition: Accumulators.h:775
Gaudi::Accumulators::CountAccumulator
CountAccumulator.
Definition: Accumulators.h:575
Gaudi::Accumulators::AccumulatorSet::AccumulatorSet
AccumulatorSet(const InternalType &t)
Definition: Accumulators.h:523
Gaudi::Accumulators::AveragingCounter::to_json
friend void to_json(nlohmann::json &j, AveragingCounter const &c)
Definition: Accumulators.h:968
Gaudi::Accumulators::PrintableCounter::print
virtual MsgStream & print(MsgStream &o, std::string_view tag) const
Definition: Accumulators.h:850
gaudirun.args
args
Definition: gaudirun.py:338
Gaudi::Accumulators::GenericAccumulator::extractJSONData
static InnerType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
Definition: Accumulators.h:481
Gaudi::Accumulators::MsgCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1166
Gaudi::Accumulators::FalseAccumulator
FalseAccumulator.
Definition: Accumulators.h:660
Gaudi::Accumulators::MaxAccumulator::max
Arithmetic max() const
Definition: Accumulators.h:553
Gaudi::Accumulators::SigmaAccumulatorBase::standard_deviation
auto standard_deviation() const
Definition: Accumulators.h:767
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:414
fmt
Definition: MessageSvcSink.cpp:25
Gaudi::Accumulators::FalseTo1
helper functor for the FalseAccumulator
Definition: Accumulators.h:650
Gaudi::Accumulators::BinomialCounter::fromJSON
static BinomialCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1115
detected.h
Gaudi::Accumulators::AccumulatorSet::reset
void reset(const InternalType &t)
Definition: Accumulators.h:524
Gaudi::Accumulators::SigmaAccumulatorBase
SigmaAccumulatorBase.
Definition: Accumulators.h:746
Gaudi::Accumulators::Buffer
Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-sa...
Definition: Accumulators.h:814
Gaudi::Accumulators::CountAccumulator::nEntries
unsigned long nEntries() const
Definition: Accumulators.h:586
Gaudi::Accumulators::GenericAccumulator::operator+
void operator+(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &&other)
Definition: Accumulators.h:473
Gaudi::Accumulators::SigmaCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:996
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:965
Gaudi::Accumulators::atomicity
atomicity
Defines atomicity of the accumulators.
Definition: Accumulators.h:236
Gaudi::Accumulators::IntegralAccumulator::sum
Arithmetic sum() const
Definition: Accumulators.h:620
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:461
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:1028
Gaudi::Accumulators::construct_empty_t
constant used to disambiguate construction of an empty Accumulator versus the copy constructor.
Definition: Accumulators.h:411
std::ostringstream::str
T str(T... args)
Gaudi::Accumulators::AveragingCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:963
Gaudi::Accumulators::BinomialAccumulator::nEntries
unsigned long nEntries() const
Definition: Accumulators.h:673
Gaudi::Accumulators::BinomialCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1082
plotSpeedupsPyRoot.counter
counter
Definition: plotSpeedupsPyRoot.py:175
Gaudi::Accumulators::SigmaCounter::fromJSON
static SigmaCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1018
Gaudi::Accumulators::SigmaAccumulatorBase::biased_sample_variance
auto biased_sample_variance() const
Definition: Accumulators.h:753
Gaudi::Accumulators::TrueAccumulator::nTrueEntries
unsigned long nTrueEntries() const
Definition: Accumulators.h:646
Gaudi::Accumulators::BinomialCounter::reset
friend void reset(BinomialCounter &c)
Definition: Accumulators.h:1104
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:651
Gaudi::Accumulators::Counter::Counter
Counter(OWNER *o, std::string const &name)
Definition: Accumulators.h:909
Gaudi::Accumulators::atomicity::none
@ none
Gaudi::Accumulators::IntegralAccumulator::operator++
IntegralAccumulator operator++(int)
Definition: Accumulators.h:614
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::full, Compare, Initial >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:385
Gaudi::Accumulators::TrueTo1::operator()
unsigned int operator()(bool v) const
Definition: Accumulators.h:635
Gaudi::Accumulators::MsgCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1137
Gaudi::Accumulators::BinomialCounter::print
MsgStream & print(MsgStream &o, std::string_view tag) const override
Definition: Accumulators.h:1102
Gaudi::Accumulators::AveragingCounter::mergeAndReset
friend void mergeAndReset(AveragingCounter &c, AveragingCounter &o)
Definition: Accumulators.h:967
Gaudi::Accumulators::SigmaCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1006
Gaudi::Accumulators::StatCounter::to_json
friend void to_json(nlohmann::json &j, StatCounter const &c)
Definition: Accumulators.h:1051
Gaudi::Accumulators::SumAccumulator::sum
Arithmetic sum() const
Definition: Accumulators.h:596
Gaudi::Accumulators::MsgCounter::fromJSON
static MsgCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1174
Gaudi::Accumulators::AveragingCounter::fromJSON
static AveragingCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:975
Gaudi::Accumulators::Counter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:929
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:1204
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:946
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:932
Gaudi::Accumulators::operator<<
std::ostream & operator<<(std::ostream &s, const PrintableCounter &counter)
external printout operator to a stream type
Definition: Accumulators.h:865
Gaudi::Accumulators::SigmaCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1005
Gaudi::Accumulators::MsgCounter::to_json
friend void to_json(nlohmann::json &j, MsgCounter const &c)
Definition: Accumulators.h:1169
Gaudi::Accumulators::SigmaCounter::mergeAndReset
friend void mergeAndReset(SigmaCounter &c, SigmaCounter &o)
Definition: Accumulators.h:1008
Gaudi::Accumulators::BufferableCounter::~BufferableCounter
~BufferableCounter()
Definition: Accumulators.h:883
MsgStream.h
Gaudi::Accumulators::AveragingCounter::reset
friend void reset(AveragingCounter &c)
Definition: Accumulators.h:966
Gaudi::Accumulators::Counter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:925
Gaudi::Accumulators::BinomialAccumulator::binomial_t::nTotal
unsigned long nTotal
Definition: Accumulators.h:697
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:630