Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4718)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4722)
@@ -186,5 +186,5 @@
     : fEnv(0), fRuns(0), fSequence(0), fExtractor(NULL), fTimeExtractor(NULL),
       fColor(MCalibrationCam::kNONE), fDisplayType(kNormalDisplay),
-      fRelTimes(kFALSE), fDataCheck(kFALSE), fDebug(kFALSE)
+      fRelTimes(kFALSE), fDataCheck(kFALSE), fDebug(kFALSE), fOverwrite(kFALSE)
 {
 
@@ -1247,4 +1247,18 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// MJCalibration allows to setup several option by a resource file:
+//   MJCalibration.OutputPath: path
+//   MJCalibration.InputPath: path
+//   MJCalibration.Display: full, datacheck, normal
+//   MJCalibration.RelTimeCalibration: yes,no
+//   MJCalibration.Datacheck: yes,no
+//   MJCalibration.Debug: yes,no
+//   MJCalibration.UseBlindPixel: yes,no
+//   MJCalibration.UsePINDiode: yes,no
+//
+// For more details see the class description and the corresponding Getters
+// 
 void MJCalibration::CheckEnv()
 {
@@ -1277,4 +1291,7 @@
     SetUseBlindPixel(fEnv->GetValue("MJCalibration.UseBlindPixel", IsUseBlindPixel()));
     SetUsePINDiode(fEnv->GetValue("MJCalibration.UsePINDiode", IsUsePINDiode()));
+
+    SetOverwrite(fEnv->GetValue("MJPedestal.AllowOverwrite", fOverwrite));
+    SetInputPath(fEnv->GetValue("MJPedestal.InputPath", fInputPath));
 }
 
@@ -1415,5 +1432,11 @@
     MDirIter iter;
     if (fSequence)
-        fSequence->SetupCalRuns(iter);
+    {
+        if (fSequence->SetupCalRuns(iter, fInputPath)==0)
+        {
+            *fLog << err << "ERROR - No input files of sequence found!" << endl;
+            return kFALSE;
+        }
+    }
 
     if (fDataCheck)
@@ -1666,4 +1689,15 @@
 // --------------------------------------------------------------------------
 //
+// Set the path from which the sequence files are read
+// 
+void MJCalibration::SetInputPath(const char *path)
+{
+    fInputPath = path;
+    if (fInputPath.EndsWith("/"))
+        fInputPath = fInputPath(0, fInputPath.Length()-1);
+}
+
+// --------------------------------------------------------------------------
+//
 // Set the useage of the Blind Pixel device 
 // 
@@ -1702,5 +1736,10 @@
     *fLog << inf << "Writing to file: " << oname << endl;
 
-    TFile file(oname, "RECREATE");
+    TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCalibration", 9);
+    if (!file.IsOpen())
+    {
+        *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
+        return kFALSE;
+    }
 
     *fLog << inf << " - MStatusDisplay..." << flush;
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4718)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4722)
@@ -91,5 +91,5 @@
 MJPedestal::MJPedestal(const char *name, const char *title) 
     : fEnv(0), fRuns(0), fSequence(0), fExtractor(NULL), fDisplayType(kNormalDisplay),
-      fDataCheck(kFALSE), fUseData(kFALSE), fMaxEvents(0)
+      fDataCheck(kFALSE), fUseData(kFALSE), fOverwrite(kFALSE), fMaxEvents(0)
 {
     fName  = name  ? name  : "MJPedestal";
@@ -451,5 +451,10 @@
     *fLog << inf << "Writing to file: " << oname << endl;
 
-    TFile file(oname, "RECREATE");
+    TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJPedestal", 9);
+    if (!file.IsOpen())
+    {
+        *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
+        return kFALSE;
+    }
 
     if (fDisplay && fDisplay->Write()<=0)
@@ -481,4 +486,15 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Set the path from which the sequence files are read
+// 
+void MJPedestal::SetInputPath(const char *path)
+{
+    fInputPath = path;
+    if (fInputPath.EndsWith("/"))
+        fInputPath = fInputPath(0, fInputPath.Length()-1);
+}
+
 void MJPedestal::SetEnv(const char *env)
 {
@@ -496,4 +512,14 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// MJPedestsl allows to setup several option by a resource file:
+//   MJPedestal.OutputPath: path
+//   MJPedestal.MaxEvents: 1000
+//   MJPedestal.AllowOverwrite: yes, no
+//   MJPedestal.UseData: yes, no (use DatRuns from sequence instead of PedRuns)
+//
+// For more details see the class description and the corresponding Getters
+// 
 void MJPedestal::CheckEnv()
 {
@@ -508,6 +534,8 @@
     }
 
-    fMaxEvents = fEnv->GetValue("MJPedestal.MaxEvents", fMaxEvents);
-    fUseData   = fEnv->GetValue("MJPedestal.UseData",   fUseData);
+    SetMaxEvents(fEnv->GetValue("MJPedestal.MaxEvents", fMaxEvents));
+    SetOverwrite(fEnv->GetValue("MJPedestal.AllowOverwrite", fOverwrite));
+
+    fUseData = fEnv->GetValue("MJPedestal.UseData", fUseData);
 }
 
@@ -548,5 +576,12 @@
     MDirIter iter;
     if (fSequence)
-        fUseData ? fSequence->SetupDatRuns(iter) : fSequence->SetupPedRuns(iter);
+    {
+        const Int_t n = fUseData ? fSequence->SetupDatRuns(iter, fInputPath) : fSequence->SetupPedRuns(iter, fInputPath);
+        if (n==0)
+        {
+            *fLog << err << "ERROR - No input files of sequence found!" << endl;
+            return kFALSE;
+        }
+    }
 
     if (fDataCheck)
Index: trunk/MagicSoft/Mars/mjobs/MSequence.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 4718)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 4722)
@@ -27,4 +27,9 @@
 //  MSequence
 //
+//  This class describes a sequence. For sequences see:
+//    http://magic.astro.uni-wuerzburg.de/mars/db/queryseq.html
+//
+//  A sequence is a collection of runs which should be used together.
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MSequence.h"
@@ -34,4 +39,5 @@
 #include <TEnv.h>
 #include <TRegexp.h>
+#include <TSystem.h> // TSystem::ExpandPath
 
 #include "MLog.h"
@@ -44,4 +50,8 @@
 using namespace std;
 
+// --------------------------------------------------------------------------
+//
+// Copy the run numbers from the TString runs into the TArrayI data
+//
 void MSequence::Split(TString &runs, TArrayI &data) const
 {
@@ -63,14 +73,16 @@
 }
 
-void MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path) const
+Int_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path) const
 {
     TString d(path);
 
     // Setup path
-    if (!path)
+    if (d.IsNull())
     {
         d  = Form("/data/MAGIC/Period%03d/rootdata/", fPeriod);
         d += fNight.GetStringFmt("%Y_%m_%d");
     }
+
+    Int_t num = 0;
 
     for (int i=0; i<arr.GetSize(); i++)
@@ -83,8 +95,13 @@
 
         // Add Path/File to TIter
-        iter.AddDirectory(d, n, 0);
-    }
-}
-
+        num += iter.AddDirectory(d, n, 0);
+    }
+    return num;
+}
+
+// --------------------------------------------------------------------------
+//
+// Read the file fname as setup file for the sequence.
+//
 MSequence::MSequence(const char *fname)
 {
@@ -96,8 +113,8 @@
     TString str;
 
-    fSequence  = env.GetValue("Sequence", -1);
-    fLastRun   = env.GetValue("LastRun", -1);
+    fSequence  = env.GetValue("Sequence",  -1);
+    fLastRun   = env.GetValue("LastRun",   -1);
     fNumEvents = env.GetValue("NumEvents", -1);
-    fPeriod    = env.GetValue("Period", -1);
+    fPeriod    = env.GetValue("Period",    -1);
 
     str = env.GetValue("Start", "");
@@ -122,7 +139,16 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Print the contents of the sequence
+//
 void MSequence::Print(Option_t *o) const
 {
     gLog << all;
+    if (!IsValid())
+    {
+        gLog << "Sequence: " << fName << " <invalid>" << endl;
+        return;
+    }
     gLog << "Sequence:     " << fSequence << endl;
     gLog << "Period:       " << fPeriod << endl;
@@ -153,21 +179,49 @@
 }
 
-void MSequence::SetupPedRuns(MDirIter &iter, const char *path) const
-{
-    SetupRuns(iter, fPedRuns, path);
-}
-
-void MSequence::SetupDatRuns(MDirIter &iter, const char *path) const
-{
-    SetupRuns(iter, fDatRuns, path);
-}
-
-void MSequence::SetupAllRuns(MDirIter &iter, const char *path) const
-{
-    SetupRuns(iter, fRuns, path);
-}
-
-void MSequence::SetupCalRuns(MDirIter &iter, const char *path) const
-{
-    SetupRuns(iter, fCalRuns, path);
-}
+// --------------------------------------------------------------------------
+//
+// Add all ped runs from the sequence to MDirIter.
+// If path==0 the standard path of the data-center is assumed.
+// If you have the runs locally use path="."
+// Return the number of files added.
+//
+Int_t MSequence::SetupPedRuns(MDirIter &iter, const char *path) const
+{
+    return SetupRuns(iter, fPedRuns, path);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add all data runs from the sequence to MDirIter.
+// If path==0 the standard path of the data-center is assumed.
+// If you have the runs locally use path="."
+// Return the number of files added.
+//
+Int_t MSequence::SetupDatRuns(MDirIter &iter, const char *path) const
+{
+    return SetupRuns(iter, fDatRuns, path);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add all runs from the sequence to MDirIter.
+// If path==0 the standard path of the data-center is assumed.
+// If you have the runs locally use path="."
+// Return the number of files added.
+//
+Int_t MSequence::SetupAllRuns(MDirIter &iter, const char *path) const
+{
+    return SetupRuns(iter, fRuns, path);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add all calibration runs from the sequence to MDirIter.
+// If path==0 the standard path of the data-center is assumed.
+// If you have the runs locally use path="."
+// Return the number of files added.
+//
+Int_t MSequence::SetupCalRuns(MDirIter &iter, const char *path) const
+{
+    return SetupRuns(iter, fCalRuns, path);
+}
Index: trunk/MagicSoft/Mars/mjobs/MSequence.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 4718)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 4722)
@@ -36,5 +36,5 @@
 
     void Split(TString &runs, TArrayI &data) const;
-    void SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path) const;
+    Int_t SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path) const;
 
 public:
@@ -45,8 +45,8 @@
     Bool_t IsValid() const { return fSequence!=(UInt_t)-1; }
 
-    void SetupPedRuns(MDirIter &iter, const char *path=0) const;
-    void SetupDatRuns(MDirIter &iter, const char *path=0) const;
-    void SetupAllRuns(MDirIter &iter, const char *path=0) const;
-    void SetupCalRuns(MDirIter &iter, const char *path=0) const;
+    Int_t SetupPedRuns(MDirIter &iter, const char *path=0) const;
+    Int_t SetupDatRuns(MDirIter &iter, const char *path=0) const;
+    Int_t SetupAllRuns(MDirIter &iter, const char *path=0) const;
+    Int_t SetupCalRuns(MDirIter &iter, const char *path=0) const;
 
     // Getter
