ATLAS Offline Software
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 
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, memMB=0, basedir=""):
9  self.name = name
10  self.cmds = []
11  self.hours = hours
12  self.nCores = nCores
13  self.memMB = memMB
14  if self.memMB == 1:
15  self.memMB = 1499
16  if self.memMB == 2:
17  self.memMB = 2499
18  self.env = {}
19  self.basedir = basedir
20  self.id = None
21  self.dependsOnOk = []
22  self.dependsOnAny = []
23 
24  def write(self, useSingularity=True, extraDirs=[]):
25  executable = "#!/bin/sh -\n"
26 
27  # COMPILER_PATH
28  if useSingularity:
29  platform = str(os.environ['COMPILER_PATH']).split('/')[-1].replace('el9', 'almalinux9')
30  executable += 'if [ "$1" != "--really" ]; then \n'
31  executable += ' exec singularity exec -e --no-home'
32  for dir in ["/cvmfs", "/var", self.basedir, "$(pwd | cut -d '/' -f 1-2)"] + extraDirs:
33  executable += ' -B '+dir
34  executable += ' /cvmfs/atlas.cern.ch/repo/containers/fs/singularity/'
35  executable += platform + ' /bin/bash -- "$0" --really "$@";\n'
36  executable += 'fi\n'
37  executable += "shift;\n\n"
38  executable += "export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase\n"
39  executable += "source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh\n"
40 
41  executable += "ulimit -f 1000000;\n"
42  executable += "cd "+self.basedir+"\n\n"
43  executable += "echo 'ncores="+str(self.nCores)+" nhours="+str(self.hours)+" "+self.basedir+"/"+self.name+".sh';\n"
44  for cmd in self.cmds:
45  executable += cmd+"\n"
46  executable += "exit 0\n"
47 
48 
49  filename = self.basedir+"/"+self.name+".sh"
50  with open(filename, 'w') as f:
51  f.write(executable)
52 
53  #make shell-files executable
54  st = os.stat(filename)
55  os.chmod(filename, st.st_mode | stat.S_IEXEC)
56 
57 
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
sherpaTarCreator.batchJobBase.batchJobBase.name
name
Definition: batchJobBase.py:9
sherpaTarCreator.batchJobBase.batchJobBase.write
def write(self, useSingularity=True, extraDirs=[])
Definition: batchJobBase.py:24
sherpaTarCreator.batchJobBase.batchJobBase.memMB
memMB
Definition: batchJobBase.py:13
sherpaTarCreator.batchJobBase.batchJobBase.basedir
basedir
Definition: batchJobBase.py:19
sherpaTarCreator.batchJobBase.batchJobBase.id
id
Definition: batchJobBase.py:20
sherpaTarCreator.batchJobBase.batchJobBase
Definition: batchJobBase.py:5
sherpaTarCreator.batchJobBase.batchJobBase.hours
hours
Definition: batchJobBase.py:11
sherpaTarCreator.batchJobBase.batchJobBase.nCores
nCores
Definition: batchJobBase.py:12
sherpaTarCreator.batchJobBase.batchJobBase.dependsOnOk
dependsOnOk
Definition: batchJobBase.py:21
Trk::open
@ open
Definition: BinningType.h:40
sherpaTarCreator.batchJobBase.batchJobBase.__init__
def __init__(self, name, hours=0, nCores=1, memMB=0, basedir="")
Definition: batchJobBase.py:8
sherpaTarCreator.batchJobBase.batchJobBase.dependsOnAny
dependsOnAny
Definition: batchJobBase.py:22
str
Definition: BTagTrackIpAccessor.cxx:11
sherpaTarCreator.batchJobBase.batchJobBase.cmds
cmds
Definition: batchJobBase.py:10
sherpaTarCreator.batchJobBase.batchJobBase.env
env
Definition: batchJobBase.py:18
Trk::split
@ split
Definition: LayerMaterialProperties.h:38