RE: [ROOT] Error in <TBuffer::ReadClass>: got wrong class: TObject

From: Philippe Canal (pcanal@fnal.gov)
Date: Tue Jul 23 2002 - 21:19:47 MEST


Hi Colin,

In addition you have a memory leak.

In your destructors you have:
  MEvent::~MEvent() {
    vertex->Delete();
  }
where vertex is a TClonesArray.
TClonesArray::Delete does delete the content of the array but NOT the TClonesArray object itself.  Since the memory footprint of your object is actually not reused you should have
  MEvent::~MEvent() {
    delete vertex; vertex = 0;
  }
(The other method can be used is complex case where one is using the full power of the TClonesArray are reuse the memory a lot).

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Colin Bernet
Sent: Monday, July 22, 2002 9:43 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Error in <TBuffer::ReadClass>: got wrong class: TObject



Hello, dear rooters.

First of all, sorry for this long mail...
I created a tree containing (as usual) vectors of tracks and
vertices. This tree has one single branch for an MEvent object : 

class MEvent : public TObject {
 
 public:
  int number;   
  vector<MVertex> vertex;
  vector<MTrack>  track;
  
  MEvent();
// ...

  ClassDef(MEvent,1)
};

As you can see, I would like to use STL vectors to store vertices and
tracks. Everything seems to work fine, except I get the following error
message at the first TTree::GetEntry(int)

Error in <TBuffer::ReadClass>: got wrong class: TObject

Does anybody know what could be the cause of this message ? 
In case you need it, my code can be found in 
/afs/cern.ch/user/c/cbernet/public/MDST

Tree is created and filled or chained and read in MDST class.
Linux/testMDST produced the tree
Linux/Debug reads the tree and produces the error message.

executables are in 
/afs/cern.ch/user/c/cbernet/public/MDST/Linux

I also have a question : At the beginning, my LinkDef was :

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class MTrack;
#pragma link C++ class MVertex;
#pragma link C++ class MEvent;
#pragma link C++ class MDST;

#endif

Then the tree was filled but the vectors of tracks and vertices were empty
at reading stage. Wandering on the root web site, I found out that
appending "+" at the end of the class names in the LinkDef solves this
problem.

Is this the normal behaviour ? is it related to the "wrong class" error
message ?

I tried with root 3.00/06 and 3.03/07.

thanks a lot if you can help me.
Colin



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:00 MET