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