Rene Brun wrote:
>
> As you have found, the classes TArrayF, etc do not derive from
> TObject, BUT they have their Streamer method.
> To be streamed to the output buffer, a class does not need to derive
> from TObject. Here are the rules:
> -If a class derives from TObject, rootcint can generate automatically
> the Streamer function if ClassDef is specified in the header file.
> -If a class does not derive from TObject (such as TArrayF), you
> can implement the Streamer function (case of TArrayF) and still use
> ClassDef in the header file.
and you MUST implement the methods:
TBuffer &operator>>(TBuffer&, YourClass *&)
TBuffer &operator<<(TBuffer &, const YourClass *)
Like for TArray:
TBuffer &operator>>(TBuffer &buf, TArray *&obj)
{
// Read TArray object from buffer. Function declared in ClassDef.
obj = (TArray *) TArray::ReadArray(buf, TArray::Class());
return buf;
}
TBuffer &operator<<(TBuffer &buf, const TArray *obj)
{
// Write TArray or derived object to buffer.
TArray::WriteArray(buf, obj);
return buf;
}
> -If a class derives from TObject and contains a TArrayF
> rootcint generates the Streamer code correctly.
> -If a class derives from TObject and contains a pointer to a TArrayF
> rootcint generates a Streamer class with the statement:
> R__b >> pointer;
> This statement must be changed to:
> pointer->Streamer(R__b);
> This could be done automatically by rootcint (not implemented).
rootcint generates the correct code:
R__b >> pointer;
and
R__b << pointer;
this will handle 0 pointers and circularities correctly.
> -If a class derives from TObject and contains a pointer to a basic type
> rootcint generates the code, issuing a warning: example
> In your class MuTrack, I have added a member
> Float_t *fX;
> You get the message:
> *** Datamember MuTrack::fX: pointer to fundamental type (need
> manual MuTrack::Streamer includes commented statements like:
> //R__b.WriteArray(fX, __COUNTER__);
> In such case, you typically have the array length as a data member
> (say member fN). Simply replace the commented statement by:
> R__b.WriteArray(fX,fN);
>
> When you provide the function Streamer yourself, you can instruct
> rootcint to not generate the code for Streamer by adding the character
> "-" to the class name in the file LinkDef.h. Example
>
> #pragma link C++ class MuTrack-;
>
> We are currently discussing:
> - the possibility to derive the TArray classes from TObject
> - the possibility to generate automatically the code in case
> of a pointer to a basic type. Consider the following example
> Int_t fN;
> Float_t *fX; //[fN] array of floats with length fN
> If rootcint finds a reference to a data member in the comments,
> it could automatically generate the instruction:
> R__b.WriteArray(fX,fN);
>
> Now concerning your last point with TVector, your code is correct.
> You hit a problem in the function TVector::ResizeTo.
> This problem has now been fixed in our development version.
> Thanks for reporting it.
>
> Rene Brun
>
-- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland Phone: +41 22 7679248 E-Mail: Fons.Rademakers@cern.ch Fax: +41 22 7677910