1+ # Author: Silia Taider CERN 03/2025
2+
3+ ################################################################################
4+ # Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. #
5+ # All rights reserved. #
6+ # #
7+ # For the licensing terms see $ROOTSYS/LICENSE. #
8+ # For the list of contributors see $ROOTSYS/README/CREDITS. #
9+ ################################################################################
10+ from __future__ import annotations
11+
12+ import types
13+ from typing import Any , Callable
14+
15+ from .indexing import _getitem , _iter , _setitem
16+ from .plotting import _axes , _counts , _kind , _values_by_copy , _values_default , _variances
17+ from .tags import _loc , _overflow , _rebin , _sum , _underflow
18+
19+ """
20+ Implementation of the module level helper functions for the UHI
21+ """
22+
23+
24+ def _add_module_level_uhi_helpers (module : types .ModuleType ) -> None :
25+ module .underflow = _underflow
26+ module .overflow = _overflow
27+ module .loc = _loc
28+ module .rebin = _rebin
29+ module .sum = _sum
30+
31+
32+ """
33+ Implementation of the indexing component of the UHI
34+ """
35+
36+
37+ def _add_indexing_features (klass : Any ) -> None :
38+ klass .__getitem__ = _getitem
39+ klass .__setitem__ = _setitem
40+ klass .__iter__ = _iter
41+
42+
43+ """
44+ Implementation of the plotting component of the UHI
45+ """
46+
47+
48+ values_func_dict : dict [str , Callable ] = {
49+ "TH1C" : _values_by_copy ,
50+ "TH2C" : _values_by_copy ,
51+ "TH3C" : _values_by_copy ,
52+ "TH2K" : _values_by_copy ,
53+ "TH3K" : _values_by_copy ,
54+ "TProfile" : _values_by_copy ,
55+ "TProfile2D" : _values_by_copy ,
56+ "TProfile2Poly" : _values_by_copy ,
57+ "TProfile3D" : _values_by_copy ,
58+ }
59+
60+
61+ def _add_plotting_features (klass : Any ) -> None :
62+ klass .kind = property (_kind )
63+ klass .variances = _variances
64+ klass .counts = _counts
65+ klass .axes = property (_axes )
66+ klass .values = values_func_dict .get (klass .__name__ , _values_default )
67+
68+
69+ """
70+ Implementation of the serialization component of the UHI
71+ """
72+
73+ def _TH1_Constructor (self , * args , ** kwargs ):
74+ """
75+ If UHI IR is detected, use the UHI deserialization constructor
76+ else forward to the original
77+ """
78+ if len (args ) == 1 and isinstance (args [0 ], dict ):
79+ from .serialization import _from_uhi_
80+
81+ _from_uhi_ (self , args [0 ])
82+ else :
83+ self ._original_init_ (* args , ** kwargs )
84+
85+ def _add_serialization_features (klass : Any ) -> None :
86+ from .serialization import _to_uhi_
87+
88+ klass ._to_uhi_ = _to_uhi_
89+
90+ klass ._original_init_ = klass .__init__
91+ klass .__init__ = _TH1_Constructor
0 commit comments