ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
MCJobOptionUtils
python
LHAPDFsupport.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2
3
# Pythonised helper functions for usage in top-level JobOptions
4
# written by Zach Marshall <zach.marshall@cern.ch>
5
# updates by Christian Gutschow <chris.g@cern.ch>
6
7
import
os
8
from
AthenaCommon
import
Logging
9
mglog = Logging.logging.getLogger(
'MCJobOptionUtils'
)
10
11
12
13
def
get_LHAPDF_DATA_PATH
():
14
return
get_LHAPDF_PATHS
()[1]
15
16
17
def
get_LHAPDF_PATHS
():
18
LHADATAPATH=
None
19
LHAPATH=
None
20
for
p
in
os.environ[
'LHAPATH'
].
split
(
':'
)+os.environ[
'LHAPDF_DATA_PATH'
].
split
(
':'
):
21
if
os.path.exists(p+
"/../../lib/"
)
and
LHAPATH
is
None
:
22
LHAPATH=p
23
for
p
in
os.environ[
'LHAPDF_DATA_PATH'
].
split
(
':'
)+os.environ[
'LHAPATH'
].
split
(
':'
):
24
if
os.path.exists(p)
and
LHADATAPATH
is
None
and
p!=LHAPATH:
25
LHADATAPATH=p
26
if
LHADATAPATH
is
None
:
27
LHADATAPATH=LHAPATH
28
if
LHAPATH
is
None
:
29
mglog.error(
'Could not find path to LHAPDF installation'
)
30
return
LHAPATH,LHADATAPATH
31
32
33
def
get_lhapdf_id_and_name
(pdf):
34
''' Function to get lhapdf id and name from either id or name.'''
35
pdfname=
''
36
pdfid=-999
37
LHADATAPATH=
get_LHAPDF_DATA_PATH
()
38
pdflist = open(LHADATAPATH+
'/pdfsets.index'
,
'r'
)
39
if
isinstance(pdf,int)
or
pdf.isdigit():
40
pdf=int(pdf)
41
pdfid=pdf
42
for
line
in
pdflist:
43
splitline=line.split()
44
if
int(splitline[0]) == pdfid:
45
pdfname=splitline[1]
46
break
47
else
:
48
pdfname=pdf
49
for
line
in
pdflist:
50
splitline=line.split()
51
if
splitline[1] == pdfname:
52
pdfid=int(splitline[0])
53
break
54
pdflist.close()
55
56
if
pdfname==
''
:
57
err=
'Couldn\'t find PDF name associated to ID %i in %s.'
%(pdfid,LHADATAPATH+
'/pdfsets.index'
)
58
mglog.error(err)
59
raise
RuntimeError(err)
60
if
pdfid<0:
61
err=
'Couldn\'t find PDF ID associated to name %s in %s.'
%(pdfname,LHADATAPATH+
'/pdfsets.index'
)
62
mglog.error(err)
63
raise
RuntimeError(err)
64
65
return
pdfid,pdfname
66
67
68
def
resetLHAPDF
(origLHAPATH='',origLHAPDF_DATA_PATH=''):
69
mglog.info(
'Restoring original LHAPDF env variables:'
)
70
os.environ[
'LHAPATH'
]=origLHAPATH
71
os.environ[
'LHAPDF_DATA_PATH'
]=origLHAPDF_DATA_PATH
72
mglog.info(
'LHAPATH='
+os.environ[
'LHAPATH'
])
73
mglog.info(
'LHAPDF_DATA_PATH='
+os.environ[
'LHAPDF_DATA_PATH'
])
74
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
python.LHAPDFsupport.get_lhapdf_id_and_name
get_lhapdf_id_and_name(pdf)
Definition
LHAPDFsupport.py:33
python.LHAPDFsupport.resetLHAPDF
resetLHAPDF(origLHAPATH='', origLHAPDF_DATA_PATH='')
Definition
LHAPDFsupport.py:68
python.LHAPDFsupport.get_LHAPDF_PATHS
get_LHAPDF_PATHS()
Definition
LHAPDFsupport.py:17
python.LHAPDFsupport.get_LHAPDF_DATA_PATH
get_LHAPDF_DATA_PATH()
Definition
LHAPDFsupport.py:13
Generated on
for ATLAS Offline Software by
1.17.0