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

Classes

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

Functions

def deprecated (message)
 
def _rationalise (path)
 
def storageManager (name)
 
def filelist (files, prefix=None)
 
def ls (path, longls=False)
 
def cp (src, dest='.')
 
def get_lumi_blocks (root_file)
 
def 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()

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

Definition at line 34 of file DiskUtils.py.

34 def _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()

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

Definition at line 127 of file DiskUtils.py.

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

def python.DiskUtils.deprecated (   message)

Definition at line 13 of file DiskUtils.py.

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

◆ filelist()

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

63 def 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")

◆ get_lumi_blocks()

def python.DiskUtils.get_lumi_blocks (   root_file)

Definition at line 142 of file DiskUtils.py.

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

◆ ls()

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

`longls` specifies long listing format

Definition at line 111 of file DiskUtils.py.

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

def python.DiskUtils.make_lumi_block_map_file (   file_set,
  path 
)

Definition at line 180 of file DiskUtils.py.

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

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

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

vtune_athena.format
format
Definition: vtune_athena.py:14
python.DiskUtils.deprecated
def deprecated(message)
Definition: DiskUtils.py:13
python.MetaReader.read_metadata
def read_metadata(filenames, file_type=None, mode='lite', promote=None, meta_key_filter=None, unique_tag_info_values=True, ignoreNonExistingLocalFiles=False)
Definition: MetaReader.py:68
python.RootUtils.import_root
def import_root(batch=True)
functions --------------------------------------------------------------—
Definition: RootUtils.py:22
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:79
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
python.DiskUtils.cp
def cp(src, dest='.')
Definition: DiskUtils.py:127
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.DiskUtils.get_lumi_blocks
def get_lumi_blocks(root_file)
Definition: DiskUtils.py:142
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.DiskUtils.filelist
def filelist(files, prefix=None)
Definition: DiskUtils.py:63
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.DiskUtils.storageManager
def storageManager(name)
Definition: DiskUtils.py:50
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.DiskUtils._rationalise
def _rationalise(path)
Definition: DiskUtils.py:34
str
Definition: BTagTrackIpAccessor.cxx:11
python.DiskUtils.ls
def ls(path, longls=False)
Definition: DiskUtils.py:111
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.DiskUtils.make_lumi_block_map_file
def make_lumi_block_map_file(file_set, path)
Definition: DiskUtils.py:180