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 35 of file DiskUtils.py.

35 def _rationalise(path):
36  """
37  Rationalise a path, removing prefix and esuring single leading slash
38  """
39  for p in ('root://castoratlas/', 'root://eosatlas.cern.ch/', 'rfio:', 'castor:'):
40  if path.startswith(p):
41  path = path[len(p):]
42  if path.startswith('//'):
43  path = path[1:]
44  if not path.startswith('/'):
45  path = '/'+path
46  break
47 
48  return path
49 
50 @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 128 of file DiskUtils.py.

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

◆ deprecated()

def python.DiskUtils.deprecated (   message)

Definition at line 14 of file DiskUtils.py.

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

◆ 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 64 of file DiskUtils.py.

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

143 def get_lumi_blocks(root_file):
144 
145  try:
146  from PyUtils.RootUtils import import_root
147  root = import_root()
148  f = root.TFile.Open(root_file, 'READ')
149 
150  meta = f.Get( 'MetaData' )
151  if not meta:
152  raise Exception('No metadata')
153 
154  meta.GetEntry( 0 )
155 
156  esiName= 'Stream'
157  esiTypeName = 'EventStreamInfo'
158  for l in meta.GetListOfLeaves():
159  if l.GetTypeName().startswith(esiTypeName):
160  esiTypeName = l.GetTypeName()
161  esiName = l.GetName()
162  break
163 
164  if esiTypeName != 'EventStreamInfo_p3':
165  raise Exception("old schema is not supported:", esiTypeName)
166 
167  import cppyy
168 
169  esic = cppyy.gbl.EventStreamInfoPTCnv_p3()
170  esi = getattr (meta, esiName)
171  if esiName.startswith(esiTypeName):
172  esiName = esiName[len(esiTypeName)+1:]
173 
174  return( list(esic.lumiBlockNumbers(esi)) )
175 
176  except Exception as e:
177  print( "Failed to read MetaData will fall back to looping ", repr(e))
178  finally:
179  f.Close()
180 
181  try:
182  from PyUtils.RootUtils import import_root
183  root = import_root()
184  f = root.TFile.Open(root_file, 'READ')
185  lumiblocks = set()
186  metadata= f.Get('CollectionMetadata') if f else None
187  if metadata:
188  metadata.GetEntry(0)
189  import ctypes
190  key_name = str(ctypes.c_char_p(metadata.Key).value)
191  assert key_name == 'POOLCollectionID'
192  del metadata
193  coll_tree = f.Get('POOLCollectionTree') if f else None
194  if coll_tree:
195  evtmax = coll_tree.GetEntries()
196  if evtmax in (-1, None):
197  evtmax = 0
198  evtmax = int(evtmax)
199  for row in range(evtmax):
200  if coll_tree.GetEntry(row) < 0:
201  break
202  lbn = coll_tree.LumiBlockN
203  lumiblocks.add(lbn)
204  del coll_tree
205  return list( lumiblocks )
206  finally:
207  f.Close()
208 

◆ ls()

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

`longls` specifies long listing format

Definition at line 112 of file DiskUtils.py.

112 def ls(path, longls=False):
113  """
114  Simple list of files
115 
116  `longls` specifies long listing format
117  """
118 
119  path = _rationalise(path)
120  mgr = storageManager(path)
121 
122  if longls:
123  return subprocess.check_output(mgr.longls % path, shell=True)
124  else:
125  return subprocess.check_output(mgr.ls % path, shell=True)
126 
127 @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 209 of file DiskUtils.py.

209 def make_lumi_block_map_file(file_set, path):
210  with open(path, 'w') as mapfile:
211  for f, lbs in file_set.with_lumi_blocks():
212  print('Reading:', f)
213  mapfile.write('{} {}\n'.format(
214  os.path.basename(f),
215  ','.join(str(x) for x in lbs)))
216 
217 

◆ storageManager()

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

Definition at line 51 of file DiskUtils.py.

51 def storageManager(name):
52  """
53  Return SotrageManager to deal with listing, copying and reading files from various storage systems
54  """
55  name = _rationalise(name)
56  if name.startswith('/castor/'):
57  return CastorMgr
58  elif name.startswith('/eos/'):
59  return EOSMgr
60  else:
61  return UnixMgr
62 
63 @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 30 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 32 of file DiskUtils.py.

◆ RFIOMgr

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

Definition at line 31 of file DiskUtils.py.

◆ StorageManager

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

Definition at line 29 of file DiskUtils.py.

◆ UnixMgr

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

Definition at line 33 of file DiskUtils.py.

vtune_athena.format
format
Definition: vtune_athena.py:14
python.DiskUtils.deprecated
def deprecated(message)
Definition: DiskUtils.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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:65
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
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:128
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.DiskUtils.get_lumi_blocks
def get_lumi_blocks(root_file)
Definition: DiskUtils.py:143
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:224
python.DiskUtils.filelist
def filelist(files, prefix=None)
Definition: DiskUtils.py:64
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:51
Trk::open
@ open
Definition: BinningType.h:40
python.DiskUtils._rationalise
def _rationalise(path)
Definition: DiskUtils.py:35
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
str
Definition: BTagTrackIpAccessor.cxx:11
python.DiskUtils.ls
def ls(path, longls=False)
Definition: DiskUtils.py:112
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:209