Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8708)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8709)
@@ -20,4 +20,61 @@
 
 
+ 2007/08/25 Thomas Bretz
+
+   * sponde.cc:
+     - check for write permissionbefore job is started
+
+   * sponde.rc, sponde_onoff.rc:
+     - cosmetics to comment
+
+   * macros/train/traindisp.C:
+     - better order of comments
+
+   * manalysis/MParameterCalc.[h,cc]:
+     - print name of output container
+     - allow setting name of output container from resource file
+
+   * mbase/MStatusDisplay.cc:
+     - added sanity check for batch mode in SetProgressBarPosition
+
+   * mfbase/MFDataPhrase.[h,cc]:
+     - initialize new data member fDefault in constructors
+     - increased class version number by one
+
+   * mhbase/MH.cc:
+     - do not divide by zero in SetBinomialErrors
+
+   * mhbase/MH3.[h,cc]:
+     - automatically set more log labels and suppress exponent
+
+   * mhbase/MHn.cc:
+     - set margin between new tabs in Divide to a small value
+
+   * mhflux/MHCollectionArea.cc:
+     - new default energy binning based on the typical simulation range
+
+   * mhflux/MHEnergyEst.cc:
+     - new default energy binning based on the typical simulation range
+     - set the impact binning to one bis as a default for speed
+       reasons. It is normally not used at all
+     - added two blue lines at the zero-bias level for convinience
+
+   * mhflux/MMcSpectrumWeight.cc:
+     - small cosmetics to Print-output
+
+   * mjobs/MJCut.cc:
+     - renamed the instances of the Calc* tasks
+     - store all three taskenvs
+
+   * mjobs/MJSpectrum.[h,cc]:
+     - handle a CalcDisp-task gotten from ganymed properly
+     - do not reexecute CalcHaronness for data
+     - renamed the instances of the Calc* tasks
+
+   * msql/MSQLMagic.cc, msql/MSQLServer.cc:
+     - delete created TSQLRow. They are not deleted automatically
+
+
+
  2007/08/24 Thomas Bretz
 
@@ -59,5 +116,40 @@
      - it turned out that we use 1/2 and not 0/1 as expected
 
-
+   * ganymed.rc, ganymed_onoff.rc, ganymed_wobble.rc:
+     - updated some comments
+     - added new CutT
+
+   * sponde.rc, sponde_onoff.rc:
+     - updated with thousands of comments
+     - adapted to new sponde respources
+     - added examples for missing resources
+     - added a new energy estimation formula which can be used instead
+       of using the random forest
+
+   * macros/optim/optimonoff.C, macros/optim/optimwobble.C:
+     - updated with the latest cuts and some comments
+
+   * macros/train/traindisp.C:
+     - updated with the latest knowledge and cuts
+     - updated with more examples
+
+   * mfbase/MFDataPhrase.[h,cc]:
+     - added a default value which can be used if no phrase is setup
+     - allow to use a constrcutor without phrase but name and title
+
+   * mjobs/MJCut.cc:
+     - removed SetAllowEmpty from CutT
+     - initialize CutT with no phrase instead of an empty one
+
+   * mjobs/MJSpectrum.h:
+     - removed obsolete function definition for IntermediateLoop
+
+   * mranforest/MRanForestCalc.cc:
+     - if weights are used output the sum of the weights for control
+       purpose
+
+   * datacenter/macros/plotdb.C, datacenter/macros/plotoptical.C,
+     datacenter/macros/plotrundb.C:
+     - delete TSQLRow if allocated
 
 
@@ -182,5 +274,5 @@
    * datacenter/scripts/runcallisto
      - modified staging of files
-   
+
    * datacenter/scripts/runstar
      - corrected server and added logfile entry for staging of files
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 8708)
+++ trunk/MagicSoft/Mars/NEWS	(revision 8709)
@@ -226,4 +226,9 @@
      positions have disappeared.
 
+   - ganymed: There is a new tab "CutT" it contains the VsSize plots
+     with the CutT, whihc is defined in ganymed.rc, applied. It
+     is resonable to use your theta-cut for it, to see if there is
+     something strange (sparks!) in your signal-region.
+
    - optim, sponde: should now properly support three off-regions.
      Just produce your ganymed summary files with three off-regions.
@@ -238,4 +243,9 @@
      Be carefull in case of three off-regions when switching on
      scale mode. Make sure that the scale interval is set correctly.
+
+   - sponde: sponde.rc and sponde_onoff.rc are now idetical
+
+   - sponde: the resouce files have been rewritten with a lot of
+     comments and a well working parametrization for an energy estimator
 
    - sponde: In the estimated energy versus monte carlo energy plot the
Index: trunk/MagicSoft/Mars/macros/train/traindisp.C
===================================================================
--- trunk/MagicSoft/Mars/macros/train/traindisp.C	(revision 8708)
+++ trunk/MagicSoft/Mars/macros/train/traindisp.C	(revision 8709)
@@ -88,5 +88,5 @@
 
     /*
-     -------------------- Magic-Cuts ----------------------
+     // -------------------- Magic-Cuts ----------------------
      MFMagicCuts cuts;
      cuts.SetHadronnessCut(MFMagicCuts::kArea);
@@ -111,9 +111,5 @@
      opt.AddPreCut(&cuts);
 
-     -------------------- Energy Slope --------------------
-     MFEnergySlope slope(-2.8);
-     opt.AddPreCut(&slope);
-
-     -------------------- Other cuts ----------------------
+     // -------------------- Other cuts ----------------------
      opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
      opt.AddPreCut("MHillas.fSize>200");
@@ -121,20 +117,5 @@
      opt.AddPreCut("MPointingPos.fZd<25");
 
-     ------------------ Zd distribution -------------------
-     TFile file("ganymed00001111.root");
-
-     MStatusArray arr;
-     if (arr.Read()<=0)
-        return;
-     TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta",  "TH1D", "OnTime");
-     if (!vstime)
-         return;
-
-     MMcSpectrumWeight weight;
-     weight.SetWeightsZd(vstime);
-     opt.AddPreTask(&weight);
-
-     ---------------------- Histogram  --------------------
-
+     // ---------------------- Histogram  --------------------
      MHn hist("MyHist", "Energy Residual (lg E_{est} - lg E_{mc})");
 
@@ -157,5 +138,30 @@
      opt.AddTestTask(&fill);
 
-     ------------------------------------------------------
+     // -------------------- Energy Slope --------------------
+     // Note, that weight normally doesn't improve anything here.
+     // This is a way to throw away events to a different slope
+     MFEnergySlope slope(-4.0); // New slope for mc spectrum
+     opt.AddPreCut(&slope);     // throw away events to change slope
+
+     // This is a way to weight the events to a different spectrum
+     MMcSpectrumWeight weight;
+     weight.SetFormula("pow(X/300, -2.31-0.26*log10(X/300))");
+     opt.SetWeights(&weight);
+
+     // ------------------ Zd distribution -------------------
+     TFile file("ganymed00001111.root");
+
+     MStatusArray arr;
+     if (arr.Read()<=0)
+        return;
+     TH1D *vstime = (TH1D*)arr.FindObjectInCanvas("Theta",  "TH1D", "OnTime");
+     if (!vstime)
+         return -1;
+
+     MMcSpectrumWeight weight;
+     weight.SetWeightsZd(vstime);
+     opt.AddPreTask(&weight);
+
+     // ------------------------------------------------------
     */
 
Index: trunk/MagicSoft/Mars/manalysis/MParameterCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MParameterCalc.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/manalysis/MParameterCalc.cc	(revision 8709)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz  6/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2005
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -36,5 +36,5 @@
 //
 // Output:
-//   MEnergyEst
+//   fNameParameter [MParameterD] <default=MParameterD>
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -110,5 +110,5 @@
         return kFALSE;
 
-    *fLog << inf << "Rule: " << fData->GetRule() << endl;
+    *fLog << inf << "Rule for " << fNameParameter << ": " << fData->GetRule() << endl;
 
     if (!fData->PreProcess(plist))
@@ -142,4 +142,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Print some execution statistics
+//
 Int_t MParameterCalc::PostProcess()
 {
@@ -180,4 +184,5 @@
 //   test.rc:
 //     MyEstimator.Rule: {0} + {1}
+//     MyEstimator.NameOutput: MParameterD
 //     MyEstimator.0: log10(MHillas.fSize)
 //     MyEstimator.1: 5.5
@@ -206,4 +211,7 @@
     }
 
-    return kTRUE;
-}
+    if (IsEnvDefined(env, prefix, "NameOutput", print))
+        fNameParameter = GetEnvValue(env, prefix, "NameOutput", fNameParameter);
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 8709)
@@ -604,4 +604,7 @@
 void MStatusDisplay::SetProgressBarPosition(Float_t p, Bool_t upd)
 {
+    if (!gClient || gROOT->IsBatch())
+        return;
+
     fBar->SetPosition(p);
     if (upd)
Index: trunk/MagicSoft/Mars/mfbase/MFDataPhrase.cc
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFDataPhrase.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mfbase/MFDataPhrase.cc	(revision 8709)
@@ -71,4 +71,9 @@
 //        gROOT->ProcessLineFast("line");
 //
+//
+// Class Version 2:
+// ----------------
+//  + Bool_t fDefault
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MFDataPhrase.h"
@@ -96,5 +101,6 @@
 // Default Constructor. Don't use.
 //
-MFDataPhrase::MFDataPhrase() : fData(NULL), fAllowEmpty(kFALSE)
+MFDataPhrase::MFDataPhrase()
+    : fData(NULL), fAllowEmpty(kFALSE), fDefault(kTRUE)
 {
     fName  = gsDefName.Data();
@@ -107,5 +113,6 @@
 // the class description above.
 //
-MFDataPhrase::MFDataPhrase(const char *text, const char *name, const char *title) : fData(NULL), fAllowEmpty(kFALSE)
+MFDataPhrase::MFDataPhrase(const char *text, const char *name, const char *title)
+    : fData(NULL), fAllowEmpty(kFALSE), fDefault(kTRUE)
 {
     fName  = name  ? name  : gsDefName.Data();
Index: trunk/MagicSoft/Mars/mfbase/MFDataPhrase.h
===================================================================
--- trunk/MagicSoft/Mars/mfbase/MFDataPhrase.h	(revision 8708)
+++ trunk/MagicSoft/Mars/mfbase/MFDataPhrase.h	(revision 8709)
@@ -61,5 +61,5 @@
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
 
-    ClassDef(MFDataPhrase, 1) // A Filter for cuts in any data member
+    ClassDef(MFDataPhrase, 2) // A Filter for cuts in any data member
 };
 
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 8709)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.35 2007-08-22 18:22:49 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.36 2007-08-25 15:30:24 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -1398,4 +1398,10 @@
         //const Double_t rc = ((1-2*w)*e1*e1+w*w*e2*e2)/(b2*b2);
 
+        if (b2==0)
+        {
+            hres.SetBinError(binx, 0);
+            continue;
+        }
+
         const Double_t c = c2==0 ? 1 : c1/c2;
         const Double_t u = b2==0 ? 0 : b1/b2;
Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 8709)
@@ -574,4 +574,14 @@
 }
 
+void MH3::HandleLogAxis(TAxis &axe) const
+{
+    if (axe.GetXmax()>3000*axe.GetXmin())
+        return;
+
+    axe.SetMoreLogLabels();
+    if (axe.GetXmax()<5000)
+        axe.SetNoExponent();
+}
+
 // --------------------------------------------------------------------------
 //
@@ -582,5 +592,6 @@
 //   PROFY: Draw a y-profile into the histogram (for 2D histograms only)
 //   ONLY:  Draw the profile histogram only (for 2D histograms only)
-//   BLUE:  Draw the profile in blue color instead of the histograms line color
+//   BLUE:  Draw the profile in blue color instead of the histograms
+//          line color
 //
 // If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
@@ -597,7 +608,19 @@
     pad->SetGridy();
 
-    if (fHist->TestBit(kIsLogx)) pad->SetLogx();
-    if (fHist->TestBit(kIsLogy)) pad->SetLogy();
-    if (fHist->TestBit(kIsLogz)) pad->SetLogz();
+    if (fHist->TestBit(kIsLogx))
+    {
+        pad->SetLogx();
+        HandleLogAxis(*fHist->GetXaxis());
+    }
+    if (fHist->TestBit(kIsLogy))
+    {
+        pad->SetLogy();
+        HandleLogAxis(*fHist->GetYaxis());
+    }
+    if (fHist->TestBit(kIsLogz))
+    {
+        pad->SetLogz();
+        HandleLogAxis(*fHist->GetZaxis());
+    }
 
     fHist->SetFillStyle(4000);
Index: trunk/MagicSoft/Mars/mhbase/MH3.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 8708)
+++ trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 8709)
@@ -27,4 +27,6 @@
     Double_t    fScale[3];       // Scale for the three axis (eg unit)
     Byte_t      fStyleBits;      // Set the range of a histogram automatically in Finalize
+
+    void HandleLogAxis(TAxis &axe) const;
 
     void StreamPrimitive(ostream &out) const;
Index: trunk/MagicSoft/Mars/mhbase/MHn.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 8709)
@@ -410,31 +410,31 @@
 
         case 2:   // 2
-            pad->Divide(1,2);
+            pad->Divide(1,2, 1e-5, 1e-5);
             break;
         case 3:   // 3
-            pad->Divide(2,2);
+            pad->Divide(2,2, 1e-5, 1e-5);
             delete pad->GetPad(4);
             break;
          case 4:   // 4
-            pad->Divide(2,2);
+            pad->Divide(2,2, 1e-5, 1e-5);
             break;
         case 5:   // 5
-            pad->Divide(3,2);
+            pad->Divide(3,2, 1e-5, 1e-5);
             delete pad->GetPad(6);
             break;
         case 6:   // 6
-            pad->Divide(3,2);
+            pad->Divide(3,2, 1e-5, 1e-5);
             break;
 
         case 12:  // 2
-            pad->Divide(2,1);
+            pad->Divide(2,1, 1e-5, 1e-5);
             break;
         case 13:  // 3
             break;
         case 14:  // 4
-            pad->Divide(2,2);
+            pad->Divide(2,2, 1e-5, 1e-5);
             break;
         case 15:  // 5
-            pad->Divide(2,3);
+            pad->Divide(2,3, 1e-5, 1e-5);
             pad->GetPad(4)->SetPad(0.51, 0.01, 0.99, 0.65);
             delete pad->GetPad(6);
Index: trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mhflux/MHCollectionArea.cc	(revision 8709)
@@ -99,5 +99,5 @@
 
     MBinning binsa, binse, binst;
-    binse.SetEdgesLog(15, 10, 1000000);
+    binse.SetEdgesLog(21, 6.3, 100000);
     binst.SetEdgesASin(67, -0.005, 0.665);
 
@@ -136,4 +136,5 @@
     MH::SetBinomialErrors(fHEnergy, *hsel, *hall);
 #endif
+
     fHEnergy.Scale(totalarea);
 
@@ -198,5 +199,4 @@
     }
 
-    // FIXME: Does this need some weighting with the number of produced events?
     if (runheader->GetImpactMax()>fMcAreaRadius*100)
     {
Index: trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc	(revision 8709)
@@ -95,8 +95,10 @@
 
     MBinning binsi, binse, binst, binsr;
-    binse.SetEdgesLog(25, 10, 1000000);
+    binse.SetEdgesLog(21, 6.3, 100000);
     binst.SetEdgesASin(51, -0.005, 0.505);
-    binsi.SetEdges(10, 0, 400);
     binsr.SetEdges(75, -1.75, 1.75);
+
+    // Use the binning in impact to do efficiency studies
+    binsi.SetEdges(1, 0, 1000);
 
     SetBinning(&fHEnergy,     &binse, &binse, &binst);
@@ -513,4 +515,8 @@
     line.DrawLine(0,0,1,1);
 
+    line.SetLineColor(kBlue);
+    line.SetLineWidth(2);
+    line.SetLineStyle(kDashed);
+
     pad2->cd(2);
     h = MakePlot(fHResolution, "zy");
@@ -521,4 +527,6 @@
     h->SetMaximum(1.3);
 
+    line.DrawLine(h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0);
+
     pad2->cd(3);
     h = MakePlot(fHResolution, "zx");
@@ -528,4 +536,6 @@
     h->SetMinimum(-1.3);
     h->SetMaximum(1.3);
+
+    line.DrawLine(h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0);
 }
 
Index: trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc	(revision 8709)
@@ -493,5 +493,5 @@
     if (hasold)
     {
-        *fLog << " Old Spectrum: " << GetFormulaSpecOldX();
+        *fLog << " Old Spectrum:  " << GetFormulaSpecOldX();
         if (fEnergyMin>=0 && fEnergyMax>0)
             *fLog << "   (I=" << GetSpecOldIntegral() << ")";
@@ -500,5 +500,5 @@
     if (hasnew)
     {
-        *fLog << " New Spectrum: " << GetFormulaSpecNewX();
+        *fLog << " New Spectrum:  " << GetFormulaSpecNewX();
         if (fEnergyMin>=0 && fEnergyMax>0)
             *fLog << "   (I=" << GetSpecNewIntegral() << ")";
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8709)
@@ -697,12 +697,12 @@
     SetupWriter(write1, "WriteAfterCut3");
 
-    MTaskEnv taskenv2("CalcHadronness");
-    taskenv2.SetDefault(fCalcHadronness);
-
-    MTaskEnv taskenv3("CalcDisp");
-    taskenv3.SetDefault(fCalcDisp);
-
-    MTaskEnv taskenv4("EstimateEnergy");
-    taskenv4.SetDefault(fEstimateEnergy);
+    MTaskEnv taskenv0("CalcDisp");
+    taskenv0.SetDefault(fCalcDisp);
+
+    MTaskEnv taskenv1("CalcHadronness");
+    taskenv1.SetDefault(fCalcHadronness);
+
+    MTaskEnv taskenv2("EstimateEnergy");
+    taskenv2.SetDefault(fEstimateEnergy);
 
     MParameterCalc setevtnum("MRawEvtHeader.fDAQEvtNumber", "SetEvtNumber");
@@ -788,8 +788,7 @@
     if (set.IsWobbleMode())
         tlist2.AddToList(&hcalc2);
-    //tlist2.AddToList(&taskenv1);
     tlist2.AddToList(&cont0);  
-    tlist2.AddToList(&taskenv2);
-    tlist2.AddToList(&taskenv3);
+    tlist2.AddToList(&taskenv0);
+    tlist2.AddToList(&taskenv1);
     tlist2.AddToList(&setrunnum);
     tlist2.AddToList(&setevtnum);
@@ -824,5 +823,5 @@
     }
     tlist2.AddToList(&cont3);
-    tlist2.AddToList(&taskenv4);
+    tlist2.AddToList(&taskenv2);
 
     if (write1)
@@ -863,8 +862,10 @@
     //if (taskenv1.GetTask())
     //    cont.Add(taskenv1.GetTask());
+    if (taskenv0.GetTask())
+        cont.Add(taskenv0.GetTask());
+    if (taskenv1.GetTask())
+        cont.Add(taskenv1.GetTask());
     if (taskenv2.GetTask())
         cont.Add(taskenv2.GetTask());
-    if (taskenv3.GetTask())
-        cont.Add(taskenv3.GetTask());
 
     if (!WriteTasks(set.GetNumAnalysis(), cont))
Index: trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8709)
@@ -86,5 +86,5 @@
 MJSpectrum::MJSpectrum(const char *name, const char *title)
     : fCutQ(0), fCut0(0),fCut1(0), fCut2(0), fCut3(0), fCutS(0),
-    fEstimateEnergy(0), fCalcHadronness(0),  fForceTheta(kFALSE)
+    fEstimateEnergy(0), fCalcHadronness(0),  fCalcDisp(0), fForceTheta(kFALSE)
 {
     fName  = name  ? name  : "MJSpectrum";
@@ -118,4 +118,6 @@
     if (fCalcHadronness)
         delete fCalcHadronness;
+    if (fCalcDisp)
+        delete fCalcDisp;
 }
 
@@ -261,4 +263,6 @@
         return -1;
     if (!ReadTask(fCalcHadronness, "CalcHadronness", kFALSE))
+        return -1;
+    if (!ReadTask(fCalcDisp,       "CalcDisp",       kFALSE))
         return -1;
 
@@ -664,11 +668,14 @@
     read.DisableAutoScheme();
     read.AddFile(fPathIn);
-
-    MTaskEnv taskenv0("CalcHadronness");
-    taskenv0.SetDefault(fCalcHadronness);
-
+/*
+    MTaskEnv taskenv0("CalcDisp");
+    taskenv0.SetDefault(fCalcDisp);
+
+    MTaskEnv taskenv1("CalcHadronness");
+    taskenv1.SetDefault(fCalcHadronness);
+ */
     MEnergyEstimate est;
-    MTaskEnv taskenv1("EstimateEnergy");
-    taskenv1.SetDefault(fEstimateEnergy ? fEstimateEnergy : &est);
+    MTaskEnv taskenv2("EstimateEnergy");
+    taskenv2.SetDefault(fEstimateEnergy ? fEstimateEnergy : &est);
 
     MContinue *cont = new MContinue("", "CutS");
@@ -693,6 +700,7 @@
     tlist.AddToList(&read);
     //tlist.AddToList(&taskenv0); // not necessary, stored in file!
+    //tlist.AddToList(&taskenv1); // not necessary, stored in file!
     tlist.AddToList(fCutS);
-    tlist.AddToList(&taskenv1);
+    tlist.AddToList(&taskenv2);
     tlist.AddToList(&f0);
     tlist.AddToList(&f1);
@@ -1560,10 +1568,13 @@
     // energy limit!
 
-    MTaskEnv taskenv0("CalcHadronness");
-    taskenv0.SetDefault(fCalcHadronness);
+    MTaskEnv taskenv0("CalcDisp");
+    taskenv0.SetDefault(fCalcDisp);
+
+    MTaskEnv taskenv1("CalcHadronness");
+    taskenv1.SetDefault(fCalcHadronness);
 
     MEnergyEstimate est;
-    MTaskEnv taskenv1("EstimateEnergy");
-    taskenv1.SetDefault(fEstimateEnergy ? fEstimateEnergy : &est);
+    MTaskEnv taskenv2("EstimateEnergy");
+    taskenv2.SetDefault(fEstimateEnergy ? fEstimateEnergy : &est);
 
     tlist2.AddToList(&read);
@@ -1582,9 +1593,10 @@
     tlist2.AddToList(fCut0);
     tlist2.AddToList(&taskenv0);
+    tlist2.AddToList(&taskenv1);
     tlist2.AddToList(fCut1);
     tlist2.AddToList(fCutS);
     tlist2.AddToList(fCut2);
     tlist2.AddToList(fCut3);
-    tlist2.AddToList(&taskenv1);
+    tlist2.AddToList(&taskenv2);
     tlist2.AddToList(&fill31);
     tlist2.AddToList(&fill4);
Index: trunk/MagicSoft/Mars/mjobs/MJSpectrum.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSpectrum.h	(revision 8708)
+++ trunk/MagicSoft/Mars/mjobs/MJSpectrum.h	(revision 8709)
@@ -33,4 +33,5 @@
     MTask *fEstimateEnergy;
     MTask *fCalcHadronness;
+    MTask *fCalcDisp;
 
     Bool_t fForceTheta;
Index: trunk/MagicSoft/Mars/msql/MSQLMagic.cc
===================================================================
--- trunk/MagicSoft/Mars/msql/MSQLMagic.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/msql/MSQLMagic.cc	(revision 8709)
@@ -69,4 +69,7 @@
     const TString rc = row ? (*row)[0] : "";
 
+    if (row)
+        delete row;
+
     delete res;
     return rc;
@@ -124,5 +127,10 @@
 
     const Int_t rc1 = row && (*row)[0] ? atoi((*row)[0]) : -1;
+
+    if (row)
+        delete row;
+
     delete res1;
+
     return rc1;
 }
@@ -191,4 +199,7 @@
     if (row && (*row)[0])
         rc=kTRUE;
+
+    if (row)
+        delete row;
 
     delete res;
Index: trunk/MagicSoft/Mars/msql/MSQLServer.cc
===================================================================
--- trunk/MagicSoft/Mars/msql/MSQLServer.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/msql/MSQLServer.cc	(revision 8709)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MSQLServer.cc,v 1.13 2006-11-01 08:29:45 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MSQLServer.cc,v 1.14 2007-08-25 15:30:26 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -82,5 +82,8 @@
 
     TSQLRow *row=res->Next();
-    const TString desc((*row)[1]);
+    const TString desc(row ? (*row)[1] : "");
+
+    if (row)
+        delete row;
 
     delete res;
@@ -178,4 +181,5 @@
     {
         TString row0((*row)[0]);
+        delete row;
 
         MSQLServer *sql = (MSQLServer*)fList.FindObject(Form("%s/%s/%s", (const char*)fDataBase, (const char*)fTable, (const char*)row0));
@@ -202,4 +206,5 @@
     {
         TString row0((*row)[0]);
+        delete row;
 
         MSQLServer *sql = (MSQLServer*)fList.FindObject(Form("%s/%s", (const char*)fDataBase, (const char*)row0));
@@ -226,4 +231,5 @@
     {
         const TString row0((*row)[0]);
+        delete row;
 
         MSQLServer *sql = (MSQLServer*)fList.FindObject(row0);
@@ -257,4 +263,6 @@
 
     TList rows;
+    rows.SetOwner();
+
     while ((row=res.Next()))
     {
@@ -305,4 +313,6 @@
 
     TList rows;
+    rows.SetOwner();
+
     while ((row=res->Next()))
         rows.Add(row);
@@ -767,10 +777,11 @@
     while ((row=res->Next()))
     {
-        TString key = (*row)[3];
-        if (key!="PRI")
-            continue;
-
-        rc = (*row)[0];
-        break;
+        const TString key = (*row)[3];
+        if (key=="PRI")
+        {
+            rc = (*row)[0];
+            break;
+        }
+        delete row;
     }
 
Index: trunk/MagicSoft/Mars/sponde.cc
===================================================================
--- trunk/MagicSoft/Mars/sponde.cc	(revision 8708)
+++ trunk/MagicSoft/Mars/sponde.cc	(revision 8709)
@@ -221,4 +221,7 @@
     job.ForceTheta(kForceTheta);
 
+    if (!job.HasWritePermission(kOutfile))
+        return 2;
+
     if (!job.Process(seq))
     {
Index: trunk/MagicSoft/Mars/sponde.rc
===================================================================
--- trunk/MagicSoft/Mars/sponde.rc	(revision 8708)
+++ trunk/MagicSoft/Mars/sponde.rc	(revision 8709)
@@ -26,5 +26,5 @@
 
 # --------------- Setup the weighting for your spectrum ---------------
-#     For more details MMcSpectrumWeight::ReadEnv
+#            For more details see McSpectrumWeight::ReadEnv
 
 # A simple power law with a differential spectral index of -4
Index: trunk/MagicSoft/Mars/sponde_onoff.rc
===================================================================
--- trunk/MagicSoft/Mars/sponde_onoff.rc	(revision 8708)
+++ trunk/MagicSoft/Mars/sponde_onoff.rc	(revision 8709)
@@ -26,5 +26,5 @@
 
 # --------------- Setup the weighting for your spectrum ---------------
-#     For more details MMcSpectrumWeight::ReadEnv
+#            For more details see MMcSpectrumWeight::ReadEnv
 
 # A simple power law with a differential spectral index of -4
