Belle II Software
development
mixins.py
1
#!/usr/bin/env python3
2
3
10
11
from
tracking.run.minimal
import
EmptyRun
12
import
tracking.root_utils
as
root_utils
13
14
import
logging
15
16
17
def
get_logger():
18
return
logging.getLogger(__name__)
19
20
21
class
RunMixin
(
EmptyRun
):
22
pass
23
24
25
class
PostProcessingRunMixin(EmptyRun):
26
"""Post-process the basf2 job output"""
27
28
29
postprocess_only =
False
30
31
def
create_argument_parser
(self, **kwds):
32
"""Parse the command-line post-processing arguments"""
33
argument_parser = super().
create_argument_parser
(**kwds)
34
postprocess_argument_group = argument_parser.add_argument_group(
"Postprocessing arguments"
)
35
postprocess_argument_group.add_argument(
36
'-po'
,
37
'--postprocess-only'
,
38
action=
'store_true'
,
39
default=self.
postprocess_only
,
40
dest=
'postprocess_only'
,
41
help=
'Only run the post processing of this run.'
,)
42
43
return
argument_parser
44
45
def
run(self, path):
46
"""Post-process the basf2 job output"""
47
if
not
self.
postprocess_only
:
48
super().run(path)
49
50
self.
postprocess
()
51
52
def
postprocess
(self):
53
"""By default, do nothing. (may be overridden)"""
54
55
56
class
BrowseTFileOnTerminateRunMixin(PostProcessingRunMixin):
57
"""Browse interactively the basf2 job output"""
58
59
60
output_file_name =
None
61
62
show_results =
False
63
64
def
create_argument_parser
(self, **kwds):
65
"""Parse the command-line TFile-browsing arguments"""
66
argument_parser = super().
create_argument_parser
(**kwds)
67
68
postprocess_argument_group = argument_parser
69
for
group
in
argument_parser._action_groups:
70
if
group.title ==
"Postprocessing arguments"
:
71
postprocess_argument_group = group
72
break
73
74
postprocess_argument_group.add_argument(
75
'-s'
,
76
'--show'
,
77
action=
'store_true'
,
78
default=self.
show_results
,
79
dest=
'show_results'
,
80
help=
'Show generated plots in a TBrowser immediately.'
,)
81
82
return
argument_parser
83
84
def
postprocess
(self):
85
"""Browse the TFile interactively"""
86
if
self.
show_results
and
self.
output_file_name
:
87
with
root_utils.root_open(self.
output_file_name
)
as
tfile:
88
root_utils.root_browse(tfile)
89
input(
"Close with return key."
)
90
91
super().
postprocess
()
92
93
94
class
RootOutputRunMixin
(
RunMixin
):
95
"""Configure for basf2 job output ROOT TFile"""
96
97
98
root_output_file =
None
99
100
def
create_argument_parser
(self, **kwds):
101
"""Parse the command-line output-file-specification argument"""
102
argument_parser = super().
create_argument_parser
(**kwds)
103
argument_parser.add_argument(
104
'root_output_file'
,
105
help=
'Output file to which the simulated events shall be written.'
106
)
107
108
return
argument_parser
109
110
def
create_path
(self):
111
"""Create a new basf2 path and add the RootOutput module to it"""
112
path = super().
create_path
()
113
114
path.add_module(
115
'RootOutput'
,
116
outputFileName=self.
root_output_file
117
)
118
119
return
path
tracking.run.minimal.EmptyRun
Definition
minimal.py:27
tracking.run.mixins.BrowseTFileOnTerminateRunMixin.output_file_name
output_file_name
There is no default for the name of the output TFile.
Definition
mixins.py:60
tracking.run.mixins.BrowseTFileOnTerminateRunMixin.create_argument_parser
create_argument_parser(self, **kwds)
Definition
mixins.py:64
tracking.run.mixins.BrowseTFileOnTerminateRunMixin.show_results
bool show_results
By default, do not show the browsing results.
Definition
mixins.py:62
tracking.run.mixins.BrowseTFileOnTerminateRunMixin.postprocess
postprocess(self)
Definition
mixins.py:84
tracking.run.mixins.PostProcessingRunMixin.postprocess_only
bool postprocess_only
By default, browse the output TFile too.
Definition
mixins.py:29
tracking.run.mixins.PostProcessingRunMixin.create_argument_parser
create_argument_parser(self, **kwds)
Definition
mixins.py:31
tracking.run.mixins.PostProcessingRunMixin.postprocess
postprocess(self)
Definition
mixins.py:52
tracking.run.mixins.RootOutputRunMixin
Definition
mixins.py:94
tracking.run.mixins.RootOutputRunMixin.root_output_file
root_output_file
There is no default for the name of the output TFile.
Definition
mixins.py:98
tracking.run.mixins.RootOutputRunMixin.create_path
create_path(self)
Definition
mixins.py:110
tracking.run.mixins.RootOutputRunMixin.create_argument_parser
create_argument_parser(self, **kwds)
Definition
mixins.py:100
tracking.run.mixins.RunMixin
Definition
mixins.py:21
tracking.root_utils
Definition
root_utils.py:1
tracking.run.minimal
Definition
minimal.py:1
tracking
scripts
tracking
run
mixins.py
Generated on Mon Sep 1 2025 02:59:09 for Belle II Software by
1.13.2