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

Classes

class  AccessError
class  Backend
class  EOS
class  FileSet
class  FilterError
class  Local

Functions

 deprecated (message)
 _rationalise (path)
 storageManager (name)
 filelist (files, prefix=None)
 ls (path, longls=False)
 cp (src, dest='.')
 get_lumi_blocks (root_file)
 make_lumi_block_map_file (file_set, path)

Variables

 StorageManager = namedtuple('StorageManager', ['name', 'prefix', 'cp', 'ls', 'longls'])
 CastorMgr = StorageManager(name='castor', prefix='root://castoratlas/', cp='xrdcp', ls='nsls %s', longls='nsls -l %s')
 RFIOMgr = StorageManager(name='rfio', prefix='rfio:', cp='rfcp', ls='rfdir %s', longls='rfdir %s')
 EOSMgr = StorageManager(name='eos', prefix='root://eosatlas.cern.ch/', cp='xrdcp', ls='/bin/sh -l -c "LD_LIBRARY_PATH=/usr/lib64/ eos ls %s"', longls='/bin/sh -l -c "LD_LIBRARY_PATH=/usr/lib64/ eos ls -l %s"')
 UnixMgr = StorageManager(name='unix', prefix='', cp='cp', ls='ls %s', longls='ls -l %s')

Function Documentation

◆ _rationalise()

python.DiskUtils._rationalise ( path)
protected
Rationalise a path, removing prefix and esuring single leading slash

Definition at line 34 of file DiskUtils.py.

34def _rationalise(path):
35 """
36 Rationalise a path, removing prefix and esuring single leading slash
37 """
38 for p in ('root://castoratlas/', 'root://eosatlas.cern.ch/', 'rfio:', 'castor:'):
39 if path.startswith(p):
40 path = path[len(p):]
41 if path.startswith('//'):
42 path = path[1:]
43 if not path.startswith('/'):
44 path = '/'+path
45 break
46
47 return path
48
49@deprecated("EOS is mounted on /eos with fuse, so you probably don't need this abstraction")

◆ cp()

python.DiskUtils.cp ( src,
dest = '.' )

Definition at line 127 of file DiskUtils.py.

127def cp(src, dest='.'):
128 src = _rationalise(src)
129 dest = _rationalise(dest)
130 srcmgr = storageManager(src)
131 destmgr = storageManager(dest)
132
133 cp = 'cp'
134 if srcmgr.cp == 'xrdcp' or destmgr.cp == 'xrdcp': cp = 'xrdcp'
135
136 return os.system('%s %s%s %s%s' %(cp, srcmgr.prefix, src, destmgr.prefix, dest))
137

◆ deprecated()

python.DiskUtils.deprecated ( message)

Definition at line 13 of file DiskUtils.py.

13def deprecated(message):
14 def deco(fn):
15 @wraps(fn)
16 def wrapper(*args, **kwargs):
17 print('WARNING: [InDetBeamSpotExample.DiskUtils]',
18 '{}() is deprecated and will be removed'.format( fn.__name__),
19 file=sys.stderr)
20 print('WARNING: ', message,
21 file=sys.stderr)
22 return fn(*args, **kwargs)
23 return wrapper
24 return deco
25
void print(char *figname, TCanvas *c1)

◆ filelist()

python.DiskUtils.filelist ( files,
prefix = None )
lists CASTOR/EOS name server directory/file entries.
If path is a directory, filelist lists the entries in the directory;
they are sorted alphabetically.

`files` specifies the CASTOR/EOS pathname.
`prefix` specifies the prefix one wants to prepend to the path found.
         (e.g. prefix='root://castoratlas/' or 'root://eosatlas.cern.ch//')
         if prefix=True it will determin the prefix based on the pathname

ex:
filelist('/castor/cern.ch/atlas/*')
filelist('/castor/cern.ch/atl*/foo?[bar]/*.pool.root.?')
filelist('/eos/atlas/*', prefix='root://eosatlas.cern.ch/')
filelist('/castor/cern.ch/atlas/*', prefix=True)

Definition at line 63 of file DiskUtils.py.

63def filelist(files, prefix=None):
64 """
65 lists CASTOR/EOS name server directory/file entries.
66 If path is a directory, filelist lists the entries in the directory;
67 they are sorted alphabetically.
68
69 `files` specifies the CASTOR/EOS pathname.
70 `prefix` specifies the prefix one wants to prepend to the path found.
71 (e.g. prefix='root://castoratlas/' or 'root://eosatlas.cern.ch//')
72 if prefix=True it will determin the prefix based on the pathname
73
74 ex:
75 filelist('/castor/cern.ch/atlas/*')
76 filelist('/castor/cern.ch/atl*/foo?[bar]/*.pool.root.?')
77 filelist('/eos/atlas/*', prefix='root://eosatlas.cern.ch/')
78 filelist('/castor/cern.ch/atlas/*', prefix=True)
79 """
80
81 path, fname = os.path.split(files)
82 path = _rationalise(path)
83
84 if ( path.count('*') > 0 or path.count('?') > 0 or
85 path.count('[') > 0 or path.count(']') > 0 ) :
86 paths = ls(path)
87 return sum([ls(os.path.join(p,fname))
88 for p in paths], [])
89
90 mgr = storageManager(path)
91
92 try:
93 flist = subprocess.check_output(mgr.ls % path, shell=True).split()
94 except subprocess.CalledProcessError as err:
95 print(err.output)
96 return []
97
98 if not (os.path.basename(files) in ['', '*']): # no need to filter
99 pattern = fnmatch.translate(os.path.basename(files))
100 flist = filter(lambda x: re.search(pattern, x), flist)
101
102 if prefix:
103 if isinstance(prefix, str):
104 return [os.path.join(prefix+path, p) for p in flist]
105 else:
106 return [os.path.join(mgr.prefix+path, p) for p in flist]
107 else:
108 return [os.path.join(path, p) for p in flist]
109
110@deprecated("EOS is mounted on /eos with fuse, so you probably don't need this abstraction")
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ get_lumi_blocks()

python.DiskUtils.get_lumi_blocks ( root_file)

Definition at line 142 of file DiskUtils.py.

142def get_lumi_blocks(root_file):
143
144 try:
145 from PyUtils.MetaReader import read_metadata
146 md = read_metadata(root_file)
147
148 return( md[root_file]['lumiBlockNumbers'] )
149 except Exception as e:
150 print( "Failed to read MetaData will fall back to looping ", repr(e))
151
152 try:
153 from PyUtils.RootUtils import import_root
154 root = import_root()
155 f = root.TFile.Open(root_file, 'READ')
156 lumiblocks = set()
157 metadata= f.Get('CollectionMetadata') if f else None
158 if metadata:
159 metadata.GetEntry(0)
160 import ctypes
161 key_name = str(ctypes.c_char_p(metadata.Key).value)
162 assert key_name == 'POOLCollectionID'
163 del metadata
164 coll_tree = f.Get('POOLCollectionTree') if f else None
165 if coll_tree:
166 evtmax = coll_tree.GetEntries()
167 if evtmax in (-1, None):
168 evtmax = 0
169 evtmax = int(evtmax)
170 for row in range(evtmax):
171 if coll_tree.GetEntry(row) < 0:
172 break
173 lbn = coll_tree.LumiBlockN
174 lumiblocks.add(lbn)
175 del coll_tree
176 return list( lumiblocks )
177 finally:
178 f.Close()
179
STL class.

◆ ls()

python.DiskUtils.ls ( path,
longls = False )
Simple list of files

`longls` specifies long listing format

Definition at line 111 of file DiskUtils.py.

111def ls(path, longls=False):
112 """
113 Simple list of files
114
115 `longls` specifies long listing format
116 """
117
118 path = _rationalise(path)
119 mgr = storageManager(path)
120
121 if longls:
122 return subprocess.check_output(mgr.longls % path, shell=True)
123 else:
124 return subprocess.check_output(mgr.ls % path, shell=True)
125
126@deprecated("EOS is mounted on /eos with fuse, so you probably don't need this abstraction")

◆ make_lumi_block_map_file()

python.DiskUtils.make_lumi_block_map_file ( file_set,
path )

Definition at line 180 of file DiskUtils.py.

180def make_lumi_block_map_file(file_set, path):
181 with open(path, 'w') as mapfile:
182 for f, lbs in file_set.with_lumi_blocks():
183 print('Reading:', f)
184 mapfile.write('{} {}\n'.format(
185 os.path.basename(f),
186 ','.join(str(x) for x in lbs)))
187
188

◆ storageManager()

python.DiskUtils.storageManager ( name)
Return SotrageManager to deal with listing, copying and reading files from various storage systems

Definition at line 50 of file DiskUtils.py.

50def storageManager(name):
51 """
52 Return SotrageManager to deal with listing, copying and reading files from various storage systems
53 """
54 name = _rationalise(name)
55 if name.startswith('/castor/'):
56 return CastorMgr
57 elif name.startswith('/eos/'):
58 return EOSMgr
59 else:
60 return UnixMgr
61
62@deprecated("DiskUtils.FileSet replaces this functionality")

Variable Documentation

◆ CastorMgr

python.DiskUtils.CastorMgr = StorageManager(name='castor', prefix='root://castoratlas/', cp='xrdcp', ls='nsls %s', longls='nsls -l %s')

Definition at line 29 of file DiskUtils.py.

◆ EOSMgr

python.DiskUtils.EOSMgr = StorageManager(name='eos', prefix='root://eosatlas.cern.ch/', cp='xrdcp', ls='/bin/sh -l -c "LD_LIBRARY_PATH=/usr/lib64/ eos ls %s"', longls='/bin/sh -l -c "LD_LIBRARY_PATH=/usr/lib64/ eos ls -l %s"')

Definition at line 31 of file DiskUtils.py.

◆ RFIOMgr

python.DiskUtils.RFIOMgr = StorageManager(name='rfio', prefix='rfio:', cp='rfcp', ls='rfdir %s', longls='rfdir %s')

Definition at line 30 of file DiskUtils.py.

◆ StorageManager

python.DiskUtils.StorageManager = namedtuple('StorageManager', ['name', 'prefix', 'cp', 'ls', 'longls'])

Definition at line 28 of file DiskUtils.py.

◆ UnixMgr

python.DiskUtils.UnixMgr = StorageManager(name='unix', prefix='', cp='cp', ls='ls %s', longls='ls -l %s')

Definition at line 32 of file DiskUtils.py.