Belle II Software development
CDCSVGPlotter Class Reference

Public Member Functions

def __init__ (self, animate=False)
 
def clone (self)
 
def styling_to_attribute_map (self, **styling)
 
def draw_superlayer_boundaries (self, **styling)
 
def draw_interaction_point (self)
 
def draw_outer_cdc_wall (self, **styling)
 
def draw_inner_cdc_wall (self, **styling)
 
def draw_iterable (self, iterable, **styling)
 
def draw_storevector (self, storeobj_name, **styling)
 
def draw_storearray (self, storearray_name, **styling)
 
def draw (self, obj, **styling)
 
def saveSVGFile (self, svgFileName='display.svg')
 
def savePNGFile (self, pngFileName='display.png')
 

Static Public Member Functions

def unpack_attributes (styling, i_obj=0, obj=None)
 

Public Attributes

 animate
 Switch to indicating if an animated SVG should be generated.
 
 eventdata_plotter
 Display the image using the event-data plotter.
 

Detailed Description

Helper class to generated the svg image from the various tracking objects.
This is a tiny wrapper around the TrackFindingCDC.EventDataPlotter.

Definition at line 21 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  animate = False 
)
Constructor methode.
@param animate switch indicating if an animated SVG should be generated

Definition at line 28 of file __init__.py.

28 def __init__(self, animate=False):
29 """
30 Constructor methode.
31 @param animate switch indicating if an animated SVG should be generated
32 """
33 top = -112
34 left = -112
35 right = 112
36 bottom = 112
37
38 default_bound = Belle2.TrackFindingCDC.BoundingBox(left, bottom, right, top)
39 default_width = 1120
40 default_height = 1120
41
42
43 self.animate = animate
44
45 self.eventdata_plotter = Belle2.TrackFindingCDC.EventDataPlotter(self.animate)
46
47 self.eventdata_plotter.setBoundingBox(default_bound)
48 self.eventdata_plotter.setCanvasHeight(default_height)
49 self.eventdata_plotter.setCanvasWidth(default_width)
50
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:21
A class that can plot event related data types.

Member Function Documentation

◆ clone()

def clone (   self)
Make a copy of the current status of the plotter.

Definition at line 51 of file __init__.py.

51 def clone(self):
52 """
53 Make a copy of the current status of the plotter.
54 """
55 cloned_plotter = CDCSVGPlotter(self.animate)
56 cloned_plotter.eventdata_plotter = Belle2.TrackFindingCDC.EventDataPlotter(self.eventdata_plotter)
57 return cloned_plotter
58

◆ draw()

def draw (   self,
  obj,
**  styling 
)
Draw an object with the specified styling

Definition at line 173 of file __init__.py.

173 def draw(self, obj, **styling):
174 """
175 Draw an object with the specified styling
176 """
177 attribute_map = self.styling_to_attribute_map(**styling)
178 self.eventdata_plotter.draw(obj, attribute_map)
179

◆ draw_inner_cdc_wall()

def draw_inner_cdc_wall (   self,
**  styling 
)
Draw the CDC inner wall

Definition at line 90 of file __init__.py.

90 def draw_inner_cdc_wall(self, **styling):
91 """
92 Draw the CDC inner wall
93 """
94 attribute_map = self.styling_to_attribute_map(**styling)
95 self.eventdata_plotter.drawInnerCDCWall(attribute_map)
96

◆ draw_interaction_point()

def draw_interaction_point (   self)
Draw the interaction point

Definition at line 77 of file __init__.py.

77 def draw_interaction_point(self):
78 """
79 Draw the interaction point
80 """
81 self.eventdata_plotter.drawInteractionPoint()
82

◆ draw_iterable()

def draw_iterable (   self,
  iterable,
**  styling 
)
Draw one or more items with the specified styling

Definition at line 112 of file __init__.py.

112 def draw_iterable(self, iterable, **styling):
113 """
114 Draw one or more items with the specified styling
115 """
116 draw = self.draw
117 unpack_attributes = self.unpack_attributes
118 for (i_obj, obj) in enumerate(iterable):
119 obj_styling = unpack_attributes(styling, i_obj, obj)
120 draw(obj, **obj_styling)
121

◆ draw_outer_cdc_wall()

def draw_outer_cdc_wall (   self,
**  styling 
)
Draw the CDC outer wall

Definition at line 83 of file __init__.py.

83 def draw_outer_cdc_wall(self, **styling):
84 """
85 Draw the CDC outer wall
86 """
87 attribute_map = self.styling_to_attribute_map(**styling)
88 self.eventdata_plotter.drawOuterCDCWall(attribute_map)
89

◆ draw_storearray()

def draw_storearray (   self,
  storearray_name,
**  styling 
)
Draw information from a StoreArray with the specified styling

Definition at line 150 of file __init__.py.

150 def draw_storearray(self, storearray_name, **styling):
151 """
152 Draw information from a StoreArray with the specified styling
153 """
154 print('Drawing StoreArray:', storearray_name, end=' ')
155 print()
156 storearray = Belle2.PyStoreArray(storearray_name)
157 if storearray:
158 print('with', storearray.getEntries(), 'entries')
159 print('Attributes are')
160 for (key, value) in list(styling.items()):
161 print(str(key), ':', str(value))
162
163 self.draw_iterable(storearray, **styling)
164
165 else:
166 print("### not present in the DataStore")
167 print("Current content of the DataStore")
168 print("StoreArrays:")
170 print("StoreObjPtr:")
172
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
static void printList(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Print list of available arrays for given durability.
Definition: PyStoreArray.cc:34
static void printList(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Print list of available objects for given durability.
Definition: PyStoreObj.cc:33

◆ draw_storevector()

def draw_storevector (   self,
  storeobj_name,
**  styling 
)
Draw information in a vector from the DataStore with the specified styling

Definition at line 122 of file __init__.py.

122 def draw_storevector(self, storeobj_name, **styling):
123 """
124 Draw information in a vector from the DataStore with the specified styling
125 """
126 print('Drawing vector from DataStore:', storeobj_name, end=' ')
127 print()
128 pystoreobj = Belle2.PyStoreObj(storeobj_name)
129
130 if pystoreobj:
131 # Wrapper around std::vector like
132 wrapped_vector = pystoreobj.obj()
133 vector = wrapped_vector.get()
134
135 print('with', vector.size(), 'entries')
136 print('Attributes are')
137 for (key, value) in list(styling.items()):
138 print(str(key), ':', str(value))
139
140 self.draw_iterable(vector, **styling)
141
142 else:
143 print("### not present in the DataStore")
144 print("Current content of the DataStore")
145 print("StoreArrays:")
147 print("StoreObjPtr:")
149
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67

◆ draw_superlayer_boundaries()

def draw_superlayer_boundaries (   self,
**  styling 
)
Draw the CDC superlayer boundaries

Definition at line 70 of file __init__.py.

70 def draw_superlayer_boundaries(self, **styling):
71 """
72 Draw the CDC superlayer boundaries
73 """
74 attribute_map = self.styling_to_attribute_map(**styling)
75 self.eventdata_plotter.drawSuperLayerBoundaries(attribute_map)
76

◆ savePNGFile()

def savePNGFile (   self,
  pngFileName = 'display.png' 
)
Save the current dom object representation to disk as a png.

Definition at line 201 of file __init__.py.

201 def savePNGFile(self, pngFileName='display.png'):
202 """
203 Save the current dom object representation to disk as a png.
204 """
205
206 import cairosvg
207 import os
208
209 temp_file_name = "tmp.svg"
210 eventdata_plotter = self.eventdata_plotter
211
212 boundingBox = eventdata_plotter.getBoundingBox()
213
214 height = boundingBox.getHeight()
215 width = boundingBox.getWidth()
216
217 totalPoints = 1120 * 1120
218 svgHeight = round(math.sqrt(totalPoints * float(height) / width))
219 svgWidth = round(math.sqrt(totalPoints * float(width) / height))
220
221 eventdata_plotter.setCanvasHeight(svgHeight)
222 eventdata_plotter.setCanvasWidth(svgWidth)
223
224 eventdata_plotter.save(temp_file_name)
225
226 with open(temp_file_name) as temp_file:
227 with open(pngFileName, "w") as output_file:
228 svg_code = temp_file.read()
229 cairosvg.svg2png(bytestring=svg_code, write_to=output_file)
230
231 os.remove(temp_file_name)

◆ saveSVGFile()

def saveSVGFile (   self,
  svgFileName = 'display.svg' 
)
Save the current dom object representation to disk.

Definition at line 180 of file __init__.py.

180 def saveSVGFile(self, svgFileName='display.svg'):
181 """
182 Save the current dom object representation to disk.
183 """
184
185 eventdata_plotter = self.eventdata_plotter
186
187 boundingBox = eventdata_plotter.getBoundingBox()
188
189 height = boundingBox.getHeight()
190 width = boundingBox.getWidth()
191
192 totalPoints = 1120 * 1120
193 svgHeight = round(math.sqrt(totalPoints * float(height) / width))
194 svgWidth = round(math.sqrt(totalPoints * float(width) / height))
195
196 eventdata_plotter.setCanvasHeight(svgHeight)
197 eventdata_plotter.setCanvasWidth(svgWidth)
198
199 return eventdata_plotter.save(svgFileName)
200

◆ styling_to_attribute_map()

def styling_to_attribute_map (   self,
**  styling 
)
Transfer the styling information to the attribute map

Definition at line 59 of file __init__.py.

59 def styling_to_attribute_map(self, **styling):
60 """
61 Transfer the styling information to the attribute map
62 """
64
65 for key, value in list(styling.items()):
66 attribute_map[str(key)] = str(value)
67
68 return attribute_map
69
Belle2::TrackFindingCDC::AttributeMap AttributeMap
A map type for attributes names to values for additional drawing information.

◆ unpack_attributes()

def unpack_attributes (   styling,
  i_obj = 0,
  obj = None 
)
static
Mapping function to unpack the attributes from the attribute maps. Mechanism and interface inspired by d3.js

Definition at line 98 of file __init__.py.

98 def unpack_attributes(styling, i_obj=0, obj=None):
99 """Mapping function to unpack the attributes from the attribute maps. Mechanism and interface inspired by d3.js"""
100 result = {}
101 for (key, value) in list(styling.items()):
102 if isinstance(value, collections.abc.Callable):
103 result[key] = value(i_obj, obj)
104 elif isinstance(value, str):
105 result[key] = value
106 elif hasattr(value, '__getitem__'):
107 result[key] = value[i_obj % len(value)]
108 else:
109 result[key] = value
110 return result
111

Member Data Documentation

◆ animate

animate

Switch to indicating if an animated SVG should be generated.

Definition at line 43 of file __init__.py.

◆ eventdata_plotter

eventdata_plotter

Display the image using the event-data plotter.

Definition at line 45 of file __init__.py.


The documentation for this class was generated from the following file: