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