Belle II Software  release-08-01-10
executionTime_utils.py
1 # !/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 #
13 # utils to measure the per-event execution time of all modules
14 # appended to the path, SVD observables are also stored in the tree
15 #
16 # in order to use this function:
17 # import it:
18 # from svd.executionTime_utils import SVDExtraEventStatisticsModule
19 # and then use it to measure execution time of your path
20 #
21 # examples are in svd/examples/executionTime.py
22 #
23 #
24 
25 from ROOT import Belle2
26 import numpy as np
27 from per_event_statistics import PerEventStatisticsGetterModule
28 
29 
31  """
32  a basf2 python module to export all module time statistics (PerEventStatisticsGetterModule) +
33  number of SVDSpacePoints, SVDClusters, SVDShaperDigits and SVDSHaperDigitsZS5
34  into a ROOT TTree written to a file.
35  """
36 
37  def __init__(self, filename):
38  """
39  creates the module
40  @param filename: name of the rootfile where the TTree is written.
41  """
42  super().__init__(filename)
43 
44  self.svdSPssvdSPs = Belle2.PyStoreArray("SVDSpacePoints")
45 
46  self.svdclusterssvdclusters = Belle2.PyStoreArray("SVDClusters")
47 
48  self.svdstripssvdstrips = Belle2.PyStoreArray("SVDShaperDigits")
49 
50  self.svdZS5stripssvdZS5strips = Belle2.PyStoreArray("SVDShaperDigitsZS5")
51 
52  self.trackstracks = Belle2.PyStoreArray("Tracks")
53 
54  def initialize(self):
55  """
56  Create the needed store object pointer in the DataStore and the TFile with the TTree.
57  """
58 
59  super().initialize()
60 
61  self.svd_spssvd_sps = np.zeros(1, dtype=np.int32)
62 
63  self.svd_clusterssvd_clusters = np.zeros(1, dtype=np.int32)
64 
65  self.svd_stripssvd_strips = np.zeros(1, dtype=np.int32)
66 
67  self.svd_ZS5stripssvd_ZS5strips = np.zeros(1, dtype=np.int32)
68 
69  self.svd_trackssvd_tracks = np.zeros(1, dtype=np.int32)
70 
71 
72  self.statisticsstatistics.Branch('svdSPs', self.svd_spssvd_sps[0:], "svdSPs/I")
73 
74  self.statisticsstatistics.Branch('svdClusters', self.svd_clusterssvd_clusters[0:], "svdClusters/I")
75 
76  self.statisticsstatistics.Branch('svdStrips', self.svd_stripssvd_strips[0:], "svdStrips/I")
77 
78  self.statisticsstatistics.Branch('svdZS5strips', self.svd_ZS5stripssvd_ZS5strips[0:], "svdZS5strips/I")
79 
80  self.statisticsstatistics.Branch('tracks', self.svd_trackssvd_tracks[0:], "tracks/I")
81 
82  self.svdSPssvdSPs.isRequired()
83  self.svdclusterssvdclusters.isRequired()
84  self.svdstripssvdstrips.isRequired()
85 
86  self.svdZS5stripssvdZS5strips.isOptional()
87  self.trackstracks.isOptional()
88 
89  def event(self):
90  """ event """
91 
92  self.svd_spssvd_sps[0] = self.svdSPssvdSPs.getEntries()
93  self.svd_clusterssvd_clusters[0] = self.svdclusterssvdclusters.getEntries()
94  self.svd_stripssvd_strips[0] = self.svdstripssvdstrips.getEntries()
95 
96  if self.svdZS5stripssvdZS5strips.isOptional():
97  self.svd_ZS5stripssvd_ZS5strips[0] = self.svdZS5stripssvdZS5strips.getEntries()
98  if self.trackstracks.isOptional():
99  self.svd_trackssvd_tracks[0] = self.trackstracks.getEntries()
100 
101  super().event()
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
svd_ZS5strips
array storing the number of ZS5 SVDShaperDigits
svd_sps
array storing the number of SVDSpacePoints
svd_strips
array storing the number of SVDShaperDigits
svd_clusters
array storing the number of SVDClusters