@@ -28,16 +28,18 @@ class LazyUncertainty(LazyUniqueObject):
28
28
class_name : NonEmptyStrictStr = Field (default = "Uncertainty" , frozen = True )
29
29
30
30
@classmethod
31
- def create_lazy_dict (cls , name : str , id : int ) -> dict :
31
+ def create_lazy_dict (cls , name : str , id : int , uncertainty_type :str , filename :str ) -> dict :
32
+ # Get the classname checking with the class_label
33
+ uncertainty_class = Uncertainty .get_class (uncertainty_type )
32
34
return {
33
35
"name" : name ,
34
36
"id" : id ,
35
- "class_name" : "Uncertainty" ,
37
+ "class_name" : uncertainty_class . __name__ ,
36
38
"adapter" : {
37
39
"adapter" : "order_uncertainty" ,
38
40
"key" : "uncertainty" ,
39
41
"arguments" : {
40
- "uncertainty_name " : name ,
42
+ "filename " : filename ,
41
43
},
42
44
},
43
45
}
@@ -52,19 +54,20 @@ def __new__(metacls, cls_name, bases, cls_dict):
52
54
cls = super ().__new__ (metacls , cls_name , bases , cls_dict )
53
55
# Store the new type in the _classes dictionary
54
56
if hasattr (cls , "class_label" ):
57
+ metacls ._classes [cls .class_label ] = cls
58
+ # check base class label
59
+ if isinstance (bases [0 ], metacls ):
55
60
if hasattr (bases [0 ], "class_label" ):
56
- metacls ._classes ["_" .join ([bases [0 ].class_label , cls .class_label ])] = cls
57
- else :
58
- metacls ._classes [cls .class_label ] = cls
59
- print (metacls ._classes )
61
+ if not cls .class_label .startswith (bases [0 ].class_label ):
62
+ raise ValueError (f"Uncertainty class label { cls .class_label } does not inherit from { bases [0 ].class_label } " )
63
+
60
64
# Save the class in the class cache of all the base classes
61
65
return cls
62
66
63
67
64
68
def get_class (cls , class_label :str ):
65
69
'''This function splits the class_label using _ and look for the
66
70
closest match in the available classes dict'''
67
- breakpoint ()
68
71
toks = class_label .split ("_" )
69
72
for i in range (len (toks ), 0 , - 1 ):
70
73
label = "_" .join (toks [:i ])
@@ -94,15 +97,20 @@ def create(cls, uncertainty_type:str, **kwargs) -> Uncertainty:
94
97
95
98
class ExperimentalUncertainty (Uncertainty ):
96
99
'''Model that represents an experimental uncertainty'''
97
- class_label : ClassVar [str ] = "exp "
100
+ class_label : ClassVar [str ] = "syst_exp "
98
101
pog : NonEmptyStrictStr = Field (default = "" , description = "POG that provides the uncertainty" )
99
102
100
103
pass
101
104
105
+ class JESUncertainty (ExperimentalUncertainty ):
106
+ '''Model that represents an experimental uncertainty'''
107
+ class_label : ClassVar [str ] = "syst_exp_JES"
108
+ pass
109
+
102
110
103
111
class TheoryUncertainty (Uncertainty ):
104
112
'''Model that represents an experimental uncertainty'''
105
- class_label : ClassVar [str ] = "theory "
113
+ class_label : ClassVar [str ] = "syst_theory "
106
114
generator : NonEmptyStrictStr = Field (default = "" , description = "Generator that provides the uncertainty" )
107
115
108
116
pass
0 commit comments