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
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
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
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
116 tntuple.Write("", write_option)
117