ATLAS Offline Software
InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 """
5 This module defines miscellaneous utility functions.
6 """
7 __author__ = 'Juerg Beringer'
8 __version__ = '$Id $'
9 
10 import os, re
11 
12 
13 def getRunFromName(name,default='',asInt=False):
14  """Extract the run number from a file name whose first part is a standard dataset name.
15  If the run number cannot be determined, returns the default value, which, by
16  default is an empty string."""
17  name = os.path.basename(name)
18  try:
19  run = re.sub('^0*','',name.split('.')[1])
20  if not re.search(r'^\d+$',run):
21  # Probably wasn't the run number, so use the default instead
22  run = default
23  else:
24  run = int(run) if asInt else run
25  except Exception:
26  run = default
27  return run
28 
29 
30 def fileListSnippet(files,dsName,taskName,jobDir=None):
31  s = ''
32  if files:
33  for f in files.split():
34  if jobDir and not os.path.exists('%s/%s/%s/%s' % (jobDir,dsName,taskName,f)):
35  s += '%s (archived)<br>' % f
36  else:
37  s += '<a href="/jobfiles/%s/%s/%s">%s</a><br>' % (dsName,taskName,f,f)
38  return s
39 
40 
41 def blankIfNone(s):
42  if s:
43  return s
44  else:
45  return ''
46 
47 
48 def getUserName(default='UNKNOWN'):
49  """Get login name in a platform-independent manner."""
50  user = ''
51  try:
52  user = os.getlogin() # this doesn't seem to work with acrontab
53  except Exception:
54  pass
55  if not user:
56  user = os.getenv('USER',default)
57  return user
58 
59 
61  import platform
62  return platform.node()
python.Utils.getHostName
def getHostName()
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:60
python.Utils.getRunFromName
def getRunFromName(name, default='', asInt=False)
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:13
python.Utils.fileListSnippet
def fileListSnippet(files, dsName, taskName, jobDir=None)
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:30
python.Utils.blankIfNone
def blankIfNone(s)
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:41
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.Utils.getUserName
def getUserName(default='UNKNOWN')
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:48