I/O of TNamed derived classes

Hi,
I have some classes which are derived from TNamed. The purpose of these class objects is to store the “simulation run related” info as the headers of the TTree (In UserInfo List). Now I have 2 problems in doing that :

  1. Pointers initiated to NULL values in default constructor of class :
    I know I can’t do that if I want to use ROOT I/O. But then can you suggest
    me some workaround for these ? I can’t avoid having pointers as data
    members of class or allocating them dynamically in the constructor. They
    have to be set after reading a related info in form of text file provided by
    user. So by default objects are created as invalid objects those should not
    be used.

  2. Ownership of these objects by UserInfo list :
    When there are multiple files opened, objects retrieved from UserInfo lists
    of different files often tend to cause crashes due to TList::Delete() call
    made at the time of file closing. Of course if one is careful in tracking
    which object is owned by which File’s UserInfo list then there is no
    problem. But it would be easier if I myself could manage creation/deletion
    of these objects. So is there a way to do that.
    Is it safe to do
    "tree->GetUserInfo()->SetOwner(kFALSE)" ;
    And then manage all the objects retrieved from these lists myself ?

[quote]1. Pointers initiated to NULL values in default constructor of class :
I know I can’t do that if I want to use ROOT I/O.[/quote]It should not be a problem to set the pointer to zero/nullptr in the constructor. How does it fail for you?

[quote]Is it safe to do…[/quote]It should be.

Cheers,
Philippe.

Thanks for the reply.

The problem happens When I want to open the file in TBrowser. If I have a Default constructor that initiates all the pointers to NULL then, as soon as a tree in the file is clicked (inside the TBrowser), there is a crash.

Hi,

This is unexpected. Can you provide a short reproducer?

Thanks,
Philippe.