| The Gaudi Framework v32r1 (f65d50dc)

CounterHolder.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_COUNTERHOLDER_H
2 #define GAUDIKERNEL_COUNTERHOLDER_H
3
4 #include <algorithm>
5 #include <functional>
6 #include <map>
7 #include <mutex>
8 #include <string>
9 #include <type_traits>
10
11 #include "GaudiKernel/Counters.h"
12
13 class INamedInterface;
14
15 template <class BASE>
16 class GAUDI_API CounterHolder : public BASE {
17 static_assert( std::is_base_of_v<INamedInterface, BASE>,
18 "CounterHolder template argument must inherit from INamedInterface" );
19
20 public:
21 using BASE::BASE;
22
23 void declareCounter( const std::string& tag, Gaudi::Accumulators::PrintableCounter& r ) {
24 std::lock_guard lock{m_mutex};
25 m_counters.emplace( tag, r );
26 }
27
28 const Gaudi::Accumulators::PrintableCounter* findCounter( const std::string& tag ) const {
29 std::lock_guard lock{m_mutex};
30 auto p = m_counters.find( tag );
31 return p != m_counters.end() ? &p->second.get() : nullptr;
32 }
33
34 template <typename Callable>
35 void forEachCounter( Callable&& f ) const {
36 std::lock_guard lock{m_mutex};
37 std::for_each( m_counters.begin(), m_counters.end(),
38 [f = std::forward<Callable>( f )]( const auto& p ) { std::invoke( f, p.first, p.second.get() ); } );
39 }
40
41 int nCounters() const {
42 std::lock_guard lock{m_mutex};
43 return m_counters.size();
44 }
45
46 std::size_t nOfCountersToBePrinted() {
47 std::lock_guard lock{m_mutex};
48 return count_if( begin( m_counters ), end( m_counters ),
49 []( const auto& c ) { return c.second.get().toBePrinted(); } );
50 }
51
52 void clearCounters() {
53 std::lock_guard lock{m_mutex};
54 m_counters.clear();
55 }
56
57 private:
58 std::map<std::string, std::reference_wrapper<Gaudi::Accumulators::PrintableCounter>> m_counters;
59 mutable std::mutex m_mutex;
60 };
61 #endif
CounterHolder::m_mutex
std::mutex m_mutex
Definition: CounterHolder.h:59
gaudirun.c
c
Definition: gaudirun.py:487
CounterHolder::findCounter
const Gaudi::Accumulators::PrintableCounter * findCounter(const std::string &tag) const
Definition: CounterHolder.h:28
Gaudi::Accumulators::PrintableCounter
An empty ancester of all counters that knows how to print themselves.
Definition: Counters.h:601
std::size_t
std::map
STL class.
std::mutex
std::string
STL class.
CounterHolder::declareCounter
void declareCounter(const std::string &tag, Gaudi::Accumulators::PrintableCounter &r)
Definition: CounterHolder.h:23
CounterHolder::nOfCountersToBePrinted
std::size_t nOfCountersToBePrinted()
Definition: CounterHolder.h:46
CounterHolder::forEachCounter
void forEachCounter(Callable &&f) const
Definition: CounterHolder.h:35
CounterHolder
Definition: CounterHolder.h:16
IOTest.end
def end
Definition: IOTest.py:112
CounterHolder::clearCounters
void clearCounters()
Definition: CounterHolder.h:52
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
std::lock_guard
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
std::for_each
T for_each(T... args)
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
CounterHolder::m_counters
std::map< std::string, std::reference_wrapper< Gaudi::Accumulators::PrintableCounter > > m_counters
Definition: CounterHolder.h:58
Counters.h
CounterHolder::nCounters
int nCounters() const
Definition: CounterHolder.h:41