ATLAS Offline Software
Loading...
Searching...
No Matches
Generators
Sherpa_i
python
sherpaTarCreator
batchJobBase.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3
import
os, stat
4
5
class
batchJobBase
:
6
"""A class containing all information necessary to run given bash commands in an arbitrary batch system."""
7
8
def
__init__
(self, name, hours=0, nCores=1, account=None, queue=None, memMB=0, mounts=[], basedir=""):
9
self.
name
= name
10
self.
cmds
= []
11
self.
hours
= hours
12
self.
nCores
= nCores
13
self.
account
= account
14
self.
queue
= queue
15
self.
memMB
= memMB
16
self.
mounts
= mounts
17
if
self.
memMB
== 1:
18
self.
memMB
= 1499
19
if
self.
memMB
== 2:
20
self.
memMB
= 2499
21
self.
env
= {}
22
self.
basedir
= basedir
23
self.
id
=
None
24
self.
dependsOnOk
= []
25
self.
dependsOnAny
= []
26
27
def
write
(self, useSingularity=True, useApptainer=False, extraDirs=[]):
28
executable =
"#!/bin/sh -\n"
29
30
# COMPILER_PATH
31
if
useSingularity:
32
platform = str(os.environ[
'COMPILER_PATH'
]).
split
(
'/'
)[-1].
replace
(
'el9'
,
'almalinux9'
)
33
executable +=
'if [ "$1" != "--really" ]; then \n'
34
executable +=
' exec singularity exec -e --no-home'
35
for
dir
in
[
"/cvmfs"
,
"/var"
, self.
basedir
,
"$(pwd | cut -d '/' -f 1-2)"
] + extraDirs:
36
executable +=
' -B '
+dir
37
executable +=
' /cvmfs/atlas.cern.ch/repo/containers/fs/singularity/'
38
executable += platform +
' /bin/bash -- "$0" --really "$@";\n'
39
executable +=
'fi\n'
40
executable +=
"shift;\n\n"
41
executable +=
"export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n"
42
executable +=
"source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh\n"
43
44
if
useApptainer:
45
wrapper =
''
46
wrapperfilename = self.
basedir
+
"/"
+self.
name
+
"_wrapper.sh"
47
platform = str(os.environ[
'COMPILER_PATH'
]).
split
(
'/'
)[-1].
replace
(
'el9'
,
'almalinux9'
)
48
executable +=
'export ALRB_CONT_SWTYPE="apptainer"\n'
49
executable +=
'export ALRB_CONT_PRESETUP="hostname -f; date; id -a"\n'
50
executable +=
'export ALRB_testPath=",,,,,,,,,,,,,,,,,,,,,,,,"\n'
51
executable +=
'export ALRB_CONT_RUNPAYLOAD="'
+wrapperfilename+
'"\n'
52
wrapper +=
"ulimit -f 1000000;\n"
53
wrapper +=
"cd "
+self.
basedir
+
";\n\n"
54
wrapper +=
"echo 'ncores="
+str(self.
nCores
)+
" nhours="
+str(self.
hours
)+
" "
+self.
basedir
+
"/"
+self.
name
+
".sh';\n"
55
for
cmd
in
self.
cmds
:
56
wrapper += cmd+
'\n'
57
with
open(wrapperfilename,
'w'
)
as
f:
58
f.write(wrapper)
59
st = os.stat(wrapperfilename)
60
os.chmod(wrapperfilename, st.st_mode | stat.S_IEXEC)
61
executable +=
"export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n"
62
executable +=
"source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh -c "
+platform+
" -b -q"
63
if
self.
mounts
!= []:
64
executable +=
"-m"
+
" "
.join(self.
mounts
)
65
else
:
66
executable +=
"\n"
67
executable +=
"exit $?\n"
68
69
else
:
70
executable +=
"ulimit -f 1000000;\n"
71
executable +=
"cd "
+self.
basedir
+
"\n\n"
72
executable +=
"echo 'ncores="
+str(self.
nCores
)+
" nhours="
+str(self.
hours
)+
" "
+self.
basedir
+
"/"
+self.
name
+
".sh';\n"
73
for
cmd
in
self.
cmds
:
74
executable += cmd+
"\n"
75
executable +=
"exit 0\n"
76
77
filename = self.
basedir
+
"/"
+self.
name
+
".sh"
78
with
open(filename,
'w'
)
as
f:
79
f.write(executable)
80
81
#make shell-files executable
82
st = os.stat(filename)
83
os.chmod(filename, st.st_mode | stat.S_IEXEC)
84
85
sherpaTarCreator.batchJobBase.batchJobBase
Definition
batchJobBase.py:5
sherpaTarCreator.batchJobBase.batchJobBase.cmds
list cmds
Definition
batchJobBase.py:10
sherpaTarCreator.batchJobBase.batchJobBase.dependsOnOk
list dependsOnOk
Definition
batchJobBase.py:24
sherpaTarCreator.batchJobBase.batchJobBase.dependsOnAny
list dependsOnAny
Definition
batchJobBase.py:25
sherpaTarCreator.batchJobBase.batchJobBase.nCores
nCores
Definition
batchJobBase.py:12
sherpaTarCreator.batchJobBase.batchJobBase.__init__
__init__(self, name, hours=0, nCores=1, account=None, queue=None, memMB=0, mounts=[], basedir="")
Definition
batchJobBase.py:8
sherpaTarCreator.batchJobBase.batchJobBase.mounts
mounts
Definition
batchJobBase.py:16
sherpaTarCreator.batchJobBase.batchJobBase.env
dict env
Definition
batchJobBase.py:21
sherpaTarCreator.batchJobBase.batchJobBase.name
name
Definition
batchJobBase.py:9
sherpaTarCreator.batchJobBase.batchJobBase.basedir
basedir
Definition
batchJobBase.py:22
sherpaTarCreator.batchJobBase.batchJobBase.hours
hours
Definition
batchJobBase.py:11
sherpaTarCreator.batchJobBase.batchJobBase.queue
queue
Definition
batchJobBase.py:14
sherpaTarCreator.batchJobBase.batchJobBase.memMB
int memMB
Definition
batchJobBase.py:15
sherpaTarCreator.batchJobBase.batchJobBase.id
id
Definition
batchJobBase.py:23
sherpaTarCreator.batchJobBase.batchJobBase.account
account
Definition
batchJobBase.py:13
sherpaTarCreator.batchJobBase.batchJobBase.write
write(self, useSingularity=True, useApptainer=False, extraDirs=[])
Definition
batchJobBase.py:27
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition
hcg.cxx:310
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:177
Generated on
for ATLAS Offline Software by
1.14.0