Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8640)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8644)
@@ -553,4 +553,10 @@
 
     // --------------------------------------------------------------------------------
+
+    if (!set.IsWobbleMode() && fNumOffSourcePos!=1)
+    {
+        *fLog << inf << "No wobble mode but NumOffSoucePos!=1 (" << fNumOffSourcePos << ")... reset to 1." << endl;
+        fNumOffSourcePos = 1;
+    }
 
     // Possible source position (eg. Wobble Mode)
Index: trunk/MagicSoft/Mars/mjobs/MJob.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJob.cc	(revision 8640)
+++ trunk/MagicSoft/Mars/mjobs/MJob.cc	(revision 8644)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -34,4 +34,6 @@
 // SetDebugEnv(3) // do 2) and debug setting env completely
 //
+// To allow overwriting the output files call SetOverwrite()
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MJob.h"
@@ -66,4 +68,12 @@
 }
 
+//------------------------------------------------------------------------
+//
+// If MJob is the owner of fEnv delete fEnv.
+//
+// Reset the owenership bit.
+//
+// Set fEnv to NULL.
+//
 void MJob::ClearEnv()
 {
@@ -74,4 +84,8 @@
 }
 
+//------------------------------------------------------------------------
+//
+// ClearEnv()
+//
 MJob::~MJob()
 {
@@ -79,18 +93,14 @@
 }
 
-Bool_t MJob::SetEnv(const char *env, const char *prefix)
-{
-    ClearEnv();
-
-    fEnv = new MEnv(env);
-    SetBit(kIsOwner);
-
-    if (!fEnv->IsValid())
-    {
-        ClearEnv();
-        return kFALSE;
-    }
-
+//------------------------------------------------------------------------
+//
+// If prefix==0 the prefix is taken from fName up to the first
+// whitespace.
+//
+// A trailing dot is removed.void MJob::SetPrefix(const char *prefix)
+void MJob::SetPrefix(const char *prefix)
+{
     fEnvPrefix = prefix;
+
     if (!prefix)
         fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
@@ -98,8 +108,33 @@
     if (fEnvPrefix.EndsWith("."))
         fEnvPrefix.Remove(fEnvPrefix.Length()-1);
-
-    return kTRUE;
-}
-
+}
+
+//------------------------------------------------------------------------
+//
+// Create a new MEnv from the file env. MJob takes of course the
+// ownership of the newly created MEnv.
+//
+// SetPrefix(prefix)
+//
+// return kFALSE if MEnv is invalid
+//
+Bool_t MJob::SetEnv(const char *env, const char *prefix)
+{
+    SetEnv(new MEnv(env), prefix);
+
+    // Take the owenership of the MEnv instance
+    SetBit(kIsOwner);
+
+    return fEnv->IsValid();
+}
+
+//------------------------------------------------------------------------
+//
+// Set a new fEnv and a new general prefix.
+//
+// Calls SetPrefix(prefix)
+//
+// MJob does not take the owenership of the MEnv instance.
+//
 void MJob::SetEnv(MEnv *env, const char *prefix)
 {
@@ -108,13 +143,17 @@
     fEnv = env;
 
-    fEnvPrefix = prefix;
-    if (!prefix)
-        fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
-
-    if (fEnvPrefix.EndsWith("."))
-        fEnvPrefix.Remove(fEnvPrefix.Length()-1);
-}
-
-void MJob::FixPath(TString &path) const
+    SetPrefix(prefix);
+}
+
+//------------------------------------------------------------------------
+//
+// Removes LF's from the path (necessary if the resource file was written
+// with a different operating system than Linux.
+//
+// Removes a trailing slash if the path is not the root-path.
+//
+// Adds fname to the path if given.
+//
+void MJob::FixPath(TString &path)
 {
     path.ReplaceAll("\015", "");
@@ -127,4 +166,30 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Calls FixPath
+//
+// Adds fname to the path if given.
+//
+TString MJob::CombinePath(TString path, TString fname)
+{
+    FixPath(path);
+
+    if (fname.IsNull())
+        return path;
+
+    if (path!=(TString)"/")
+        path += "/";
+
+    path += fname;
+
+    return path;
+}
+
+//------------------------------------------------------------------------
+//
+// Sets the output path. The exact meaning (could also be a file) is
+// deined by the derived class.
+//
 void MJob::SetPathOut(const char *path)
 {
@@ -133,4 +198,9 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Sets the input path. The exact meaning (could also be a file) is
+// deined by the derived class.
+//
 void MJob::SetPathIn(const char *path)
 {
@@ -139,4 +209,8 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Returns the TEnv
+//
 const TEnv *MJob::GetEnv() const
 {
@@ -144,4 +218,9 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
+// For details see MParContainer
+//
 Int_t MJob::GetEnv(const char *name, Int_t dflt) const
 {
@@ -149,4 +228,9 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
+// For details see MParContainer
+//
 Double_t MJob::GetEnv(const char *name, Double_t dflt) const
 {
@@ -154,4 +238,9 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
+// For details see MParContainer
+//
 const char *MJob::GetEnv(const char *name, const char *dflt) const
 {
@@ -159,4 +248,9 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Checks IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug>2)
+// For details see MParContainer
+//
 Bool_t MJob::HasEnv(const char *name) const
 {
@@ -164,4 +258,15 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Check the resource file for
+//   PathOut
+//   PathIn
+//   MaxEvents
+//   Overwrite
+//   EnvDebug
+//
+// and call the virtual function CheckEnvLocal
+//
 Bool_t MJob::CheckEnv()
 {
@@ -202,4 +307,9 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Call the eventsloops ReadEnv and print untouched resources afterwards
+// if fEnvDebug>1
+//
 Bool_t MJob::SetupEnv(MEvtLoop &loop) const
 {
@@ -214,4 +324,33 @@
 
     return kTRUE;
+}
+
+//------------------------------------------------------------------------
+//
+// Checks whether write permissions to fname exists including
+// the fOverwrite data amember.
+//
+Bool_t MJob::HasWritePermission(TString fname) const
+{
+    gSystem->ExpandPathName(fname);
+
+    const Bool_t exists = !gSystem->AccessPathName(fname, kFileExists);
+    if (!exists)
+        return kTRUE;
+
+    const Bool_t write = !gSystem->AccessPathName(fname, kWritePermission);
+    if (!write)
+    {
+        *fLog << err << "ERROR - No permission to write to " << fname << endl;
+        return kFALSE;
+    }
+
+    if (!fOverwrite)
+        return kTRUE;
+
+    *fLog << err;
+    *fLog << "ERROR - File " << fname << " already exists and overwrite not allowed." << endl;
+
+    return kFALSE;
 }
 
@@ -274,6 +413,6 @@
 //------------------------------------------------------------------------
 //
-// Write containers in cont (and - if available) the status display to
-// fPathOut+"/"+name
+// Write containers in cont to fPathOut+"/"+name, or fPathOut only
+// if name is empty.
 //
 Bool_t MJob::WriteContainer(TCollection &cont, const char *name, const char *option, const int compr) const
@@ -285,15 +424,9 @@
     }
 
-    TString oname(fPathOut);
-    if (!TString(name).IsNull())
-    {
-        if (oname!="/")
-            oname += "/";
-        oname += name;
-    }
+    const TString oname = CombinePath(fPathOut, name);
 
     *fLog << inf << "Writing to file: " << oname << endl;
 
-    TString title("File Written by ");
+    TString title("File written by ");
     title += fName;
 
@@ -308,4 +441,14 @@
 }
 
+//------------------------------------------------------------------------
+//
+// return kTRUE if no display is set.
+//
+// Write the display to the TFile with name name, options option and
+// compression level comp.
+//
+// If name IsNull fPathOut is assumed to contain the name, otherwise
+// name is appended to fPathOut. fPathOut might be null.
+//
 Bool_t MJob::WriteDisplay(const char *name, const char *option, const int compr) const
 {
@@ -348,9 +491,5 @@
 
     // check if path ends with a slash
-    if (!path.EndsWith("/"))
-        path += "/";
-
-    // compile full qualified path
-    path += fname;
+    path = CombinePath(path, fname);
 
     gLog << dbg << "MJob::ExpandPath - Filename expanded to " << path << endl;
@@ -360,4 +499,8 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Sorts the array.
+//
 void MJob::SortArray(TArrayI &arr)
 {
Index: trunk/MagicSoft/Mars/mjobs/MJob.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJob.h	(revision 8640)
+++ trunk/MagicSoft/Mars/mjobs/MJob.h	(revision 8644)
@@ -14,7 +14,13 @@
     enum { kIsOwner = BIT(14) };
 
-    void FixPath(TString &path) const;
+    // Helper functions for paths
+    static TString CombinePath(TString path, TString fname);
+    static void FixPath(TString &path);
+
+    // Helper functions to set a new fEnv
+    void SetPrefix(const char *prefix);
     void ClearEnv();
 
+    // Data members for resource files
     const MEnv *fEnv;         // Resource file
     TString     fEnvPrefix;   // Prefix for resources
@@ -28,4 +34,5 @@
     Int_t     fMaxEvents;     // Maximum number of events
 
+    // FIXME: Split into MJobSequence and MJobDataSet
     MSequence fSequence;      // Sequence
 
@@ -71,4 +78,6 @@
     TString GetPathIn() const   { return fPathIn; }
 
+    Bool_t HasWritePermission(TString fname) const;
+
     // Others
     MStatusDisplay *GetDisplay() { return fDisplay; }
