RE: TClonesArray::Streamer expecting class

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 11 Aug 2005 10:38:40 -0500


Hi Dmitry,

I tried and failed to reproduce your problem (It ask for a file nuclon.root)  

However, it sounds like the TTree still sees the address of the deleted TClonesArray.
It would be better if, you function was more like (i.e. keep the existing object alive):

void NEvent::SetDetectorResponse(TClonesArray* copy) {

   fDetResponse->Clear();
   for() {

      new ( (*fDetResponse)[i] ) ObjectType( copy->At(i) );    }
}

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Dmitry V.Naumov
Sent: Wednesday, August 10, 2005 8:48 AM To: roottalk_at_cern.ch
Subject: [ROOT] TClonesArray::Streamer expecting class

Dear rooters,

I have the following problem which I can not figure out myself. As the output of VMC+G4 code I save the root file with TTree containg NEvent as a branch. The structure of this event is very simple:

class NEvent: public TObject {
public:
<skip>
private:

NEventHeader *fHeader; // Event header
TClonesArray *fDetResponse; // -> detector response with hits, etc TObjArray *fTracks; // -> tracks
};

In the code I have the pointer of type NEvent which I fill with needed information. For example I use methods like: void NEvent::SetDetectorResponse(TClonesArray* copy) { fDetResponse = (TClonesArray*)copy->Clone(); <skip>
}

in order to delete consequently copy from the main body of the code. Finally the tree is saved with usual TTree::Fill() method. What I get sometimes (and this is what I do not understand) that reading back
the output from the root file reading of some events gives: TClonesArray::Streamer expecting class

To be more precise:

Reading 2 event
Reading 3 event
Reading 4 event
TClonesArray::Streamer expecting class 4Ã?}` Reading 5 event
TClonesArray::Streamer expecting class
Error in <TBuffer::CheckByteCount>: object of class TClonesArray read too few bytes: 15 instead of 625760311
Error in <TBuffer::CheckByteCount>: Byte count probably corrupted around buffer position 6807:
625760311 for a possible maximum of 25174

I was checking in the core of the code that the pointer I pass to my NEvent is
not empty, some slots of TClonesArray are always filled. Doing TTree::Print() before
closing the file looks also OK:



**

*Tree :nuclon : nuclon tree *
*Entries : 6 : Total = 242395 bytes File Size = 74081 *

*Branch :fEvent *
*Entries : 6 : BranchElement (see below) *
*...........................................................................
.*

*Br 0 :fUniqueID : *
*Entries : 6 : Total Size= 682 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*...........................................................................
.*

*Br 1 :fBits : *
*Entries : 6 : Total Size= 658 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*...........................................................................
.*

*Br 2 :fHeader : *
*Entries : 6 : Total Size= 1400 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*...........................................................................
.*

*Br 3 :fDetResponse : *
*Entries : 6 : Total Size= 237055 bytes File Size = 74081 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 2.98 *
*...........................................................................
.*

*Br 4 :fTracks : *
*Entries : 6 : Total Size= 824 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *
*...........................................................................
.*

On the root website I found some references for the similar problems from which
I did not figure out the solution or diagnosis like: http://root.cern.ch/root/roottalk/roottalk02/4747.html

The tar ball with the code can be found at : dnaumov_at_lxplus.cern.ch:~/public/nuc.tar.gz The variables are set with source source_me. The problem can be reproduced running run_g4.C and then
root[].x EventAnalysis.C
click "next" 5-6 times to see it.

Thanks in advance, Dmitry Received on Thu Aug 11 2005 - 17:40:28 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:11 MET