while upgrading our pyroot analysis framework from ROOT 6.18 to 6.22 I’ve come across the changed behaviour of ROOT.AddressOf. Reading the docs, I understood that it should be replaced with ROOT addressof.
This causes a problem with TChain.SetBranchAddress when I’m trying to read branches from a flat ntuple using an instance myClass (of a custom class MyClass). In particular,
fails, because addressof returns an int while SetBranchAddress expects a void pointer.
I’ve tried casting with ctypes.c_void_p which technically runs, but is not functional, i.e., myClass.met_pt is not changed. The same code with ROOT.AddressOf runs successfully in 6.18.
I put a minimal example into this repository which should make it straightforward to reproduce the problem:
It would be nice if somebody could take a look!
Thanks a lot,
PS: I can not not use TChains - the code is part of a larger framework.
Yes, the basic change is that, in the old PyROOT, AddressOf(o, "field") returned the address of the field as a buffer, while addressof(o, "field"), which is cppyy’s addressof, returns that address as an integer.
Therefore, your solution of casting that integer to a void* so it can be consumed by SetBranchAddress is a good option. This could also be handled in the pythonization of SetBranchAddress (Python-specific behaviour for that method), but it isn’t at the moment.