TTree with vector<TObject*>

I have a strange problem with reading TTree which includes std::vector<TObject*>.
My event class objects:

class event : public TObject
    {
        public:
            event() : TObject() { };
            event(int w) : TObject(), i(w) {
                                           v1_pos.push_back(db::get()->get_db_position(w));
                                           v_pos.push_back(db::get()->get_db_position(w));
                                           v_pos.push_back(db::get()->get_db_position(0));
                                           vv_pos.push_back(*db::get()->get_db_position(w));
                                           vv_pos.push_back(*db::get()->get_db_position(0));
                                           };
 
            virtual ~event() {};
        private:
            std::vector< position*>  v_pos;
            std::vector< position*>  v1_pos;
            std::vector< position >  vv_pos;
            int i;
             
        ClassDef(event,1)
    };

are branched in TTree, where class position is:

class position : public TObject
    {
        public:
            position() : TObject() { };
            position(int wx) : TObject(), xx(wx) {};
            int get_x() { return xx; };
        private:
 
        int xx;
        ClassDef(position,1)
    };

In vector v_pos I store only pointers to db::m_pos[] which is saved in the same root file.

class db : public TNamed
    {
        public:
            db() : TNamed() { };
            static db* get();
            position* get_db_position(int w) { return  m_pos[w]; };
 
        private:
            db(char* name, const char* title);
            static db* me;
            std::map<int, position* > m_pos;
 
        ClassDef(db,1)
    };

To this message I enclosed tar.gz file which includes sources and Makefile. So, you
can test it by yourself. After compilation and execution (./echidna) I load tree1.root file to root:

root -l tree1.root
root [0]
Attaching file tree1.root as _file0...
Warning in <TClass::TClass>: no dictionary for class event is available
Warning in <TClass::TClass>: no dictionary for class position is available

and without dictionaries I am able to scan the tree:

t1->Scan("v1_pos.xx")
t1->Scan("vv_pos.xx")
t1->Scan("v_pos.xx")

but after loading dictonaries it is not possible to read v_pos :

root [5] .L libechidna.so
root [6] t1->Scan("v_pos.xx")
***********************************
*    Row   * Instance *  v_pos.xx *
***********************************
 
 *** Break *** segmentation violation
 Generating stack trace...
 0x4142e4a8 in <unknown> from /lib/i686/libc.so.6
 0x401da0a4 in TGenCollectionProxy::Value::DeleteItem(void*) + 0x32 from /home/mlody/root/lib/libCore.so 0x401dc5d2 in TGenCollectionProxy::DeleteItem(bool, void*) const + 0x74 from /home/mlody/root/lib/libCore.so

Scanning vv_pos.xx and v1_pos.xx looks exactly the same as before loading the dictionaries. I realized that the problem occurs only if the vector<TObjects*> stores
more than one pointer.

Marcin Misiaszek
stl_vector_of_pointers.tar.gz (2.56 KB)

I can reproduce the problem.
I will check into it.

Philippe

Is there any progress fixing the problem?

Marcin Misiaszek

From the look of the data it looks like you create the vector of pointer to object with several time the same pointer. Because we have (to avoid memory leaks) to clean up the vector, this will lead to a double deletion and thus a crash.
When using a vector of object, you do not have this problem since the object are copied each time they are entered.

Cheers,
Philippe.