Streamer crash with std::vector of histograms

Hi,

I’m having trouble in ROOT 5.32 writing out an object containing vectors of histograms. I get a segmentation fault when trying to write it out to a file. Also, I get a segmentation fault when trying to Clone the object.

I do have a Linkdef file specifying the new streamer method.

I’m pretty sure it’s the vector part causing the trouble because if I add //! after the vectors in my class, it saves fine. I thought it could be a problem with the directory of the histograms , but setting it to 0 or to the output TFile object doesn’t help.

Even more strangely, a member of the class I’m writing out is another user-defined class that has its own vector of TH2F’s and that writes out fine…

I have attached the output of a Dump() and Write() (and the ensuing seg fault) with gDebug =6 in hopes that it may be helpful.

The write of the object does NOT run in its own thread, but threads are used elsewhere in the program (including where the object I’m saving is created, but taking that out of a thread doesn’t help the problem).

I tried creating a simple example demonstrating the problem, but it doesn’t behave in the same way (crash on output). It does, however, crash when trying to read the object, which may be a related problem. That is also attached.
simpleExample.tar (10 KB)
dump.txt (146 KB)

Hi,

To work around the problem (issue with ‘reusing’ non-empty vector of pointers), add: MyClass(TRootIOCtor*) {};to your class definition.

Cheers,
Philippe.

HI,

The real issue in your example is: data.push_back(h); data2.push_back(h); where you push the same pointer value on both array. This conflicts with the semantic that the vector of pointers are consider by the ROOT I/O to be owner of the object pointed at. Using: data.push_back(h); data2.push_back(h2);solves the issue. If you meant for both to points to the same object you should consider replacing the second one with a vector containing the index in the first vector.

Cheers,
Philippe.

You’re quite right about the example… that was an oversight that created a new problem.

I have since changed my object to not persist the vectors of pointers (since they weren’t essential), but I’ll check if the first reply fixed the problem when I get to it…