The Gaudi Framework  master (37c0b60a)
CounterAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 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 #include <Gaudi/Accumulators.h>
14 #include <deque>
15 #include <fmt/format.h>
16 #include <mutex>
17 
20 
22 
23  void operator()() const override {
24  // update all counters by some fixed values
25  ++basic;
26  avg += 1.5;
27  sig += 2.5;
28  stat += 3.5;
29  binomial += true;
30  ++msg;
31  avg_int += 1;
32  avg_noAto += 1.5;
33  // update counters in the deque, creating new ones for the first 20 events
34  // and dropping first 10 in the next 10 events
35  {
36  // needs to be protected by a mutex in case of multithreaded usage as the
37  // deque is not thread safe
38  std::scoped_lock lock( counterDequeMutex );
39  if ( counterCount < 20 ) {
40  counterDeque.emplace_back( this, fmt::format( "DQCounter{}", counterDeque.size() ) );
41  ++counterCount;
42  }
43  if ( counterCount == 20 && counterDeque.size() > 10 ) { counterDeque.pop_front(); }
44  for ( auto& c : counterDeque ) ++c;
45  }
46  }
47 
48  // declare all sorts of counters with default options (double values, atomicity full)
49  mutable Gaudi::Accumulators::Counter<> basic{ this, "Basic" };
50  mutable Gaudi::Accumulators::AveragingCounter<> avg{ this, "Average" };
51  mutable Gaudi::Accumulators::SigmaCounter<> sig{ this, "Sigma" };
52  mutable Gaudi::Accumulators::StatCounter<> stat{ this, "Stat" };
53  mutable Gaudi::Accumulators::BinomialCounter<> binomial{ this, "Binomial" };
54  mutable Gaudi::Accumulators::MsgCounter<MSG::INFO> msg{ this, "Super nice message, max 5 times", 5 };
55 
56  // test change of some template parameters
59  this, "AverageNonAtomic" };
60 
61  // test set of counters stored in a deque
62  mutable int counterCount{ 0 };
65 };
66 
CounterAlg
Definition: CounterAlg.py:1
CounterAlg::operator()
void operator()() const override
Definition: CounterAlg.cpp:23
Gaudi::Functional::Consumer
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition: Consumer.h:69
Gaudi::Accumulators::SigmaCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:1025
std::deque::pop_front
T pop_front(T... args)
Gaudi::Accumulators::Counter<>
CounterAlg::counterCount
int counterCount
Definition: CounterAlg.cpp:62
std::deque::size
T size(T... args)
CounterAlg::avg
Gaudi::Accumulators::AveragingCounter avg
Definition: CounterAlg.cpp:50
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition: Accumulators.h:983
CounterAlg::avg_noAto
Gaudi::Accumulators::AveragingCounter< double, Gaudi::Accumulators::atomicity::none > avg_noAto
Definition: CounterAlg.cpp:58
gaudirun.c
c
Definition: gaudirun.py:525
CounterAlg::stat
Gaudi::Accumulators::StatCounter stat
Definition: CounterAlg.cpp:52
Gaudi::Functional::details::Consumer
Definition: Consumer.h:24
CounterAlg::binomial
Gaudi::Accumulators::BinomialCounter binomial
Definition: CounterAlg.cpp:53
Consumer.h
basic
Definition: basic.py:1
CounterAlg::avg_int
Gaudi::Accumulators::AveragingCounter< unsigned int > avg_int
Definition: CounterAlg.cpp:57
CounterAlg::basic
Gaudi::Accumulators::Counter basic
Definition: CounterAlg.cpp:49
CounterAlg::sig
Gaudi::Accumulators::SigmaCounter sig
Definition: CounterAlg.cpp:51
CounterAlg::counterDeque
std::deque< Gaudi::Accumulators::Counter<> > counterDeque
Definition: CounterAlg.cpp:63
Gaudi::Accumulators::BinomialCounter
A counter dealing with binomial data.
Definition: Accumulators.h:1111
std::deque
STL class.
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Gaudi::Accumulators::MsgCounter< MSG::INFO >
Accumulators.h
std::deque::emplace_back
T emplace_back(T... args)
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
CounterAlg::msg
Gaudi::Accumulators::MsgCounter< MSG::INFO > msg
Definition: CounterAlg.cpp:54
Gaudi::Accumulators::StatCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:1066
std::mutex
STL class.
CounterAlg::counterDequeMutex
std::mutex counterDequeMutex
Definition: CounterAlg.cpp:64