Belle II Software  release-05-01-25
wrapper.py
1 # Nice display features imports
2 from trackfindingcdc.cdcdisplay import CDCSVGDisplayModule
3 from tracking.validation.harvesting import HarvestingModule
4 import os
5 import multiprocessing
6 
7 
9 
10  """
11  A wrapper around the svg drawer in the tracking package that
12  writes its output files as a list to the queue
13  """
14 
15  def __init__(self, queue=None, label=None, *args, **kwargs):
16  """ The same as the base class, except:
17 
18  Arguments
19  ---------
20 
21  queue: The queue to write to
22  label: The key name in the queue
23  """
24 
25  self.queue = queue
26 
27 
28  self.label = label
29 
30  CDCSVGDisplayModule.__init__(self, interactive=False, *args, **kwargs)
31 
32 
33  self.use_cpp = True
34 
35 
36  self.manager = multiprocessing.Manager()
37 
38 
39  self.file_list = self.manager.list([])
40 
41  def terminate(self):
42  """ Overwrite the terminate to put the list to the queue"""
43  CDCSVGDisplayModule.terminate(self)
44  file_list = self.file_list
45  files = [file_list[i] for i in range(len(file_list))]
46  if self.queue:
47  self.queue.put(self.label, files)
48 
50  """ Overwrite the function to listen for every new filename """
51  output_file_name = CDCSVGDisplayModule.new_output_filename(self)
52  self.file_list.append(output_file_name)
53  return output_file_name
54 
55 
56 def show_image(filename, show=True):
57  """ Display an image file in ipython """
58  from IPython.core.display import Image, display
59 
60  os.system("convert " + filename + " " + filename[:-3] + str("png"))
61  image = Image(filename[:-3] + str("png"))
62  if show:
63  display(image)
64  return image
65 
66 
67 class QueueHarvester(HarvestingModule):
68 
69  """ Wrapper for the HarvestingModule to write its output file name to the queue """
70 
71  def __init__(self, queue, foreach, output_file_name, name=None, title=None, contact=None, expert_level=None):
72  """ The same as the base class except for the queue argument """
73  queue.put(self.__class__.__name__ + "_output_file_name", output_file_name)
74  HarvestingModule.__init__(self, foreach=foreach,
75  output_file_name=output_file_name,
76  name=name, title=title, contact=contact,
77  expert_level=expert_level)
wrapper.QueueDrawer.terminate
def terminate(self)
Definition: wrapper.py:41
wrapper.QueueDrawer.manager
manager
We store the files in a list and this list must be accessible also in multiprocessing,...
Definition: wrapper.py:36
wrapper.QueueDrawer
Definition: wrapper.py:8
wrapper.QueueHarvester
Definition: wrapper.py:67
trackfindingcdc.cdcdisplay.CDCSVGDisplayModule
Definition: __init__.py:25
trackfindingcdc.cdcdisplay
Definition: __init__.py:1
wrapper.QueueDrawer.label
label
The label for writing to the queue.
Definition: wrapper.py:28
wrapper.QueueHarvester.__init__
def __init__(self, queue, foreach, output_file_name, name=None, title=None, contact=None, expert_level=None)
Definition: wrapper.py:71
wrapper.QueueDrawer.new_output_filename
def new_output_filename(self)
Definition: wrapper.py:49
wrapper.QueueDrawer.queue
queue
The queue to handle.
Definition: wrapper.py:25
display
Definition: display.py:1
wrapper.QueueDrawer.use_cpp
use_cpp
We want to use cpp for sure.
Definition: wrapper.py:33
wrapper.QueueDrawer.file_list
file_list
The list of created paths.
Definition: wrapper.py:39
wrapper.QueueDrawer.__init__
def __init__(self, queue=None, label=None, *args, **kwargs)
Definition: wrapper.py:15