diff --git a/ostap/io/root_file.py b/ostap/io/root_file.py index 814652df..3fdf5c73 100755 --- a/ostap/io/root_file.py +++ b/ostap/io/root_file.py @@ -1137,6 +1137,7 @@ def copy_file ( source , destination , progress = True ) : ## alias copy_root_file = copy_file + # ============================================================================= ## @class RootFiles # Some specialzation of gheneric class Files for ROOT files diff --git a/ostap/trees/data_utils.py b/ostap/trees/data_utils.py index 7c0e39a8..0e0e14f4 100755 --- a/ostap/trees/data_utils.py +++ b/ostap/trees/data_utils.py @@ -62,7 +62,6 @@ # ============================================================================= if not hasattr ( ROOT.TTree , '__len__' ) : ROOT.TTree. __len__ = lambda s : s.GetEntries() - # ============================================================================= ## @class Data @@ -104,28 +103,7 @@ def __init__( self , ## initialize the base class RootFiles.__init__( self , files , description , maxfiles , silent = silent , sorted = sorted , parallel = parallel ) - # ========================================================================= - ## get a common path (prefix) for all files in collection - # - protocols are ignored - @property - def commonpath ( self ) : - """'commonpath': common path (prefix) for all files in collection - - protocols are ignored - """ - from ostap.utils.basic import commonpath - ## - if any ( RootFiles.has_protocol ( f ) for f in self.files ) : - files = [] - for f in self.files : - files .append ( RootFiles.strip_protocol ( f ) ) - else : files = self.files - - if not files : return '' - - cp = commonpath ( files ) - return cp if os.path.isdir ( cp ) else os.path.dirname ( cp ) - # ========================================================================= - + # ========================================================================= @property def validate ( self ) : """'check' : make check for `TTree`/`TChain` structures @@ -237,6 +215,9 @@ def table ( self , title = '' , prefix = '' ) : nn = max ( len ( files ) , len ( bad ) ) nfmt = '%%%dd' % ( math.floor ( math.log10 ( nn ) ) + 1 ) + total_size = 0 + total_entries = 0 + from itertools import chain for i , f in enumerate ( chain ( files , bad ) , start = 1 ) : @@ -253,6 +234,9 @@ def table ( self , title = '' , prefix = '' ) : vv , unit = fsize_unit ( fsize ) row.append ( '%3d %s' % ( vv , unit) ) ## file size + + total_size += fsize + total_entries += entries else : @@ -262,6 +246,16 @@ def table ( self , title = '' , prefix = '' ) : row .append ( f ) rows.append ( row ) + ## summary row + from ostap.logger.colorized import infostr + vv , unit = fsize_unit ( total_size ) + row = '' , \ + infostr ( '%d' % total_entries ) , \ + infostr ( '%3d %s' % ( vv , unit ) ) , \ + infostr ( self.commonpath ) + + rows.append ( row ) + title = title if title else "Data(chain='%s')" % self.chain_name import ostap.logger.table as T return T.table ( rows , title = title , prefix = prefix , alignment = 'rrrw' ) @@ -505,6 +499,10 @@ def table ( self , title = '' , prefix = '' ) : nn = max ( len ( files ) , len ( bad ) ) nfmt = '%%%dd' % ( math.floor ( math.log10 ( nn ) ) + 1 ) + total_entries1 = 0 + total_entries2 = 0 + total_size = 0 + from itertools import chain for i , f in enumerate ( chain ( files , bad ) , start = 1 ) : @@ -526,6 +524,10 @@ def table ( self , title = '' , prefix = '' ) : vv , unit = fsize_unit ( fsize ) row.append ( '%3d %s' % ( vv , unit ) ) ## value + total_size += fsize + total_entries1 += entries1 + total_entries2 += entries2 + else : row.append ( '???' ) ## entries1 @@ -535,6 +537,16 @@ def table ( self , title = '' , prefix = '' ) : row .append ( f ) rows.append ( row ) + ## summary row + from ostap.logger.colorized import infostr + vv , unit = fsize_unit ( total_size ) + row = '' , \ + infostr ( '%d' % total_entries1 ) , \ + infostr ( '%d' % total_entries2 ) , \ + infostr ( '%3d %s' % ( vv , unit ) ) , \ + infostr ( self.commonpath ) + rows.append ( row ) + title = title if title else "Data2(chani1='%s',chani2='%s')" % ( self.chain1_name , self.chain2_name ) import ostap.logger.table as T return T.table ( rows , title = title , prefix = prefix , alignment = 'rrrrw' ) diff --git a/ostap/utils/files.py b/ostap/utils/files.py index bc97c770..3022133a 100644 --- a/ostap/utils/files.py +++ b/ostap/utils/files.py @@ -533,13 +533,15 @@ def table ( self , title = 'Files' , prefix = '' ) : nn = max ( len ( files ) , len ( bad ) ) nfmt = '%%%dd' % ( math.floor ( math.log10 ( nn ) ) + 1 ) - from itertools import chain + from itertools import chain + total_size = 0 for i , f in enumerate ( chain ( files , bad ) , start = 1 ) : row = [ nfmt % i ] fsize = self.get_file_size ( f ) if 0 <= fsize : - vv , unit = fsize_unit ( fsize ) + total_size += fsize + vv , unit = fsize_unit ( fsize ) row.append ( '%3d %s' % ( vv , unit ) ) else : row.append ( '???' ) @@ -547,6 +549,14 @@ def table ( self , title = 'Files' , prefix = '' ) : row .append ( f ) rows.append ( row ) + ## the last row: summary + from ostap.logger.colorized import infostr + vv , unit = fsize_unit ( total_size ) + row = '' , \ + infostr ( '%3d %s' % ( vv , unit ) ) , \ + infostr ( self.commonpath ) + rows.append ( row ) + import ostap.logger.table as T return T.table ( rows , title = title , prefix = prefix , alignment = 'rrw' )