207 def _printResult(self, result, depth=0, weight=None):
208 """ Print the result of calling a certain member.
209 As we want the test to be independent of memory we have to be a bit careful
210 how to not just print() but check whether the object is maybe a pointer to another
211 DataStore object or if it is a TObject with implements Print().
212 Also, call recursively std::pair
213
214 Args:
215 result: object to print
216 depth (int): depth for recursive printing, controls the level of indent
217 weight (float or None): weight to print in addition to object, only used for
218 relations
219 """
220
221 if depth:
222 print(" " * (depth + 1), end="")
223
224 if weight is not None:
225 weight = f" (weight: {weight:.6g})"
226 else:
227 weight = ""
228
229
230 if hasattr(result, "getArrayName") and hasattr(result, "getArrayIndex"):
231 if not result:
232 print(f"-> NULL{weight}")
233 else:
234 print(f"-> {result.getArrayName()}#{int(result.getArrayIndex())}{weight}")
235
236 elif hasattr(result, "GetNrows") and hasattr(result, "GetNcols"):
237 print(weight, end="")
238 for row in range(result.GetNrows()):
239 print("\n" + " " * (depth + 2), end="")
240 for col in range(result.GetNcols()):
241 print(f"{result(row, col):13.6e} ", end="")
242
243 print()
244
245 elif isinstance(result, TVector3):
246 print("(" + ",".join(f"{result[i]:.6g}" for i in range(3)) + ")")
247 elif isinstance(result, XYZVector):
248 print("(" + ",".join(f"{Belle2.B2Vector3D(result)[i]:.6g}" for i in range(3)) + ")")
249
250 elif isinstance(result, TLorentzVector):
251 print("(" + ",".join(f"{result[i]:.6g}" for i in range(4)) + ")")
252
253 elif hasattr(result, "first") and hasattr(result, "second"):
254 print(f"pair{weight}")
255 self._printResult(result.first, depth + 1)
256 self._printResult(result.second, depth + 1)
257
258 elif (hasattr(result, "size") and hasattr(result, "begin")
259 and hasattr(result, "end")) and not hasattr(result, "npos") \
260 and not isinstance(result, Const.DetectorSet):
261 print(f"size({int(result.size())}){weight}")
262
263
264 weight_getter = getattr(result, "weight", None)
265 weight = None
266
267
268 for i, e in enumerate(result):
269 if weight_getter is not None:
270 weight = weight_getter(i)
271 self._printResult(e, depth + 1, weight=weight)
272
273 elif isinstance(result, float):
274 print(f"{result:.6g}{weight}")
275
276 elif isinstance(result, str) and len(result) == 1:
277 print(ord(result), weight, sep="")
278
279 else:
280 print(result, weight, sep="")
281
282
283
284