Re: [ROOT] custom Streamer: stream TObject

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Jul 13 2000 - 16:01:18 MEST


Hi,
Your Streamer does not need to call TObject::Streamer if you do not use any of
the features of TObject (fBits and fUniqueID).

In our example with TShape::Streamer, we also do not need to call
TAtt3D::Streamer because this class contains only functions and no data members.

Rene Brun

mathes@ik3.fzk.de wrote:
> 
> Hi,
> I have a question concerning custom streamers:
> Do I have to write a Streamer (or call the Streamer method) for each base
> class of an user defined class ?
> In particular, must I call the TObject::Streamer(TBuffer&) from my custom
> Streamer ?
> 
> The example:
> http://root.cern.ch/root/InputOutput.html#streamer
> calls the Tnamed, TAttLine and TAttFill Streamers but not the TAtt3D
> Streamer
> 
> In my application I have:
> class TMirrorEvent  : public TObject
>  {
>   public:
>    TMirrorEvent();                     // standard ctor
>    TMirrorEvent( MiEvent );            // ctor from MiEvent
>    TMirrorEvent( TShmEvent* );         // ctor from TShmEvent
>    virtual ~TMirrorEvent();
> 
>    inline void Dump();                 // 'dump' contents to stdout
>    void Update( TShmEvent* );          // update internal references ...
> 
>                                        // access functions for sub structures
>   public:
>    inline TMirrorEventHeader* EventHeader();
>    inline TMirrorPixelData* PixelData();
>    inline TMirrorPixelList* PixelList();
>    inline TMirrorFADCData* FADCData();
> 
>   private:
>    MiEvent pMiEvent;
>    enum Constructor_t { kCREATE, kMIEVENT, kTSHMEVENT };
>    enum Constructor_t      fConstructorType;   // how object was created
> 
>   private:
>    TMirrorEventHeader*     pHeader;            // ptr. to TMirrorEventHeader
>    TMirrorPixelData*       pPixelData;         // ptr. to TMirrorPixelData
>    TMirrorPixelList*       pPixelList;         // ptr. to TMirrorPixelList
>    TMirrorFADCData*        pFADCData;          // ptr. to TMirrorFADCData
> 
>    ClassDef(TMirrorEvent,MiEVENTVERSION)
> };
> 
> with the Streamer():
> void TMirrorEvent::Streamer(TBuffer &b)
>  {
>   if (b.IsReading()) {
>     Version_t v = b.ReadVersion();
>     if ( v != MiEVENTVERSIONv1 ) {
>       cerr << "Version mismatch in TMirrorPixelList::Streamer()!" << endl;
>     }
>     // is this really needed ?
>     TObject::Streamer( b );
>   } else {
>     b.WriteVersion(TMirrorEvent::IsA());
>     // is this really needed ?
>     TObject::Streamer( b );
>   }
> 
>   pHeader->Streamer( b );
>   pPixelData->Streamer( b );
>   pPixelList->Streamer( b );
>   pFADCData->Streamer( b );
> }
> 
> The other classes (TMirror*) inherit indeed also from TObject, but don't
> call TObject::Streamer(). Both versions work (writing and reading), as
> long as I don't mix the data files. But what is the really compatible,
> recommended way to go ?
> 
> Thanks and Regards
>   Hermann-Josef
> 
> **************************************************************************
> *                                                                        *
> *   Dr. Hermann-Josef Mathes                                             *
> *   KASCADE & AUGER Collaboration                                        *
> *   Forschungszentrum Karlsruhe                Phone: +49 7247 822429    *
> *   Institut fuer Kernphysik                   FAX:   +49 7247 824075    *
> *   POB 3640                                                             *
> *   D-76021 Karlsruhe/Germany                  Mail:  mathes@ik3.fzk.de  *
> *                                                     hjmathes@web.de    *
> *                                                                        *
> **************************************************************************
> *   Feel free to visit my homepage:                                      *
> *          http://www-ik3.fzk.de/~mathes/Welcome.html                    *
> *   My software project page for DAQ:                                    *
> *          http://www-ik3.fzk.de/~mathes/software/software.html          *
> *                                                                        *
> *   Visit the institute and project homepages:                           *
> *          http://www-ik3.fzk.de/                                        *
> *          http://www-ik1.fzk.de/KASCADE_home.html                       *
> **************************************************************************



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:29 MET