ATLAS Offline Software
Loading...
Searching...
No Matches
python.TrfUtils Namespace Reference

Classes

class  JobRunnerTransform

Functions

 readJSON (fname)
 writeJSON (fname, data)
 getDataSetName (name, sep='#')
 getFileName (name, sep='#')
 parseQualifiedFileNames (inputList, sep='#')
 getGuid (name)
 getFileDescription (fileName, dsname='')

Variables

str __author__ = 'Juerg Beringer'
str __version__ = 'TrfUtils.py atlas/athena'

Detailed Description

Utilities for writing job transforms for use at T0 and at the CAF Task Management System.

Function Documentation

◆ getDataSetName()

python.TrfUtils.getDataSetName ( name,
sep = '#' )
Extract dataset name from a qualified file name.

Definition at line 33 of file TrfUtils.py.

33def getDataSetName(name, sep='#'):
34 """Extract dataset name from a qualified file name."""
35 if isinstance(name, str) :
36 """Old format of ds/file """
37 if sep in name:
38 return name.split(sep)[0]
39 else:
40 return None
41 elif isinstance(name, dict) :
42 """New format of ds/file """
43 return name['dsn']
44

◆ getFileDescription()

python.TrfUtils.getFileDescription ( fileName,
dsname = '' )
Return a dictionary with the standard file description required by T0 conventions.
   If no explicit dataset name is provided in dsname, the dataset name is
   assumed to be prepended to the fileName (first part, before '#').

Definition at line 95 of file TrfUtils.py.

95def getFileDescription(fileName,dsname=''):
96 """Return a dictionary with the standard file description required by T0 conventions.
97 If no explicit dataset name is provided in dsname, the dataset name is
98 assumed to be prepended to the fileName (first part, before '#')."""
99 if not dsname:
100 dsname = getDataSetName(fileName)
101 d = {
102 'dataset': dsname,
103 'subFiles':[
104 {
105 'name': getFileName(fileName),
106 'file_guid': getGuid(fileName),
107 'file_size': 0,
108 'nentries': 0,
109 'checkSum': 0,
110
111 }
112 ]
113 }
114 return d
115
116

◆ getFileName()

python.TrfUtils.getFileName ( name,
sep = '#' )
Extract file name from a qualified file name.

Definition at line 45 of file TrfUtils.py.

45def getFileName(name, sep='#'):
46 """Extract file name from a qualified file name."""
47 if isinstance(name, str) :
48 """Old format of ds/file """
49 if sep in name:
50 return name.split(sep)[1]
51 else:
52 return name
53 elif isinstance(name, dict) :
54 """New format of ds/file """
55 return name['lfn']
56
57

◆ getGuid()

python.TrfUtils.getGuid ( name)
Get GUID of file name from local Pool file catalog (from Armin Nairz, as used at Tier-0).

Definition at line 71 of file TrfUtils.py.

71def getGuid(name):
72 """Get GUID of file name from local Pool file catalog (from Armin Nairz, as used at Tier-0)."""
73 pfc='PoolFileCatalog.xml'
74 if not os.path.isfile(pfc) :
75 try :
76 (s,o) = subprocess.getstatusoutput('uuidgen')
77 guid = o.strip()
78 except Exception:
79 guid = 'UUIDGENERROR'
80 else :
81 try :
82 cmd = 'grep -B2 %s %s' % (name,pfc)
83 cmd += ' | grep "File ID" | sed -e "s/ <File ID=\\\"//g" | sed -e "s/\\\">//g"'
84 (s,o) = subprocess.getstatusoutput(cmd)
85 guid = o.strip()
86 # there might be a PFC from earlier processing steps
87 if guid == '' :
88 (s,o) = subprocess.getstatusoutput('uuidgen')
89 guid = o.strip()
90 except Exception:
91 guid = 'PFCPARSINGERROR'
92 return guid
93
94

◆ parseQualifiedFileNames()

python.TrfUtils.parseQualifiedFileNames ( inputList,
sep = '#' )
Parse a list of qualified file names (file names that are prepended with
   their dataset name). Returns a tuple consisting of the dataset name and the
   list of unqualified file names.

Definition at line 58 of file TrfUtils.py.

58def parseQualifiedFileNames(inputList, sep='#'):
59 """Parse a list of qualified file names (file names that are prepended with
60 their dataset name). Returns a tuple consisting of the dataset name and the
61 list of unqualified file names."""
62 if not inputList:
63 return (None, [])
64 dataset = getDataSetName(inputList[0],sep)
65 files = []
66 for f in inputList:
67 files.append(getFileName(f,sep))
68 return (dataset,files)
69
70

◆ readJSON()

python.TrfUtils.readJSON ( fname)
Read a JSON file and return its data.

Definition at line 19 of file TrfUtils.py.

19def readJSON(fname):
20 """Read a JSON file and return its data."""
21 f = open(fname,'r')
22 """JSON converts strings to unicode, so we use YAML instead."""
23 data = yaml.load(f,Loader=yaml.FullLoader)
24 f.close()
25 return data
26

◆ writeJSON()

python.TrfUtils.writeJSON ( fname,
data )
Serialize data and write to fname.

Definition at line 27 of file TrfUtils.py.

27def writeJSON(fname, data):
28 """Serialize data and write to fname."""
29 f = open(fname,'w')
30 print (json.dumps(data), file=f)
31 f.close()
32

Variable Documentation

◆ __author__

str python.TrfUtils.__author__ = 'Juerg Beringer'
private

Definition at line 8 of file TrfUtils.py.

◆ __version__

str python.TrfUtils.__version__ = 'TrfUtils.py atlas/athena'
private

Definition at line 9 of file TrfUtils.py.