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 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
void print(char *figname, TCanvas *c1)

◆ _get_total_size()

python.PoolFile._get_total_size ( branch)
protected

Definition at line 308 of file PoolFile.py.

308def _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()

python.PoolFile._root_open ( fname)
protected

Definition at line 394 of file PoolFile.py.

394def _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()

python.PoolFile._save_csv_report ( self,
fileName )
protected
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()

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

python.PoolFile._setup_ssl ( root)
protected

Definition at line 380 of file PoolFile.py.

380def _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()

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

Definition at line 320 of file PoolFile.py.

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

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

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

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

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

Definition at line 419 of file PoolFile.py.

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

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__

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

◆ poolFile

python.PoolFile.poolFile

Definition at line 947 of file PoolFile.py.

◆ stdout

python.PoolFile.stdout

Definition at line 876 of file PoolFile.py.