15 A basf2 python module to export *all* module time statistics (of every event, not just averaged)
16 into a ROOT TTree written to a file.
21 Create a new PerEventStatisticsGetterModule. You have to give the name of the
22 file, where the TTree with the full event statistics will be saved.
51 Create the needed store object pointer in the DataStore
and the TFile
with the TTree.
63 self.
statistics = ROOT.TTree(
"statistics",
"Per event execution Statistics for all modules")
78 The event loop: Store the statistics as a new row
in the TTree.
87 module_stats = basf2.statistics.modules
101 if ROOT.Belle2.ProcHandler.parallelProcessingUsed()
and not ROOT.Belle2.ProcHandler.isOutputProcess():
102 basf2.B2FATAL(
"PerEventStatisticsGetterModule can only be used in single processing mode or in the output process")
104 self.
ttree_inputs = np.zeros(len(module_stats), dtype=float)
105 self.
last_time_sum = np.zeros(len(module_stats), dtype=float)
107 for i, stat
in enumerate(module_stats):
110 module_name = f
"{ROOT.Belle2.MakeROOTCompatible.makeROOTCompatible(stat.name)}_{i}"
112 ttree.Branch(module_name, self.
ttree_inputs[i:], f
"{module_name}/D")
117 time_sum = np.array([m.time_sum(basf2.statistics.EVENT)
for m
in module_stats], dtype=float)
128 ROOT.gDirectory = old
132 Write out the merged statistics to the ROOT file.
133 This should only be called once, as we would end up
with different versions otherwise.
139 old = ROOT.gDirectory
146 ROOT.gDirectory = old
statistics
Will host the TTree later.
last_time_sum
Last recored sum of event calls for all modules.
ttree_inputs
The columns for the statistics TTree (they will be filled in the event function).
output_file_name
Name of the output file.
event_meta_data
The event meta data.
tfile
Will host the pointer to the opened TFile later.
event_number
The columns to store the event number.
branches_added
A flag to indicate that we have already added the Branches to the TTree (which we will do in the firs...
def __init__(self, output_file_name)