ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tools
PyJobTransforms
python
trfEnv.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3
6
7
import
os
8
import
os.path
as
path
9
10
import
logging
11
msg = logging.getLogger(__name__)
12
13
15
class
environmentUpdate
(object):
16
17
def
__init__
(self):
18
self.
_envdict
= {}
19
20
22
def
setStandardEnvironment
(self, argdict, name='all', substep=''):
23
self.
probeIMFSettings
(argdict, name=name, substep=substep)
24
self.
probeTcmallocSettings
(argdict, name=name, substep=substep)
25
self.
probeOtherSettings
(argdict, name=name, substep=substep)
26
27
28
def
probeIMFSettings
(self, argdict, name='all', substep=''):
29
# If imf=True/False then follow its lead, but otherwise try to detect the release
30
# and enable if we have a release >= 17.7
31
if
'imf'
in
argdict:
32
if
argdict[
'imf'
].returnMyValue(name=name, substep=substep)
is
False
:
33
msg.info(
'Skipping inclusion of imf libraries: --imf is set to False'
)
34
else
:
35
msg.info(
'Enabling inclusion of imf libraries: --imf is set to True'
)
36
self.
_addIMFSettings
()
37
return
38
39
self.
_addIMFSettings
()
40
41
42
def
_addIMFSettings
(self):
43
if
'ATLASMKLLIBDIR_PRELOAD'
not
in
os.environ:
44
msg.warning(
'"ATLASMKLLIBDIR_PRELOAD" not found in the current environment'
45
' - no setup of MKL is possible'
)
46
return
47
48
if
'ATLASMKLLIBDIR_PRELOAD'
in
os.environ:
49
if
"LD_PRELOAD"
not
in
self.
_envdict
:
50
self.
_envdict
[
"LD_PRELOAD"
] =
pathVar
(
"LD_PRELOAD"
)
51
self.
_envdict
[
"LD_PRELOAD"
].
add
(path.join(
"$ATLASMKLLIBDIR_PRELOAD"
,
"libimf.so"
))
52
self.
_envdict
[
"LD_PRELOAD"
].
add
(path.join(
"$ATLASMKLLIBDIR_PRELOAD"
,
"libintlc.so.5"
))
53
54
55
56
def
probeTcmallocSettings
(self, argdict, name='all', substep=''):
57
# We only do this if tcmalloc=True in atgdict
58
if
'tcmalloc'
not
in
argdict
or
argdict[
'tcmalloc'
].returnMyValue(name=name, substep=substep)
is
False
:
59
msg.info(
'Skipping inclusion of tcmalloc'
)
60
return
61
62
if
'TCMALLOCDIR'
not
in
os.environ:
63
msg.warning(
'"TCMALLOCDIR" not found in the current environment'
64
' - no setup of tcmalloc is possible'
)
65
return
66
67
# For now we support the minimal version (it's the default)
68
if
"LD_PRELOAD"
not
in
self.
_envdict
:
69
self.
_envdict
[
"LD_PRELOAD"
] =
pathVar
(
"LD_PRELOAD"
)
70
self.
_envdict
[
"LD_PRELOAD"
].
add
(path.join(
"$TCMALLOCDIR"
,
"libtcmalloc_minimal.so"
))
71
72
73
74
def
probeOtherSettings
(self, argdict, name='all', substep=''):
75
if
'env'
not
in
argdict:
76
return
77
78
myEnv = argdict[
'env'
].returnMyValue(name=name, substep=substep)
79
if
myEnv
is
None
:
80
return
81
82
for
setting
in
myEnv:
83
try
:
84
k, v = setting.split(
'='
, 1)
85
self.
_envdict
[k] = v
86
except
ValueError:
87
msg.warning(
'Environment setting "{0}" seems to be invalid (must be KEY=VALUE)'
)
88
89
90
def
value
(self, key):
91
return
str(self.
_envdict
[key])
92
93
94
@property
95
def
values
(self):
96
return
[
"{0}={1}"
.format(k, v)
for
k, v
in
self.
_envdict
.items() ]
97
98
99
@property
100
def
len
(self):
101
return
len
(self.
_envdict
)
102
103
104
105
class
pathVar
(object):
106
_currentEnvironmentValue =
"+++CURRENT+++"
107
108
def
__init__
(self, varname, separator=":
", testForExistance=True):
109
self.
_name
= varname
110
self.
_separator
= separator
111
self.
_testExistance
= testForExistance
112
113
# Note the special value @c _currentEnvironmentValue that will be expanded to the current
114
# setting in the environment (i.e., @c os.environ['self._name']), if it exists
115
self.
_value
= [self.
_currentEnvironmentValue
]
116
117
118
def
add
(self, value, prepend=True):
119
msg.debug(
'Adding new value "{0}" to envvar {1} (currently {2}'
.format(value, self.
_name
, self.
_value
))
120
if
value
in
self.
_value
:
121
msg.warning(
'Attempt to add environment element {0} twice to {1}'
.format(value, self.
_name
))
122
if
self.
_testExistance
:
123
# expand environment variables (will only check current release, but this is the most common anyways)
124
test_value = value
125
if
'$'
in
test_value:
126
test_value = os.path.join(os.environ[os.path.dirname(value)[1:]], os.path.basename(value))
127
if
not
os.access(test_value, os.R_OK):
128
msg.warning(
"Path to {0} is not readable - will not add it to {1}"
.format(value, self.
_name
))
129
return
130
if
prepend:
131
self.
_value
[0:0] = [value]
132
else
:
133
self.
_value
.append(value)
134
135
136
def
__str__
(self):
137
valStr =
""
138
for
v
in
self.
_value
:
139
if
v == self.
_currentEnvironmentValue
:
140
if
self.
_name
in
os.environ:
141
valStr +=
"$"
+ self.
_name
+ self.
_separator
142
else
:
143
valStr += v + self.
_separator
144
valStr = valStr[:-1]
145
return
valStr
python.trfEnv.environmentUpdate
Class holding the update to an environment that will be passed on to an executor.
Definition
trfEnv.py:15
python.trfEnv.environmentUpdate.__init__
__init__(self)
Definition
trfEnv.py:17
python.trfEnv.environmentUpdate.probeIMFSettings
probeIMFSettings(self, argdict, name='all', substep='')
Add the libimf maths library to the setup.
Definition
trfEnv.py:28
python.trfEnv.environmentUpdate.setStandardEnvironment
setStandardEnvironment(self, argdict, name='all', substep='')
Setup the standard execution environment according to the switches in the transform configuration.
Definition
trfEnv.py:22
python.trfEnv.environmentUpdate.len
len(self)
Count the number of environment items that need to be updated.
Definition
trfEnv.py:100
python.trfEnv.environmentUpdate.probeOtherSettings
probeOtherSettings(self, argdict, name='all', substep='')
Add other settings.
Definition
trfEnv.py:74
python.trfEnv.environmentUpdate._addIMFSettings
_addIMFSettings(self)
Definition
trfEnv.py:42
python.trfEnv.environmentUpdate._envdict
dict _envdict
Definition
trfEnv.py:18
python.trfEnv.environmentUpdate.value
value(self, key)
Return the value for a key, string converted.
Definition
trfEnv.py:90
python.trfEnv.environmentUpdate.probeTcmallocSettings
probeTcmallocSettings(self, argdict, name='all', substep='')
Add TCMALLOC to the setup.
Definition
trfEnv.py:56
python.trfEnv.environmentUpdate.values
values(self)
Return a list of KEY=VALUE pairs for this environment.
Definition
trfEnv.py:95
python.trfEnv.pathVar
Helper class for environment variables using colon separated paths.
Definition
trfEnv.py:105
python.trfEnv.pathVar._testExistance
_testExistance
Definition
trfEnv.py:111
python.trfEnv.pathVar._value
list _value
Definition
trfEnv.py:115
python.trfEnv.pathVar.__str__
__str__(self)
Return the correct string representing the value for the shell.
Definition
trfEnv.py:136
python.trfEnv.pathVar._separator
_separator
Definition
trfEnv.py:110
python.trfEnv.pathVar.add
add(self, value, prepend=True)
Add a new element to the variable.
Definition
trfEnv.py:118
python.trfEnv.pathVar.__init__
__init__(self, varname, separator=":", testForExistance=True)
Definition
trfEnv.py:108
python.trfEnv.pathVar._name
_name
Definition
trfEnv.py:109
python.trfEnv.pathVar._currentEnvironmentValue
str _currentEnvironmentValue
Definition
trfEnv.py:106
add
bool add(const std::string &hname, TKey *tobj)
Definition
fastadd.cxx:55
Generated on
for ATLAS Offline Software by
1.17.0