ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
Root
LocalDriver.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
//
9
// includes
10
//
11
12
#include <
EventLoop/LocalDriver.h
>
13
14
#include <sstream>
15
#include <TSystem.h>
16
#include <
AsgMessaging/StatusCode.h
>
17
#include <
EventLoop/Job.h
>
18
#include <
EventLoop/ManagerData.h
>
19
#include <
EventLoop/MessageCheck.h
>
20
#include <
RootCoreUtils/Assert.h
>
21
#include <
RootCoreUtils/ShellExec.h
>
22
#include <mutex>
23
#include <thread>
24
25
//
26
// method implementations
27
//
28
29
ClassImp
(
EL::LocalDriver
)
30
31
namespace
EL
32
{
33
void
LocalDriver ::
34
testInvariant ()
const
35
{}
36
37
38
39
LocalDriver ::
40
LocalDriver ()
41
{
42
RCU_NEW_INVARIANT
(
this
);
43
}
44
45
46
47
::StatusCode
LocalDriver ::
48
doManagerStep (Detail::ManagerData& data)
const
49
{
50
RCU_READ_INVARIANT
(
this
);
51
using namespace
msgEventLoop;
52
ANA_CHECK
(
BatchDriver::doManagerStep
(data));
53
switch
(data.step)
54
{
55
case
Detail::ManagerStep::batchScriptVar
:
56
{
57
data.batchSkipReleaseSetup =
true
;
58
}
59
break
;
60
61
case
Detail::ManagerStep::submitJob
:
62
case
Detail::ManagerStep::doResubmit
:
63
{
64
// safely ignoring: resubmit
65
66
const
std::string dockerImage {
67
data.options.castString(
Job::optDockerImage
)};
68
const
std::string dockerOptions {
69
data.options.castString(
Job::optDockerOptions
)};
70
int
numParallelProcs
71
= data.options.castDouble (
Job::optNumParallelProcs
, 1);
72
if
(numParallelProcs < 0)
73
{
74
ANA_MSG_ERROR
(
"invalid number of parallel processes: "
<< numParallelProcs);
75
return
StatusCode::FAILURE;
76
}
77
78
std::ostringstream basedirName;
79
basedirName << data.submitDir <<
"/tmp"
;
80
if
(!data.resubmit)
81
{
82
if
(gSystem->MakeDirectory (basedirName.str().c_str()) != 0)
83
{
84
ANA_MSG_ERROR
(
"failed to create directory "
<< basedirName.str());
85
return
StatusCode::FAILURE;
86
}
87
}
88
auto
submitSingle = [&] (std::size_t
index
)
noexcept
->
StatusCode
89
{
90
try
91
{
92
std::ostringstream dirName;
93
dirName << basedirName.str() <<
"/"
<<
index
;
94
if
(gSystem->MakeDirectory (dirName.str().c_str()) != 0)
95
{
96
ANA_MSG_ERROR
(
"failed to create directory "
+ dirName.str());
97
return
StatusCode::FAILURE;
98
}
99
100
std::ostringstream cmd;
101
cmd <<
"cd "
<< dirName.str() <<
" && "
;
102
if
(!dockerImage.empty())
103
cmd <<
"docker run --rm -v "
<<
RCU::Shell::quote
(data.submitDir) <<
":"
<<
RCU::Shell::quote
(data.submitDir) <<
" "
<< dockerOptions <<
" "
<< dockerImage <<
" "
;
104
cmd <<
RCU::Shell::quote
(data.submitDir) <<
"/submit/run "
<<
index
;
105
RCU::Shell::exec
(cmd.str());
106
}
catch
(std::exception& e)
107
{
108
ANA_MSG_ERROR
(
"exception in job "
<<
index
<<
": "
<< e.what());
109
return
StatusCode::FAILURE;
110
}
111
return
StatusCode::SUCCESS;
112
};
113
if
(numParallelProcs == 1)
114
{
115
for
(std::size_t
index
: data.batchJobIndices)
116
{
117
if
(submitSingle (
index
).isFailure())
118
return
StatusCode::FAILURE;
119
}
120
}
else
121
{
122
if
(numParallelProcs == 0)
123
numParallelProcs = std::thread::hardware_concurrency();
124
// hardware_concurrency() may legally return 0; make sure we still
125
// create at least one worker thread so the job makes progress
126
if
(numParallelProcs < 1)
127
numParallelProcs = 1;
128
if
(numParallelProcs >
int
(data.batchJobIndices.size()))
129
numParallelProcs = data.batchJobIndices.size();
130
std::vector<std::thread> threads;
131
std::mutex
mutex
;
132
auto
indexIter = data.batchJobIndices.begin();
133
bool
abort =
false
;
134
while
(threads.size() < unsigned (numParallelProcs))
135
{
136
threads.emplace_back ([&] ()
noexcept
137
{
138
std::unique_lock<std::mutex>
lock
(
mutex
);
139
while
(indexIter != data.batchJobIndices.end() && !abort)
140
{
141
auto
myindex = *indexIter;
142
++ indexIter;
143
lock
.unlock();
144
if
(submitSingle (myindex).isFailure())
145
{
146
abort =
true
;
147
return
;
148
}
149
lock
.lock ();
150
}
151
});
152
}
153
for
(
auto
& thread : threads)
154
thread.join();
155
if
(abort)
156
return
StatusCode::FAILURE;
157
}
158
data.submitted =
true
;
159
}
160
break
;
161
162
default
:
163
break
;
164
}
165
return ::StatusCode::SUCCESS;
166
}
167
}
Assert.h
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
StatusCode.h
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Job.h
ClassImp
ClassImp(EL::LocalDriver) namespace EL
Definition
LocalDriver.cxx:29
LocalDriver.h
ManagerData.h
MessageCheck.h
ShellExec.h
EL::BatchDriver::doManagerStep
virtual::StatusCode doManagerStep(Detail::ManagerData &data) const override
EL::Job::optDockerOptions
static const std::string optDockerOptions
any extra options we may want to pass to docker
Definition
Job.h:523
EL::Job::optNumParallelProcs
static const std::string optNumParallelProcs
the option to specify the number of parallel jobs in LocalDriver (0 = number of hardware cores) (defa...
Definition
Job.h:431
EL::Job::optDockerImage
static const std::string optDockerImage
this is the name of the docker image, when using docker with a supported batch driver
Definition
Job.h:520
EL::LocalDriver
a Driver for running batch jobs locally for testing purposes
Definition
LocalDriver.h:26
mutex
STL class.
EL::Detail::ManagerStep::doResubmit
@ doResubmit
call the actual doResubmit method
Definition
ManagerStep.h:116
EL::Detail::ManagerStep::submitJob
@ submitJob
do the actual job submission
Definition
ManagerStep.h:92
EL::Detail::ManagerStep::batchScriptVar
@ batchScriptVar
create the variables needed for the batch-run script
Definition
ManagerStep.h:83
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
RCU::Shell::exec
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition
ShellExec.cxx:27
RCU::Shell::quote
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
Definition
ShellExec.cxx:65
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0