PyROOT and TKey::ReadObjectAny


I am trying to read an object from a root file that is not derived from TObject using PyROOT. The dictionary for this class is available but I am not sure how to get a python instance of the correct type after calling ReadObjectAny:

>>> ROOT.RCTransLog
<class 'ROOT.RCTransLog'>
>>> r = k.ReadObjectAny(ROOT.TClass.GetClass("RCTransLog"))
>>> r.__class__
<type 'ROOT.PyLongBuffer'>

How do I convert PyLongBuffer into RCTransLog ?


Answering my own question, this seems to work:

>>> ROOT.TPython.ObjectProxy_FromVoidPtr(r,"RCTransLog") <ROOT.RCTransLog object at 0xa59d848>


or the more direct ROOT.BindObject(), which takes r[0], though (i.e. a long address, rather than the buffer). Difference being that ROOT.TPython is supposed to work from CINT, so calls to it from python go through the dictionary layer once more, and that BindObject() will take CObjects as well and can handle classes (rather than only strings). In the end, they call the same function, though.