ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExHive
src
HiveExSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
HiveExSvc.h
"
6
#include "GaudiKernel/ISvcLocator.h"
7
#include "GaudiKernel/ConcurrencyFlags.h"
8
#include "GaudiKernel/EventContext.h"
9
10
#include <map>
11
12
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14
HiveExSvc::HiveExSvc
(
const
std::string& name, ISvcLocator* svc)
15
: base_class( name, svc ) {}
16
17
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18
19
HiveExSvc::~HiveExSvc
() =
default
;
20
21
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22
23
StatusCode
24
HiveExSvc::initialize
() {
25
26
size_t
nslots = Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
27
if
(nslots == 0) {
28
nslots = 1;
29
}
30
31
ATH_MSG_INFO
(
"initialize structures of size "
<< nslots);
32
33
// initialize the structures with the number of concurrent events
34
m_times
.resize( nslots );
35
m_locks
.resize( nslots );
36
for
(
auto
& m :
m_locks
) {
37
m = std::make_unique<std::mutex>();
38
}
39
40
return
StatusCode::SUCCESS;
41
}
42
43
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
44
45
StatusCode
46
HiveExSvc::finalize
() {
47
ATH_MSG_INFO
(
"finalize"
);
48
49
// calculate the standard deviation of the sleep times
50
std::map<std::string,unsigned int> sum;
51
std::map<std::string,unsigned int> sumSq;
52
std::map<std::string,unsigned int> num;
53
54
for
(
const
auto
&ve :
m_times
) {
55
for
(
const
auto
&e : ve) {
56
sum[e.algName] += e.sleep_time;
57
sumSq[e.algName] += e.sleep_time * e.sleep_time;
58
num[e.algName] ++;
59
}
60
}
61
62
info() <<
"listing timing by alg:"
;
63
for
(
const
auto
&s : sum) {
64
float
avg =
static_cast<
float
>
(s.second)/num[s.first];
65
float
sig = sqrt( ( sumSq[s.first] - 2*s.second*avg + num[s.first]*avg*avg )/(num[s.first]) );
66
info() <<
"\n "
<< s.first
67
<<
" avg: "
<< avg <<
" sig: "
<< sig;
68
}
69
info() <<
endmsg
;
70
71
return
StatusCode::SUCCESS;
72
}
73
74
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
75
76
void
77
HiveExSvc::add
(
const
EventContext& ctx,
const
std::string& algName,
const
unsigned
int
& time) {
78
79
// even though we have separate data structures per concurrent
80
// event (slot), we can't be sure that multiple threads aren't
81
// processing the same slot at the same time, so need to lock the mutex.
82
// this reduces the waiting for a lock, compared with locking the
83
// whole structure, as it's unlikely that we'll have the same Alg in
84
// different concurrent events executing at the same time.
85
86
// for a true lock-free design, we would need a separate container for
87
// each Algorithm in each slot
88
89
const
EventContext::ContextID_t slot = ctx.slot();
90
std::lock_guard<std::mutex>
lock
( *
m_locks
[slot] );
91
m_times
[slot].push_back(
tDat
(algName, time) );
92
}
93
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
HiveExSvc.h
Simple service that accumulates timings for Algorithms by name.
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
HiveExSvc::~HiveExSvc
virtual ~HiveExSvc()
HiveExSvc::add
virtual void add(const EventContext &, const std::string &, const unsigned int &) override
Definition
HiveExSvc.cxx:77
HiveExSvc::m_locks
std::vector< std::unique_ptr< std::mutex > > m_locks
Definition
HiveExSvc.h:49
HiveExSvc::m_times
std::vector< std::list< tDat > > m_times
Definition
HiveExSvc.h:45
HiveExSvc::HiveExSvc
HiveExSvc(const std::string &name, ISvcLocator *svc)
Definition
HiveExSvc.cxx:14
HiveExSvc::finalize
virtual StatusCode finalize() override
Definition
HiveExSvc.cxx:46
HiveExSvc::initialize
virtual StatusCode initialize() override
Definition
HiveExSvc.cxx:24
HiveExSvc::tDat
Definition
HiveExSvc.h:38
Generated on
for ATLAS Offline Software by
1.17.0