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

Classes

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

Functions

 isRNTuple (obj)
 _get_total_size (branch)
 file_name (fname)
 _setup_ssl (root)
 _root_open (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 951 of file PoolFile.py.

951 def __del__(self):
952 if self.poolFile and hasattr(self.poolFile, 'Close'):
953 try:
954 self.poolFile.Close()
955 self.poolFile = None
956 except Exception as err:
957 print("WARNING:",err)
958 pass
959
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

◆ _root_open()

python.PoolFile._root_open ( fname)
protected

Definition at line 399 of file PoolFile.py.

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

◆ _save_csv_report()

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

Definition at line 929 of file PoolFile.py.

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

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

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

◆ _setup_ssl()

python.PoolFile._setup_ssl ( root)
protected

Definition at line 385 of file PoolFile.py.

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

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

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

◆ poolRecord()

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

Definition at line 884 of file PoolFile.py.

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

◆ retrieveBranchInfos()

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

Definition at line 424 of file PoolFile.py.

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

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

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

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

◆ poolFile

python.PoolFile.poolFile

Definition at line 952 of file PoolFile.py.

◆ stdout

python.PoolFile.stdout

Definition at line 881 of file PoolFile.py.