[ROOT] Getting different classes out of a TMessage

From: Rasmus Ischebeck (rasmus@mail.desy.de)
Date: Wed Apr 26 2000 - 01:08:57 MEST


Hello everybody,

in the example hserv2.C (in the tutorials directory), the program reads
objects from a network connection via the type TMessage:

  ... 
  TMessage mess 
  ... 
  s->Recv(mess); 
  ... 
  if (mess->What() == kMESS_OBJECT) 
  {
    printf("got object of class: %s\n", mess->GetClass()->GetName());
    TH1 *h = (TH1 *)mess->ReadObject(mess->GetClass());
  ...

This works fine as long as the message contains only objects of one class.
However, I would like to put several objects of different classes in one
message. As I understand, this is supported since version 2.00/06 (see the
message by Judith Katzy from May 18 1998).

If I just add another statement
 
  TH1 *h = (TH1 *)mess->ReadObject(mess->GetClass());
  MyClass *m = (MyClass *)mess->ReadObject(mess->GetClass());

the second line produces the error message 

  Error in <TMessage::ReadClass>: got wrong class

The two objects are however extracted correctly from the message, as long
as I extract them in the same order as they were put in.

Looking at the source code for TMessage::GetClass() (in TMessage.h), one
sees that GetClass() returns the private variable fClass, which contains a
pointer to the class of the first object put into the message. Thus the
error message is what one would expect: in the second call, ReadObject
would like to have a pointer to MyClass, not to TH1.

Now my question is: is there any way to get a pointer to the next class
that will be extracted of a TMessage? 

I am using ROOT 2.24/02 on SunOS 5.7.


Thanks for your help,

Rasmus.
___

http://www.desy.de/~rasmus



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET