Storing std::shared_ptr to user defined class in ROOT TTree

Dear Rooters,
I am trying to store shared_ptr to user defined classes in ROOT tree,
but it seems that i am not able to generated streamers for shared_ptr.

If i dont make shared_ptr then its work fine, but i want to store share_ptr to
my classes so that the memory deallocation will be done automtically by compiler,
as soon as i delete the vector containing the shared_ptrs.

Following are details platform related details

_ROOT Version: 6.22/08
Platform: Ubuntu linux
Compiler: 9.3 in ubuntu 20, 7.5 in ubuntu 18

Getting following output after running the code which is suppose to write my shared_ptr to the TTree


Warning in TStreamerInfo::Build: __shared_ptr<lite_interface::B>: base class __shared_ptr_access<lite_interface::B,__gnu_cxx::_Lock_policy::_S_atomic,false,false> has no streamer or dictionary it will not be saved
Warning in TStreamerInfo::Build: __shared_ptr<lite_interface::B>: __shared_count<__gnu_cxx::_Lock_policy::_S_atomic> has no streamer or dictionary, data member “_M_refcount” will not be saved
Warning in TStreamerInfo::Build: shared_ptr<lite_interface::B>: base class __shared_ptr<lite_interface::B> has no streamer or dictionary it will not be saved
Error in TStreamerInfo::Build: __shared_count<__gnu_cxx::_Lock_policy::_S_atomic>: _Sp_counted_base<__gnu_cxx::_Lock_policy::_S_atomic>* has no streamer or dictionary, data member _M_pi will not be saved
Warning in TStreamerInfo::Build: __shared_ptr<lite_interface::A>: base class __shared_ptr_access<lite_interface::A,__gnu_cxx::_Lock_policy::_S_atomic,false,false> has no streamer or dictionary it will not be saved
Warning in TStreamerInfo::Build: __shared_ptr<lite_interface::A>: __shared_count<__gnu_cxx::_Lock_policy::_S_atomic> has no streamer or dictionary, data member “_M_refcount” will not be saved
Warning in TStreamerInfo::Build: shared_ptr<lite_interface::A>: base class __shared_ptr<lite_interface::A> has no streamer or dictionary it will not be saved
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
Warning in TStreamerInfo::Build: _Sp_counted_base<__gnu_cxx::_Lock_policy::_S_atomic>: base class _Mutex_base<__gnu_cxx::_Lock_policy::_S_atomic> has no streamer or dictionary it will not be saved
Warning in TStreamerInfo::Build: _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic>: base class _Sp_counted_base<__gnu_cxx::_Lock_policy::_S_atomic> has no streamer or dictionary it will not be saved
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::B*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
Warning in TStreamerInfo::Build: _Sp_counted_ptr<lite_interface::B*,__gnu_cxx::_Lock_policy::_S_atomic>: base class _Sp_counted_base<__gnu_cxx::_Lock_policy::_S_atomic> has no streamer or dictionary it will not be saved
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.
Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr<lite_interface::A*,__gnu_cxx::_Lock_policy::_S_atomic> has no public constructor
which can be called without argument, objects of this class
can not be read with the current library. You will need to
add a default constructor before attempting to read it.


Here is the sample code attached to reproduce the above mentioned message by running the executable RootDict
RootDictExample.tar.gz (31.2 KB)

Hi @rasehgal ,
sorry for the high latency! Unfortunately ROOT does not support I/O of shared pointers.

@pcanal or @Axel can further comment and/or suggest workarounds.

Cheers,
Enrico

Indeed, we do support unique_ptr, though, but I suppose that’s not an option in your case?

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