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

Classes

class  Counter
 
class  DiffFiles
 
class  PoolFile
 
class  PoolFileCatalog
 
class  PoolOpts
 
class  PoolRecord
 
class  Units
 — data ---------------------------------------------------------------— More...
 

Functions

def _get_total_size (branch)
 
def file_name (fname)
 
def _setup_ssl (root)
 
def _root_open (fname)
 
def retrieveBranchInfos (branch, poolRecord, ident="")
 
def make_pool_record (branch, dirType)
 
def extract_items (pool_file, verbose=True, items_type='eventdata')
 
def poolRecord (self, name)
 
def saveReport (self, fileName)
 
def _save_shelve_report (self, fileName)
 
def _save_csv_report (self, fileName)
 
def __del__ (self)
 

Variables

 __author__
 
 __all__
 — data ---------------------------------------------------------------— More...
 
 stdout
 out.write( "#### Map ####" + os.linesep ) out.flush() self.poolFile.Map() out.write( "#" * 80 + os.linesep ) More...
 
 poolFile
 

Function Documentation

◆ __del__()

def python.PoolFile.__del__ (   self)

Definition at line 964 of file PoolFile.py.

964  def __del__(self):
965  if self.poolFile and hasattr(self.poolFile, 'Close'):
966  try:
967  self.poolFile.Close()
968  self.poolFile = None
969  except Exception as err:
970  print("WARNING:",err)
971  pass
972 

◆ _get_total_size()

def python.PoolFile._get_total_size (   branch)
private

Definition at line 301 of file PoolFile.py.

301 def _get_total_size (branch):
302  if PoolOpts.FAST_MODE:
303  return -1.
304  if not PoolOpts.SUPER_DETAILED_BRANCH_SZ:
305  return branch.GetTotalSize()
306  brSize = 0
307  branch.LoadBaskets()
308  for bnum in range(0, branch.GetWriteBasket()):
309  basket = branch.GetBasket(bnum)
310  brSize += basket.GetObjlen() - 8
311  return brSize
312 

◆ _root_open()

def python.PoolFile._root_open (   fname)
private

Definition at line 387 of file PoolFile.py.

387 def _root_open(fname):
388  import PyUtils.RootUtils as ru
389  root = ru.import_root()
390  import re
391 
392  with ShutUp(filters=[
393  re.compile('TClass::TClass:0: RuntimeWarning: no dictionary for class.*') ]):
394  root.gSystem.Load('libRootCollection')
395  root_open = root.TFile.Open
396 
397  # we need to get back the protocol b/c of the special
398  # case of secure-http which needs to open TFiles as TWebFiles...
399  protocol, _ = file_name(fname)
400  if protocol == 'https':
401  _setup_ssl(root)
402  root_open = root.TWebFile.Open
403 
404  f = root_open(fname, 'READ')
405  if f is None or not f:
406  import errno
407  raise IOError(errno.ENOENT,
408  'No such file or directory',fname)
409  return f
410  return
411 

◆ _save_csv_report()

def python.PoolFile._save_csv_report (   self,
  fileName 
)
private
Save all the gathered informations into a CSV file

Definition at line 942 of file PoolFile.py.

942  def _save_csv_report(self, fileName):
943  """
944  Save all the gathered informations into a CSV file
945  """
946  import csv, os
947  if os.path.exists (fileName):
948  os.unlink (fileName)
949  args = {'newline' : ''}
950  f = open (fileName, 'w', **args)
951  o = csv.writer (f)
952  o.writerow (['file name', self._fileInfos['name']])
953  o.writerow (['file size', self._fileInfos['size']])
954  o.writerow (['nbr evts', self.dataHeader.nEntries])
955  o.writerow (['mem size', 'disk size', 'mem size nozip', 'items',
956  'container name', 'branch type'])
957 
958  for d in self.data:
959  o.writerow ([d.memSize, d.diskSize, d.memSizeNoZip,
960  d.nEntries, d.name, d.dirType])
961  f.close()
962  return
963 

◆ _save_shelve_report()

def python.PoolFile._save_shelve_report (   self,
  fileName 
)
private
Save all the gathered informations into a python shelve
Data can then be read like so:
 >>> import shelve
 >>> db = shelve.open( 'myfile.dat', 'r' )
 >>> report = db['report']
 >>> print ('fileSize:',report['fileSize'])
 >>> print ('dataHeader/memSize:',report['dataHeader'].memSize)
 >>> for d in report['data']:
 ...   print ('data:',d.name,d.nEntries,d.memSize)

Definition at line 917 of file PoolFile.py.

917  def _save_shelve_report(self, fileName):
918  """
919  Save all the gathered informations into a python shelve
920  Data can then be read like so:
921  >>> import shelve
922  >>> db = shelve.open( 'myfile.dat', 'r' )
923  >>> report = db['report']
924  >>> print ('fileSize:',report['fileSize'])
925  >>> print ('dataHeader/memSize:',report['dataHeader'].memSize)
926  >>> for d in report['data']:
927  ... print ('data:',d.name,d.nEntries,d.memSize)
928  """
929  import shelve, os
930  if os.path.exists (fileName):
931  os.unlink (fileName)
932  db = shelve.open (fileName)
933  db['report'] = {
934  'fileInfos' : self._fileInfos,
935  'nbrEvts' : self.dataHeader.nEntries,
936  'dataHeader' : self.dataHeader,
937  'data' : self.data
938  }
939  db.close()
940  return
941 

◆ _setup_ssl()

def python.PoolFile._setup_ssl (   root)
private

Definition at line 373 of file PoolFile.py.

373 def _setup_ssl(root):
374  x509_proxy = os.environ.get('X509_USER_PROXY', '')
375  if x509_proxy:
376  # setup proper credentials
377  root.TSSLSocket.SetUpSSL(
378  x509_proxy,
379  "/etc/grid-security/certificates",
380  x509_proxy,
381  x509_proxy)
382  else:
383  print("## warning: protocol https is requested but no X509_USER_PROXY was found! (opening the file might fail.)")
384  pass
385  return
386 

◆ extract_items()

def python.PoolFile.extract_items (   pool_file,
  verbose = True,
  items_type = 'eventdata' 
)
Helper function to read a POOL file and extract the item-list from the
DataHeader content.
@params
  `pool_file`  the name of the pool file to inspect
  `verbose`    self-explanatory
  `items_type` what kind of items one is interested in
               allowed values: 'eventdata' 'metadata'
Note: this function is actually executed in a forked sub-process
      if `fork` is True

Definition at line 446 of file PoolFile.py.

446 def extract_items(pool_file, verbose=True, items_type='eventdata'):
447  """Helper function to read a POOL file and extract the item-list from the
448  DataHeader content.
449  @params
450  `pool_file` the name of the pool file to inspect
451  `verbose` self-explanatory
452  `items_type` what kind of items one is interested in
453  allowed values: 'eventdata' 'metadata'
454  Note: this function is actually executed in a forked sub-process
455  if `fork` is True
456  """
457  _allowed_values = ('eventdata',
458  'metadata',)
459  if items_type not in _allowed_values:
460  err = "".join([
461  "invalid argument for 'items_type'. ",
462  "got: [%s] " % items_type,
463  "(allowed values: %r)" % _allowed_values
464  ])
465  raise ValueError(err)
466 
467  key = '%s_items' % items_type
468  f_root = _root_open(pool_file)
469  import PyUtils.FilePeekerTool as fpt
470  fp = fpt.FilePeekerTool(f_root)
471  items = fp.getPeekedData(key)
472 
473  if items is None:
474  items = []
475  return items
476 

◆ file_name()

def python.PoolFile.file_name (   fname)
take a file name, return the pair (protocol, 'real' file name)

Definition at line 313 of file PoolFile.py.

313 def file_name(fname):
314  """take a file name, return the pair (protocol, 'real' file name)
315  """
316  fname = os.path.expanduser(os.path.expandvars(fname))
317 
318  def _normalize_uri(uri):
319  if uri.startswith('/'):
320  return 'file:'+uri
321  return uri
322 
323  from urllib.parse import urlsplit
324  url = urlsplit(_normalize_uri(fname))
325  protocol = url.scheme
326  def _normalize(fname):
327  from posixpath import normpath
328  fname = normpath(fname)
329  if fname.startswith('//'): fname = fname[1:]
330  return fname
331 
332  if protocol in ('', 'file', 'pfn'):
333  protocol = ''
334  fname = _normalize(url.path)
335 
336 
337  if fname.startswith('/castor/'):
338  protocol = 'rfio'
339  fname = protocol + ':' + fname
340 
341  elif protocol in ('rfio', 'castor'):
342  protocol = 'rfio'
343  fname = _normalize(url.path)
344  fname = protocol+':'+fname
345 
346  elif protocol in ('root','dcap', 'dcache', 'http', 'https', 'dav', 'davs'):
347  pass
348 
349  elif protocol in ('gsidcap',):
350  protocol = 'gfal:gsidcap'
351  pass
352 
353  elif protocol in ('lfn','fid',):
354  # percolate through the PoolFileCatalog
355  from PyUtils.PoolFile import PoolFileCatalog as pfc
356  fname = pfc().pfn(protocol+':'+url.path)
357  pass
358 
359  elif protocol in ('ami',):
360  # !! keep order of tokens !
361  for token in ('ami:', '//', '/'):
362  if fname.startswith(token):
363  fname = fname[len(token):]
364  fname = 'ami://' + fname
365  pass
366 
367  else:
368  print(f'## warning: unknown protocol [{protocol}]. we will just return our input')
369  pass
370 
371  return (protocol, fname)
372 

◆ make_pool_record()

def python.PoolFile.make_pool_record (   branch,
  dirType 
)

Definition at line 433 of file PoolFile.py.

433 def make_pool_record (branch, dirType):
434  memSize = _get_total_size (branch) / Units.kb
435  zipBytes = branch.GetZipBytes()
436  memSizeNoZip = memSize if zipBytes < 0.001 else 0.
437  diskSize = branch.GetZipBytes() / Units.kb
438  typeName = branch.GetClassName()
439  if not typeName and (leaf := branch.GetListOfLeaves().At(0)):
440  typeName = leaf.GetTypeName()
441  return PoolRecord(branch.GetName(), memSize, diskSize, memSizeNoZip,
442  branch.GetEntries(),
443  dirType=dirType,
444  typeName=typeName)
445 

◆ poolRecord()

def python.PoolFile.poolRecord (   self,
  name 
)
Return a PoolRecord according to its (branch) name
Raise KeyError if no match is found

Definition at line 897 of file PoolFile.py.

897  def poolRecord(self, name):
898  """
899  Return a PoolRecord according to its (branch) name
900  Raise KeyError if no match is found
901  """
902  for data in self.data:
903  if data.name == name:
904  return data
905  raise KeyError("No PoolRecord with name [%s]" % name)
906 

◆ retrieveBranchInfos()

def python.PoolFile.retrieveBranchInfos (   branch,
  poolRecord,
  ident = "" 
)

Definition at line 412 of file PoolFile.py.

412 def retrieveBranchInfos( branch, poolRecord, ident = "" ):
413  fmt = "%s %3i %8.3f %8.3f %8.3f %s"
414  if 0:
415  out = fmt % ( ident,
416  branch.GetListOfBranches().GetSize(),
417  _get_total_size (branch),
418  branch.GetTotBytes(),
419  branch.GetZipBytes(),
420  branch.GetName() )
421  print(out)
422 
423  branches = branch.GetListOfBranches()
424  for b in branches:
425  poolRecord.memSize += _get_total_size (b) / Units.kb
426  if (b.GetZipBytes() < 0.001):
427  poolRecord.memSizeNoZip += _get_total_size (b) / Units.kb
428  poolRecord.diskSize += b.GetZipBytes() / Units.kb
429  poolRecord = retrieveBranchInfos ( b, poolRecord, ident+" " )
430 
431  return poolRecord
432 

◆ saveReport()

def python.PoolFile.saveReport (   self,
  fileName 
)
Save all the gathered informations into a python shelve or a CSV file
(depending on the @param `fileName` extension)

Definition at line 907 of file PoolFile.py.

907  def saveReport (self, fileName):
908  """
909  Save all the gathered informations into a python shelve or a CSV file
910  (depending on the @param `fileName` extension)
911  """
912  import os
913  if os.path.splitext(fileName)[-1] == '.csv':
914  return self._save_csv_report (fileName)
915  return self._save_shelve_report (fileName)
916 

Variable Documentation

◆ __all__

python.PoolFile.__all__
private

— data ---------------------------------------------------------------—

Definition at line 11 of file PoolFile.py.

◆ __author__

python.PoolFile.__author__
private

Definition at line 8 of file PoolFile.py.

◆ poolFile

python.PoolFile.poolFile

Definition at line 968 of file PoolFile.py.

◆ stdout

python.PoolFile.stdout

out.write( "#### Map ####" + os.linesep ) out.flush() self.poolFile.Map() out.write( "#" * 80 + os.linesep )

Definition at line 894 of file PoolFile.py.

python.PoolFile._save_shelve_report
def _save_shelve_report(self, fileName)
Definition: PoolFile.py:917
python.PoolFile.__del__
def __del__(self)
Definition: PoolFile.py:964
python.PoolFile.poolRecord
def poolRecord(self, name)
Definition: PoolFile.py:897
python.PoolFile.saveReport
def saveReport(self, fileName)
Definition: PoolFile.py:907
python.PoolFile.file_name
def file_name(fname)
Definition: PoolFile.py:313
python.PoolFile.retrieveBranchInfos
def retrieveBranchInfos(branch, poolRecord, ident="")
Definition: PoolFile.py:412
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.PoolFile._save_csv_report
def _save_csv_report(self, fileName)
Definition: PoolFile.py:942
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.PoolFile.make_pool_record
def make_pool_record(branch, dirType)
Definition: PoolFile.py:433
python.PoolFile._setup_ssl
def _setup_ssl(root)
Definition: PoolFile.py:373
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.PoolFile._root_open
def _root_open(fname)
Definition: PoolFile.py:387
python.PoolFile.extract_items
def extract_items(pool_file, verbose=True, items_type='eventdata')
Definition: PoolFile.py:446
python.PoolFile._get_total_size
def _get_total_size(branch)
Definition: PoolFile.py:301