Ignore:
Timestamp:
06/03/08 15:12:40 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mgeom
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.cc

    r8920 r8921  
    9696    fPixels.SetOwner();
    9797
     98    // For root versions <5.18 AddAt is mandatory, for newer
     99    // root-version the []-operator can be used safely
    98100    for (UInt_t i=0; i<npix; i++)
    99101        fPixels.AddAt(new MGeomPix, i);
     
    354356}
    355357
    356 
    357358// --------------------------------------------------------------------------
    358359//
     
    398399        fPixels.Print();
    399400}
    400 
    401 // --------------------------------------------------------------------------
    402 //
    403 //  Create a clone of this container. This is very easy, because we
    404 //  simply have to create a new object of the same type.
    405 //
    406 TObject *MGeomCam::Clone(const char *newname) const
    407 {
    408     if (IsA()==MGeomCam::Class())
    409     {
    410         MGeomCam *cam = new MGeomCam(fNumPixels, fCamDist);
    411         for (UInt_t i=0; i<fNumPixels; i++)
    412         {
    413             //if (fPixels.UncheckedAt(i))
    414                 (*this)[i].Copy((*cam)[i]);
    415         }
    416         cam->InitGeometry();
    417         return cam;
    418     }
    419 
    420     return (TObject*)IsA()->New();
    421 }
    422401
    423402// --------------------------------------------------------------------------
     
    546525}
    547526
    548 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,00)
    549 #include <TClass.h>
    550 #endif
     527// --------------------------------------------------------------------------
     528//
     529// This workaround reproduces (as much as possible) the contents
     530// of fPixels which got lost writing MGeomCam in which the
     531// fPixels were filles with the []-operator instead of AddAt
     532// and a root version previous to 5.18.
     533// You try to read broken contents from file if fNumPixels is empty
     534// but fNumPixels>0.
     535// If you ever read broken contents from a split branch you
     536// MUST call this function after reading.
     537//
     538void MGeomCam::StreamerWorkaround()
     539{
     540    if (fNumPixels==0 || !fPixels.IsEmpty())
     541        return;
     542
     543    TObject *cam = (TObject*)IsA()->New();
     544    cam->Copy(*this);
     545    delete cam;
     546}
    551547
    552548// --------------------------------------------------------------------------
     
    566562    {
    567563        MGeomCam::Class()->ReadBuffer(b, this);
    568 
    569 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,00)
    570         if (IsA()!=MGeomCam::Class() && fPixels.GetEntriesFast()==0)
    571         {
    572             MGeomCam *c = (MGeomCam*)IsA()->New();
    573             c->Copy(*this);
    574             delete c;
    575         }
    576 #endif
     564        StreamerWorkaround();
    577565    }
    578566    else
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.h

    r8920 r8921  
    5050    MGeomCam(UInt_t npix=0, Float_t dist=1, const char *name=NULL, const char *title=NULL);
    5151
    52     TObject *Clone(const char *newname=NULL) const;
    5352    void Copy(TObject &o) const;
    5453
    55     void CalcPixRatio();
    5654    // FIXME, workaround: this function is made public just to allow
    5755    // the use of some camera files from the 0.7 beta version in which the
    5856    // array containing pixel ratios is not initialized.
     57    void CalcPixRatio();
     58
     59    // FIXME, workaround broken streaming
     60    void StreamerWorkaround();
     61
    5962    void InitGeometry()
    6063    {
     
    106109    Int_t GetNeighbor(UInt_t idx, Int_t dir) const;
    107110
    108     virtual void Print(Option_t *opt=NULL)  const;
     111    void Print(Option_t *opt=NULL) const;
    109112
    110113    ClassDef(MGeomCam, 5)  // Geometry base class for the camera
Note: See TracChangeset for help on using the changeset viewer.