The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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
21 using Gaudi::Functional::Consumer<void()>::Consumer;
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() ) );
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" };
54 mutable Gaudi::Accumulators::MsgCounter<MSG::INFO> msg{ this, "Super nice message, max 5 times", 5 };
55
56 // test change of some template parameters
60
61 // test set of counters stored in a deque
62 mutable int counterCount{ 0 };
63 mutable std::deque<Gaudi::Accumulators::Counter<>> counterDeque;
64 mutable std::mutex counterDequeMutex;
65};
66
#define DECLARE_COMPONENT(type)
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition Consumer.h:69
Definition basic.py:1
Gaudi::Accumulators::MsgCounter< MSG::INFO > msg
Gaudi::Accumulators::AveragingCounter< double, Gaudi::Accumulators::atomicity::none > avg_noAto
std::deque< Gaudi::Accumulators::Counter<> > counterDeque
Gaudi::Accumulators::AveragingCounter avg
Gaudi::Accumulators::StatCounter stat
void operator()() const override
Gaudi::Accumulators::SigmaCounter sig
std::mutex counterDequeMutex
Gaudi::Accumulators::BinomialCounter binomial
Gaudi::Accumulators::AveragingCounter< unsigned int > avg_int
A counter aiming at computing sum and average.
A counter dealing with binomial data.
A basic integral counter;.
A counter aiming at computing average and sum2 / variance / standard deviation.
A counter aiming at computing average and sum2 / variance / standard deviation.