Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8641)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8642)
@@ -18,4 +18,48 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+ 2007/07/18 Thomas Bretz
+
+   * mpointing/MPointingDevCalc.cc:
+     - changed limit for starguide calibration from 87751 to 85240
+
+   * mbase/MContinue.cc:
+     - changed some debug output
+     - fixed a bug if the filter already decided to be skiped
+
+   * mbase/MEvtLoop.cc:
+     - changed RecursiveRemove to use the newly implemented scheme
+
+   * mbase/MParContainer.[h,cc], mbase/MParList.[h,cc],
+     mbase/MTask.[h,cc], mbase/MTaskList.[h,cc]:
+     - improved debug output
+     - added RecursiveRemove member function
+     - removed screen output from Remove function
+     - call RecursiveRemove when something is removed from the list
+
+   * mbase/MStatusDisplay.h:
+     - aaded a new enum kLastElement
+
+   * mbase/MTask.cc:
+     - set kMustCleanup for fFilter
+
+   * mbase/MTaskList.cc:
+     - added debugg code
+
+   * mfileio/MWriteRootFile.cc:
+     - always set kMustCleanup when a TFile is created
+     - make sure RecursiveRemove is called in the correct way
+
+   * mmain/MEventDisplay.h:
+     - fixed the starting index for the first gui element
+
+   * msignal/MExtractor.cc:
+     - added some initializations in the constructor suggested by 
+       valgrind
+
+   * mcalib/MCalibrateData.cc:
+     - improved output
+
 
 
Index: trunk/MagicSoft/Mars/mbase/MContinue.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 8642)
@@ -131,6 +131,6 @@
         }
 
-        *fLog << err << dbginf << "Unknown fatal Error! (fFilter=NULL?!?)" << endl;
-        return kFALSE;
+        *fLog << inf << "My filter has vanished... skipping." << endl;
+        return kSKIP;
     }
 
@@ -153,5 +153,5 @@
     if (!fTaskList->AddToListBefore(GetFilter(), this))
     {
-        *fLog << err << dbginf << "ERROR - Adding filter before MContinue... abort." << endl;
+        *fLog << err << dbginf << "ERROR - Adding filter before MContinue failed... abort." << endl;
         return kFALSE;
     }
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 8642)
@@ -102,5 +102,5 @@
 // default constructor
 //
-MEvtLoop::MEvtLoop(const char *name) : fParList(NULL), fProgress(NULL)
+MEvtLoop::MEvtLoop(const char *name) : fParList(NULL), fTaskList(NULL), fProgress(NULL)
 {
     fName = name;
@@ -1108,4 +1108,9 @@
 void MEvtLoop::RecursiveRemove(TObject *obj)
 {
+    // If the tasklist was deleted... remove it
+    if (obj==fTaskList)
+        fTaskList = NULL;
+
+    // If the parlist was deleted...invalidate par- and tasklist
     if (obj==fParList)
     {
@@ -1114,15 +1119,16 @@
     }
 
+    // if the progress bar was deleted...remove it
     if (obj==fProgress)
         fProgress = NULL;
 
-    if (obj==fDisplay)
-        SetDisplay(NULL);
-
-    if (obj==fLog)
-    {
-        if (fParList)
-            fParList->SetLogStream(NULL);
-        SetLogStream(NULL);
-    }
-}
+    // If it was something else check par- and tasklist
+    if (fParList)
+        fParList->RecursiveRemove(obj);
+    else
+        if (fTaskList) // Note that the tasklist is included in the parlist
+            fTaskList->RecursiveRemove(obj);
+
+    // Now check for fDisplay and fLog
+    MParContainer::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 8642)
@@ -71,4 +71,6 @@
 #include "MLogManip.h"
 
+#include "MStatusDisplay.h"
+
 TList *gListOfPrimitives; // forard declaration in MParContainer.h
 
@@ -116,5 +118,5 @@
         return;
 
-    *fLog << all << "Deleting " << GetDescriptor() << endl;
+    *fLog << all << "Deleting " << this << " " << GetDescriptor() << endl;
     if (TestBit(kMustCleanup) && gROOT && gROOT->MustClean())
     {
@@ -921,2 +923,26 @@
     return ((TEnv&)env).GetValue(prefix, dflt);
 }
+
+// --------------------------------------------------------------------------
+//
+// If object to remove is fDisplay set fDisplay to NULL.
+// If object to remove is fLog     set fLog     to NULL.
+// Call TObject::RecursiveRemove
+//
+void MParContainer::RecursiveRemove(TObject *obj)
+{
+    if (obj==fDisplay)
+        fDisplay=NULL;
+
+    if (obj==fLog)
+        fLog=NULL;
+
+    if (fDisplay)
+        fDisplay->RecursiveRemove(obj);
+
+    if (fLog)
+        fLog->RecursiveRemove(obj);
+
+    TObject::RecursiveRemove(obj);
+}
+
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 8642)
@@ -146,4 +146,6 @@
     MParContainer *GetNewObject(const char *name, TClass *base=MParContainer::Class()) const;
 
+    void RecursiveRemove(TObject *obj);
+
     ClassDef(MParContainer, 0)  //The basis for all parameter containers
 };
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 8642)
@@ -312,14 +312,33 @@
 
     TObject *obj = fContainer->Remove(cont);
-    if (!obj)
-    {
-        *fLog << warn << "Object not found in list..." << endl;
-        return;
-    }
-
-    *fLog << inf << "MParContainer '" << cont->GetName() << "' removed..." << endl;
-
-    if (IsOwner() && !fAutodelete->FindObject(obj))
+
+    fContainer->RecursiveRemove(obj);
+
+    // if (!obj)
+    // {
+        //        *fLog << warn << "Object not found in list..." << endl;
+    //    return;
+    //}
+
+//    *fLog << inf << "MParContainer '" << cont->GetName() << "' removed..." << endl;
+
+    if (obj && IsOwner() && !fAutodelete->FindObject(obj))
         delete obj;
+}
+
+// --------------------------------------------------------------------------
+//
+// Call MParContainer::RecursiveRemove
+// Call fContainer->RecursiveRemove
+//
+void MParList::RecursiveRemove(TObject *obj)
+{
+    MParContainer::RecursiveRemove(obj);
+
+    if (obj==fContainer)
+        fContainer = NULL;
+
+    if (fContainer)
+        fContainer->RecursiveRemove(obj);
 }
 
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 8642)
@@ -86,4 +86,6 @@
     }
 
+    void RecursiveRemove(TObject *obj);
+
     void Reset();
     void SetReadyToSave(Bool_t flag=kTRUE);
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 8642)
@@ -66,5 +66,7 @@
         kPicMagic, kPicMars,
         // kGui
-        kSearch, kTabs
+        kSearch, kTabs,
+        // kLastElement
+        kLastElement
     } Status_t;
 
Index: trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 8642)
@@ -147,6 +147,9 @@
 {
     fFilter=filter;
-    if (filter)
-        AddToBranchList(filter->GetDataMember());
+    if (!filter)
+        return;
+
+    fFilter->SetBit(kMustCleanup);    // Better is better ;-)
+    AddToBranchList(filter->GetDataMember());
 }
 
@@ -557,2 +560,18 @@
     *fLog << "%) Evts skipped: " << str << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+// If obj==fFilter set fFilter to NULL
+// Call MParcontainer::RecursiveRemove
+//
+void MTask::RecursiveRemove(TObject *obj)
+{
+    if (obj==fFilter)
+        fFilter=NULL;
+
+    if (fFilter)
+        fFilter->RecursiveRemove(obj);
+
+    MParContainer::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.h	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MTask.h	(revision 8642)
@@ -123,4 +123,7 @@
     void SavePrimitive(ofstream &out, Option_t *o="");
 
+    // TObject
+    void RecursiveRemove(TObject *obj);
+
     ClassDef(MTask, 2) //Abstract base class for a task
 };
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 8642)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -80,4 +80,7 @@
 using namespace std;
 
+//#define DEBUG_PROCESS
+#undef DEBUG_PROCESS
+
 const TString MTaskList::gsDefName  = "MTaskList";
 const TString MTaskList::gsDefTitle = "A list for tasks to be executed";
@@ -89,5 +92,5 @@
 // this name in the parameter list (by MEvtLoop::SetParList)
 //
-MTaskList::MTaskList(const char *name, const char *title) : fNumPasses(0), fNumPass(0)
+MTaskList::MTaskList(const char *name, const char *title) : fTasks(0), fParList(0), fNumPasses(0), fNumPass(0)
 {
     fName  = name  ? name  : gsDefName.Data();
@@ -465,8 +468,37 @@
 void MTaskList::Remove(MTask *task)
 {
+    if (!task)
+        return;
+
+    // First remove it from the list(s) so that a later RecursiveRemove
+    // cannot fint the task again
     TObject *obj = fTasks->Remove(task);
 
-    if (TestBit(kIsOwner))
+    // Now do a recursive remove on all other tasks.
+    fTasks->RecursiveRemove(task);
+
+    if (obj && TestBit(kIsOwner))
         delete obj;
+}
+
+// --------------------------------------------------------------------------
+//
+// Call MTask::RecursiveRemove
+// Call fTasks->RecursiveRemove
+//
+void MTaskList::RecursiveRemove(TObject *obj)
+{
+    MTask::RecursiveRemove(obj);
+
+    if (obj==fTasks)
+        fTasks=NULL;
+
+    if (fTasks)
+    {
+        fTasks->RecursiveRemove(obj);
+
+        // In theory this call is obsolete
+        fTasksProcess.RecursiveRemove(obj);
+    }
 }
 
@@ -620,4 +652,8 @@
     MTask *task=NULL;
 
+#ifdef DEBUG_PROCESS
+    *fLog << all << "ProcessTaskList - " << GetDescriptor() << " - start." << endl;
+#endif
+
     //
     // loop over all tasks for processing
@@ -626,4 +662,8 @@
     while ( (task=(MTask*)Next()) )
     {
+#ifdef DEBUG_PROCESS
+        *fLog << all << "Process - " << (void*)task << " " << flush;
+        *fLog << task->GetDescriptor() << "... " << flush;
+#endif
         //
         // if the task has the wrong stream id skip it.
@@ -646,4 +686,7 @@
             // everything was OK: go on with the next task
             //
+#ifdef DEBUG_PROCESS
+            *fLog << "true." << endl;
+#endif
             continue;
 
@@ -668,4 +711,7 @@
             // something occured: skip the rest of the tasks for this event
             //
+#ifdef DEBUG_PROCESS
+            *fLog << "continue." << endl;
+#endif
             rc = kCONTINUE;
             break;
@@ -677,4 +723,8 @@
         break;
     }
+
+#ifdef DEBUG_PROCESS
+    *fLog << all << "ProcessTaskList - " << GetDescriptor() << " - done." << endl;
+#endif
 
     return rc;
Index: trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 8641)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 8642)
@@ -97,4 +97,6 @@
     Bool_t WriteEnv(TEnv &env, TString prefix, Bool_t print=kFALSE) const;
 
+    void   RecursiveRemove(TObject *obj);
+
     operator TIterator*() const;
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 8642)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MCalibrateData.cc,v 1.69 2007-05-10 12:14:54 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MCalibrateData.cc,v 1.70 2007-07-18 19:30:12 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -668,5 +668,5 @@
             *fLog << warn << GetDescriptor() << ": ";
             *fLog << "Conv.factor " << calibConv << " of Pixel " << pixidx << " out of range ]";
-            *fLog << fCalibConvMinLimit << "," << fCalibConvMaxLimit << "[... set to 0. " << endl;
+            *fLog << fCalibConvMinLimit << "," << fCalibConvMaxLimit << "[... set unsuitable. " << endl;
 	  }
 
Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 8642)
@@ -101,6 +101,5 @@
     //fTrees.SetOwner();
 
-    gROOT->GetListOfCleanups()->Add(this); // To remove fDisplay
-    SetBit(kMustCleanup);
+    gROOT->GetListOfCleanups()->Add(this); // To remove fOut if deleted
 }
 
@@ -133,4 +132,5 @@
 
         file->SetOption(option); // IMPORTANT!
+        file->SetBit(kMustCleanup);
         ResetBit(kIsNotOwner);
         return file;
@@ -227,4 +227,5 @@
     {
         fOut = new TFile("/dev/null", "READ", ftitle, comp);
+        fOut->SetBit(kMustCleanup);
         return;
     }
@@ -1071,8 +1072,15 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// If the output file is deleted set fOut to NULL.
+// Call MTask::RecursiveRemove
+//
 void MWriteRootFile::RecursiveRemove(TObject *obj)
 {
     if (obj==fOut)
-        fOut=0;
+        fOut=NULL;
+
+    MWriteFile::RecursiveRemove(obj);
 }
 
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.h	(revision 8641)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.h	(revision 8642)
@@ -19,5 +19,5 @@
     enum
     {
-        kEvtPrev = MStatusDisplay::kSearch + 1,
+        kEvtPrev = MStatusDisplay::kLastElement + 1,
         kEvtNext,
         kEvtNumber,
Index: trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 8641)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 8642)
@@ -136,5 +136,5 @@
     : fResolutionPerPheHiGain(0), fResolutionPerPheLoGain(0),
     fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL), fSignal(NULL),
-    fNumHiGainSamples(0), fNumLoGainSamples(0)
+    fLoGainLast(0), fNumHiGainSamples(0), fNumLoGainSamples(0)
 {
     fName  = name  ? name  : "MExtractor";
