Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.cc	(revision 4367)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsMerge.cc	(revision 4368)
@@ -53,4 +53,8 @@
 // constructor. To keep track of all bad pixels the instance this pointer
 // is pointing to is used to collect all bad pixels used so far.
+//
+//
+// ToDo:
+//   - Take a setup file (ReadEnv-implementation) as input
 //
 //
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 4367)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 4368)
@@ -72,4 +72,5 @@
 #include <fstream>          // ofstream, SavePrimitive
 
+#include <TEnv.h>           // TEnv
 #include <TRint.h>          // gApplication, TRint::Class()
 #include <TTime.h>          // TTime
@@ -956,4 +957,14 @@
 // --------------------------------------------------------------------------
 //
+// Calls 'ReadEnv' with a TEnv initialized with the given file name.
+// If 'config=0' kTRUE is returned.
+//
+Bool_t MEvtLoop::ReadEnv(const char *config)
+{
+    return config ? ReadEnv(TEnv(config)) : kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Write the contents/setup of a parameter container/task to a TEnv
 // instance (steering card/setup file).
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 4367)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 4368)
@@ -80,4 +80,6 @@
     Bool_t WriteEnv(TEnv &env, TString prefix="", Bool_t print=kFALSE) const;
 
+    Bool_t ReadEnv(const char *config);
+
     void RecursiveRemove(TObject *obj);
 
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4367)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4368)
@@ -32,11 +32,12 @@
 
 #include <TF1.h>
+#include <TEnv.h>
 #include <TFile.h>
+#include <TLine.h>
+#include <TLatex.h>
 #include <TString.h>
 #include <TCanvas.h>
 #include <TSystem.h>
-#include <TLine.h>
 #include <TLegend.h>
-#include <TLatex.h>
 
 #include "MLog.h"
@@ -70,10 +71,12 @@
 const Double_t MJPedestal::fgPedRmsMin   = 0.;
 const Double_t MJPedestal::fgPedRmsMax   = 20.;
-const Float_t  MJPedestal::fgRefPedClosedLids    = 9.635;
-const Float_t  MJPedestal::fgRefPedExtraGalactic = 9.93;
-const Float_t  MJPedestal::fgRefPedGalactic      = 10.03;
-const Float_t  MJPedestal::fgRefPedRmsClosedLids = 1.7;
+
+const Float_t  MJPedestal::fgRefPedClosedLids       = 9.635;
+const Float_t  MJPedestal::fgRefPedExtraGalactic    = 9.93;
+const Float_t  MJPedestal::fgRefPedGalactic         = 10.03;
+const Float_t  MJPedestal::fgRefPedRmsClosedLids    = 1.7;
 const Float_t  MJPedestal::fgRefPedRmsExtraGalactic = 5.6;
 const Float_t  MJPedestal::fgRefPedRmsGalactic      = 6.92;
+
 // --------------------------------------------------------------------------
 //
@@ -83,5 +86,5 @@
 //
 MJPedestal::MJPedestal(const char *name, const char *title) 
-    : fRuns(0), fExtractor(NULL), fDataCheck(kFALSE)
+    : fEnv(0), fRuns(0), fExtractor(NULL), fDataCheck(kFALSE)
 {
     fName  = name  ? name  : "MJPedestal";
@@ -89,17 +92,20 @@
 }
 
+MJPedestal::~MJPedestal()
+{
+    if (fEnv)
+        delete fEnv;
+}
+
 const char* MJPedestal::GetOutputFile() const
 {
-
-  if (!fRuns)
-    return "";
-
-  return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
-
+    if (!fRuns)
+        return "";
+
+    return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
 }
 
 Bool_t MJPedestal::ReadPedestalCam()
 {
-
     const TString fname = GetOutputFile();
 
@@ -139,5 +145,4 @@
 void MJPedestal::DisplayResult(MParList &plist)
 {
-
     if (!fDisplay)
         return;
@@ -148,5 +153,6 @@
     TString title = fDisplay->GetTitle();
     title += "--  Pedestal ";
-    title += fRuns->GetRunsAsString();
+    if (fRuns)  // FIXME: What to do if an environmentfile was used?
+        title += fRuns->GetRunsAsString();
     title += "  --";
     fDisplay->SetTitle(title);
@@ -179,186 +185,180 @@
     c3.Divide(2,3);
 
-    if (fDataCheck)
-      {
-
-        c3.cd(1);
-        gPad->SetBorderMode(0);
-        gPad->SetTicks();
-        MHCamera *obj1=(MHCamera*)disp0.DrawCopy("hist");
-        obj1->SetDirectory(NULL);
-	//
-	// for the datacheck, fix the ranges!!
-	//
-        obj1->SetMinimum(fgPedestalMin);
-        obj1->SetMaximum(fgPedestalMax);
-	//
-	// set reference lines
-	//
-	DisplayReferenceLines(obj1,0);
-	//
-	// end reference lines
-	//
-        c3.cd(3);
-        gPad->SetBorderMode(0);
-        obj1->SetPrettyPalette();
-        obj1->Draw();
-        
-        c3.cd(5);
-        gPad->SetBorderMode(0);
-        gPad->SetTicks();
-        obj1->DrawProjection(7);
-
-        c3.cd(2);
-        gPad->SetBorderMode(0);
-        gPad->SetTicks();
-        MHCamera *obj2=(MHCamera*)disp1.DrawCopy("hist");
-        obj2->SetDirectory(NULL);
-        obj2->SetMinimum(fgPedRmsMin);
-        obj2->SetMaximum(fgPedRmsMax);
-	//
-	// set reference lines
-	//
-	DisplayReferenceLines(obj1,1);
-
-        c3.cd(4);
-        gPad->SetBorderMode(0);
-        obj2->SetPrettyPalette();
-        obj2->Draw();
-        
-        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 s0(6);
-          s0[0] = 6;
-          s0[1] = 1;
-          s0[2] = 2;
-          s0[3] = 3;
-          s0[4] = 4;
-          s0[5] = 5;
-
-          TArrayI s1(3);
-          s1[0] = 6;
-          s1[1] = 1;
-          s1[2] = 2;
-          
-          TArrayI s2(3);
-          s2[0] = 3;
-          s2[1] = 4;
-          s2[2] = 5;
-
-          gPad->Clear();
-          TVirtualPad *pad = gPad;
-          pad->Divide(2,1);
-          
-          TH1D *inout[2];
-          inout[0] = disp1.ProjectionS(s0, inner, "Inner");
-          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);
-              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");
-              
-	      //
-	      // Display the outliers as dead and noisy pixels
-	      //
-	      DisplayOutliers(inout[i]);
-
-	      //
-	      // Display the two half of the camera separately
-	      //
-	      TH1D *half[2];
-	      half[0] = disp1.ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
-	      half[1] = disp1.ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
-	      
-	      for (int j=0; j<2; j++)
-		{
-		  half[j]->SetLineColor(kRed+i+2*j+1);
-		  half[j]->SetDirectory(NULL);
-		  half[j]->SetBit(kCanDelete);
-		  half[j]->Draw("same");
-		  leg2->AddEntry(half[j],half[j]->GetName(),"l");
-		}
-	      leg2->Draw();
-	    }
-	}
-      }
-    else
-      {
+    if (!fDataCheck)
+    {
         disp0.CamDraw(c3, 1, 2, 1);
         disp1.CamDraw(c3, 2, 2, 6);
-      }
+        return;
+    }
+
+    c3.cd(1);
+    gPad->SetBorderMode(0);
+    gPad->SetTicks();
+    MHCamera *obj1=(MHCamera*)disp0.DrawCopy("hist");
+    obj1->SetDirectory(NULL);
+
+    //
+    // for the datacheck, fix the ranges!!
+    //
+    obj1->SetMinimum(fgPedestalMin);
+    obj1->SetMaximum(fgPedestalMax);
+
+    //
+    // set reference lines
+    //
+    DisplayReferenceLines(obj1,0);
+
+    //
+    // end reference lines
+    //
+    c3.cd(3);
+    gPad->SetBorderMode(0);
+    obj1->SetPrettyPalette();
+    obj1->Draw();
+
+    c3.cd(5);
+    gPad->SetBorderMode(0);
+    gPad->SetTicks();
+    obj1->DrawProjection(7);
+
+    c3.cd(2);
+    gPad->SetBorderMode(0);
+    gPad->SetTicks();
+    MHCamera *obj2=(MHCamera*)disp1.DrawCopy("hist");
+    obj2->SetDirectory(NULL);
+    obj2->SetMinimum(fgPedRmsMin);
+    obj2->SetMaximum(fgPedRmsMax);
+
+    //
+    // set reference lines
+    //
+    DisplayReferenceLines(obj1,1);
+
+    c3.cd(4);
+    gPad->SetBorderMode(0);
+    obj2->SetPrettyPalette();
+    obj2->Draw();
+
+    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 s0(6);
+        s0[0] = 6;
+        s0[1] = 1;
+        s0[2] = 2;
+        s0[3] = 3;
+        s0[4] = 4;
+        s0[5] = 5;
+
+        TArrayI s1(3);
+        s1[0] = 6;
+        s1[1] = 1;
+        s1[2] = 2;
+
+        TArrayI s2(3);
+        s2[0] = 3;
+        s2[1] = 4;
+        s2[2] = 5;
+
+        gPad->Clear();
+        TVirtualPad *pad = gPad;
+        pad->Divide(2,1);
+
+        TH1D *inout[2];
+        inout[0] = disp1.ProjectionS(s0, inner, "Inner");
+        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);
+            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");
+
+            //
+            // Display the outliers as dead and noisy pixels
+            //
+            DisplayOutliers(inout[i]);
+
+            //
+            // Display the two half of the camera separately
+            //
+            TH1D *half[2];
+            half[0] = disp1.ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
+            half[1] = disp1.ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
+
+            for (int j=0; j<2; j++)
+            {
+                half[j]->SetLineColor(kRed+i+2*j+1);
+                half[j]->SetDirectory(NULL);
+                half[j]->SetBit(kCanDelete);
+                half[j]->Draw("same");
+                leg2->AddEntry(half[j],half[j]->GetName(),"l");
+            }
+            leg2->Draw();
+        }
+    }
 }
 
 void  MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
 {
-
-  TLine *gala = new TLine(0,
-			  what ? fgRefPedRmsGalactic : fgRefPedGalactic,cam->GetNbinsX(),
-			  what ? fgRefPedRmsGalactic : fgRefPedGalactic);
-  gala->SetBit(kCanDelete);
-  gala->SetLineColor(4);
-  gala->SetLineStyle(2);
-  gala->SetLineWidth(3);
-  gala->Draw();
-  TLine *extr = new TLine(0,
-			  what ? fgRefPedRmsExtraGalactic : fgRefPedExtraGalactic,cam->GetNbinsX(),
-			  what ? fgRefPedRmsExtraGalactic : fgRefPedExtraGalactic);  
-  extr->SetBit(kCanDelete);
-  extr->SetLineColor(5);
-  extr->SetLineStyle(2);
-  extr->SetLineWidth(3);
-  extr->Draw();
-  TLine *close = new TLine(0,
-			  what ? fgRefPedRmsClosedLids : fgRefPedClosedLids,cam->GetNbinsX(),
-			  what ? fgRefPedRmsClosedLids : fgRefPedClosedLids);  
-  close->SetBit(kCanDelete);
-  close->SetLineColor(6);
-  close->SetLineStyle(2);
-  close->SetLineWidth(3);
-  close->Draw();
-  TLegend *leg = new TLegend(0.4,0.75,0.7,0.99);
-  leg->SetBit(kCanDelete);
-  leg->AddEntry(gala,"Galactic Source","l");
-  leg->AddEntry(extr,"Extra-Galactic Source","l");
-  leg->AddEntry(close,"Closed Lids","l");
-  leg->Draw();
+    const Double_t x = cam->GetNbinsX();
+
+    TLine line;
+    line.SetLineStyle(kDashed);
+    line.SetLineWidth(3);
+    
+    line.SetLineColor(kBlue);
+    TLine *l1 = line.DrawLine(0, what ? fgRefPedRmsGalactic : fgRefPedGalactic,
+                              x, what ? fgRefPedRmsGalactic : fgRefPedGalactic);
+
+    line.SetLineColor(kYellow);
+    TLine *l2 = line.DrawLine(0, what ? fgRefPedRmsExtraGalactic : fgRefPedExtraGalactic,
+                              x, what ? fgRefPedRmsExtraGalactic : fgRefPedExtraGalactic);
+
+    line.SetLineColor(kMagenta);
+    TLine *l3 = line.DrawLine(0, what ? fgRefPedRmsClosedLids : fgRefPedClosedLids,
+                              x, what ? fgRefPedRmsClosedLids : fgRefPedClosedLids);
+
+    
+    TLegend *leg = new TLegend(0.4,0.75,0.7,0.99);
+    leg->SetBit(kCanDelete);
+    leg->AddEntry(l1, "Galactic Source","l");
+    leg->AddEntry(l2, "Extra-Galactic Source","l");
+    leg->AddEntry(l3, "Closed Lids","l");
+    leg->Draw();
 }
 
 void  MJPedestal::DisplayOutliers(TH1D *hist) const
 {
-  
-  const Float_t mean  = hist->GetFunction("gaus")->GetParameter(1);
-  const Float_t lolim = mean - 3.5*hist->GetFunction("gaus")->GetParameter(2);
-  const Float_t uplim = mean + 3.5*hist->GetFunction("gaus")->GetParameter(2);
-  const Stat_t  dead  = hist->Integral(0,hist->FindBin(lolim)-1);
-  const Stat_t  noisy = hist->Integral(hist->FindBin(uplim)+1,hist->GetNbinsX()+1);
-	      
-  TLatex deadtex;
-  deadtex.SetTextSize(0.06);
-  deadtex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.1,Form("%3i dead pixels",(Int_t)dead));
-  
-  TLatex noisytex;
-  noisytex.SetTextSize(0.06);
-  noisytex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.2,Form("%3i noisy pixels",(Int_t)noisy));
-  
+    const Float_t mean  = hist->GetFunction("gaus")->GetParameter(1);
+    const Float_t lolim = mean - 3.5*hist->GetFunction("gaus")->GetParameter(2);
+    const Float_t uplim = mean + 3.5*hist->GetFunction("gaus")->GetParameter(2);
+    const Stat_t  dead  = hist->Integral(0,hist->FindBin(lolim)-1);
+    const Stat_t  noisy = hist->Integral(hist->FindBin(uplim)+1,hist->GetNbinsX()+1);
+
+    TLatex deadtex;
+    deadtex.SetTextSize(0.06);
+    deadtex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.1,Form("%3i dead pixels",(Int_t)dead));
+
+    TLatex noisytex;
+    noisytex.SetTextSize(0.06);
+    noisytex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.2,Form("%3i noisy pixels",(Int_t)noisy));
 }
 
@@ -402,4 +402,11 @@
 }
 
+void MJPedestal::SetEnv(const char *env)
+{
+    if (fEnv)
+        delete fEnv;
+    fEnv = new TEnv(env);
+}
+
 Bool_t MJPedestal::Process()
 {
@@ -412,10 +419,10 @@
 Bool_t MJPedestal::ProcessFile()
 {
-    if (!fRuns)
-    {
-        *fLog << err << "No Runs choosen... abort." << endl;
-        return kFALSE;
-    }
-    if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
+    if (!fRuns && !fEnv)
+    {
+        *fLog << err << "Neither AddRuns was called nor SetEnv was used... abort." << endl;
+        return kFALSE;
+    }
+    if (fRuns && fRuns->GetNumRuns() != fRuns->GetNumEntries())
     {
         *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
@@ -425,5 +432,9 @@
     *fLog << inf;
     fLog->Separator(GetDescriptor());
-    *fLog << "Calculate MPedestalCam from Runs " << fRuns->GetRunsAsString() << endl;
+    *fLog << "Calculate MPedestalCam from Runs ";
+    if (fRuns)
+        *fLog << fRuns->GetRunsAsString() << endl;
+    else
+        *fLog << "in " << fEnv->GetName() << endl;
     *fLog << endl;
 
@@ -437,11 +448,13 @@
     if (fDataCheck)
     {
-	rawread.AddFiles(*fRuns);
+        if (fRuns)
+            rawread.AddFiles(*fRuns);
 	tlist.AddToList(&rawread);
     }
     else
     {
-	read.DisableAutoScheme();
-	static_cast<MRead&>(read).AddFiles(*fRuns);
+        read.DisableAutoScheme();
+        if (fRuns)
+            static_cast<MRead&>(read).AddFiles(*fRuns);
 	tlist.AddToList(&read);
     }
@@ -454,21 +467,20 @@
 
     MGeomApply      geomapl;
-    // MBadPixelsMerge merge(&fBadPixels);
+    MBadPixelsMerge merge(&fBadPixels);
     MPedCalcPedRun  pedcalc;
 
     if (fExtractor)
-      {
+    {
         pedcalc.SetWindowSize((Int_t)fExtractor->GetNumHiGainSamples());
         pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
-      }
+    }
     else
-      {
-        *fLog << warn << GetDescriptor() 
-            << ": No extractor has been chosen, take default number of FADC samples " << endl;
-      }
+    {
+        *fLog << warn << GetDescriptor();
+        *fLog << ": No extractor has been chosen, take default number of FADC samples " << endl;
+    }
 
     tlist.AddToList(&geomapl);
-    //    tlist.AddToList(&merge);
-    //tlist.AddToList(&sigcalc);
+    tlist.AddToList(&merge);
     tlist.AddToList(&pedcalc);
 
@@ -480,4 +492,6 @@
     evtloop.SetDisplay(fDisplay);
     evtloop.SetLogStream(fLog);
+    if (fEnv)
+        evtloop.ReadEnv(*fEnv);
 
     // Execute first analysis
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 4367)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 4368)
@@ -9,4 +9,5 @@
 #endif
 
+class TEnv;
 class TCanvas;
 class MParList;
@@ -15,58 +16,62 @@
 class TH1D;
 class MExtractor;
-class MJPedestal : public MParContainer  
+
+class MJPedestal : public MParContainer
 {
 private:
+    static const Double_t fgPedestalMin;
+    static const Double_t fgPedestalMax;
+    static const Double_t fgPedRmsMin;
+    static const Double_t fgPedRmsMax;
 
-  static const Double_t fgPedestalMin;
-  static const Double_t fgPedestalMax;  
-  static const Double_t fgPedRmsMin;
-  static const Double_t fgPedRmsMax;  
+    static const Float_t  fgRefPedClosedLids;
+    static const Float_t  fgRefPedExtraGalactic;
+    static const Float_t  fgRefPedGalactic;
 
-  static const Float_t  fgRefPedClosedLids;
-  static const Float_t  fgRefPedExtraGalactic;
-  static const Float_t  fgRefPedGalactic;
+    static const Float_t  fgRefPedRmsClosedLids;
+    static const Float_t  fgRefPedRmsExtraGalactic;
+    static const Float_t  fgRefPedRmsGalactic;
 
-  static const Float_t  fgRefPedRmsClosedLids;
-  static const Float_t  fgRefPedRmsExtraGalactic;
-  static const Float_t  fgRefPedRmsGalactic;
+    TString fOutputPath;
 
-  TString fOutputPath;
-  
-  MRunIter   *fRuns;
-  MExtractor *fExtractor;                         // Signal extractor, used to find the nr. of used FADC slices
+    TEnv       *fEnv;           // Input setup-file
 
-  MPedestalCam  fPedestalCam;
-  MBadPixelsCam fBadPixels;
-  
-  Bool_t fDataCheck;                              // Flag if the data check is run on raw data
-  
-  Bool_t ReadPedestalCam();
-  Bool_t WriteResult();
-  
-  void   DisplayResult(MParList &plist);
-  void   DisplayReferenceLines(MHCamera *cam, const Int_t what) const;
-  void   DisplayOutliers(      TH1D *hist) const;
-  
+    MRunIter   *fRuns;
+    MExtractor *fExtractor;     // Signal extractor, used to find the nr. of used FADC slices
+
+    MPedestalCam  fPedestalCam;
+    MBadPixelsCam fBadPixels;
+
+    Bool_t fDataCheck;          // Flag if the data check is run on raw data
+
+    Bool_t ReadPedestalCam();
+    Bool_t WriteResult();
+
+    void   DisplayResult(MParList &plist);
+    void   DisplayReferenceLines(MHCamera *cam, const Int_t what) const;
+    void   DisplayOutliers(TH1D *hist) const;
+
 public:
+    MJPedestal(const char *name=NULL, const char *title=NULL);
+    ~MJPedestal();
 
-  MJPedestal(const char *name=NULL, const char *title=NULL);
+    MPedestalCam &GetPedestalCam()            { return fPedestalCam; }
+    const MBadPixelsCam &GetBadPixels() const { return fBadPixels;   }
 
-  MPedestalCam &GetPedestalCam()            { return fPedestalCam; }
-  const MBadPixelsCam &GetBadPixels() const { return fBadPixels;   }
-  
-  const char* GetOutputFile() const;
-  const Bool_t IsDataCheck() const    { return fDataCheck;  }
-  
-  Bool_t Process();
-  Bool_t ProcessFile();
-  
-  void SetBadPixels ( const MBadPixelsCam &bad) { bad.Copy(fBadPixels); }
-  void SetDataCheck ( const Bool_t b=kTRUE    ) { fDataCheck = b;       }
-  void SetExtractor (       MExtractor* ext   ) { fExtractor = ext;     }
-  void SetInput     (       MRunIter *iter    ) { fRuns      = iter;    }
-  void SetOutputPath( const char *path="."    );
-  
-  ClassDef(MJPedestal, 0) // Tool to create a pedestal file (MPedestalCam)
+    const char* GetOutputFile() const;
+    const Bool_t IsDataCheck() const    { return fDataCheck;  }
+
+    Bool_t Process();
+    Bool_t ProcessFile();
+
+    void SetBadPixels(const MBadPixelsCam &bad) { bad.Copy(fBadPixels); }
+    void SetExtractor(MExtractor* ext   ) { fExtractor = ext;     }
+    void SetInput(MRunIter *iter) { fRuns = iter; }
+    void SetOutputPath(const char *path=".");
+    void SetEnv(const char *env);
+
+    void SetDataCheck(const Bool_t b=kTRUE) { fDataCheck = b; }
+
+    ClassDef(MJPedestal, 0) // Tool to create a pedestal file (MPedestalCam)
 };
 
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 4367)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 4368)
@@ -101,4 +101,9 @@
 //   fLoGainWindowSize = fgLoGainWindowSize = 0
 //
+//
+// ToDo:
+//   - Take a setup file (ReadEnv-implementation) as input
+//
+//
 //  Input Containers:
 //   MRawEvtData
Index: trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 4367)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 4368)
@@ -25,5 +25,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-//   MExtractor
+// MExtractor
+// ==========
 //
 //   Base class for the signal extractors, used the functions 
@@ -38,4 +39,7 @@
 //   - fSqrtLoGainSamples
 //
+//   The signal extractor classes can be setup from an environmental
+//   setup file. For more information see ReadEnv and MEvtLoop::ReadEnv
+//
 // Input Containers:
 //   MRawEvtData
@@ -71,4 +75,5 @@
 
 const Byte_t MExtractor::fgSaturationLimit = 254;
+
 // --------------------------------------------------------------------------
 //
@@ -88,5 +93,4 @@
       fSaturationLimit(fgSaturationLimit)
 {
-
     fName  = name  ? name  : "MExtractor";
     fTitle = title ? title : "Base class for signal extractors";
@@ -99,13 +103,10 @@
 void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
 {
-  
-  fHiGainFirst = hifirst;
-  fHiGainLast  = hilast;
-
-  fLoGainFirst = lofirst;
-  fLoGainLast  = lolast;
-
-}
-
+    fHiGainFirst = hifirst;
+    fHiGainLast  = hilast;
+
+    fLoGainFirst = lofirst;
+    fLoGainLast  = lolast;
+}
 
 // --------------------------------------------------------------------------
@@ -123,5 +124,4 @@
 Int_t MExtractor::PreProcess(MParList *pList)
 {
-
     fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
     if (!fRawEvt)
@@ -178,62 +178,49 @@
 Bool_t MExtractor::ReInit(MParList *pList)
 {
-  
-  Int_t lastdesired   = (Int_t)(fLoGainLast);
-  Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
-
-  if (lastavailable < 0)
-    *fLog << warn << GetDescriptor() 
-          << ": WARNING: Number of available Low-Gain Slices is smaller than or equal zero!" << endl;
-  
+    Int_t lastdesired   = (Int_t)(fLoGainLast);
+    Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
+
+    if (lastavailable < 0)
+        *fLog << warn << GetDescriptor() << " - WARNING: Number of available Low-Gain Slices is smaller than or equal zero!" << endl;
+
+    if (lastdesired > lastavailable)
+    {
+        const Int_t diff = lastdesired - lastavailable;
+
+        *fLog << endl;
+        *fLog << warn << GetDescriptor() << ": Selected Lo Gain FADC Window [";
+        *fLog << Form("%2i,%2i", (int)fLoGainFirst, lastdesired);
+        *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
+        *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
+        SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
+    }
+
+    lastdesired   = (Int_t)fHiGainLast;
+    lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
+
+    if (lastavailable < 0)
+    {
+        *fLog << err << GetDescriptor();
+        *fLog << " - ERROR: Number of available High-Gain Slices is smaller than or equal zero!" << endl;
+        return kFALSE;
+    }
+
   if (lastdesired > lastavailable)
-    {
+  {
       const Int_t diff = lastdesired - lastavailable;
-      *fLog << endl; 
-      *fLog << warn << GetDescriptor()
-            << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [",
-                    (int)fLoGainFirst,",",lastdesired,
-                    "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
-      *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl;
-      SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff);
-    }
-
-  lastdesired   = (Int_t)fHiGainLast;
-  lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1;
-  
-  if (lastavailable < 0)
-    {
-      *fLog << err << GetDescriptor() 
-            << ": ERROR: Number of available High-Gain Slices is smaller than or equal zero!" << endl;
-      return kFALSE;
-    }
-
-  if (lastdesired > lastavailable)
-    {
-      const Int_t diff = lastdesired - lastavailable;
+
       *fLog << endl;
-      *fLog << warn << GetDescriptor()
-            << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [",
-                    (int)fHiGainFirst,",",lastdesired,
-                    "] ranges out of the available limits: [0,",lastavailable,"].") << endl;
-      *fLog << warn << GetDescriptor() 
-            << Form("%s%2i%s",": Will use ",diff," samples from the Low-Gain for the High-Gain extraction")
-            << endl;
+      *fLog << warn << GetDescriptor() << ": Selected Hi Gain FADC Window [";
+      *fLog << Form("%2i,%2i%s%2i%s", (int)fHiGainFirst,",",lastdesired);
+      *fLog << "] ranges out of the available limits: [0," << Form("%2i", lastavailable) << "]" << endl;
+      *fLog << warn << GetDescriptor() << ": Will use ";
+      *fLog << Form("%2i", diff) << " samples from the Low-Gain for the High-Gain extraction";
+      *fLog << endl;
+
       fHiGainLast -= diff;
       fHiLoLast    = diff;
-    }
+  }
 
   return kTRUE;
-}
-
-
-
-void MExtractor::FindSignalHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Byte_t &sat) const
-{
-  return;
-}
-
-void MExtractor::FindSignalLoGain(Byte_t *firstused, Float_t &sum, Byte_t &sat) const
-{
-  return;
 }
 
@@ -245,5 +232,4 @@
 Int_t MExtractor::Process()
 {
-
   MRawEvtPixelIter pixel(fRawEvt);
   fSignals->Clear();
@@ -290,13 +276,12 @@
 void MExtractor::StreamPrimitive(ofstream &out) const
 {
-
   out << "   " << ClassName() << " " << GetUniqueName() << "(\"";
   out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
   
   if (fSaturationLimit!=fgSaturationLimit)
-    {
+  {
       out << "   " << GetUniqueName() << ".SetSaturationLimit(";
       out << (int)fSaturationLimit << ");" << endl;
-    }
+  }
   
   out << "   " << GetUniqueName() << ".SetRange(";
@@ -308,2 +293,35 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Read the setup from a TEnv, eg:
+//   MJPedestal.MExtractor.HiGainFirst: 5
+//   MJPedestal.MExtractor.LoGainFirst: 5
+//   MJPedestal.MExtractor.HiGainLast:  10
+//   MJPedestal.MExtractor.LoGainLast:  10
+//   MJPedestal.MExtractor.SaturationLimit: 88
+//
+Bool_t MExtractor::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Byte_t hf = fHiGainFirst;
+    Byte_t lf = fLoGainFirst;
+    Byte_t hl = fHiGainLast;
+    Byte_t ll = fLoGainLast;
+
+    if (IsEnvDefined(env, prefix, "HiGainFirst", print))
+        hf = GetEnvValue(env, prefix, "HiGainFirst", hf);
+    if (IsEnvDefined(env, prefix, "LoGainFirst", print))
+        lf = GetEnvValue(env, prefix, "LoGainFirst", lf);
+
+    if (IsEnvDefined(env, prefix, "HiGainLast", print))
+        hl = GetEnvValue(env, prefix, "HiGainLast", hl);
+    if (IsEnvDefined(env, prefix, "LoGainLast", print))
+        ll = GetEnvValue(env, prefix, "LoGainLast", ll);
+
+    SetRange(hf, hl, lf, ll);
+
+    if (IsEnvDefined(env, prefix, "SaturationLimit", print))
+        SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", fSaturationLimit));
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/msignal/MExtractor.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 4367)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 4368)
@@ -47,22 +47,22 @@
     Byte_t  fSaturationLimit;
 
-    virtual void FindSignalHiGain(Byte_t *firstused, Byte_t *lowgain, Float_t &sum, Byte_t &sat) const;
-    virtual void FindSignalLoGain(Byte_t *firstused, Float_t &sum, Byte_t &sat) const;
+    virtual void FindSignalHiGain(Byte_t *firstused, Byte_t *lowgain, Float_t &sum, Byte_t &sat) const { }
+    virtual void FindSignalLoGain(Byte_t *firstused, Float_t &sum, Byte_t &sat) const { }
 
-    virtual Int_t  PreProcess(MParList *pList);
-    virtual Bool_t ReInit(MParList *pList);
-    virtual Int_t  Process();
-    virtual void   StreamPrimitive(ofstream &out) const;
+    Int_t  PreProcess(MParList *pList);
+    Bool_t ReInit(MParList *pList);
+    Int_t  Process();
+    void   StreamPrimitive(ofstream &out) const;
+    Bool_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
 public:
-
     MExtractor(const char *name=NULL, const char *title=NULL);
 
-    Byte_t  GetHiGainFirst()      const      { return fHiGainFirst;      }
-    Byte_t  GetHiGainLast ()      const      { return fHiGainLast ;      }
-    Byte_t  GetLoGainFirst()      const      { return fLoGainFirst;      }
-    Byte_t  GetLoGainLast ()      const      { return fLoGainLast ;      }
-    Float_t GetNumHiGainSamples() const      { return fNumHiGainSamples; }
-    Float_t GetNumLoGainSamples() const      { return fNumLoGainSamples; }
+    Byte_t  GetHiGainFirst()      const { return fHiGainFirst;      }
+    Byte_t  GetHiGainLast ()      const { return fHiGainLast ;      }
+    Byte_t  GetLoGainFirst()      const { return fLoGainFirst;      }
+    Byte_t  GetLoGainLast ()      const { return fLoGainLast ;      }
+    Float_t GetNumHiGainSamples() const { return fNumHiGainSamples; }
+    Float_t GetNumLoGainSamples() const { return fNumLoGainSamples; }
     
     virtual void SetRange  (Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
