Re: Including none-TObjects

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Mar 23 1998 - 16:09:11 MET


Hi Rutger,

   for non-TObject classes you need to provide a custom TBuffer &operator>>()
and TBuffer &operator<<() in case you want to be able to save the objects
via pointers to such objects. In case you want to save directly the objects
(as opposed to pointers to objects) you need only a Streamer().
The default generated Streamer() should be ok (depending if you use pointers
to basic types, in which case you need to make a custom Streamer()).
For example:

class MPipo : public TObject {   <-- base class goes via TObject::Streamer()
private:
   MAap    fAap;        <-- goes via MAap::Streamer()
   MNoot  *fNoot;       <-- goes via TBuffer &operator<<(), fNoot can be 0
   ...
};

A good example of a class having its own operator<< and operator>> is
http://root.cern.ch/root/html/src/TArray.cxx.html and see also
http://root.cern.ch/root/html/src/TArrayC.cxx.html for special operator>>.

In case you don't want rootcint to generate the Streamer() and operator>>
you have to put in the LinkDef.h file:

#pragma link C++ class TArrayC-!;

where - means no Streamer() and ! no operator>>() (can also be only !
or -).

Currently objects containing non-TObject derived objects can not
be stored in Trees in split mode. For this and other rules see:
http://root.cern.ch/root/HowtoWriteTree.html

Cheers, Fons.


Rutger van der Eijk wrote:
> 
> Hi All,
> 
> I'm having problems including some none-TObjects into a (root)shared
> library.
> 
> I have a simple Event class (MTRawEvent) declared as follows:
> (some members not shown for clarity):
> 
> ---- MTRawEvent.H ----
> #ifndef _MTRawEvent_H_
> #define _MTRawEvent_H_
> 
> #include "TObject.h"
> #include "MTRawHit.H"
> 
> class MTRawEvent: public TObject {
> public:
>   MTRawEvent(); // create uninitialized
> 
>   void SetRawHit(MTRawHit rawHit); // temp set hit as long as not array...
>   MTRawHit GetRawHit() const; // temp get the single raw hit
> 
>   virtual ~MTRawEvent();                  // destroy Event-object
> 
>   ClassDef(MTRawEvent, 1) // RawEvent class
> private:
>   MTRawHit fRawHit; // raw hit
> };
> 
> #endif // _MTRawEvent_H_
> ---- ----
> 
> It contains a MTRawHit object as datamember, which is NOT a TObject:
> 
> ---- MTRawHit.H ----
> #ifndef _MTRawHit_H_
> #define _MTRawHit_H_
> 
> #include "MTChannelId.H"
> 
> class MTRawHit {
> public:
>   MTRawHit(MTChannelId channelId = 0, Int_t tdcValue = 0);
> 
>   MTChannelId GetChannelId() const; // get channel id
>   Int_t GetTDCValue() const;   // get TDC value
> 
>   ~MTRawHit();                      // destroy Hit-object
> 
> private:
>   MTChannelId fChannelId; // channel Id
>   Int_t fTDCValue; // TDC value
> };
> 
> #endif // _MTRawHit_H_
> ---- ----
> 
> It contains as datamembers a Int_t and another none-TObject class
> MTChannelId.
> 
> My problem:
> 
> The MTRawEvent I (ofcourse) want to somewhere put in a TTree and a TFile.
> With rootcint I can then create the appropriate Streamer methods for
> classes inheriting from TObject. From reading the ROOT tutorial and
> 'course' and browsing the web-pages it doesn't become completely clear
> to me what the best procedure is to handle none-TObject classes.
> 
> My questions:
> 
> - Should I (manually) write Streamer (and ShowMember) member functions for
> the none-TObjects (MTRawHit and MTChannelId) or should I only modify the
> TObject MTRawEvent?
> - If I write (or modify) a Streamer member function definition should I
> also put the declaration in the class declaration? Actually I don't
> understand why this seems NOT to be necesarry for TObjects...
> - Should I include classes of the none-TObjects in the linkdef.h file
> (with #pragma link C++ class MTChannelId-; (or with also '!' ?))
> 
> I would appriciate any help and/or simple-example ,
> 
> Rutger van der Eijk

-- 
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



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:31 MET