Streamer for Reflex::Object

Hi Experts,

If I construct an object from its reflex dict. like:

[color=blue]myobj=Reflex::Object::Type::ByName(“myobjtype”).Construct()[/color]

Is there a way to serialize/stream this object? It will be the best if I could get a char[] (with length) of the serialized object and I can do something like hashing them. And, of course, the reverse - construct an object.

I know it must be being done somewhere inside root, otherwise we can’t put reflex object inside ttrees, right?

By the way, I’m a bit confused about TClass/TObject and Reflex, aren’t they doing the same thing in terms of describing/constructing objects?

Many thanks for your help!.

-Yushu

[quote]Is there a way to serialize/stream this object?[/quote]Of course :slight_smile:, (assuming you have called Cintex::Enable in order to back fill ROOT and Cint with the information from Reflex).

[quote]By the way, I’m a bit confused about TClass/TObject and Reflex, aren’t they doing the same thing in terms of describing/constructing objects?[/quote]TClass predate Reflex by a decade or so and the Reflex is not yet the default C++ information store for ROOT (the Cint structures are).

To store your object do:TBufferFile buffer(TBuffer::kWrite); TClass::GetClass("myobjtype")->Streamer(myobj,buffer);
and the char[] is available at buffer.Buffer() and its length at buffer.Length().

Cheers,
Philippe.

Thanks Philippe,

That works very well.

Just another quick question:

Assume I’ve got a class serialized into a TBuffer buf. And I would like to put this buffer into a branch of a ttree. What type of branch should I use? Can I do a Ttree.Branch(“mybranch”,&buf)?

I’m not directly putting the object itself into the branch since I would like to put different type of objects into the same branch.

Thanks.

-Yushu

[quote]I’m not directly putting the object itself into the branch since I would like to put different type of objects into the same branch. [/quote]Why? Could a collection of pointers (to a base class) do it easier?

Cheers,
Philippe.

[quote]
To store your object do:TBufferFile buffer(TBuffer::kWrite); TClass::GetClass("myobjtype")->Streamer(myobj,buffer);
and the char[] is available at buffer.Buffer() and its length at buffer.Length().
Cheers,
Philippe.[/quote]

Just wondering how do I do the inverse of this. I.e. I have a char* and want to create a Reflex::Object from it.

Thanks a lot!

-Yushu

Use:TBufferFile buffer(TBuffer::kRead, charbuf_len, charbuf_ptr, kFALSE); TClass::GetClass("myobjtype")->Streamer(myobj,buffer);

Cheers,
Philippe.

[quote=“pcanal”]Use:TBufferFile buffer(TBuffer::kRead, charbuf_len, charbuf_ptr, kFALSE); TClass::GetClass("myobjtype")->Streamer(myobj,buffer);

Cheers,
Philippe.[/quote]

Great! That works, thanks a lot!