Belle II Software development
ValidationFiguresOfMerit Class Reference
Inheritance diagram for ValidationFiguresOfMerit:
ValidationManyFiguresOfMerit

Public Member Functions

 __init__ (self, name, description='', check='', contact='', title='')
 
 __str__ (self)
 
 write (self, tdirectory=None)
 
 __setitem__ (self, figure_name, value)
 
 __getitem__ (self, figure_name)
 
 __delitem__ (self, figure_name)
 
 __iter__ (self)
 
 __len__ (self)
 

Public Attributes

 name = root_save_name(name)
 cached name for this figure of merit
 
 description = description
 cached description for this figure of merit
 
 check = check
 cached user-check action for this figure of merit
 
 contact = contact
 cached contact person for this figure of merit
 
 title = title
 cached title for this figure of merit
 
 figures_by_name = collections.OrderedDict()
 cached dictionary of figures for this figure of merit
 

Detailed Description

Create and write an TNtuple of the validation figures of merit

Definition at line 19 of file fom.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
name,
description = '',
check = '',
contact = '',
title = '' )
Constructor

Definition at line 22 of file fom.py.

29 ):
30 """Constructor"""
31
32 ## cached name for this figure of merit
33 self.name = root_save_name(name)
34 ## cached description for this figure of merit
35 self.description = description
36 ## cached user-check action for this figure of merit
37 self.check = check
38 ## cached contact person for this figure of merit
39 self.contact = contact
40 ## cached title for this figure of merit
41 self.title = title
42
43 ## cached dictionary of figures for this figure of merit
44 self.figures_by_name = collections.OrderedDict()
45

Member Function Documentation

◆ __delitem__()

__delitem__ ( self,
figure_name )
Braketed item deletion for figures of merit

Definition at line 128 of file fom.py.

128 def __delitem__(self, figure_name):
129 """Braketed item deletion for figures of merit"""
130
131 del self.figures_by_name[figure_name]
132

◆ __getitem__()

__getitem__ ( self,
figure_name )
Braketed item lookup for figures of merit

Definition at line 123 of file fom.py.

123 def __getitem__(self, figure_name):
124 """Braketed item lookup for figures of merit"""
125
126 return self.figures_by_name[figure_name]
127

◆ __iter__()

__iter__ ( self)
Implements the iter() hook as if it was a dictionary.

Definition at line 133 of file fom.py.

133 def __iter__(self):
134 """Implements the iter() hook as if it was a dictionary."""
135
136 return iter(self.figures_by_name)
137

◆ __len__()

__len__ ( self)
Returns the number of figures of merit assigned. Implements the len() hook.

Definition at line 138 of file fom.py.

138 def __len__(self):
139 """Returns the number of figures of merit assigned. Implements the len() hook."""
140
141 return len(self.figures_by_name)
142
143

◆ __setitem__()

__setitem__ ( self,
figure_name,
value )
Braketed item assignment for figures of merit

Definition at line 118 of file fom.py.

118 def __setitem__(self, figure_name, value):
119 """Braketed item assignment for figures of merit"""
120
121 self.figures_by_name[figure_name] = value
122

◆ __str__()

__str__ ( self)
Informal string output listing the assigned figures of merit.

Definition at line 46 of file fom.py.

46 def __str__(self):
47 """Informal string output listing the assigned figures of merit."""
48
49 figures_by_name = self.figures_by_name
50 return '\n'.join(f'{key} : {figures_by_name[key]}'
51 for key in
52 figures_by_name.keys())
53

◆ write()

write ( self,
tdirectory = None )
Writes the figures of merit as a TNtuple.

Parameters
----------
tdirectory : ROOT.TDirectory, optional
    The directory to which the TNtuple shall be written.
    Defaults to the current directory.

Reimplemented in ValidationManyFiguresOfMerit.

Definition at line 54 of file fom.py.

54 def write(self, tdirectory=None):
55 """Writes the figures of merit as a TNtuple.
56
57 Parameters
58 ----------
59 tdirectory : ROOT.TDirectory, optional
60 The directory to which the TNtuple shall be written.
61 Defaults to the current directory.
62 """
63 name = self.name
64
65 if not self.figures_by_name:
66 get_logger().warning(f'Do not create Ntuple for empty ValidationFiguresOfMerit {name}')
67 return
68
69 title = self.title or name
70 contact = self.contact
71
72 description = self.description
73 check = self.check
74
75 figure_names = [root_save_name(key) for key in list(self.figures_by_name.keys())]
76 values = list(self.figures_by_name.values())
77
78 with root_cd(tdirectory) as tdirectory:
79 # Try to find the object first
80 tntuple = tdirectory.Get(name)
81 if tntuple:
82 former_description = tntuple.GetAlias('Description')
83 former_check = tntuple.GetAlias('Check')
84 former_figure_names = []
85 former_values = []
86 tntuple.GetEntry(0)
87 for tleaf in tntuple.GetListOfLeaves():
88 former_figure_names.append(tleaf.GetName())
89 former_values.append(tleaf.GetValue())
90
91 # Append the description and check of this figure of merit to whatever is there
92 description = former_description + ' <br/>\n' + description
93 check = former_check + ' <br/>\n' + check
94
95 figure_names = former_figure_names + figure_names
96 values = former_values + values
97
98 # Need both delete and overwrite to get rid of the former object.
99 tdirectory.Delete(name)
100 write_option = ROOT.TObject.kOverwrite
101
102 else:
103 write_option = 0
104
105 leaf_specification = ':'.join(figure_names)
106 tntuple = ROOT.TNtuple(name, title, leaf_specification)
107
108 array_of_values = array.array('f', values)
109 tntuple.Fill(array_of_values)
110
111 tntuple.SetAlias('Description', description)
112 tntuple.SetAlias('Check', check)
113 tntuple.SetAlias('Contact', contact)
114
115 # Overwrite the former TNtuple if one was there
116 tntuple.Write("", write_option)
117

Member Data Documentation

◆ check

check = check

cached user-check action for this figure of merit

Definition at line 37 of file fom.py.

◆ contact

contact = contact

cached contact person for this figure of merit

Definition at line 39 of file fom.py.

◆ description

description = description

cached description for this figure of merit

Definition at line 35 of file fom.py.

◆ figures_by_name

figures_by_name = collections.OrderedDict()

cached dictionary of figures for this figure of merit

Definition at line 44 of file fom.py.

◆ name

name = root_save_name(name)

cached name for this figure of merit

Definition at line 33 of file fom.py.

◆ title

title = title

cached title for this figure of merit

Definition at line 41 of file fom.py.


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