Ignore:
Timestamp:
10/26/09 15:13:28 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MStatusArray.cc

    r9039 r9519  
    7272// --------------------------------------------------------------------------
    7373//
     74// Remove objects matching the id (the first character of their class
     75// name) recuresively
     76//
     77void MStatusArray::RecursiveDelete(TVirtualPad *p, const char id) const
     78{
     79    if (!p)
     80        return;
     81
     82    TIter Next2(p->GetListOfPrimitives());
     83    TObject *o=0;
     84    while ((o=Next2()))
     85    {
     86        if (!dynamic_cast<TVirtualPad*>(o) && (o->ClassName()[0]==id || id==0))
     87            delete p->GetListOfPrimitives()->Remove(o);
     88        else
     89            RecursiveDelete(dynamic_cast<TVirtualPad*>(o), id);
     90    }
     91
     92}
     93
     94// --------------------------------------------------------------------------
     95//
     96// Make sure to set the kMustCleanup for all object in our tree
     97// which will later be deleted when the array is destructed.
     98//
     99void MStatusArray::SetCleanup(TObject *obj) const
     100{
     101    if (!obj)
     102        return;
     103
     104    TVirtualPad *pad = dynamic_cast<TVirtualPad*>(obj);
     105
     106    // Do not set the bit for pads because it would end in
     107    // endless recursions
     108    if (pad && !dynamic_cast<TCanvas*>(obj))
     109        obj->ResetBit(kMustCleanup);
     110    else
     111        obj->SetBit(kMustCleanup);
     112
     113    if (!pad)
     114        return;
     115
     116    TIter Next(pad->GetListOfPrimitives());
     117    TObject *o=0;
     118    while ((o=Next()))
     119        SetCleanup(o);
     120}
     121
     122// --------------------------------------------------------------------------
     123//
     124// Try to do a delete of the whole list in a way which is less vulnarable
     125// to double deletion due to wrongly set bits or other things
     126//
     127void MStatusArray::Delete(Option_t *)
     128{
     129    // Add this to the list of cleanups to ensure as many cleaning
     130    // operations as possible are propagated
     131    gROOT->GetListOfCleanups()->Add(this);
     132
     133    // First make sure that all kMustCleanup bits are se
     134    TIter Next(this);
     135    TObject *o=0;
     136    while ((o=Next()))
     137        SetCleanup(o);
     138
     139    // Now delete the MARS object first because we have full control
     140    // of them
     141    TIter Next2(this);
     142    while ((o=Next2()))
     143        RecursiveDelete(dynamic_cast<TVirtualPad*>(o), 'M');
     144
     145    // Now delete all root objects
     146    TIter Next3(this);
     147    while ((o=Next3()))
     148        RecursiveDelete(dynamic_cast<TVirtualPad*>(o));
     149
     150    // And delete all the rest
     151    TObjArray::Delete();
     152
     153    // Remove it from the list again
     154    gROOT->GetListOfCleanups()->Remove(this);
     155}
     156
     157// --------------------------------------------------------------------------
     158//
    74159// If o==NULL a new status display is created, otherwise the one with name o
    75160// is searched in gROOT->GetListOfSpecials().
     
    335420}
    336421
     422MStatusArray::~MStatusArray()
     423{
     424    // This is the destructor from TObjArray...
     425    // It must be here, because for some reason I don't know it
     426    // is otherwise not correctly executed from the Interpreter
     427    // (root 5.12/00f)
     428    if (IsOwner())
     429        Delete();
     430
     431    TStorage::Dealloc(fCont);
     432
     433    fCont = 0;
     434    fSize = 0;
     435}
     436
    337437// --------------------------------------------------------------------------
    338438//
     
    344444    // It seems that the contents are not properly deleted by TObjArray::Read
    345445    Delete();
     446
     447    SetOwner();
    346448
    347449    const TString keyname = name?name:"MStatusDisplay";
     
    372474            TObject *o2=0;
    373475            while ((o2=Next2()))
    374                 if (o2->InheritsFrom("MParContainer"))
     476                if (o2->InheritsFrom(MParContainer::Class()))
    375477                    o2->SetBit(kCanDelete);
    376478        }
  • trunk/MagicSoft/Mars/mbase/MStatusArray.h

    r9490 r9519  
    1919    };
    2020
     21    void     SetCleanup(TObject *obj) const;
     22    void     RecursiveDelete(TVirtualPad *p, const char id=0) const;
     23
    2124    void     SetCanDelete(const TCollection *list) const;
    2225    void     SetMyCanDelete(const TCollection *list) const;
     
    2831    MStatusArray() : TObjArray() { }
    2932    MStatusArray(const MStatusDisplay &d);
     33    ~MStatusArray();
    3034
    3135    TObject *DisplayIn(Option_t *o=0) const;         // *MENU*
     
    5660
    5761    void EnableTH1Workaround(const TCollection *list=0) const;
     62    void Delete(Option_t *option="");
    5863
    5964    ClassDef(MStatusArray, 0) // Helper class for status display
Note: See TracChangeset for help on using the changeset viewer.