[ROOT] Streamer of a class containing a TClonesArray

From: GUEZ David (davguez@mail.dotcom.fr)
Date: Thu Jun 07 2001 - 05:31:26 MEST


Hello,

In the exemple program bellow, I have reproduced a strange problem...

-----------------------------------------------------------------------

With the code 

#include <iostream>

#include <TROOT.h>
#include <TClonesArray.h>

class A :public TObject
{
 protected:
  Int_t fX;

  TClonesArray *pb; // here is the problem source...
>>>>---------------------------------------<<<<<                  

 public:
  A():TObject(){cout<<"Default A constructor"<<endl; fX=0;}
  A(Int_t x):TObject(){cout<<"Creating A with x="<<x<<endl;fX=x;}
  ~A(){cout<<"Deleting A with x="<<fX<<endl;}
  Int_t X() const {return fX;}
  Int_t X(Int_t x){return fX=x;}
  ClassDef(A,1)
};

the copy of the dict.cxx file generated by rootcint is

void A::Streamer(TBuffer &R__b)
{
   // Stream an object of class A.

   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
      TObject::Streamer(R__b);
      R__b >> fX;

      pb->Streamer(R__b);
>>>>----   My Problem .... ----------<<<<<<<<<

      R__b.CheckByteCount(R__s, R__c, A::IsA());
   } else {
      R__c = R__b.WriteVersion(A::IsA(), kTRUE);
      TObject::Streamer(R__b);
      R__b << fX;
      pb->Streamer(R__b);
      R__b.SetByteCount(R__c, kTRUE);
   }
}
------------------------------------------------------------------------

As you can see, this streamer expect <pb> to be well instanciated.
Since 
1) the default constructor is supposed to not allocate memory,
and 2) this default constructor is used on file reading
then, as you can imagine, I'm facing a 
 *** Break *** segmentation violation
error.
I also add a -> on comments but nothing is changed (and I think that
this
should be used exactly for the opposite goal....)
This is really strange, because, if I replace TClonesArray* by TTree*
(for instance) the code generated use a "normal" R__b>>pb
Then, since it's a special case, may be I miss a special rule, but, if
so, please tell me which one

	Thanks in advance
		DAVID

--
David GUEZ
davguez@mail.dotcom.fr
WEB : www.fairesuivre.com/~davguez
ICQ : 6229724



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:48 MET