The Gaudi Framework  v32r0 (3325bb39)
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 template <class BASE>
14 class GaudiCommon;
15 class INamedInterface;
16 class Algorithm;
17 class AlgTool;
18 namespace Gaudi {
19  class Sequence;
20 }
21 
22 template <class BASE>
23 class GAUDI_API CounterHolder : public BASE {
25  "CounterHolder template argument must inherit from INamedInterface" );
26 
27 public:
28  using BASE::BASE;
29 
31  std::lock_guard<std::mutex> lock( m_countersMutex );
32  m_counters.emplace( tag, r );
33  }
34 
36  std::lock_guard<std::mutex> lock( m_countersMutex );
37  auto p = this->m_counters.find( tag );
38  return p != m_counters.end() ? &p->second.get() : nullptr;
39  }
40 
41  template <typename Callable>
42  void forEachCounter( Callable&& f ) const {
43  std::lock_guard<std::mutex> lock( m_countersMutex );
44  std::for_each( m_counters.begin(), m_counters.end(),
45  [f = std::forward<Callable>( f )]( const auto& p ) { std::invoke( f, p.first, p.second.get() ); } );
46  }
47 
48  int nCounters() const {
49  std::lock_guard<std::mutex> lock( m_countersMutex );
50  return m_counters.size();
51  }
52 
53  void clearCounters() {
54  std::lock_guard<std::mutex> lock( m_countersMutex );
55  m_counters.clear();
56  }
57 
58 private:
61 };
62 #endif
void forEachCounter(Callable &&f) const
Definition: CounterHolder.h:42
An empty ancester of all counters that knows how to print themselves.
Definition: Counters.h:605
STL class.
const Gaudi::Accumulators::PrintableCounter * findCounter(const std::string &tag) const
Definition: CounterHolder.h:35
STL class.
void declareCounter(const std::string &tag, Gaudi::Accumulators::PrintableCounter &r)
Definition: CounterHolder.h:30
int nCounters() const
Definition: CounterHolder.h:48
void clearCounters()
Definition: CounterHolder.h:53
Alias for backward compatibility.
Definition: Algorithm.h:56
IInterface compliant class extending IInterface with the name() method.
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:47
Implements the common functionality between GaudiTools and GaudiAlgorithms.
Definition: GaudiCommon.h:91
T for_each(T...args)
#define GAUDI_API
Definition: Kernel.h:71
std::map< std::string, std::reference_wrapper< Gaudi::Accumulators::PrintableCounter > > m_counters
Definition: CounterHolder.h:59
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
std::mutex m_countersMutex
Definition: CounterHolder.h:60