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