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

Classes

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

Functions

 isRNTuple (obj)
 _get_total_size (branch)
 file_name (fname)
 retrieveBranchInfos (branch, poolRecord, ident="")
 make_pool_record (branch, dirType)
 poolRecord (self, name)
 saveReport (self, fileName)
 _save_shelve_report (self, fileName)
 _save_csv_report (self, fileName)
 __del__ (self)

Variables

str __author__ = "Sebastien Binet <binet@cern.ch>"
list __all__
 — data ---------------------------------------------------------------—
 stdout
 data
 poolFile

Function Documentation

◆ __del__()

python.PoolFile.__del__ ( self)

Definition at line 912 of file PoolFile.py.

912 def __del__(self):
913 if self.poolFile and hasattr(self.poolFile, 'Close'):
914 try:
915 self.poolFile.Close()
916 self.poolFile = None
917 except Exception as err:
918 print("WARNING:",err)
919 pass
920
void print(char *figname, TCanvas *c1)

◆ _get_total_size()

python.PoolFile._get_total_size ( branch)
protected

Definition at line 313 of file PoolFile.py.

313def _get_total_size (branch):
314 if PoolOpts.FAST_MODE:
315 return -1.
316 if not PoolOpts.SUPER_DETAILED_BRANCH_SZ:
317 return branch.GetTotalSize()
318 brSize = 0
319 branch.LoadBaskets()
320 for bnum in range(0, branch.GetWriteBasket()):
321 basket = branch.GetBasket(bnum)
322 brSize += basket.GetObjlen() - 8
323 return brSize
324

◆ _save_csv_report()

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

Definition at line 890 of file PoolFile.py.

890 def _save_csv_report(self, fileName):
891 """
892 Save all the gathered informations into a CSV file
893 """
894 import csv, os
895 if os.path.exists (fileName):
896 os.unlink (fileName)
897 args = {'newline' : ''}
898 f = open (fileName, 'w', **args)
899 o = csv.writer (f)
900 o.writerow (['file name', self._fileInfos['name']])
901 o.writerow (['file size', self._fileInfos['size']])
902 o.writerow (['nbr evts', self.dataHeader.nEntries])
903 o.writerow (['mem size', 'disk size', 'mem size nozip', 'items',
904 'container name', 'branch type'])
905
906 for d in self.data:
907 o.writerow ([d.memSize, d.diskSize, d.memSizeNoZip,
908 d.nEntries, d.name, d.dirType])
909 f.close()
910 return
911

◆ _save_shelve_report()

python.PoolFile._save_shelve_report ( self,
fileName )
protected
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 865 of file PoolFile.py.

865 def _save_shelve_report(self, fileName):
866 """
867 Save all the gathered informations into a python shelve
868 Data can then be read like so:
869 >>> import shelve
870 >>> db = shelve.open( 'myfile.dat', 'r' )
871 >>> report = db['report']
872 >>> print ('fileSize:',report['fileSize'])
873 >>> print ('dataHeader/memSize:',report['dataHeader'].memSize)
874 >>> for d in report['data']:
875 ... print ('data:',d.name,d.nEntries,d.memSize)
876 """
877 import shelve, os
878 if os.path.exists (fileName):
879 os.unlink (fileName)
880 db = shelve.open (fileName)
881 db['report'] = {
882 'fileInfos' : self._fileInfos,
883 'nbrEvts' : self.dataHeader.nEntries,
884 'dataHeader' : self.dataHeader,
885 'data' : self.data
886 }
887 db.close()
888 return
889

◆ file_name()

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

Definition at line 325 of file PoolFile.py.

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

◆ isRNTuple()

python.PoolFile.isRNTuple ( obj)

Definition at line 35 of file PoolFile.py.

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

python.PoolFile.make_pool_record ( branch,
dirType )

Definition at line 406 of file PoolFile.py.

406def make_pool_record (branch, dirType):
407 memSize = _get_total_size (branch) / Units.kb
408 zipBytes = branch.GetZipBytes()
409 memSizeNoZip = memSize if zipBytes < 0.001 else 0.
410 diskSize = branch.GetZipBytes() / Units.kb
411 typeName = branch.GetClassName()
412 if not typeName and (leaf := branch.GetListOfLeaves().At(0)):
413 typeName = leaf.GetTypeName()
414 return PoolRecord(branch.GetName(), memSize, diskSize, memSizeNoZip,
415 branch.GetEntries(),
416 dirType=dirType,
417 typeName=typeName)
418

◆ poolRecord()

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

Definition at line 845 of file PoolFile.py.

845 def poolRecord(self, name):
846 """
847 Return a PoolRecord according to its (branch) name
848 Raise KeyError if no match is found
849 """
850 for data in self.data:
851 if data.name == name:
852 return data
853 raise KeyError("No PoolRecord with name [%s]" % name)
854

◆ retrieveBranchInfos()

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

Definition at line 385 of file PoolFile.py.

385def retrieveBranchInfos( branch, poolRecord, ident = "" ):
386 fmt = "%s %3i %8.3f %8.3f %8.3f %s"
387 if 0:
388 out = fmt % ( ident,
389 branch.GetListOfBranches().GetSize(),
390 _get_total_size (branch),
391 branch.GetTotBytes(),
392 branch.GetZipBytes(),
393 branch.GetName() )
394 print(out)
395
396 branches = branch.GetListOfBranches()
397 for b in branches:
398 poolRecord.memSize += _get_total_size (b) / Units.kb
399 if (b.GetZipBytes() < 0.001):
400 poolRecord.memSizeNoZip += _get_total_size (b) / Units.kb
401 poolRecord.diskSize += b.GetZipBytes() / Units.kb
402 poolRecord = retrieveBranchInfos ( b, poolRecord, ident+" " )
403
404 return poolRecord
405

◆ saveReport()

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

855 def saveReport (self, fileName):
856 """
857 Save all the gathered informations into a python shelve or a CSV file
858 (depending on the @param `fileName` extension)
859 """
860 import os
861 if os.path.splitext(fileName)[-1] == '.csv':
862 return self._save_csv_report (fileName)
863 return self._save_shelve_report (fileName)
864

Variable Documentation

◆ __all__

list python.PoolFile.__all__
private
Initial value:
1= [
2 'PoolFileCatalog',
3 'PoolOpts',
4 'isRNTuple',
5 'PoolRecord',
6 'PoolFile',
7 'DiffFiles',
8 ]

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

Definition at line 11 of file PoolFile.py.

◆ __author__

str python.PoolFile.__author__ = "Sebastien Binet <binet@cern.ch>"
private

Definition at line 8 of file PoolFile.py.

◆ data

python.PoolFile.data

Definition at line 850 of file PoolFile.py.

◆ poolFile

python.PoolFile.poolFile

Definition at line 913 of file PoolFile.py.

◆ stdout

python.PoolFile.stdout

Definition at line 842 of file PoolFile.py.