Index: trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 4562)
+++ trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 4601)
@@ -4,4 +4,6 @@
 #pragma link off all classes;
 #pragma link off all functions;
+
+#pragma link C++ class MSequence+;
 
 #pragma link C++ class MJPedestal+;
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4562)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4601)
@@ -44,4 +44,6 @@
 #include "MLogManip.h"
 
+#include "MTaskEnv.h"
+#include "MSequence.h"
 #include "MRunIter.h"
 #include "MParList.h"
@@ -86,5 +88,5 @@
 //
 MJPedestal::MJPedestal(const char *name, const char *title) 
-    : fEnv(0), fRuns(0), fExtractor(NULL), fDisplayType(kNormalDisplay),
+    : fEnv(0), fRuns(0), fSequence(0), fExtractor(NULL), fDisplayType(kNormalDisplay),
       fDataCheck(kFALSE)
 {
@@ -101,4 +103,7 @@
 const char* MJPedestal::GetOutputFile() const
 {
+    if (fSequence)
+        return Form("%s/calped%05d", (const char*)fOutputPath, fSequence->GetSequence());
+
     if (!fRuns)
         return "";
@@ -143,5 +148,4 @@
 }
 
-
 void MJPedestal::DisplayResult(MParList &plist)
 {
@@ -154,6 +158,9 @@
     TString title = fDisplay->GetTitle();
     title += "--  Pedestal ";
-    if (fRuns)  // FIXME: What to do if an environmentfile was used?
-        title += fRuns->GetRunsAsString();
+    if (fSequence)
+        title += fSequence->GetName();
+    else
+        if (fRuns)  // FIXME: What to do if an environmentfile was used?
+            title += fRuns->GetRunsAsString();
     title += "  --";
     fDisplay->SetTitle(title);
@@ -242,14 +249,13 @@
     c3.cd(6);
     gPad->SetBorderMode(0);
-    gPad->SetTicks();
-
-    TArrayI inner(1);
-    inner[0] = 0;
-
-    TArrayI outer(1);
-    outer[0] = 1;
 
     if (geomcam.InheritsFrom("MGeomCamMagic"))
     {
+        TArrayI inner(1);
+        inner[0] = 0;
+
+        TArrayI outer(1);
+        outer[0] = 1;
+
         TArrayI s0(6);
         s0[0] = 6;
@@ -270,5 +276,4 @@
         s2[2] = 5;
 
-        gPad->Clear();
         TVirtualPad *pad = gPad;
         pad->Divide(2,1);
@@ -278,17 +283,19 @@
         inout[1] = disp1.ProjectionS(s0, outer, "Outer");
 
-        inout[0]->SetDirectory(NULL);
-        inout[1]->SetDirectory(NULL);
-
         for (int i=0; i<2; i++)
         {
-            TLegend *leg2 = new TLegend(0.6,0.2,0.9,0.55);
-            leg2->SetHeader(inout[i]->GetName());
             pad->cd(i+1);
+            gPad->SetBorderMode(0);
+            gPad->SetTicks();
+
+            inout[i]->SetDirectory(NULL);
             inout[i]->SetLineColor(kRed+i);
             inout[i]->SetBit(kCanDelete);
             inout[i]->Draw();
-            inout[i]->Fit("gaus","Q");
-            leg2->AddEntry(inout[i],inout[i]->GetName(),"l");
+            inout[i]->Fit("gaus", "Q");
+
+            TLegend *leg2 = new TLegend(0.6,0.2,0.9,0.55);
+            leg2->SetHeader(inout[i]->GetName());
+            leg2->AddEntry(inout[i], inout[i]->GetName(), "l");
 
             //
@@ -310,5 +317,5 @@
                 half[j]->SetBit(kCanDelete);
                 half[j]->Draw("same");
-                leg2->AddEntry(half[j],half[j]->GetName(),"l");
+                leg2->AddEntry(half[j], half[j]->GetName(), "l");
             }
             leg2->Draw();
@@ -419,10 +426,10 @@
 Bool_t MJPedestal::ProcessFile()
 {
-    if (!fRuns && !fEnv)
-    {
-        *fLog << err << "Neither AddRuns was called nor SetEnv was used... abort." << endl;
-        return kFALSE;
-    }
-    if (fRuns && fRuns->GetNumRuns() != fRuns->GetNumEntries())
+    if (!fRuns && !fEnv && !fSequence)
+    {
+        *fLog << err << "Neither AddRuns nor SetSequence nor SetEnv was called... abort." << endl;
+        return kFALSE;
+    }
+    if (!fSequence && fRuns && fRuns->GetNumRuns() != fRuns->GetNumEntries())
     {
         *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
@@ -433,8 +440,11 @@
     fLog->Separator(GetDescriptor());
     *fLog << "Calculate MPedestalCam from Runs ";
-    if (fRuns)
-        *fLog << fRuns->GetRunsAsString() << endl;
+    if (fSequence)
+        *fLog << fSequence->GetName() << endl;
     else
-        *fLog << "in " << fEnv->GetName() << endl;
+        if (fRuns)
+            *fLog << fRuns->GetRunsAsString() << endl;
+        else
+            *fLog << "in " << fEnv->GetName() << endl;
     *fLog << endl;
 
@@ -446,15 +456,19 @@
     MRawFileRead rawread(NULL);
 
+    MDirIter iter;
+    if (fSequence)
+        fSequence->SetupPedRuns(iter);
+
     if (fDataCheck)
     {
-        if (fRuns)
-            rawread.AddFiles(*fRuns);
-	tlist.AddToList(&rawread);
+        if (fRuns || fSequence)
+            rawread.AddFiles(fSequence ? iter : *fRuns);
+        tlist.AddToList(&rawread);
     }
     else
     {
         read.DisableAutoScheme();
-        if (fRuns)
-            static_cast<MRead&>(read).AddFiles(*fRuns);
+        if (fRuns || fSequence)
+            static_cast<MRead&>(read).AddFiles(fSequence ? iter : *fRuns);
 	tlist.AddToList(&read);
     }
@@ -468,5 +482,9 @@
     MGeomApply      geomapl;
     MBadPixelsMerge merge(&fBadPixels);
+
     MPedCalcPedRun  pedcalc;
+
+    MTaskEnv taskenv("ExtractPedestal");
+    taskenv.SetDefault(&pedcalc);
 
     if (fExtractor)
@@ -483,5 +501,5 @@
     tlist.AddToList(&geomapl);
     tlist.AddToList(&merge);
-    tlist.AddToList(&pedcalc);
+    tlist.AddToList(&taskenv);
 
     //
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 4562)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 4601)
@@ -12,4 +12,5 @@
 class TCanvas;
 class MParList;
+class MSequence;
 class MRunIter;
 class MHCamera;
@@ -36,6 +37,7 @@
 
     TEnv       *fEnv;           // Input setup-file
+    MRunIter   *fRuns;
+    MSequence  *fSequence;      //
 
-    MRunIter   *fRuns;
     MExtractor *fExtractor;     // Signal extractor, used to find the nr. of used FADC slices
 
@@ -70,6 +72,7 @@
 
     void SetBadPixels(const MBadPixelsCam &bad) { bad.Copy(fBadPixels); }
-    void SetExtractor(MExtractor* ext   ) { fExtractor = ext;     }
+    void SetExtractor(MExtractor* ext) { fExtractor = ext; }
     void SetInput(MRunIter *iter) { fRuns = iter; }
+    void SetSequence(MSequence *seq) { fSequence = seq; }
     void SetOutputPath(const char *path=".");
     void SetEnv(const char *env);
Index: trunk/MagicSoft/Mars/mjobs/MSequence.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 4601)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 4601)
@@ -0,0 +1,166 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MSequence
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MSequence.h"
+
+#include <stdlib.h>
+
+#include <TEnv.h>
+#include <TRegexp.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MDirIter.h"
+
+ClassImp(MSequence);
+
+using namespace std;
+
+void MSequence::Split(TString &runs, TArrayI &data) const
+{
+    const TRegexp regexp("[0-9]+");
+
+    data.Set(0);
+    runs = runs.Strip(TString::kTrailing);
+
+    while (!runs.IsNull())
+    {
+        TString num = runs(regexp);
+
+        const Int_t n = data.GetSize();
+        data.Set(n+1);
+        data[n] = atoi(num.Data());
+
+        runs.Remove(0, runs.First(num)+num.Length());
+    }
+}
+
+void MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr) const
+{
+    for (int i=0; i<arr.GetSize(); i++)
+    {
+        TString d, n;
+        d  = "/data/MAGIC/Period";
+        d += Form("%03d", fPeriod);
+        d += "/rootdata/";
+        d += fNight.GetStringFmt("%Y_%m_%d");
+        n =  fNight.GetStringFmt("%Y%m%d_");
+        n += Form("%05d", arr[i]);
+        n += "_*_E.root";
+
+        iter.AddDirectory(d, n, 0);
+    }
+}
+
+MSequence::MSequence(const char *fname)
+{
+    fName  = fname;
+    fTitle = Form("Sequence contained in file %s", fName.Data());
+
+    TEnv env(fname);
+
+    TString str;
+
+    fSequence  = env.GetValue("Sequence", -1);
+    fLastRun   = env.GetValue("LastRun", -1);
+    fNumEvents = env.GetValue("NumEvents", -1);
+    fPeriod    = env.GetValue("Period", -1);
+
+    str = env.GetValue("Start", "");
+    fStart.SetSqlDateTime(str);
+    str = env.GetValue("Night", "");
+    str += " 00:00:00";
+    fNight.SetSqlDateTime(str);
+
+    fProject      = env.GetValue("Project", "");
+    fSource       = env.GetValue("Source", "");
+    fTriggerTable = env.GetValue("TriggerTable", "");
+    fHvSettings   = env.GetValue("HvSettings", "");
+
+    str = env.GetValue("Runs", "");
+    Split(str, fRuns);
+    str = env.GetValue("CalRuns", "");
+    Split(str, fCalRuns);
+    str = env.GetValue("PedRuns", "");
+    Split(str, fPedRuns);
+    str = env.GetValue("DatRuns", "");
+    Split(str, fDatRuns);
+}
+
+void MSequence::Print(Option_t *o) const
+{
+    gLog << all;
+    gLog << "Sequence:     " << fSequence << endl;
+    gLog << "Period:       " << fPeriod << endl;
+    gLog << "Night:        " << fNight << endl << endl;
+    gLog << "Start:        " << fStart << endl;
+    gLog << "LastRun:      " << fLastRun << endl;
+    gLog << "NumEvents:    " << fNumEvents << endl;
+    gLog << "Project:      " << fProject << endl;
+    gLog << "Source:       " << fSource << endl;
+    gLog << "TriggerTable: " << fTriggerTable << endl;
+    gLog << "HvSettings:   " << fHvSettings << endl << endl;
+    gLog << "Runs:";
+    for (int i=0; i<fRuns.GetSize(); i++)
+        gLog << " " << fRuns[i];
+    gLog << endl;
+    gLog << "CalRuns:";
+    for (int i=0; i<fCalRuns.GetSize(); i++)
+        gLog << " " << fCalRuns[i];
+    gLog << endl;
+    gLog << "PedRuns:";
+    for (int i=0; i<fPedRuns.GetSize(); i++)
+        gLog << " " << fPedRuns[i];
+    gLog << endl;
+    gLog << "DatRuns:";
+    for (int i=0; i<fDatRuns.GetSize(); i++)
+        gLog << " " << fDatRuns[i];
+    gLog << endl;
+}
+
+void MSequence::SetupPedRuns(MDirIter &iter) const
+{
+    SetupRuns(iter, fPedRuns);
+}
+
+void MSequence::SetupDatRuns(MDirIter &iter) const
+{
+    SetupRuns(iter, fDatRuns);
+}
+
+void MSequence::SetupAllRuns(MDirIter &iter) const
+{
+    SetupRuns(iter, fRuns);
+}
+
+void MSequence::SetupCalRuns(MDirIter &iter) const
+{
+    SetupRuns(iter, fCalRuns);
+}
Index: trunk/MagicSoft/Mars/mjobs/MSequence.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 4601)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 4601)
@@ -0,0 +1,56 @@
+#ifndef MARS_MSequence
+#define MARS_MSequence
+
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
+
+#ifndef MARS_MTime
+#include "MTime.h"
+#endif
+
+class MDirIter;
+
+class MSequence : public MParContainer
+{
+private:
+    UInt_t fSequence;
+
+    MTime  fStart;
+
+    UInt_t fLastRun;
+    UInt_t fNumEvents;
+
+    UInt_t fPeriod;
+    MTime  fNight;
+
+    TString fProject;
+    TString fSource;
+    TString fTriggerTable;
+    TString fHvSettings;
+
+    TArrayI fRuns;
+    TArrayI fCalRuns;
+    TArrayI fPedRuns;
+    TArrayI fDatRuns;
+
+    void Split(TString &runs, TArrayI &data) const;
+    void SetupRuns(MDirIter &iter, const TArrayI &arr) const;
+
+public:
+    MSequence(const char *fname);
+
+    void Print(Option_t *o="") const;
+
+    void SetupPedRuns(MDirIter &iter) const;
+    void SetupDatRuns(MDirIter &iter) const;
+    void SetupAllRuns(MDirIter &iter) const;
+    void SetupCalRuns(MDirIter &iter) const;
+
+    // Getter
+    UInt_t GetSequence() const { return fSequence; }
+
+    ClassDef(MSequence, 0)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mjobs/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mjobs/Makefile	(revision 4562)
+++ trunk/MagicSoft/Mars/mjobs/Makefile	(revision 4601)
@@ -25,5 +25,6 @@
 #manalysis: MChisqEval (MParameters)
 
-SRCFILES = MJPedestal.cc \
+SRCFILES = MSequence.cc \
+	   MJPedestal.cc \
            MJCalibration.cc \
            MJExtractSignal.cc \
