Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9575)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9576)
@@ -18,4 +18,29 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2010/04/22 Thomas Bretz
+
+   * showplot.cc:
+     - added --debug-mem option
+
+   * mbase/MParSpline.cc, mhbase/MH3.cc, mhbase/MHn.cc,
+     mhflux/MHAlpha.cc, mhist/MHCamEvent.cc:
+     - added missing call to the RecursiveRemove of the base class
+
+   * mfileio/MReadTree.cc:
+     - In the case Notify failed since about two years accidentaly
+       kTRUE instead of kERROR was returned
+
+   * mfileio/MWriteRootFile.cc:
+     - added some more debug output
+
+   * mhflux/MAlphaFitter.cc:
+     - Return if fit failed
+
+   * mhflux/MHPhi.cc:
+     - avoid inf and nan when producing histogram (the divisor could
+       have been zero in case of the inetgral of an empty histogram)
+
+
 
  2010/04/21 Thomas Bretz
@@ -47,7 +72,14 @@
 
 
+ 2010/04/20 Thomas Bretz
+
+   * mfileio/MReadTree.cc:
+     - no error was returned anymore when Notify() failed. Fixed.
+
+
+
  2010/04/19 Thomas Bretz
 
-   * mase/MStatusArray.cc:
+   * mbase/MStatusArray.cc:
      - added a workaround to prevent crashes in case of double
        deleteion of the fHistogram in TGraphs
Index: trunk/MagicSoft/Mars/mbase/MParSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParSpline.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mbase/MParSpline.cc	(revision 9576)
@@ -327,3 +327,5 @@
     if (obj==fSpline)
         fSpline=0;
-}
+
+    MParContainer::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 9576)
@@ -1001,5 +1001,5 @@
         case MChain::kFatalError:
             *fLog << err << GetDescriptor() << " - ERROR: Notify() failed." << endl;
-            return kTRUE;
+            return kERROR;
         case MChain::kCannotAccessFile:
             *fLog << err << GetDescriptor() << " - ERROR: TChain::LoadTree is unable to access requested file." << endl;
Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 9576)
@@ -716,5 +716,5 @@
             if (!b->GetBranch()->Fill())
             {
-                *fLog << err << "ERROR - Zero bytes written to branch '" << b->GetBranch()->GetName() << "'... abort." << endl;
+                *fLog << err << "ERROR - MWriteRootFile: Zero bytes written to branch '" << b->GetBranch()->GetName() << "'... abort." << endl;
                 return kFALSE;
             }
@@ -730,4 +730,11 @@
     {
         TTree *t = (TTree*)fTrees[idx];
+        if (!t)
+        {
+            *fLog << err << "ERROR - MWriteRootFile: The Tree with index " << idx << endl;
+            *fLog << " in fTrees is NULL. This should never happen. Please send" << endl;
+            *fLog << " a bug report." << endl;
+            return kFALSE;
+        }
 
         //
@@ -746,5 +753,5 @@
         if (!t->Fill())
         {
-            *fLog << err << "ERROR - Zero bytes written to tree '" << t->GetName() << "'... abort." << endl;
+            *fLog << err << "ERROR - MWriteRootFiole: Zero bytes written to tree '" << t->GetName() << "'... abort." << endl;
             return kFALSE;
         }
Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 9576)
@@ -1306,3 +1306,5 @@
     if (obj==fHist)
         fHist = 0;
-}
+
+    MH::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/mhbase/MHn.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 9576)
@@ -609,3 +609,5 @@
             fHist[i]->RecursiveRemove(obj);
     }
-}
+
+    MH::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 9576)
@@ -208,5 +208,7 @@
     //           Q  quiet mode
     //           E  Perform better Errors estimation using Minos technique
-    h.Fit(fFunc, "NQI", "", fBgMin, fBgMax);
+    if (h.Fit(fFunc, "NQI", "", fBgMin, fBgMax))
+        return kFALSE;
+
     fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF();
 
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 9576)
@@ -1153,3 +1153,5 @@
     if (obj==fOffData)
         fOffData = 0;
-}
+
+    MH::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/mhflux/MHPhi.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHPhi.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mhflux/MHPhi.cc	(revision 9576)
@@ -355,7 +355,10 @@
     TVirtualPad *pad4 = gPad->GetPad(4);
 
+    const Double_t i2 = fHInhom.Integral();
+/*
     Double_t sig2 = 0;
     Double_t bg2  = 0;
     Double_t f2   = 1;
+*/
     TH1D *htemp = pad1 ? dynamic_cast<TH1D*>(pad1->FindObject("Template")) : NULL;
     if (htemp)
@@ -373,8 +376,13 @@
             fHPhi.Copy(*res);
 
+            const Double_t i0 = res->Integral(fNumBinsSignal+1, 9999);
+            const Double_t i1 = fHInhom.Integral(fNumBinsSignal+1, 9999);
+            const Double_t i3 = htemp->Integral();
+            const Double_t i4 = htemp->Integral(fNumBinsSignal+1, 9999);
+
             // Scale inhomogeneity to match the phi-plot in the off-region
-            sc1 = res->Integral(fNumBinsSignal+1, 9999)/fHInhom.Integral(fNumBinsSignal+1, 9999);
+            sc1 = i1==0 ? 0 : i0/i1;
             // Scale inhomogeneity to match the phi-plot in the off-region
-            sc2 = fHInhom.Integral()/htemp->Integral();
+            sc2 = i3==0 ? 0 : i2/i3;
 
             res->Add(&fHInhom, -sc1);
@@ -383,9 +391,9 @@
             res->SetDirectory(0);
 
-            htemp->Scale(res->Integral(fNumBinsSignal+1, 9999)/htemp->Integral(fNumBinsSignal+1, 9999));
-
-            sig2 = res->Integral(1, fNumBinsSignal);
-            bg2  = fHPhi.Integral(fNumBinsSignal+1, 9999);
-            f2   = htemp->Integral(1, fNumBinsSignal)/htemp->Integral(fNumBinsSignal+1, 9999);
+            htemp->Scale(i4==0 ? 0 : i0/i4);
+
+            //sig2 = res->Integral(1, fNumBinsSignal);
+            //bg2  = fHPhi.Integral(fNumBinsSignal+1, 9999);
+            //f2   = htemp->Integral(1, fNumBinsSignal)/i4;
         }
 
@@ -403,6 +411,8 @@
     if (htemp)
     {
+        const Double_t integ = htemp->Integral();
+
         fHTemplate.Copy(*htemp);
-        htemp->Scale(fHInhom.Integral()/htemp->Integral());
+        htemp->Scale(integ==0 ? 0 : i2/integ);
         htemp->SetName("Template");
         htemp->SetDirectory(0);
Index: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/mhist/MHCamEvent.cc	(revision 9576)
@@ -409,3 +409,5 @@
     if (obj==fSum)
         fSum = 0;
-}
+
+    MH::RecursiveRemove(obj);
+}
Index: trunk/MagicSoft/Mars/showplot.cc
===================================================================
--- trunk/MagicSoft/Mars/showplot.cc	(revision 9575)
+++ trunk/MagicSoft/Mars/showplot.cc	(revision 9576)
@@ -3,4 +3,5 @@
 #include <TGClient.h>
 #include <TRint.h>
+#include <TObjectTable.h>
 
 #include "MLog.h"
@@ -68,4 +69,5 @@
     gLog << "   --auto-size               Determin optimum size (not available in batch mode)" << endl;
     gLog << endl;
+    gLog << "   --debug-mem               Debug memory usage" << endl;
     gLog << "   --version, -V             Show startup message with version number" << endl;
     gLog << "   -?, -h, --help            This help" << endl;
@@ -165,4 +167,5 @@
     const Bool_t kBatch      = arg.HasOnlyAndRemove("-b");
     const Bool_t kRoot       = arg.HasOnlyAndRemove("-r");
+    const Bool_t kDebugMem   = arg.HasOnlyAndRemove("--debug-mem");
 
     const Int_t  kTab        = arg.GetIntAndRemove("--tab=", -1);
@@ -231,4 +234,7 @@
         return 3;
     }
+
+    if (kDebugMem)
+        TObject::SetObjectStat(kTRUE);
 
     //
@@ -314,4 +320,11 @@
     app->Run(kFALSE);
     delete app;
+
+    if (TObject::GetObjectStat())
+    {
+        TObject::SetObjectStat(kFALSE);
+        gObjectTable->Print();
+    }
+
     return 0;
 }
