Skip to content

Commit

Permalink
more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Apr 19, 2024
1 parent 8b550b8 commit c2778f1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
1 change: 1 addition & 0 deletions ostap/io/root_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 35 additions & 23 deletions ostap/trees/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
# =============================================================================
if not hasattr ( ROOT.TTree , '__len__' ) :
ROOT.TTree. __len__ = lambda s : s.GetEntries()


# =============================================================================
## @class Data
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) :

Expand All @@ -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 :

Expand All @@ -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' )
Expand Down Expand Up @@ -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 ) :

Expand All @@ -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
Expand All @@ -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' )
Expand Down
14 changes: 12 additions & 2 deletions ostap/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,30 @@ 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 ( '???' )

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

Expand Down

0 comments on commit c2778f1

Please sign in to comment.