The Gaudi Framework  v36r5 (befafb8a)
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/algorithm/string/predicate.hpp"
208 #include "boost/format.hpp"
209 #include <atomic>
210 #include <cmath>
211 #include <iostream>
212 #include <limits>
213 #include <nlohmann/json.hpp>
214 #include <sstream>
215 #include <tuple>
216 #include <type_traits>
217 #include <utility>
218 
220 #include "GaudiKernel/MsgStream.h"
221 #include "GaudiKernel/detected.h"
222 
223 // Json serialization for std::chrono::duration
224 namespace nlohmann {
225  template <class Rep, class Period>
226  struct adl_serializer<std::chrono::duration<Rep, Period>> {
227  static void to_json( json& j, const std::chrono::duration<Rep, Period>& d ) { j = d.count(); }
228  static void from_json( const json& j, std::chrono::duration<Rep, Period>& d ) {
229  d = std::chrono::duration<Rep, Period>{ j.get<Rep>() };
230  }
231  };
232 } // namespace nlohmann
233 
234 namespace Gaudi::Accumulators {
235 
237  enum class atomicity { none, full };
238 
240  template <class T>
241  auto sqrt( T d );
242 
246  template <typename T, T N>
247  struct Constant {
248  template <typename U>
249  constexpr T operator()( U&& ) const noexcept {
250  return N;
251  }
252  };
253 
257  struct Identity {
258  template <typename U>
259  constexpr decltype( auto ) operator()( U&& v ) const noexcept {
260  return std::forward<U>( v );
261  }
262  };
263 
267  struct Square {
268  template <typename U>
269  constexpr decltype( auto ) operator()( U&& v ) const noexcept {
270  return v * v;
271  }
272  };
273 
277  template <typename T, typename = int>
278  using has_fetch_add_ = decltype( std::declval<T&>().fetch_add( 0 ) );
279  template <typename T>
280  inline constexpr bool has_fetch_add_v = Gaudi::cpp17::is_detected_v<has_fetch_add_, T>;
281 
285  template <typename Arithmetic, typename Result = double>
286  using fp_result_type = std::conditional_t<std::is_integral_v<Arithmetic>, Result, Arithmetic>;
287 
291  template <typename Arithmetic, atomicity Atomicity>
293 
297  template <typename Arithmetic>
298  struct BaseValueHandler<Arithmetic, atomicity::none> {
299  using OutputType = Arithmetic;
300  using InternalType = Arithmetic;
301  static constexpr OutputType getValue( const InternalType& v ) noexcept { return v; };
302  static Arithmetic exchange( InternalType& v, Arithmetic newv ) noexcept { return std::exchange( v, newv ); }
303  };
304 
308  template <typename Arithmetic>
309  struct BaseValueHandler<Arithmetic, atomicity::full> {
310  using OutputType = Arithmetic;
312  static constexpr OutputType getValue( const InternalType& v ) noexcept {
313  return v.load( std::memory_order_relaxed );
314  };
315  static Arithmetic exchange( InternalType& v, Arithmetic newv ) noexcept { return v.exchange( newv ); }
316  };
317 
322  template <typename Arithmetic, atomicity Atomicity>
323  struct Adder;
324 
328  template <typename Arithmetic>
329  struct Adder<Arithmetic, atomicity::none> : BaseValueHandler<Arithmetic, atomicity::none> {
332  static constexpr OutputType DefaultValue() { return Arithmetic{}; }
333  static void merge( InternalType& a, Arithmetic b ) noexcept { a += b; };
334  };
335 
339  template <typename Arithmetic>
340  struct Adder<Arithmetic, atomicity::full> : BaseValueHandler<Arithmetic, atomicity::full> {
343  static constexpr OutputType DefaultValue() { return Arithmetic{}; }
344  static void merge( InternalType& a, Arithmetic b ) noexcept {
345  if ( DefaultValue() == b ) return; // avoid atomic operation if b is "0"
346  if constexpr ( has_fetch_add_v<InternalType> ) {
347  a.fetch_add( b, std::memory_order_relaxed );
348  } else {
350  while ( !a.compare_exchange_weak( current, current + b ) )
351  ;
352  }
353  };
354  };
355 
360  template <typename Arithmetic, atomicity Atomicity, typename Compare, Arithmetic ( *Initial )()>
361  struct Extremum;
362 
366  template <typename Arithmetic, typename Compare, Arithmetic ( *Initial )()>
367  struct Extremum<Arithmetic, atomicity::none, Compare, Initial> : BaseValueHandler<Arithmetic, atomicity::none> {
370  static constexpr OutputType DefaultValue() { return Initial(); }
371  static void merge( InternalType& a, Arithmetic b ) noexcept {
372  if ( Compare{}( b, a ) ) a = b;
373  };
374  };
375 
379  template <typename Arithmetic, typename Compare, Arithmetic ( *Initial )()>
380  struct Extremum<Arithmetic, atomicity::full, Compare, Initial> : BaseValueHandler<Arithmetic, atomicity::full> {
383  static constexpr OutputType DefaultValue() { return Initial(); }
384  static void merge( InternalType& a, Arithmetic b ) noexcept {
385  Arithmetic prev_value = BaseValueHandler<Arithmetic, atomicity::full>::getValue( a );
386  while ( Compare{}( b, prev_value ) && !a.compare_exchange_weak( prev_value, b ) )
387  ;
388  };
389  };
390 
395  template <typename Arithmetic, atomicity Atomicity = atomicity::full>
397 
402  template <typename Arithmetic, atomicity Atomicity = atomicity::full>
404 
411  explicit construct_empty_t() = default;
412  };
414 
432  template <typename InputTypeT, typename InnerType, atomicity Atomicity = atomicity::full,
433  typename InputTransform = Identity, typename OutputTransform = Identity,
434  typename ValueHandler = Adder<InnerType, Atomicity>>
436  template <typename, typename, atomicity, typename, typename, typename>
437  friend class GenericAccumulator;
438 
439  public:
440  using InputType = InputTypeT;
441  using OutputType = std::decay_t<std::result_of_t<OutputTransform( InnerType )>>;
442  using InternalType = InnerType;
445  ValueHandler::merge( m_value, InputTransform{}( by ) );
446  return *this;
447  }
448  GenericAccumulator() = default;
450  template <atomicity ato, typename VH>
453  : GenericAccumulator() {}
454  template <typename... Args>
455  GenericAccumulator( std::in_place_t, Args&&... args ) : m_value( std::forward<Args>( args )... ) {}
456  GenericAccumulator( const GenericAccumulator& other ) : m_value( ValueHandler::getValue( other.m_value ) ) {}
458  m_value = ValueHandler::getValue( other.m_value );
459  return *this;
460  }
461  OutputType value() const { return OutputTransform{}( ValueHandler::getValue( m_value ) ); }
462  void reset() { reset( ValueHandler::DefaultValue() ); }
463  template <atomicity ato, typename VH>
465  ValueHandler::merge( m_value, VH::exchange( other.m_value, VH::DefaultValue() ) );
466  }
467  template <atomicity ato, typename VH>
469  ValueHandler::merge( m_value, other.m_value );
470  }
471 
472  protected:
473  auto rawValue() const { return ValueHandler::getValue( m_value ); }
474  void reset( InnerType in ) { m_value = std::move( in ); }
475  static InnerType extractJSONData( const nlohmann::json& j, const JSONStringEntriesType& entries ) {
476  return j.at( entries ).get<InnerType>();
477  }
478 
479  private:
480  typename ValueHandler::InternalType m_value{ ValueHandler::DefaultValue() };
481  };
482 
488  template <typename Arithmetic, atomicity Atomicity, typename InputTypeT = Arithmetic,
489  template <atomicity, typename> class... Bases>
490  class AccumulatorSet : public Bases<Atomicity, Arithmetic>... {
491  public:
492  using InputType = InputTypeT;
496  constexpr AccumulatorSet() = default;
498  template <atomicity ato>
500  : AccumulatorSet() {}
502  ( Bases<Atomicity, Arithmetic>::operator+=( by ), ... );
503  return *this;
504  }
505  OutputType value() const { return std::make_tuple( Bases<Atomicity, Arithmetic>::value()... ); }
506  void reset() { ( Bases<Atomicity, Arithmetic>::reset(), ... ); }
507  template <atomicity Ato>
509  ( Bases<Atomicity, Arithmetic>::mergeAndReset( static_cast<Bases<Ato, Arithmetic>&&>( other ) ), ... );
510  }
511  template <atomicity Ato>
513  ( Bases<Atomicity, Arithmetic>::operator+( static_cast<Bases<Ato, Arithmetic>&&>( other ) ), ... );
514  }
515 
516  protected:
517  void reset( const InternalType& t ) {
518  std::apply( [this]( const auto&... i ) { ( this->Bases<Atomicity, Arithmetic>::reset( i ), ... ); }, t );
519  }
521  return extractJSONDataHelper( j, entries, std::index_sequence_for<Bases<Atomicity, Arithmetic>...>{} );
522  }
523 
524  private:
525  template <size_t... Is>
527  std::index_sequence<Is...> ) {
528  return extractJSONDataHelper( j, std::get<Is>( entries )... );
529  }
530  static InternalType
532  typename Bases<Atomicity, Arithmetic>::JSONStringEntriesType... entries ) {
533  return { Bases<Atomicity, Arithmetic>::extractJSONData( j, entries )... };
534  }
535  };
536 
541  template <atomicity Atomicity, typename Arithmetic = double>
543  : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Maximum<Arithmetic, Atomicity>> {
544  using GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity,
546  Arithmetic max() const { return this->value(); }
547  };
548 
553  template <atomicity Atomicity, typename Arithmetic = double>
555  : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity, Minimum<Arithmetic, Atomicity>> {
556  using GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity, Identity,
558  Arithmetic min() const { return this->value(); }
559  };
560 
567  template <atomicity Atomicity, typename Arithmetic = double>
568  struct CountAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, Constant<unsigned long, 1UL>> {
571  ( *this ) += Arithmetic{};
572  return *this;
573  }
575  auto copy = *this;
576  ++( *this );
577  return copy;
578  }
579  unsigned long nEntries() const { return this->value(); }
580  };
581 
586  template <atomicity Atomicity, typename Arithmetic = double>
587  struct SumAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity> {
589  Arithmetic sum() const { return this->value(); }
590  };
591 
597  template <atomicity Atomicity, typename Arithmetic = unsigned long>
598  struct IntegralAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Identity> {
599  static_assert( std::is_integral_v<Arithmetic>,
600  "Invalid Arithmetic type for IntegralAccumulator. It must be an integral type" );
601 
604  ( *this ) += 1;
605  return *this;
606  }
608  auto copy = *this;
609  ++( *this );
610  return copy;
611  }
612  Arithmetic nEntries() const { return this->value(); }
613  Arithmetic sum() const { return this->value(); }
614  };
615 
620  template <atomicity Atomicity, typename Arithmetic = double>
621  struct SquareAccumulator : GenericAccumulator<Arithmetic, Arithmetic, Atomicity, Square> {
623  Arithmetic sum2() const { return this->value(); };
624  };
625 
627  struct TrueTo1 {
628  unsigned int operator()( bool v ) const { return v; }
629  };
630 
636  template <atomicity Atomicity, typename Arithmetic>
637  struct TrueAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, TrueTo1> {
639  unsigned long nTrueEntries() const { return this->value(); };
640  };
641 
643  struct FalseTo1 {
644  unsigned int operator()( bool v ) const { return !v; }
645  };
646 
652  template <atomicity Atomicity, typename Arithmetic>
653  struct FalseAccumulator : GenericAccumulator<Arithmetic, unsigned long, Atomicity, FalseTo1> {
655  unsigned long nFalseEntries() const { return this->value(); };
656  };
657 
663  template <atomicity Atomicity, typename Arithmetic>
664  struct BinomialAccumulator : AccumulatorSet<bool, Atomicity, bool, TrueAccumulator, FalseAccumulator> {
666  unsigned long nEntries() const { return this->nTrueEntries() + this->nFalseEntries(); };
667 
668  template <typename Result = fp_result_type<Arithmetic>>
669  auto efficiency() const {
670  auto nbEntries = nEntries();
671  if ( 1 > nbEntries ) return Result{ -1 };
672  return static_cast<Result>( this->nTrueEntries() ) / nbEntries;
673  }
674  auto eff() const { return efficiency(); }
675 
676  template <typename Result = fp_result_type<Arithmetic>>
677  auto efficiencyErr() const {
678  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
679  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
681  using std::sqrt;
682  auto nbEntries = nEntries();
683  if ( 1 > nbEntries ) return Result{ -1 };
684  return sqrt( static_cast<Result>( this->nTrueEntries() * this->nFalseEntries() ) / nbEntries ) / nbEntries;
685  }
686  auto effErr() const { return efficiencyErr(); }
688  struct binomial_t {
689  unsigned long nPass;
690  unsigned long nTotal;
691  };
692  BinomialAccumulator& operator+=( binomial_t b ) {
693  assert( b.nPass <= b.nTotal );
695  TrueAccumulator<atomicity::none, bool>{ std::in_place, b.nPass } );
697  FalseAccumulator<atomicity::none, bool>{ std::in_place, b.nTotal - b.nPass } );
698  return *this;
699  }
700  };
701 
707  template <atomicity Atomicity, typename Arithmetic, template <atomicity, typename> typename CountAcc,
708  template <atomicity, typename> typename SumAcc>
710  : AccumulatorSet<Arithmetic, Atomicity, typename CountAcc<Atomicity, Arithmetic>::InputType, CountAcc, SumAcc> {
711  static_assert( std::is_same_v<typename CountAcc<Atomicity, Arithmetic>::InputType,
712  typename SumAcc<Atomicity, Arithmetic>::InputType>,
713  "Incompatible Counters in definition of AveragingAccumulator. Both should have identical Input" );
715  SumAcc>::AccumulatorSet;
716  template <typename Result = fp_result_type<Arithmetic>>
717  auto mean() const {
718  auto n = this->nEntries();
719  Result sum = this->sum();
720  return ( n > 0 ) ? static_cast<Result>( sum / n ) : Result{};
721  }
722  };
723 
728  template <atomicity Atomicity, typename Arithmetic>
730 
736  template <atomicity Atomicity, typename Arithmetic, template <atomicity, typename> typename AvgAcc,
737  template <atomicity, typename> typename SquareAcc>
739  : AccumulatorSet<Arithmetic, Atomicity, typename AvgAcc<Atomicity, Arithmetic>::InputType, AvgAcc, SquareAcc> {
740  static_assert( std::is_same_v<typename AvgAcc<Atomicity, Arithmetic>::InputType,
741  typename SquareAcc<Atomicity, Arithmetic>::InputType>,
742  "Incompatible Counters in definition of SigmaAccumulator. Both should have identical Input" );
744  SquareAcc>::AccumulatorSet;
745  template <typename Result = fp_result_type<Arithmetic>>
746  auto biased_sample_variance() const {
747  auto n = this->nEntries();
748  Result sum = this->sum();
749  return ( n > 0 ) ? static_cast<Result>( ( this->sum2() - sum * ( sum / n ) ) / n ) : Result{};
750  }
751 
752  template <typename Result = fp_result_type<Arithmetic>>
754  auto n = this->nEntries();
755  Result sum = this->sum();
756  return ( n > 1 ) ? static_cast<Result>( ( this->sum2() - sum * ( sum / n ) ) / ( n - 1 ) ) : Result{};
757  }
758 
759  template <typename Result = fp_result_type<Arithmetic>>
760  auto standard_deviation() const {
761  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
762  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
764  using std::sqrt;
765  Result v = biased_sample_variance();
766  return ( Result{ 0 } > v ) ? Result{} : static_cast<Result>( sqrt( v ) );
767  }
768  [[deprecated( "The name 'rms' has changed to standard_deviation" )]] Arithmetic rms() const {
769  return standard_deviation();
770  }
771 
772  template <typename Result = fp_result_type<Arithmetic>>
773  auto meanErr() const {
774  auto n = this->nEntries();
775  if ( 0 == n ) return Result{};
776  // Note the usage of using, aiming at using the std version of sqrt by default, without preventing
777  // more specialized versions to be used via ADL (see http://en.cppreference.com/w/cpp/language/adl)
779  using std::sqrt;
780  Result v = biased_sample_variance();
781  return ( Result{ 0 } > v ) ? Result{} : static_cast<Result>( sqrt( v / n ) );
782  }
783  };
784 
789  template <atomicity Atomicity, typename Arithmetic>
791 
796  template <atomicity Atomicity, typename Arithmetic>
799 
806  template <template <atomicity Ato, typename... Int> class ContainedAccumulator, atomicity Atomicity, typename... Args>
807  class Buffer : public ContainedAccumulator<atomicity::none, Args...> {
808  using prime_type = ContainedAccumulator<Atomicity, Args...>;
809  using base_type = ContainedAccumulator<atomicity::none, Args...>;
810 
811  public:
812  Buffer() = delete;
813  Buffer( prime_type& p ) : base_type( construct_empty, p ), m_prime( p ) {}
814  Buffer( const Buffer& ) = delete;
815  void operator=( const Buffer& ) = delete;
816  Buffer( Buffer&& other ) : base_type( other ), m_prime( other.m_prime ) { other.reset(); }
817  void push() { m_prime.mergeAndReset( static_cast<base_type&&>( *this ) ); }
818  ~Buffer() { push(); }
819 
820  private:
822  };
823 
829  PrintableCounter() = default;
831  virtual ~PrintableCounter() = default;
832  // add tag to printout
833  template <typename stream>
834  stream& printImpl( stream& s, std::string_view tag ) const {
835  s << boost::format{ " | %|-48.48s|%|50t|" } % ( std::string{ '\"' }.append( tag ).append( "\"" ) );
836  return print( s, true );
837  }
839  virtual std::ostream& print( std::ostream&, bool tableFormat = false ) const = 0;
840  virtual MsgStream& print( MsgStream&, bool tableFormat = true ) const = 0;
842  virtual std::ostream& print( std::ostream& o, std::string_view tag ) const { return printImpl( o, tag ); }
843  virtual MsgStream& print( MsgStream& o, std::string_view tag ) const { return printImpl( o, tag ); }
846  virtual bool toBePrinted() const { return true; }
849  std::ostringstream ost;
850  print( ost );
851  return ost.str();
852  }
854  virtual nlohmann::json toJSON() const = 0;
855  };
856 
860  inline std::ostream& operator<<( std::ostream& s, const PrintableCounter& counter ) { return counter.print( s ); }
861  inline MsgStream& operator<<( MsgStream& s, const PrintableCounter& counter ) { return counter.print( s ); }
868  template <atomicity Atomicity, template <atomicity Ato, typename... Int> class Accumulator, typename... Args>
869  class BufferableCounter : public PrintableCounter, public Accumulator<Atomicity, Args...> {
870  public:
871  BufferableCounter() = default;
872  template <typename OWNER, typename... CARGS>
873  BufferableCounter( OWNER* o, std::string const& name, const std::string counterType, CARGS... args )
874  : Accumulator<Atomicity, Args...>( args... ), m_monitoringHub( &o->serviceLocator()->monitoringHub() ) {
875  m_monitoringHub->registerEntity( o->name(), name, counterType, *this );
876  }
877  template <typename OWNER>
878  BufferableCounter( OWNER* o, std::string const& name ) : BufferableCounter( o, name, "counter" ) {}
879  Buffer<Accumulator, Atomicity, Args...> buffer() { return { *this }; }
883  if ( m_monitoringHub ) { m_monitoringHub->removeEntity( *this ); }
884  }
885 
886  private:
887  Monitoring::Hub* m_monitoringHub{ nullptr };
888  };
889 
894  template <atomicity Atomicity = atomicity::full, typename Arithmetic = unsigned long>
895  struct Counter : BufferableCounter<Atomicity, IntegralAccumulator, Arithmetic> {
896  inline static const std::string typeString{ std::string{ "counter:Counter:" } + typeid( unsigned long ).name() };
898  template <typename OWNER>
899  Counter( OWNER* o, std::string const& name )
900  : BufferableCounter<Atomicity, IntegralAccumulator, Arithmetic>( o, name, typeString ) {}
901  Counter& operator++() { return ( *this ) += 1; }
902  Counter& operator+=( const Arithmetic v ) {
904  return *this;
905  }
907 
908  template <typename stream>
909  stream& printImpl( stream& o, bool tableFormat ) const {
910  // Avoid printing empty counters in non DEBUG mode
911  auto fmt = ( tableFormat ? "|%|10d| |" : "#=%|-7lu|" );
912  return o << boost::format{ fmt } % this->nEntries();
913  }
914 
915  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
916  return printImpl( o, tableFormat );
917  }
918  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
919  bool toBePrinted() const override { return this->nEntries() > 0; }
920  virtual nlohmann::json toJSON() const override {
921  return { { "type", typeString }, { "empty", this->nEntries() == 0 }, { "nEntries", this->nEntries() } };
922  }
923  static Counter fromJSON( const nlohmann::json& j ) {
924  return CountAccumulator<Atomicity, int>::extractJSONData( j, { "nEntries" } );
925  }
926  };
927 
932  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
933  struct AveragingCounter : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic> {
934  inline static const std::string typeString{ std::string{ "counter:AveragingCounter:" } +
935  typeid( Arithmetic ).name() };
937  template <typename OWNER>
938  AveragingCounter( OWNER* o, std::string const& name )
939  : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic>( o, name, typeString ) {}
941 
942  template <typename stream>
943  stream& printImpl( stream& o, bool tableFormat ) const {
944  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |" : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g|" );
945  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean();
946  }
947 
948  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
949  return printImpl( o, tableFormat );
950  }
951  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
952 
953  bool toBePrinted() const override { return this->nEntries() > 0; }
954  virtual nlohmann::json toJSON() const override {
955  return { { "type", typeString },
956  { "empty", this->nEntries() == 0 },
957  { "nEntries", this->nEntries() },
958  { "sum", this->sum() },
959  { "mean", this->mean() } };
960  }
962  return AveragingAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { "nEntries", "sum" } );
963  }
964  };
965  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
967 
972  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
973  struct SigmaCounter : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic> {
974  inline static const std::string typeString{ std::string{ "counter:SigmaCounter:" } + typeid( Arithmetic ).name() };
976  template <typename OWNER>
977  SigmaCounter( OWNER* o, std::string const& name )
978  : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic>( o, name, typeString ) {}
980 
981  template <typename stream>
982  stream& printImpl( stream& o, bool tableFormat ) const {
983  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |"
984  : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g|" );
985  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean() % this->standard_deviation();
986  }
987 
988  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
989  return printImpl( o, tableFormat );
990  }
991  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
992  bool toBePrinted() const override { return this->nEntries() > 0; }
993  virtual nlohmann::json toJSON() const override {
994  return { { "type", typeString },
995  { "empty", this->nEntries() == 0 },
996  { "nEntries", this->nEntries() },
997  { "sum", this->sum() },
998  { "mean", this->mean() },
999  { "sum2", this->sum2() },
1000  { "standard_deviation", this->standard_deviation() } };
1001  }
1002  static SigmaCounter fromJSON( const nlohmann::json& j ) {
1003  return SigmaAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { { "nEntries", "sum" }, "sum2" } );
1004  }
1005  };
1006 
1011  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
1012  struct StatCounter : BufferableCounter<Atomicity, StatAccumulator, Arithmetic> {
1013  inline static const std::string typeString{ std::string{ "counter:StatCounter:" } + typeid( Arithmetic ).name() };
1015  template <typename OWNER>
1016  StatCounter( OWNER* o, std::string const& name )
1017  : BufferableCounter<Atomicity, StatAccumulator, Arithmetic>( o, name, typeString ) {}
1019 
1020  template <typename stream>
1021  stream& printImpl( stream& o, bool tableFormat ) const {
1022  auto fmt = ( tableFormat ? "|%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |"
1023  : "#=%|-7lu| Sum=%|-11.5g| Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" );
1024  return o << boost::format{ fmt } % this->nEntries() % this->sum() % this->mean() % this->standard_deviation() %
1025  this->min() % this->max();
1026  }
1027 
1028  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1029  return printImpl( o, tableFormat );
1030  }
1031  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1032  bool toBePrinted() const override { return this->nEntries() > 0; }
1033  virtual nlohmann::json toJSON() const override {
1034  return { { "type", typeString },
1035  { "empty", this->nEntries() == 0 },
1036  { "nEntries", this->nEntries() },
1037  { "sum", this->sum() },
1038  { "mean", this->mean() },
1039  { "sum2", this->sum2() },
1040  { "standard_deviation", this->standard_deviation() },
1041  { "min", this->min() },
1042  { "max", this->max() } };
1043  }
1044  static StatCounter fromJSON( const nlohmann::json& j ) {
1046  j, { { { "nEntries", "sum" }, "sum2" }, "min", "max" } );
1047  }
1048  };
1049 
1054  template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
1055  struct BinomialCounter : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic> {
1056  inline static const std::string typeString{ std::string{ "counter:BinomialCounter:" } +
1057  typeid( Arithmetic ).name() };
1059  template <typename OWNER>
1060  BinomialCounter( OWNER* o, std::string const& name )
1061  : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic>( o, name, typeString ) {}
1062 
1063  template <typename stream>
1064  stream& printImpl( stream& o, bool tableFormat ) const {
1065  auto fmt = ( tableFormat ? "|%|10d| |%|11.5g| |(%|#9.7g| +- %|-#8.7g|)%% |"
1066  : "#=%|-7lu| Sum=%|-11.5g| Eff=|(%|#9.7g| +- %|-#8.6g|)%%|" );
1067  return o << boost::format{ fmt } % this->nEntries() % this->nTrueEntries() % ( this->efficiency() * 100 ) %
1068  ( this->efficiencyErr() * 100 );
1069  }
1070 
1071  std::ostream& print( std::ostream& o, bool tableFormat = false ) const override {
1072  return printImpl( o, tableFormat );
1073  }
1074  MsgStream& print( MsgStream& o, bool tableFormat = false ) const override { return printImpl( o, tableFormat ); }
1075 
1076  template <typename stream>
1077  stream& printImpl( stream& o, std::string_view tag ) const {
1078  // override default print to add a '*' in from of the name
1079  o << boost::format{ " |*%|-48.48s|%|50t|" } % ( std::string{ "\"" }.append( tag ).append( "\"" ) );
1080  return print( o, true );
1081  }
1083  std::ostream& print( std::ostream& o, std::string_view tag ) const override { return printImpl( o, tag ); }
1084  MsgStream& print( MsgStream& o, std::string_view tag ) const override { return printImpl( o, tag ); }
1085  bool toBePrinted() const override { return this->nEntries() > 0; }
1086  virtual nlohmann::json toJSON() const override {
1087  return { { "type", typeString },
1088  { "empty", this->nEntries() == 0 },
1089  { "nEntries", this->nTrueEntries() + this->nFalseEntries() },
1090  { "nTrueEntries", this->nTrueEntries() },
1091  { "nFalseEntries", this->nFalseEntries() },
1092  { "efficiency", this->efficiency() },
1093  { "efficiencyErr", this->efficiencyErr() } };
1094  }
1096  return BinomialAccumulator<Atomicity, Arithmetic>::extractJSONData( j, { "nTrueEntries", "nFalseEntries" } );
1097  }
1098  };
1099 
1100  namespace details::MsgCounter {
1101  template <atomicity Atomicity>
1102  struct Handler : Adder<unsigned long, Atomicity> {
1104  static void merge( typename Base::InternalType& orig, bool b ) {
1105  if ( b ) Base::merge( orig, 1 );
1106  }
1107  };
1108  // note that Arithmetic type is unused in this case but needs to be there in case
1109  // we want to create AccumulatorSets with this Accumulator
1110  template <atomicity Atomicity, typename Arithmetic = double>
1112  } // namespace details::MsgCounter
1113 
1114  template <MSG::Level level, atomicity Atomicity = atomicity::full>
1116  public:
1117  inline static const std::string typeString{ "counter:MsgCounter" };
1118  template <typename OWNER>
1119  MsgCounter( OWNER* o, std::string const& ms, int nMax = 10 )
1120  : m_monitoringHub{ o->serviceLocator()->monitoringHub() }, logger( o ), msg( ms ), max( nMax ) {
1121  m_monitoringHub.registerEntity( o->name(), std::move( ms ), typeString, *this );
1122  }
1124  ( *this ) += true;
1125  return *this;
1126  }
1127  MsgCounter& operator+=( const bool by ) {
1129  if ( by ) log();
1130  return *this;
1131  }
1132  MsgCounter( MsgCounter const& ) = delete;
1133  MsgCounter& operator=( MsgCounter const& ) = delete;
1135  template <typename stream>
1136  stream& printImpl( stream& o, bool tableFormat ) const {
1137  return o << boost::format{ tableFormat ? "|%|10d| |" : "#=%|-7lu|" } % this->value();
1138  }
1140  std::ostream& print( std::ostream& os, bool tableFormat ) const override { return printImpl( os, tableFormat ); }
1141  MsgStream& print( MsgStream& os, bool tableFormat ) const override { return printImpl( os, tableFormat ); }
1142  bool toBePrinted() const override { return this->value() > 0; }
1143  virtual nlohmann::json toJSON() const override {
1144  return { { "type", typeString },
1145  { "empty", this->value() == 0 },
1146  { "nEntries", this->value() },
1147  { "level", level },
1148  { "max", max },
1149  { "msg", msg } };
1150  }
1151  static MsgCounter fromJSON( const nlohmann::json& j ) {
1152  MsgCounter c = MsgCounter::extractJSONData( j, { "nEntries" } );
1153  c.msg = j.at( "msg" ).get<std::string>();
1154  c.max = j.at( "max" ).get<unsigned long>();
1155  }
1156 
1157  private:
1159  const CommonMessagingBase* logger{ nullptr };
1161  unsigned long max;
1162  void log() {
1163  if ( this->value() <= max && logger ) {
1164  if ( this->value() == max ) {
1165  logger->msgStream( level ) << "Suppressing message: " << std::quoted( msg, '\'' ) << endmsg;
1166  } else {
1167  logger->msgStream( level ) << msg << endmsg;
1168  }
1169  }
1170  }
1171  };
1172 
1178  template <typename Counter, typename Container, typename Fun>
1179  void accumulate( Counter& counter, const Container& container, Fun f = Identity{} ) {
1180  auto b = counter.buffer();
1181  for ( const auto& elem : container ) b += f( elem );
1182  }
1183 
1184 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::full >::OutputType
Arithmetic OutputType
Definition: Accumulators.h:310
Gaudi::Accumulators::PrintableCounter
An empty ancester of all counters that knows how to print themselves.
Definition: Accumulators.h:828
Gaudi::Accumulators::BufferableCounter::buffer
Buffer< Accumulator, Atomicity, Args... > buffer()
Definition: Accumulators.h:879
Gaudi::Accumulators::PrintableCounter::printImpl
stream & printImpl(stream &s, std::string_view tag) const
Definition: Accumulators.h:834
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:442
Gaudi::Accumulators::BinomialCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1056
Gaudi::Accumulators::Buffer::m_prime
prime_type & m_prime
Definition: Accumulators.h:821
Gaudi::Accumulators::AccumulatorSet::extractJSONData
static InternalType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
Definition: Accumulators.h:520
std::make_tuple
T make_tuple(T... args)
Gaudi::Accumulators::SigmaCounter::toJSON
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
Definition: Accumulators.h:993
Gaudi::Accumulators::MsgCounter::logger
const CommonMessagingBase * logger
Definition: Accumulators.h:1159
Gaudi::Accumulators::StatCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1021
Gaudi::Accumulators::CountAccumulator::operator++
CountAccumulator & operator++()
Definition: Accumulators.h:570
Gaudi::Accumulators::MsgCounter::log
void log()
Definition: Accumulators.h:1162
Write.stream
stream
Definition: Write.py:32
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::InternalType
Arithmetic InternalType
Definition: Accumulators.h:300
Gaudi::Accumulators::Buffer::prime_type
ContainedAccumulator< Atomicity, Args... > prime_type
Definition: Accumulators.h:808
std::string
STL class.
Gaudi::Accumulators::Buffer::push
void push()
Definition: Accumulators.h:817
GaudiPython.HistoUtils.nEntries
nEntries
Definition: HistoUtils.py:939
Gaudi::Accumulators::TrueAccumulator
TrueAccumulator.
Definition: Accumulators.h:637
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:1083
Gaudi::Accumulators::BaseValueHandler
Base type for all functors used as ValuesHandler.
Definition: Accumulators.h:292
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(BufferableCounter const &)=delete
Gaudi::Accumulators::AccumulatorSet::operator+=
AccumulatorSet & operator+=(const InputType by)
Definition: Accumulators.h:501
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:480
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(MsgCounter const &)=delete
std::move
T move(T... args)
Gaudi::Accumulators::SigmaCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:973
Gaudi::Accumulators::MsgCounter::m_monitoringHub
Monitoring::Hub & m_monitoringHub
Definition: Accumulators.h:1158
Gaudi::Accumulators::Adder< Arithmetic, atomicity::full >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:343
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::full >::getValue
static constexpr OutputType getValue(const InternalType &v) noexcept
Definition: Accumulators.h:312
Gaudi::Accumulators::PrintableCounter::toBePrinted
virtual bool toBePrinted() const
hint whether we should print that counter or not.
Definition: Accumulators.h:846
Gaudi::Accumulators::BufferableCounter::operator=
BufferableCounter & operator=(BufferableCounter const &)=delete
MonitoringHub.h
Gaudi::Accumulators::GenericAccumulator::rawValue
auto rawValue() const
Definition: Accumulators.h:473
Gaudi::Accumulators::AccumulatorSet
AccumulatorSet is an Accumulator that holds a set of Accumulators templated by same Arithmetic and At...
Definition: Accumulators.h:490
Gaudi::Accumulators::SumAccumulator
SumAccumulator.
Definition: Accumulators.h:587
Gaudi::Accumulators::AveragingCounter::AveragingCounter
AveragingCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:938
Gaudi::Accumulators::atomicity::full
@ full
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::exchange
static Arithmetic exchange(InternalType &v, Arithmetic newv) noexcept
Definition: Accumulators.h:302
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:346
Gaudi::Accumulators::StatCounter::fromJSON
static StatCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1044
Gaudi::Accumulators::MsgCounter::MsgCounter
MsgCounter(OWNER *o, std::string const &ms, int nMax=10)
Definition: Accumulators.h:1119
Gaudi::Accumulators::MsgCounter::print
MsgStream & print(MsgStream &os, bool tableFormat) const override
Definition: Accumulators.h:1141
Gaudi::Accumulators::SigmaCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:988
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:301
Gaudi::Accumulators::PrintableCounter::toString
std::string toString() const
get a string representation
Definition: Accumulators.h:848
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter()=default
Gaudi::Accumulators::details::MsgCounter::Handler
Definition: Accumulators.h:1102
Gaudi::Accumulators::MsgCounter::msg
std::string msg
Definition: Accumulators.h:1160
Gaudi::Accumulators::IntegralAccumulator
IntegralAccumulator.
Definition: Accumulators.h:598
Gaudi::Accumulators::BinomialCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1085
Gaudi::Accumulators::AveragingCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:948
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::none, Compare, Initial >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:371
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(std::in_place_t, Args &&... args)
Definition: Accumulators.h:455
Gaudi::Accumulators::SquareAccumulator
SquareAccumulator.
Definition: Accumulators.h:621
std::chrono::duration
Gaudi::Accumulators::GenericAccumulator::reset
void reset()
Definition: Accumulators.h:462
Gaudi::Accumulators::Counter::fromJSON
static Counter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:923
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::none >::OutputType
Arithmetic OutputType
Definition: Accumulators.h:299
Gaudi::Accumulators::PrintableCounter::print
virtual MsgStream & print(MsgStream &, bool tableFormat=true) const =0
nlohmann
Definition: Accumulators.h:224
Gaudi::Accumulators::MsgCounter::operator++
MsgCounter & operator++()
Definition: Accumulators.h:1123
Gaudi::Accumulators::MsgCounter::~MsgCounter
~MsgCounter()
Definition: Accumulators.h:1134
CommonMessagingBase
Definition: CommonMessaging.h:68
Gaudi::Accumulators::MinAccumulator
MinAccumulator.
Definition: Accumulators.h:555
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition: Accumulators.h:933
Gaudi::Accumulators::PrintableCounter::PrintableCounter
PrintableCounter()=default
IOTest.N
int N
Definition: IOTest.py:115
Gaudi::Accumulators::AccumulatorSet::reset
void reset()
Definition: Accumulators.h:506
Gaudi::Accumulators::Buffer::Buffer
Buffer(const Buffer &)=delete
Gaudi::Accumulators::BinomialCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1074
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:499
Gaudi::Accumulators::BinomialCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1071
std::tuple
Gaudi::Accumulators::MinAccumulator::min
Arithmetic min() const
Definition: Accumulators.h:558
gaudirun.c
c
Definition: gaudirun.py:525
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:842
Gaudi::Accumulators::SigmaAccumulatorBase::meanErr
auto meanErr() const
Definition: Accumulators.h:773
class
#define class
Definition: HistogramPersistencySvc.cpp:54
Gaudi::Accumulators::BinomialAccumulator::operator+=
BinomialAccumulator & operator+=(binomial_t b)
Definition: Accumulators.h:692
Gaudi::Accumulators::BinomialCounter::BinomialCounter
BinomialCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:1060
Counter
Definition: Counter.py:1
Gaudi::Accumulators::AccumulatorSet::operator+
void operator+(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &&other)
Definition: Accumulators.h:512
Gaudi::Accumulators::MsgCounter::operator=
MsgCounter & operator=(MsgCounter const &)=delete
Gaudi::Accumulators::Counter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:909
Gaudi::Accumulators::TrueTo1
helper functor for the TrueAccumulator
Definition: Accumulators.h:627
Gaudi::Accumulators::AveragingAccumulatorBase
AveragingAccumulatorBase.
Definition: Accumulators.h:710
jsonFromLHCbLog.json
dictionary json
Definition: jsonFromLHCbLog.py:87
Gaudi::Accumulators::BaseValueHandler< Arithmetic, atomicity::full >::exchange
static Arithmetic exchange(InternalType &v, Arithmetic newv) noexcept
Definition: Accumulators.h:315
Gaudi::Accumulators::Buffer::base_type
ContainedAccumulator< atomicity::none, Args... > base_type
Definition: Accumulators.h:809
Gaudi::Accumulators::SigmaCounter::SigmaCounter
SigmaCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:977
Gaudi::Accumulators::BinomialAccumulator::binomial_t
Definition: Accumulators.h:688
std::sqrt
T sqrt(T... args)
Gaudi::Accumulators::Counter::operator+=
Counter & operator+=(const Arithmetic v)
Definition: Accumulators.h:902
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:878
Gaudi::Accumulators::AccumulatorSet::extractJSONDataHelper
static InternalType extractJSONDataHelper(const nlohmann::json &j, typename Bases< Atomicity, Arithmetic >::JSONStringEntriesType... entries)
Definition: Accumulators.h:531
Gaudi::Accumulators::Square
A Square functor.
Definition: Accumulators.h:267
Gaudi::Accumulators::Counter::operator++
Counter & operator++()
Definition: Accumulators.h:901
Gaudi::Units::ms
constexpr double ms
Definition: SystemOfUnits.h:154
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::InputType
bool InputType
Definition: Accumulators.h:440
Gaudi::Accumulators::MsgCounter::operator+=
MsgCounter & operator+=(const bool by)
Definition: Accumulators.h:1127
Gaudi::Accumulators::AccumulatorSet::mergeAndReset
void mergeAndReset(AccumulatorSet< Arithmetic, Ato, InputType, Bases... > &&other)
Definition: Accumulators.h:508
Gaudi::Accumulators::Counter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:918
Gaudi::Accumulators::GenericAccumulator::operator+=
GenericAccumulator operator+=(const InputType by)
Definition: Accumulators.h:444
Gaudi::Accumulators::StatCounter::StatCounter
StatCounter(OWNER *o, std::string const &name)
Definition: Accumulators.h:1016
Gaudi::Accumulators::StatCounter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:1028
bug_34121.t
t
Definition: bug_34121.py:30
Gaudi::Accumulators::BinomialAccumulator
BinomialAccumulator.
Definition: Accumulators.h:664
Gaudi::Accumulators::BinomialAccumulator::eff
auto eff() const
Definition: Accumulators.h:674
Gaudi::Accumulators::IntegralAccumulator::nEntries
Arithmetic nEntries() const
Definition: Accumulators.h:612
Gaudi::Accumulators::Extremum
An Extremum ValueHandler, to be reused for Minimum and Maximum operator(a, b) means if (Compare(b,...
Definition: Accumulators.h:361
Gaudi::Accumulators::IntegralAccumulator::operator++
IntegralAccumulator & operator++()
Definition: Accumulators.h:603
Gaudi::Accumulators::AveragingCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:943
Gaudi::Accumulators::Adder
An Adder ValueHandler operator(a, b) means a += b.
Definition: Accumulators.h:323
Gaudi::Accumulators::CountAccumulator::operator++
CountAccumulator operator++(int)
Definition: Accumulators.h:574
Gaudi::Accumulators::has_fetch_add_v
constexpr bool has_fetch_add_v
Definition: Accumulators.h:280
Gaudi::Accumulators::SigmaAccumulatorBase::unbiased_sample_variance
auto unbiased_sample_variance() const
Definition: Accumulators.h:753
TimingHistograms.name
name
Definition: TimingHistograms.py:25
Gaudi::Accumulators::BinomialAccumulator::efficiencyErr
auto efficiencyErr() const
Definition: Accumulators.h:677
std::ostream
STL class.
Gaudi::Accumulators::StatCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:1031
Gaudi::Accumulators::PrintableCounter::toJSON
virtual nlohmann::json toJSON() const =0
Basic JSON export for Gaudi::Monitoring::Hub support.
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:228
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::full, Compare, Initial >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:383
Gaudi::Accumulators::BinomialCounter::printImpl
stream & printImpl(stream &o, std::string_view tag) const
Definition: Accumulators.h:1077
Gaudi::Accumulators::AccumulatorSet::InternalType
std::tuple< typename Bases< Atomicity, Arithmetic >::InternalType... > InternalType
Definition: Accumulators.h:494
Gaudi::Accumulators::AveragingAccumulatorBase::mean
auto mean() const
Definition: Accumulators.h:717
Gaudi::Accumulators::Buffer::Buffer
Buffer(prime_type &p)
Definition: Accumulators.h:813
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::none, Compare, Initial >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:370
Gaudi::Accumulators::Buffer::Buffer
Buffer(Buffer &&other)
Definition: Accumulators.h:816
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:451
Gaudi::Accumulators::GenericAccumulator< double, double, Atomicity, Identity, Identity, Maximum< double, Atomicity > >::GenericAccumulator
friend class GenericAccumulator
Definition: Accumulators.h:437
Gaudi::Accumulators::Counter::typeString
static const std::string typeString
Definition: Accumulators.h:896
Gaudi::Accumulators::AccumulatorSet::value
OutputType value() const
Definition: Accumulators.h:505
Gaudi::Accumulators::GenericAccumulator< bool, unsigned long, Atomicity, TrueTo1 >::OutputType
std::decay_t< std::result_of_t< Identity(unsigned long)> > OutputType
Definition: Accumulators.h:441
Gaudi::Accumulators::GenericAccumulator::operator=
GenericAccumulator & operator=(const GenericAccumulator &other)
Definition: Accumulators.h:457
Gaudi::Accumulators::BinomialCounter
A counter dealing with binomial data.
Definition: Accumulators.h:1055
Gaudi::Accumulators::details::MsgCounter::Handler::merge
static void merge(typename Base::InternalType &orig, bool b)
Definition: Accumulators.h:1104
Gaudi::Accumulators::Buffer::~Buffer
~Buffer()
Definition: Accumulators.h:818
Gaudi::Monitoring::Hub::registerEntity
void registerEntity(std::string c, std::string n, std::string t, T &ent)
Definition: MonitoringHub.h:136
Gaudi::Accumulators::Adder< Arithmetic, atomicity::none >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:333
Gaudi::Accumulators::AccumulatorSet::extractJSONDataHelper
static InternalType extractJSONDataHelper(const nlohmann::json &j, const JSONStringEntriesType &entries, std::index_sequence< Is... >)
Definition: Accumulators.h:526
Gaudi::Accumulators::BinomialAccumulator::binomial_t::nPass
unsigned long nPass
Definition: Accumulators.h:689
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::MsgCounter::print
std::ostream & print(std::ostream &os, bool tableFormat) const override
prints the counter to a stream
Definition: Accumulators.h:1140
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:144
Gaudi::Accumulators::MsgCounter
Definition: Accumulators.h:1115
std::atomic
STL class.
Gaudi::Accumulators::AccumulatorSet< Arithmetic, Atomicity, CountAcc< Atomicity, Arithmetic >::InputType, CountAcc, SumAcc >::InputType
CountAcc< Atomicity, Arithmetic >::InputType InputType
Definition: Accumulators.h:492
Gaudi::Accumulators::FalseAccumulator::nFalseEntries
unsigned long nFalseEntries() const
Definition: Accumulators.h:655
Gaudi::Accumulators::BinomialCounter::toJSON
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
Definition: Accumulators.h:1086
Gaudi::Accumulators::BinomialAccumulator::efficiency
auto efficiency() const
Definition: Accumulators.h:669
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:435
gaudirun.level
level
Definition: gaudirun.py:364
GaudiPython.HistoUtils.mean
mean
Definition: HistoUtils.py:904
Gaudi::Accumulators::Constant
A functor always returning the value N.
Definition: Accumulators.h:247
MsgStream
Definition: MsgStream.h:34
Gaudi::Accumulators::BufferableCounter::BufferableCounter
BufferableCounter(OWNER *o, std::string const &name, const std::string counterType, CARGS... args)
Definition: Accumulators.h:873
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:227
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:235
Gaudi::Accumulators::GenericAccumulator::value
OutputType value() const
Definition: Accumulators.h:461
std::string::append
T append(T... args)
Gaudi::Accumulators::GenericAccumulator::reset
void reset(InnerType in)
Definition: Accumulators.h:474
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:1032
Gaudi::Accumulators::BufferableCounter
An empty ancester of all counters that provides a buffer method that returns a buffer on itself Also ...
Definition: Accumulators.h:869
HistoDumpEx.v
v
Definition: HistoDumpEx.py:27
Gaudi::Accumulators::StatCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1013
std::ostringstream
STL class.
Gaudi::Accumulators::Identity
An Identity functor.
Definition: Accumulators.h:257
Gaudi::Accumulators::BinomialAccumulator::effErr
auto effErr() const
Definition: Accumulators.h:686
Gaudi::Accumulators
Definition: HistogramsTests.cpp:19
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:1136
Gaudi::Accumulators::Buffer::Buffer
Buffer()=delete
Gaudi::Accumulators::SigmaCounter::typeString
static const std::string typeString
Definition: Accumulators.h:974
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:286
Gaudi::Accumulators::MaxAccumulator
MaxAccumulator.
Definition: Accumulators.h:543
Gaudi::Accumulators::MsgCounter::max
unsigned long max
Definition: Accumulators.h:1161
Gaudi::Accumulators::SigmaAccumulatorBase::rms
Arithmetic rms() const
Definition: Accumulators.h:768
Gaudi::Accumulators::CountAccumulator
CountAccumulator.
Definition: Accumulators.h:568
Gaudi::Accumulators::AveragingCounter::toJSON
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
Definition: Accumulators.h:954
Gaudi::Accumulators::PrintableCounter::print
virtual MsgStream & print(MsgStream &o, std::string_view tag) const
Definition: Accumulators.h:843
gaudirun.args
args
Definition: gaudirun.py:336
Gaudi::Accumulators::GenericAccumulator::extractJSONData
static InnerType extractJSONData(const nlohmann::json &j, const JSONStringEntriesType &entries)
Definition: Accumulators.h:475
Gaudi::Accumulators::MsgCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:1142
Gaudi::Accumulators::FalseAccumulator
FalseAccumulator.
Definition: Accumulators.h:653
Gaudi::Accumulators::MaxAccumulator::max
Arithmetic max() const
Definition: Accumulators.h:546
Gaudi::Accumulators::SigmaAccumulatorBase::standard_deviation
auto standard_deviation() const
Definition: Accumulators.h:760
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:413
fmt
Gaudi::Accumulators::GenericAccumulator::mergeAndReset
void mergeAndReset(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &&other)
Definition: Accumulators.h:464
Gaudi::Accumulators::FalseTo1
helper functor for the FalseAccumulator
Definition: Accumulators.h:643
Gaudi::Accumulators::BinomialCounter::fromJSON
static BinomialCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1095
detected.h
Gaudi::Accumulators::AccumulatorSet::reset
void reset(const InternalType &t)
Definition: Accumulators.h:517
Gaudi::Accumulators::SigmaAccumulatorBase
SigmaAccumulatorBase.
Definition: Accumulators.h:739
Gaudi::Accumulators::Buffer
Buffer is a non atomic Accumulator which, when it goes out-of-scope, updates the underlying thread-sa...
Definition: Accumulators.h:807
Gaudi::Accumulators::CountAccumulator::nEntries
unsigned long nEntries() const
Definition: Accumulators.h:579
Gaudi::Accumulators::GenericAccumulator::operator+
void operator+(GenericAccumulator< InputType, InnerType, ato, InputTransform, OutputTransform, VH > &&other)
Definition: Accumulators.h:468
Gaudi::Accumulators::SigmaCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:982
std::chrono::duration::count
T count(T... args)
Gaudi::Accumulators::MsgCounter::toJSON
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
Definition: Accumulators.h:1143
Gaudi::Accumulators::AveragingCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:953
Gaudi::Accumulators::atomicity
atomicity
Defines atomicity of the accumulators.
Definition: Accumulators.h:237
Gaudi::Accumulators::IntegralAccumulator::sum
Arithmetic sum() const
Definition: Accumulators.h:613
Gaudi::Accumulators::Adder< Arithmetic, atomicity::full >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:344
Gaudi::Accumulators::GenericAccumulator::GenericAccumulator
GenericAccumulator(const GenericAccumulator &other)
Definition: Accumulators.h:456
Gaudi::Accumulators::Adder< Arithmetic, atomicity::none >::DefaultValue
static constexpr OutputType DefaultValue()
Definition: Accumulators.h:332
Gaudi::Accumulators::StatCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:1012
Gaudi::Accumulators::construct_empty_t
constant used to disambiguate construction of an empty Accumulator versus the copy constructor.
Definition: Accumulators.h:410
plotSpeedupsPyRoot.counter
int counter
Definition: plotSpeedupsPyRoot.py:170
std::ostringstream::str
T str(T... args)
Gaudi::Accumulators::AveragingCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:951
Gaudi::Accumulators::BinomialAccumulator::nEntries
unsigned long nEntries() const
Definition: Accumulators.h:666
Gaudi::Accumulators::BinomialCounter::printImpl
stream & printImpl(stream &o, bool tableFormat) const
Definition: Accumulators.h:1064
Gaudi::Accumulators::SigmaCounter::fromJSON
static SigmaCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1002
Gaudi::Accumulators::SigmaAccumulatorBase::biased_sample_variance
auto biased_sample_variance() const
Definition: Accumulators.h:746
Gaudi::Accumulators::TrueAccumulator::nTrueEntries
unsigned long nTrueEntries() const
Definition: Accumulators.h:639
Gaudi::Accumulators::StatCounter::toJSON
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
Definition: Accumulators.h:1033
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:55
Gaudi::Accumulators::FalseTo1::operator()
unsigned int operator()(bool v) const
Definition: Accumulators.h:644
Gaudi::Accumulators::Counter::Counter
Counter(OWNER *o, std::string const &name)
Definition: Accumulators.h:899
Gaudi::Accumulators::atomicity::none
@ none
Gaudi::Accumulators::IntegralAccumulator::operator++
IntegralAccumulator operator++(int)
Definition: Accumulators.h:607
Gaudi::Accumulators::Extremum< Arithmetic, atomicity::full, Compare, Initial >::merge
static void merge(InternalType &a, Arithmetic b) noexcept
Definition: Accumulators.h:384
Gaudi::Accumulators::TrueTo1::operator()
unsigned int operator()(bool v) const
Definition: Accumulators.h:628
Gaudi::Accumulators::MsgCounter::typeString
static const std::string typeString
Definition: Accumulators.h:1117
Gaudi::Accumulators::BinomialCounter::print
MsgStream & print(MsgStream &o, std::string_view tag) const override
Definition: Accumulators.h:1084
Gaudi::Accumulators::SigmaCounter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:992
Gaudi::Accumulators::SumAccumulator::sum
Arithmetic sum() const
Definition: Accumulators.h:589
Gaudi::Accumulators::MsgCounter::fromJSON
static MsgCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:1151
Gaudi::Accumulators::AveragingCounter::fromJSON
static AveragingCounter fromJSON(const nlohmann::json &j)
Definition: Accumulators.h:961
Gaudi::Accumulators::Counter::toBePrinted
bool toBePrinted() const override
hint whether we should print that counter or not.
Definition: Accumulators.h:919
Gaudi::Accumulators::Constant::operator()
constexpr T operator()(U &&) const noexcept
Definition: Accumulators.h:249
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:1179
std::numeric_limits
Gaudi::operator+
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:448
Gaudi::Accumulators::AveragingCounter::typeString
static const std::string typeString
Definition: Accumulators.h:934
Gaudi::Accumulators::operator<<
std::ostream & operator<<(std::ostream &s, const PrintableCounter &counter)
external printout operator to a stream type
Definition: Accumulators.h:860
Gaudi::Accumulators::SigmaCounter::print
MsgStream & print(MsgStream &o, bool tableFormat=false) const override
Definition: Accumulators.h:991
Gaudi::Accumulators::BufferableCounter::~BufferableCounter
~BufferableCounter()
Definition: Accumulators.h:882
MsgStream.h
Gaudi::Accumulators::Counter::print
std::ostream & print(std::ostream &o, bool tableFormat=false) const override
prints the counter to a stream
Definition: Accumulators.h:915
Gaudi::Accumulators::BinomialAccumulator::binomial_t::nTotal
unsigned long nTotal
Definition: Accumulators.h:690
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:278
Gaudi::Accumulators::SquareAccumulator::sum2
Arithmetic sum2() const
Definition: Accumulators.h:623
Gaudi::Accumulators::Counter::toJSON
virtual nlohmann::json toJSON() const override
Basic JSON export for Gaudi::Monitoring::Hub support.
Definition: Accumulators.h:920