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(f"({result.X():.6g},{result.Y():.6g},{result.Z():.6g})")
257 elif isinstance(result, TLorentzVector):
258 print("(" + ",".join(f"{result[i]:.6g}" for i in range(4)) + ")")
259
260 elif hasattr(result, "first") and hasattr(result, "second"):
261 print(f"pair{weight}")
262 self._printResult(result.first, depth + 1)
263 self._printResult(result.second, depth + 1)
264
265 elif (hasattr(result, "size") and hasattr(result, "begin")
266 and hasattr(result, "end")) and not hasattr(result, "npos") \
267 and not isinstance(result, Const.DetectorSet):
268 print(f"size({int(result.size())}){weight}")
269
270
271 weight_getter = getattr(result, "weight", None)
272 weight = None
273
274
275 for i, e in enumerate(result):
276 if weight_getter is not None:
277 weight = weight_getter(i)
278 self._printResult(e, depth + 1, weight=weight)
279
280 elif isinstance(result, float):
281 print(f"{result:.6g}{weight}")
282
283 elif isinstance(result, str) and len(result) == 1:
284 print(ord(result), weight, sep="")
285
286 else:
287 print(result, weight, sep="")
288
289
290
291