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 isRNTuple (obj)
 
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 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 946 of file PoolFile.py.

946  def __del__(self):
947  if self.poolFile and hasattr(self.poolFile, 'Close'):
948  try:
949  self.poolFile.Close()
950  self.poolFile = None
951  except Exception as err:
952  print("WARNING:",err)
953  pass
954 

◆ _get_total_size()

def python.PoolFile._get_total_size (   branch)
private

Definition at line 308 of file PoolFile.py.

308 def _get_total_size (branch):
309  if PoolOpts.FAST_MODE:
310  return -1.
311  if not PoolOpts.SUPER_DETAILED_BRANCH_SZ:
312  return branch.GetTotalSize()
313  brSize = 0
314  branch.LoadBaskets()
315  for bnum in range(0, branch.GetWriteBasket()):
316  basket = branch.GetBasket(bnum)
317  brSize += basket.GetObjlen() - 8
318  return brSize
319 

◆ _root_open()

def python.PoolFile._root_open (   fname)
private

Definition at line 394 of file PoolFile.py.

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

◆ _save_csv_report()

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

Definition at line 924 of file PoolFile.py.

924  def _save_csv_report(self, fileName):
925  """
926  Save all the gathered informations into a CSV file
927  """
928  import csv, os
929  if os.path.exists (fileName):
930  os.unlink (fileName)
931  args = {'newline' : ''}
932  f = open (fileName, 'w', **args)
933  o = csv.writer (f)
934  o.writerow (['file name', self._fileInfos['name']])
935  o.writerow (['file size', self._fileInfos['size']])
936  o.writerow (['nbr evts', self.dataHeader.nEntries])
937  o.writerow (['mem size', 'disk size', 'mem size nozip', 'items',
938  'container name', 'branch type'])
939 
940  for d in self.data:
941  o.writerow ([d.memSize, d.diskSize, d.memSizeNoZip,
942  d.nEntries, d.name, d.dirType])
943  f.close()
944  return
945 

◆ _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 899 of file PoolFile.py.

899  def _save_shelve_report(self, fileName):
900  """
901  Save all the gathered informations into a python shelve
902  Data can then be read like so:
903  >>> import shelve
904  >>> db = shelve.open( 'myfile.dat', 'r' )
905  >>> report = db['report']
906  >>> print ('fileSize:',report['fileSize'])
907  >>> print ('dataHeader/memSize:',report['dataHeader'].memSize)
908  >>> for d in report['data']:
909  ... print ('data:',d.name,d.nEntries,d.memSize)
910  """
911  import shelve, os
912  if os.path.exists (fileName):
913  os.unlink (fileName)
914  db = shelve.open (fileName)
915  db['report'] = {
916  'fileInfos' : self._fileInfos,
917  'nbrEvts' : self.dataHeader.nEntries,
918  'dataHeader' : self.dataHeader,
919  'data' : self.data
920  }
921  db.close()
922  return
923 

◆ _setup_ssl()

def python.PoolFile._setup_ssl (   root)
private

Definition at line 380 of file PoolFile.py.

380 def _setup_ssl(root):
381  x509_proxy = os.environ.get('X509_USER_PROXY', '')
382  if x509_proxy:
383  # setup proper credentials
384  root.TSSLSocket.SetUpSSL(
385  x509_proxy,
386  "/etc/grid-security/certificates",
387  x509_proxy,
388  x509_proxy)
389  else:
390  print("## warning: protocol https is requested but no X509_USER_PROXY was found! (opening the file might fail.)")
391  pass
392  return
393 

◆ file_name()

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

Definition at line 320 of file PoolFile.py.

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

◆ isRNTuple()

def python.PoolFile.isRNTuple (   obj)

Definition at line 35 of file PoolFile.py.

35 def isRNTuple(obj):
36  # MN: remove the "try" after migration to ROOT 6.34
37  try: from ROOT import RNTuple
38  except(ImportError): from ROOT.Experimental import RNTuple
39  return isinstance( obj, RNTuple )
40 
41 

◆ make_pool_record()

def python.PoolFile.make_pool_record (   branch,
  dirType 
)

Definition at line 440 of file PoolFile.py.

440 def make_pool_record (branch, dirType):
441  memSize = _get_total_size (branch) / Units.kb
442  zipBytes = branch.GetZipBytes()
443  memSizeNoZip = memSize if zipBytes < 0.001 else 0.
444  diskSize = branch.GetZipBytes() / Units.kb
445  typeName = branch.GetClassName()
446  if not typeName and (leaf := branch.GetListOfLeaves().At(0)):
447  typeName = leaf.GetTypeName()
448  return PoolRecord(branch.GetName(), memSize, diskSize, memSizeNoZip,
449  branch.GetEntries(),
450  dirType=dirType,
451  typeName=typeName)
452 

◆ 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 879 of file PoolFile.py.

879  def poolRecord(self, name):
880  """
881  Return a PoolRecord according to its (branch) name
882  Raise KeyError if no match is found
883  """
884  for data in self.data:
885  if data.name == name:
886  return data
887  raise KeyError("No PoolRecord with name [%s]" % name)
888 

◆ retrieveBranchInfos()

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

Definition at line 419 of file PoolFile.py.

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

◆ 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 889 of file PoolFile.py.

889  def saveReport (self, fileName):
890  """
891  Save all the gathered informations into a python shelve or a CSV file
892  (depending on the @param `fileName` extension)
893  """
894  import os
895  if os.path.splitext(fileName)[-1] == '.csv':
896  return self._save_csv_report (fileName)
897  return self._save_shelve_report (fileName)
898 

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 950 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 876 of file PoolFile.py.

python.PoolFile._save_shelve_report
def _save_shelve_report(self, fileName)
Definition: PoolFile.py:899
python.PoolFile.__del__
def __del__(self)
Definition: PoolFile.py:946
python.PoolFile.poolRecord
def poolRecord(self, name)
Definition: PoolFile.py:879
python.PoolFile.saveReport
def saveReport(self, fileName)
Definition: PoolFile.py:889
python.PoolFile.file_name
def file_name(fname)
Definition: PoolFile.py:320
python.PoolFile.retrieveBranchInfos
def retrieveBranchInfos(branch, poolRecord, ident="")
Definition: PoolFile.py:419
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.PoolFile._save_csv_report
def _save_csv_report(self, fileName)
Definition: PoolFile.py:924
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
python.PoolFile.make_pool_record
def make_pool_record(branch, dirType)
Definition: PoolFile.py:440
python.PoolFile._setup_ssl
def _setup_ssl(root)
Definition: PoolFile.py:380
python.PoolFile.isRNTuple
def isRNTuple(obj)
Definition: PoolFile.py:35
python.PoolFile._root_open
def _root_open(fname)
Definition: PoolFile.py:394
python.PoolFile._get_total_size
def _get_total_size(branch)
Definition: PoolFile.py:308