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