Custom streamer for contained objects

I have a problem in using a custom class streamer when the object is contained inside a std::vector. To reproduce the problem (code here) I have created two classes, MyClass and ContainedClass; the latter has a custom streamer function. When I place a ContainedClass object inside MyClass, and then write MyClass on file, then the custom streamer for ContainedClass is used

$ ./test 
Register custom streamer for ContainedClass
ContainedClassStreamer

If instead I place a std::vector<ContainedClass> inside MyClass then I get this:

$ ./test 
Register custom streamer for ContainedClass

so the custom streamer is not called. Is this the intended behavior? And if yes, why? I’d say that if a class has a custom streamer then it is necessary to serialize it in a non-trivial way, so the custom streamer should always be used…


ROOT Version: 6.14.04
Platform: Linux
Compiler: gcc 9.1


Hi @Nicola_Mori ,

I suggest that we wait for our I/O expert @pcanal to be back next Monday.

Hi @Nicola_Mori ,

In your example the contained vector is empty, when this is the case, the contained streamer will (of course) never be called.

Once at element is added, the test appears to work but this is ‘just’ because the class is empty.

Once I added a data member to ContainedClass, I can reproduce the problem and indeed there is a missing detection for this case.

You can easily work-around the problem by calling SetCanSplit after the call to SetStreamerFunc:

      tClass->SetStreamerFunc(ContainedClassStreamer);
      tClass->SetCanSplit(kFALSE);

Cheers,
Philippe.

Hi Philippe, sorry for the poorly-crafted reproducer; I don’t really understand what’s the problem so once I got the same error on the reproducer I didn’t bother to check further. I tested your solution also in my real code and it works, so thank you very much.
Just for information: is this “missing detection” issue a bug in Root? If yes, is it going to be fixed? Thanks.

Yes the missing detection is a bug and the fixed will be uploaded sometime this week.

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.