TSocket, Dictionary and Containers

Dear ROOTers,

I have 2 questions:
When transfering a ROOT container (e.g. TMap) or a TDirectory through a TSocket (by writing the whole container/directory to a message) do also the contained objects get written to the socket/message? If not by default, which is the way to do this? (The obvious solution is of course to send the contained objects one by one using an iterator).
In order to transfer objects from my own classes through TSocket, is it needed for them to inherit from TObject, create a dictionary, or both? In general, It is not clear to me from the documentation whether ROOT system object I/O is related to TObject properties or ROOT dictionary. Is there a techincal presentation for these? Best regards,

filimon

Hi,

if you stream a collection to a TMessage all objects in the collection are streamed to the message. Your class does not have to derive from TObject but it must have a dictionary.

Cheers, Fons.

Thank you Fons. Two more questions:

  1. I get this message
    Warning in : since MyTestClass had no public constructor
    which can be called without argument, objects of this class
    can not be read with the current library. You would need to
    add a default constructor before attempting to read it.

I do not want to have a public default constructor for my class, I have it private. I thought that declaring the TMessage class as friend would do the trick, but does not work. Is there another way to achieve this? (Maybe declaring another friend class)?

  1. Since MyTestClass inherits publicly from TNamed, I would expect that TMessage uses WriteObject and not WriteObjectAny. Is this the intended behaviour and if not could it be related to the previous condition? I see from TBuffer code that there are two possible functions to use, WriteObject(TObject*), WriteObjectAny(…) and a protected WriteObject. With the specific situation in hand, that is a template class publicly derived from TNamed, which is in your opinion the recommended solution to write to TBuffer? I note that moving the default constructors to public section stops the warning but I would strongly like to avoid this. Thanks,

filimon

[quote]Is there another way to achieve this? (Maybe declaring another friend class)?[/quote]The TMessage class only very indirectly calls the constructor, this code is deep in the I/O. The alternative is to define an “I/O” constructor having the signature:MyTestClass(TRootIOCtor*);(actually you can also customize the type (TRootIOCtor) in the linkdef file (see User’s Guide). This constructor must initialize properly the data members.

[quote]Since MyTestClass inherits publicly from TNamed, I would expect that TMessage uses WriteObject and not WriteObjectAny. [/quote]Indeed, for your class you can/should use WriteObject (which is trivially implemented in term of WriteObjectAny, so you might indeed see this function name appear in stack trace).

Cheers,
Philippe