Skip to content

Commit

Permalink
1. explicitely delete all created styles, see [here](root-project/ro…
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Nov 13, 2024
1 parent 8a8704f commit 8b28f34
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PA

message ( "----> C-compiler : " $ENV{CC} )
message ( "----> C++-compiler : " $ENV{CXX} )
message ( "----> C-compiler ID : " ${CMAKE_CXX_COMPILER_ID} )
message ( "----> C++-compiler ID : " ${CMAKE_CXX_COMPILER_ID} )

# You need to tell CMake where to find the ROOT installation. This can be done in a number of ways:
# - ROOT built with classic configure/make use the provided $ROOTSYS/etc/cmake/FindROOT.cmake
Expand Down
3 changes: 2 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
1. add `isfinite` method for `(W)Covariance` objects
1. add `Ostap::MoreRooFit::Hypot` and `var_hypot`
1. add Fizher's Z-distribution

1. explicitely delete all created styles, see [here](https://github.com/root-project/root/issues/16918)

## Backward incompatible

## Bug fixes
Expand Down
52 changes: 37 additions & 15 deletions ostap/plotting/makestyles.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@
## @class StyleStore
# Store for all created/configured styles
class StyleStore(object) :
"""Store for all created/cofigures styles
""" Store for all created/cofigures styles
"""
__styles = {}
__styles = {}
__own_styles = {}
@classprop
def styles ( kls ) :
def styles ( kls ) :
return kls.__styles
@classprop
def own_styles ( kls ) :
return kls.__own_styles

# =============================================================================
## get the ROOT style by name
Expand All @@ -148,7 +152,7 @@ def root_style ( name ) :
# getters, setters, special = style_methods()
# @endcode
def style_methods () :
"""Get the essential methods of class ROOT.TStyle
""" Get the essential methods of class ROOT.TStyle
>>> getters, setters, special = style_methods()
"""
# The style getters
Expand Down Expand Up @@ -231,7 +235,7 @@ def style_methods () :
# conf = style.get () ## ditto
# @endcode
def dump_style ( style ) :
"""Dump the style to the dictionary
""" Dump the style to the dictionary
>>> style = ...
>>> conf = dump_style ( style )
>>> conf = style.dump () ## ditto
Expand Down Expand Up @@ -280,7 +284,7 @@ def dump_style ( style ) :
# =============================================================================
## Dump the style as a table
def table_style ( style , prefix = '' , title = '' ) :
"""Dump the style as a table"""
""" Dump the style as a table"""

conf = dump_style ( style )

Expand All @@ -302,7 +306,7 @@ def table_style ( style , prefix = '' , title = '' ) :

ROOT.TStyle.table = table_style
# =============================================================================
## extr aattribvutes
## extra attributes
extra = 'NumberOfColors' , 'showeditor', 'showeventstatus', 'showtoolbar', 'basestyle', 'ostaplike'
# =============================================================================
## Set the style from the configuration dictionary
Expand All @@ -313,7 +317,7 @@ def table_style ( style , prefix = '' , title = '' ) :
# style.set ( config ) ## ditto
# @endcode
def set_style ( style , config , base_style = '' , **kwargs ) :
"""Set the style from the configurtaion dictionary
""" Set the style from the configurtaion dictionary
>>> config = ...
>>> style = ...
>>> set_style ( style , config )
Expand Down Expand Up @@ -590,7 +594,7 @@ def set_style ( style , config , base_style = '' , **kwargs ) :
## Parse the configuration and create
# all the styles according to configuration
def make_styles ( config = None ) :
"""Parse the configuration and create
""" Parse the configuration and create
all the styles according to configuration
"""

Expand All @@ -617,7 +621,7 @@ def make_styles ( config = None ) :
if not style :
logger.debug ( 'Create new generic style %s/%s' % ( name , description ) )
style = ROOT.TStyle ( name , description )

StyleStore.own_styles.update ( { name : style } )
set_style ( style , section )

if name in StyleStore.styles :
Expand All @@ -629,8 +633,7 @@ def make_styles ( config = None ) :
if nname in StyleStore.styles :
logger.info ( "The configuration %s replaced" % nname )
StyleStore.styles.update ( { nname : style } )



# ==============================================================================
def get_float ( config , name , default ) :
try :
Expand Down Expand Up @@ -680,7 +683,8 @@ def make_ostap_style ( name ,
description = 'The Style' ,
config = {} ,
base_style = '' , **kwargs ) :

""" Make ostap-like style
"""

kw = cidict ( transform = cidict_fun )
kw.update ( kwargs )
Expand Down Expand Up @@ -935,18 +939,36 @@ def make_ostap_style ( name ,

## create the style
style = root_style ( name )

if not style :
logger.debug ( "Create new Ostap style `%s'" % name )
style = ROOT.TStyle ( name , description )
StyleStore.own_styles.update ( { name : style } )
print ( 'CREATE NEW OSTAP STYLE', name )

StyleStore.styles.update ( { name : style } )
set_style ( style , conf , base_style = base_style )

return style

# =============================================================================
## read the configuration files and create the styles
make_styles ()




import atexit
@atexit.register
def styles_clean () :
""" The styles need to be deleted
- see https://github.com/root-project/root/issues/16918
"""
while StyleStore.styles :
_ , _ = StyleStore.styles.popitem ()
while StyleStore.own_styles :
_ , st = StyleStore.own_styles.popitem ()
del st

# =============================================================================
_decorated_classes_ = (
ROOT.TStyle ,
Expand Down
24 changes: 22 additions & 2 deletions ostap/plotting/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# @file ostap/plotting/style.py
# Ostap style file for ROOT-plots
# =============================================================================
"""Ostap Style for ROOT-plots"""
""" Ostap Style for ROOT-plots"""
# =============================================================================
__all__ = (
'UseStyle' , ## context manager for the style (class)
Expand Down Expand Up @@ -55,7 +55,7 @@ def OstapStyle ( name ,
force = True ,
scale = 1.0 ,
colz = False ) :
"""Create Ostap-style for the plots
""" Create Ostap-style for the plots
"""

# ================================================================
Expand Down Expand Up @@ -255,6 +255,26 @@ def useStyle ( style = None , **config ) :
"""
return UseStyle ( style , **config )


import atexit
@atexit.register
def styles_delete () :
""" The styles need to be deleted
- see https://github.com/root-project/root/issues/16918
"""
global Style1Z, Style2Z, Style3Z
global Style1 , Style2 , Style3
global Style , StyleZ , ostapStyle

del Style1Z
del Style2Z
del Style3Z
del Style1
del Style2
del Style3
del StyleZ
del Style
del ostapStyle

# =============================================================================
if '__main__' == __name__ :
Expand Down

0 comments on commit 8b28f34

Please sign in to comment.