Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CounterAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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"
13 
14 #include "GaudiAlg/Consumer.h"
15 
16 #include <deque>
17 #include <fmt/format.h>
18 #include <mutex>
19 
22 
24 
25  void operator()() const override {
26  // update all counters by some fixed values
27  ++basic;
28  avg += 1.5;
29  sig += 2.5;
30  stat += 3.5;
31  binomial += true;
32  ++msg;
33  avg_int += 1;
34  avg_noAto += 1.5;
35  // update counters in the deque, creating new ones for the first 20 events
36  // and dropping first 10 in the next 10 events
37  {
38  // needs to be protected by a mutex in case of multithreaded usage as the
39  // deque is not thread safe
40  std::scoped_lock lock( counterDequeMutex );
41  if ( counterCount < 20 ) {
42  counterDeque.emplace_back( this, fmt::format( "DQCounter{}", counterDeque.size() ) );
43  ++counterCount;
44  }
45  if ( counterCount == 20 && counterDeque.size() > 10 ) { counterDeque.pop_front(); }
46  for ( auto& c : counterDeque ) ++c;
47  }
48  }
49 
50  // declare all sorts of counters with default options (double values, atomicity full)
51  mutable Gaudi::Accumulators::Counter<> basic{ this, "Basic" };
52  mutable Gaudi::Accumulators::AveragingCounter<> avg{ this, "Average" };
53  mutable Gaudi::Accumulators::SigmaCounter<> sig{ this, "Sigma" };
54  mutable Gaudi::Accumulators::StatCounter<> stat{ this, "Stat" };
55  mutable Gaudi::Accumulators::BinomialCounter<> binomial{ this, "Binomial" };
56  mutable Gaudi::Accumulators::MsgCounter<MSG::INFO> msg{ this, "Super nice message, max 5 times", 5 };
57 
58  // test change of some template parameters
61  this, "AverageNonAtomic" };
62 
63  // test set of counters stored in a deque
64  mutable int counterCount{ 0 };
67 };
68 
CounterAlg
Definition: CounterAlg.py:1
CounterAlg::operator()
void operator()() const override
Definition: CounterAlg.cpp:25
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:983
std::deque::pop_front
T pop_front(T... args)
Gaudi::Accumulators::Counter<>
CounterAlg::counterCount
int counterCount
Definition: CounterAlg.cpp:64
std::deque::size
T size(T... args)
CounterAlg::avg
Gaudi::Accumulators::AveragingCounter avg
Definition: CounterAlg.cpp:52
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
Gaudi::Accumulators::AveragingCounter
A counter aiming at computing sum and average.
Definition: Accumulators.h:943
CounterAlg::avg_noAto
Gaudi::Accumulators::AveragingCounter< double, Gaudi::Accumulators::atomicity::none > avg_noAto
Definition: CounterAlg.cpp:60
gaudirun.c
c
Definition: gaudirun.py:527
CounterAlg::stat
Gaudi::Accumulators::StatCounter stat
Definition: CounterAlg.cpp:54
Gaudi::Functional::details::Consumer
Definition: Consumer.h:24
CounterAlg::binomial
Gaudi::Accumulators::BinomialCounter binomial
Definition: CounterAlg.cpp:55
Consumer.h
basic
Definition: basic.py:1
CounterAlg::avg_int
Gaudi::Accumulators::AveragingCounter< unsigned int > avg_int
Definition: CounterAlg.cpp:59
CounterAlg::basic
Gaudi::Accumulators::Counter basic
Definition: CounterAlg.cpp:51
CounterAlg::sig
Gaudi::Accumulators::SigmaCounter sig
Definition: CounterAlg.cpp:53
CounterAlg::counterDeque
std::deque< Gaudi::Accumulators::Counter<> > counterDeque
Definition: CounterAlg.cpp:65
Gaudi::Accumulators::BinomialCounter
A counter dealing with binomial data.
Definition: Accumulators.h:1065
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:56
Gaudi::Accumulators::StatCounter
A counter aiming at computing average and sum2 / variance / standard deviation.
Definition: Accumulators.h:1022
std::mutex
STL class.
CounterAlg::counterDequeMutex
std::mutex counterDequeMutex
Definition: CounterAlg.cpp:66