Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <map>
6 #include <mutex>
7 #include <string>
8 #include <type_traits>
9 
10 #include "GaudiKernel/Counters.h"
11 #include "GaudiKernel/invoke.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(), [f = std::forward<Callable>( f )]( const auto& p ) {
45  Gaudi::invoke( f, p.first, p.second.get() );
46  } );
47  }
48 
49  int nCounters() const {
50  std::lock_guard<std::mutex> lock( m_countersMutex );
51  return m_counters.size();
52  }
53 
54  void clearCounters() {
55  std::lock_guard<std::mutex> lock( m_countersMutex );
56  m_counters.clear();
57  }
58 
59 private:
62 };
63 #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:619
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:49
void clearCounters()
Definition: CounterHolder.h:54
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:92
auto invoke(F &&f, ArgTypes &&...args) noexcept(noexcept(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))) -> decltype(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))
Definition: invoke.h:82
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:60
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::mutex m_countersMutex
Definition: CounterHolder.h:61