tbufferfile in pyroot

From: Andy Mastbaum <mastbaum_at_hep.upenn.edu>
Date: Sun, 13 Nov 2011 21:38:28 -0500


Dear ROOTers,

I'm trying to send some TObjects from a (C++) server program to both C++ and Python (PyROOT) clients. It all works in C++, but I am having trouble with receiving objects in Python. I serialize/deserialize with a TBufferFile in all cases. I'm using ZeroMQ to do the sockets, but I don't think that's relevant.

When I try to read an object out of my TBufferFile in Python, I get things like this:

    Error in <TBufferFile::ReadObject>: object tag too large, I/O buffer corrupted

I've had to do some casting trickery since the third argument in the TBufferFile constructor is a void*:

    msg = socket.recv(copy=False)
    buf = ROOT.TBufferFile(ROOT.TBuffer.kRead, len(msg.buffer), sip.voidptr(id(msg.buffer)).ascobject(), False)

    o = id(buf.ReadObjectAny(ROOT.TH1F.Class())) # error!

I use SIP for casting, since I believe that's what PyROOT is written with, but I get the same results using ctypes c_void_p. Same if I treat msg as a string or bytes. The msg.buffer here is a Python buffer object containing the contents of the packet -- a TBuffer's Buffer() from the server.

Is there a better way to pass void* arguments to ROOT methods from PyROOT? I suspect that's the most likely culprit.

Any suggestions would be greatly appreciated!

I've attached a C++ server and a C++ and Python client, and a script to build them (zmq library required).

Thanks,
Andy

Received on Mon Nov 14 2011 - 03:38:36 CET

This archive was generated by hypermail 2.2.0 : Mon Nov 14 2011 - 11:50:01 CET