ATLAS Offline Software
Loading...
Searching...
No Matches
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"""
5This module defines miscellaneous utility functions.
6"""
7__author__ = 'Juerg Beringer'
8__version__ = '$Id $'
9
10import os, re
11
12
13def 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
30def 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
42 if s:
43 return s
44 else:
45 return ''
46
47
48def 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()
fileListSnippet(files, dsName, taskName, jobDir=None)