Belle II Software  release-08-01-10
display.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 from tracking.run.tracked_event_generation import ReadOrGenerateTrackedEventsRun
13 import trackfindingcdc.cdcdisplay as cdcdisplay
14 import tempfile
15 
16 
18  """Prepare and execute a basf2 job to read generated events or generate new events then display the CDC tracks"""
19 
20 
21  output_folder = tempfile.gettempdir()
22 
23 
24  iteractive = True
25 
26 
27  show_all_drawoptions = False
28 
29 
30  filename_prefix = ""
31 
32  def __init__(self):
33  """Constructor"""
34  super().__init__()
35 
36  self._cdc_display_module_cdc_display_module = cdcdisplay.CDCSVGDisplayModule(self.output_folderoutput_folder)
37 
38  @property
39  def cdc_display_module(self):
40  """Get the display module"""
41  cdc_display_module = self._cdc_display_module_cdc_display_module
42  return cdc_display_module
43 
44  def create_argument_parser(self, **kwds):
45  """Translate the command-lne arguments to basf2-job parameter"""
46  argument_parser = super().create_argument_parser(**kwds)
47 
48  argument_parser.add_argument(
49  '-o',
50  '--output-folder',
51  dest='output_folder',
52  default=self.output_folderoutput_folder,
53  help='Folder where the output files are written to. If the folder does not exist create it. '
54  )
55 
56  argument_parser.add_argument(
57  '--non-interactive',
58  dest='interactive',
59  action='store_false',
60  help='Run in batch mode and do not show each event.'
61  )
62 
63  argument_parser.add_argument(
64  '--use-python',
65  dest='use_python',
66  action='store_true',
67  help='Swtich to activate the legacy implementation written in python'
68  )
69 
70  argument_parser.add_argument(
71  "--use_time_in_filename",
72  action='store_true',
73  help='Use the current time in the names of the generated files'
74  )
75 
76  argument_parser.add_argument(
77  "-pf",
78  '--filename_prefix',
79  default=self.filename_prefixfilename_prefix,
80  help='Prefix to the names of the generated files'
81  )
82 
83  argument_parser.add_argument(
84  '-m',
85  '--mc-tracks',
86  action='store_const',
87  dest='finder_module',
88  const='TrackFinderMCTruthRecoTracks',
89  default=self.finder_modulefinder_module,
90  help='Generate the mc tracks using the TrackFinderMCTruthRecoTracks. Short hand for -f TrackFinderMCTruthRecoTracks'
91  )
92 
93  subparser_description = \
94  """
95 Various options to configure what shall be drawn in the display.
96 Note that some options are only relevant, if the cellular automaton finder in the CDC has been run before.
97 """
98  draw_argument_group = argument_parser.add_argument_group(
99  title='Draw options',
100  description=subparser_description
101  )
102 
103  cdc_display_module = self.cdc_display_modulecdc_display_module
104 
105  if self.show_all_drawoptionsshow_all_drawoptions:
106  drawoptions = cdc_display_module.all_drawoptions
107  else:
108  drawoptions = cdc_display_module.drawoptions
109 
110  for option in sorted(drawoptions):
111  options_flag = '--%s ' % option.replace('_', '-')
112 
113  draw_argument_group.add_argument(
114  options_flag,
115  dest=option,
116  action='store_true',
117  default=getattr(cdc_display_module, option)
118  )
119 
120  return argument_parser
121 
122  def configure(self, arguments):
123  """Configure the basf2 job script using the translated command-line arguments"""
124  super().configure(arguments)
125 
126  cdc_display_module = self.cdc_display_modulecdc_display_module
127 
128  cdc_display_module.output_folder = arguments.output_folder
129  cdc_display_module.interactive = arguments.interactive
130 
131  cdc_display_module.use_python = arguments.use_python
132  cdc_display_module.use_cpp = not arguments.use_python
133  cdc_display_module.use_time_in_filename = arguments.use_time_in_filename
134  cdc_display_module.filename_prefix = arguments.filename_prefix
135 
136  if self.show_all_drawoptionsshow_all_drawoptions:
137  drawoptions = cdc_display_module.all_drawoptions
138  else:
139  drawoptions = cdc_display_module.drawoptions
140 
141  for option in drawoptions:
142  try:
143  is_active_option = getattr(arguments, option)
144  except AttributeError:
145  continue
146  else:
147  print('Setting', option, 'to', is_active_option)
148  setattr(cdc_display_module, option, is_active_option)
149 
150  def create_path(self):
151  """Create the basf2 path"""
152  main_path = super().create_path()
153  main_path.add_module(self.cdc_display_modulecdc_display_module)
154  return main_path
def create_path(self)
Definition: display.py:150
def cdc_display_module(self)
Definition: display.py:39
def create_argument_parser(self, **kwds)
Definition: display.py:44
_cdc_display_module
Use the CDCSVGDisplay module to draw the CDC and tracks/hits.
Definition: display.py:36
def configure(self, arguments)
Definition: display.py:122
bool show_all_drawoptions
Switch to also show draw command line options only related to the cellular automaton track finder.
Definition: display.py:27
def __init__(self)
Definition: display.py:32
string filename_prefix
Prefix of the output files.
Definition: display.py:30
output_folder
Destination folder for displays.
Definition: display.py:21
finder_module
Name of the finder module to be used - can be everything that is accepted by tracking....