ATLAS Offline Software
Classes | Functions | Variables
python.TrfUtils Namespace Reference

Classes

class  JobRunnerTransform
 

Functions

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

Variables

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

Function Documentation

◆ getDataSetName()

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

Definition at line 33 of file TrfUtils.py.

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

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

95 def 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()

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

Definition at line 45 of file TrfUtils.py.

45 def 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()

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

71 def 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()

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

58 def 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()

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

Definition at line 19 of file TrfUtils.py.

19 def 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()

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

Definition at line 27 of file TrfUtils.py.

27 def 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__

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

Definition at line 8 of file TrfUtils.py.

◆ __version__

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

Definition at line 9 of file TrfUtils.py.

python.TrfUtils.getFileDescription
def getFileDescription(fileName, dsname='')
Definition: TrfUtils.py:95
python.TrfUtils.writeJSON
def writeJSON(fname, data)
Definition: TrfUtils.py:27
python.TrfUtils.getDataSetName
def getDataSetName(name, sep='#')
Definition: TrfUtils.py:33
python.TrfUtils.readJSON
def readJSON(fname)
Definition: TrfUtils.py:19
Trk::open
@ open
Definition: BinningType.h:40
python.TrfUtils.parseQualifiedFileNames
def parseQualifiedFileNames(inputList, sep='#')
Definition: TrfUtils.py:58
python.TrfUtils.getFileName
def getFileName(name, sep='#')
Definition: TrfUtils.py:45
python.TrfUtils.getGuid
def getGuid(name)
Definition: TrfUtils.py:71