33def 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