Belle II Software development
MetaOptionParser Class Reference

Public Member Functions

def __init__ (self, Optional[Iterable] meta_option_list=None)
 
bool has_option (self, str option_name)
 
float pvalue_warn (self)
 
float pvalue_error (self)
 
float float_value (self, key, Optional[float] default=None)
 
int int_value (self, key, Optional[int] default=None)
 
def parse_key_value (self, str key)
 

Detailed Description

Class to simplify the parsing of plot options
supplied by the MetaOption named object attached
to root plots.

A typical meta options list might look like this:
["pvalue-warn=0.9", "pvalue-error=0.4"]

Definition at line 15 of file metaoptions.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
Optional[Iterable]   meta_option_list = None 
)
Initialize MetaOptionParser
@param meta_option_list: list of meta options read from ROOT object
    or None

Definition at line 25 of file metaoptions.py.

25 def __init__(self, meta_option_list: Optional[Iterable] = None):
26 """
27 Initialize MetaOptionParser
28 @param meta_option_list: list of meta options read from ROOT object
29 or None
30 """
31 if meta_option_list is None:
32 meta_option_list = []
33 meta_option_list = list(meta_option_list)
34
35 self.mo: List[str] = meta_option_list
36

Member Function Documentation

◆ float_value()

float float_value (   self,
  key,
Optional[float]   default = None 
)
Extract the float value from a meta option list
@param key: the key to identify the value from the list
@param default: default value
@return: The float value or the default value if this key did not exist
         or the float value could not be parsed.

Definition at line 61 of file metaoptions.py.

61 def float_value(self, key, default: Optional[float] = None) -> float:
62 """
63 Extract the float value from a meta option list
64 @param key: the key to identify the value from the list
65 @param default: default value
66 @return: The float value or the default value if this key did not exist
67 or the float value could not be parsed.
68 """
69 v = self.parse_key_value(key)
70 if v is None:
71 return default
72 try:
73 return float(v)
74 except ValueError:
75 return default
76

◆ has_option()

bool has_option (   self,
str  option_name 
)
Checks whether an option is contained in the
meta options
@param option_name: name of the option to check for
@return: True if the option is contained in the meta option list
         False otherwise

Definition at line 37 of file metaoptions.py.

37 def has_option(self, option_name: str) -> bool:
38 """
39 Checks whether an option is contained in the
40 meta options
41 @param option_name: name of the option to check for
42 @return: True if the option is contained in the meta option list
43 False otherwise
44 """
45 return option_name in self.mo
46

◆ int_value()

int int_value (   self,
  key,
Optional[int]   default = None 
)
Extract the int value from a meta option list
@param key: the key to identify the value from the list
@param default: default value
@return: The int value or None if this key did not exist
         or the float value could not be parsed.

Definition at line 77 of file metaoptions.py.

77 def int_value(self, key, default: Optional[int] = None) -> int:
78 """
79 Extract the int value from a meta option list
80 @param key: the key to identify the value from the list
81 @param default: default value
82 @return: The int value or None if this key did not exist
83 or the float value could not be parsed.
84 """
85 v = self.parse_key_value(key)
86 if v is None:
87 return default
88 try:
89 return int(v)
90 except ValueError:
91 return default
92

◆ parse_key_value()

def parse_key_value (   self,
str  key 
)
Searches the meta options list for a key value entry and parses it
@param key: The key to look for
@return: The value which was associated to the key or None if the
        key was not found.

Definition at line 93 of file metaoptions.py.

93 def parse_key_value(self, key: str):
94 """
95 Searches the meta options list for a key value entry and parses it
96 @param key: The key to look for
97 @return: The value which was associated to the key or None if the
98 key was not found.
99 """
100 it = [s for s in self.mo if s.startswith(key + "=")]
101 if len(it) == 0:
102 return None
103
104 key_value_pair = it[0].split("=")
105
106 if len(key_value_pair) < 2:
107 return None
108
109 return key_value_pair[1]

◆ pvalue_error()

float pvalue_error (   self)
@return: The custom error level for the pvalue setting of plot
         comparison. None if no custom value was set for the plot.

Definition at line 54 of file metaoptions.py.

54 def pvalue_error(self) -> float:
55 """
56 @return: The custom error level for the pvalue setting of plot
57 comparison. None if no custom value was set for the plot.
58 """
59 return self.float_value("pvalue-error")
60

◆ pvalue_warn()

float pvalue_warn (   self)
@return: The custom warning level for the pvalue setting of plot
         comparison. None if no custom value was set for the plot.

Definition at line 47 of file metaoptions.py.

47 def pvalue_warn(self) -> float:
48 """
49 @return: The custom warning level for the pvalue setting of plot
50 comparison. None if no custom value was set for the plot.
51 """
52 return self.float_value("pvalue-warn")
53

The documentation for this class was generated from the following file: