ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoopGrid
Root
pool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include "
pool.h
"
7
8
#include <thread>
9
#include <mutex>
10
11
namespace
{
12
13
using
WorkList_cit = std::vector<WorkUnit>::const_iterator;
14
15
const
WorkList_cit safe_advance(WorkList_cit& next,
const
WorkList_cit end)
16
{
17
static
std::mutex
mutex
;
18
std::lock_guard<std::mutex>
lock
(
mutex
);
19
return
next
!=
end
?
next
++ :
end
;
20
}
21
22
void
worker(WorkList_cit& next,
const
WorkList_cit end)
23
{
24
for
(;;) {
25
const
WorkList_cit last = safe_advance(next, end);
26
if
(last == end) {
return
; }
27
(*last)();
28
}
29
}
30
31
struct
Threads
32
{
33
Threads(
const
size_t
n, std::function<
void
(
void
)> function)
34
{
35
for
(
size_t
k = 0;
k
!=
n
;
k
++) { threads.emplace_back( function ); }
36
}
37
~Threads() {
for
(
auto
& t : threads) {
t
.join(); } }
38
private
:
39
std::vector<std::thread> threads;
40
};
41
42
}
//namespace
43
44
void
process
(
const
WorkList
& workList,
const
size_t
nThreads)
45
{
46
WorkList_cit begin(std::begin(workList)), end(std::end(workList));
47
if
(nThreads == 0) {
48
worker(begin, end);
49
}
else
{
50
Threads(nThreads, [&](){ worker(begin, end); });
51
}
52
}
53
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
pool.h
WorkList
std::vector< WorkUnit > WorkList
Definition
PhysicsAnalysis/D3PDTools/EventLoopGrid/Root/pool.h:13
mutex
STL class.
process
const std::string process
Definition
fbtTestBasics.cxx:76
beamspotman.n
n
Definition
beamspotman.py:727
fillPileUpNoiseLumi.next
next
Definition
fillPileUpNoiseLumi.py:52
fitman.k
k
Definition
fitman.py:528
mergePhysValFiles.end
end
Definition
DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
read_hist_ntuple.t
t
Definition
read_hist_ntuple.py:8
Generated on
for ATLAS Offline Software by
1.17.0