Index: trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 4722)
+++ trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 4723)
@@ -9,5 +9,5 @@
 #pragma link C++ class MJPedestal+;
 #pragma link C++ class MJCalibration+;
-//#pragma link C++ class MJCalibrateSignal+;
+#pragma link C++ class MJCalibrateSignal+;
 #pragma link C++ class MJExtractSignal+;
 #pragma link C++ class MJExtractCalibTest+;
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 4723)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 4723)
@@ -0,0 +1,366 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MJCalibrateSignal
+//
+// This class is reading the output written by callisto. It calibrates
+// signal and time.
+//
+// The signal and time extractors are read from the callisto-output. In
+// pricipal you could overwrite these default using the resource file,
+// but this is NOT recommended!
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MJCalibrateSignal.h"
+
+#include <TEnv.h>
+#include <TFile.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MSequence.h"
+#include "MDirIter.h"
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+#include "MJPedestal.h"
+#include "MStatusDisplay.h"
+
+#include "MHCamEvent.h"
+#include "MPedestalCam.h"
+#include "MBadPixelsCam.h"
+#include "MCalibrationQECam.h"
+#include "MCalibrationChargeCam.h"
+#include "MCalibrationRelTimeCam.h"
+
+#include "MReadMarsFile.h"
+#include "MGeomApply.h"
+#include "MPedCalcFromLoGain.h"
+#include "MExtractor.h"
+#include "MTaskEnv.h"
+#include "MCalibrateData.h"
+#include "MCalibrateRelTimes.h"
+#include "MBadPixelsMerge.h"
+#include "MBadPixelsCalc.h"
+#include "MBadPixelsTreat.h"
+#include "MFillH.h"
+#include "MWriteRootFile.h"
+
+ClassImp(MJCalibrateSignal);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
+//
+MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title) 
+    : fOverwrite(kFALSE), fMaxEvents(0)
+{
+    fName  = name  ? name  : "MJCalibrateSignal";
+    fTitle = title ? title : "Tool to calibrate data";
+}
+
+MJCalibrateSignal::~MJCalibrateSignal()
+{
+}
+
+Bool_t MJCalibrateSignal::WriteResult(const MSequence &seq)
+{
+    if (fOutputPath.IsNull())
+        return kTRUE;
+
+    const TString oname = Form("%s/calped%06d.root", (const char*)fOutputPath, seq.GetSequence());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "RECREATE");
+
+    *fLog << inf << " - MStatusDisplay..." << flush;
+    if (fDisplay && fDisplay->Write()<=0)
+    {
+        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
+        return kFALSE;
+    }
+    *fLog << inf << "ok." << endl;
+
+    return kTRUE;
+}
+
+void MJCalibrateSignal::SetOutputPath(const char *path)
+{
+    fOutputPath = path;
+    if (fOutputPath.EndsWith("/"))
+        fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
+}
+void MJCalibrateSignal::SetInputPath(const char *path)
+{
+    fInputPath = path;
+    if (fInputPath.EndsWith("/"))
+        fInputPath = fInputPath(0, fInputPath.Length()-1);
+}
+
+void MJCalibrateSignal::CheckEnv(const char *env)
+{
+    TEnv e(env);
+
+    TString e1 = e.GetValue("MJCalibrateSignal.OutputPath", "");
+    if (!e1.IsNull())
+    {
+        e1.ReplaceAll("\015", "");
+        SetOutputPath(e1);
+    }
+
+    fMaxEvents = e.GetValue("MJCalibrateSignal.MaxEvents", fMaxEvents);
+}
+
+Bool_t MJCalibrateSignal::ReadCalibration(const MSequence &seq, const char *path,
+                                          MCalibrationCam &calcam,
+                                          MCalibrationCam &qecam,
+                                          MCalibrationCam &tmcam,
+                                          MBadPixelsCam &badpix, MTask* &ext1, MTask* &ext2) const
+{
+    TString inpath(path);
+    if (inpath.EndsWith("/"))
+        inpath = inpath(0, inpath.Length()-1);
+
+    const TString fname = Form("%s/calib%06d.root", inpath.Data(), seq.GetSequence());
+
+    TFile file(fname, "READ");
+    if (!file.IsOpen())
+    {
+        *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
+        return kFALSE;
+    }
+
+    if (calcam.Read("MCalibrationChargeCam")<=0)
+    {
+        *fLog << err << dbginf << "ERROR - Unable to read MCalibrationChargeCam from file " << fname << endl;
+        return kFALSE;
+    }
+    if (qecam.Read("MCalibrationQECam")<=0)
+    {
+        *fLog << err << dbginf << "ERROR - Unable to read MCalibrationQECam from file " << fname << endl;
+        return kFALSE;
+    }
+    if (tmcam.Read("MCalibrationRelTimeCam")<=0)
+    {
+        *fLog << err << dbginf << "ERROR - Unable to read MCalibrationRelTimeCam from file " << fname << endl;
+        return kFALSE;
+    }
+    if (badpix.Read("MBadPixelsCam")<=0)
+    {
+        *fLog << err << dbginf << "ERROR - Unable to read MBadPixelsCam from file " << fname << endl;
+        return kFALSE;
+    }
+
+    TObject *o = file.Get("ExtractSignal");
+    if (!o)
+    {
+        *fLog << err << dbginf << "ERROR - Unable to read ExtractSignal from file " << fname << endl;
+        return kFALSE;
+    }
+    if (!o->InheritsFrom(MExtractor::Class()))
+    {
+        *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
+        return kFALSE;
+    }
+    ext1 = (MTask*)o->Clone();
+
+    o = file.Get("ExtractTime");
+    if (!o)
+    {
+        *fLog << err << dbginf << "ERROR - Unable to read ExtractTime from file " << fname << endl;
+        return kFALSE;
+    }
+    if (!o->InheritsFrom(MExtractor::Class()))
+    {
+        *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
+        return kFALSE;
+    }
+    ext2 = (MTask*)o->Clone();
+
+    return kTRUE;
+}
+
+Bool_t MJCalibrateSignal::ProcessFile(const MSequence &seq, const char *env, const char *path)
+{
+    *fLog << inf;
+    fLog->Separator(GetDescriptor());
+    *fLog << "Calculate calibrated data from runs ";
+    *fLog << seq.GetName() << endl;
+    *fLog << endl;
+
+    CheckEnv(env);
+
+    // -------------------------------------------------------------------------------
+
+    MJPedestal job1;
+    job1.SetSequence(&seq);
+    job1.SetDisplay(fDisplay);;
+    job1.SetEnv(env);
+
+    if (!job1.ProcessFile())
+        return kFALSE;
+
+    // --------------------------------------------------------------------------------
+
+    MDirIter iter;
+    if (seq.SetupDatRuns(iter, fInputPath)==0)
+    {
+            *fLog << err << "ERROR - No input files of sequence found!" << endl;
+            return kFALSE;
+    }
+
+    // Read File
+    MCalibrationChargeCam  calcam;
+    MCalibrationQECam      qecam;
+    MCalibrationRelTimeCam tmcam;
+    MBadPixelsCam          badpix;
+
+    MTask *extractor1=0;
+    MTask *extractor2=0;
+
+    if (!ReadCalibration(seq, path, calcam, qecam, tmcam, badpix, extractor1, extractor2))
+        return kFALSE;
+
+    *fLog << all;
+    *fLog << "Extractors read from file" << endl;
+    *fLog << "=========================" << endl;
+    extractor1->Print();
+    *fLog << endl;
+    extractor2->Print();
+    *fLog << endl;
+
+    // This is necessary for the case in which it is not in the files
+    MBadPixelsCam badcam;
+
+    // Setup Parlist
+    MParList plist;
+    plist.AddToList(this); // take care of fDisplay!
+    plist.AddToList(&calcam);
+    plist.AddToList(&qecam);     
+    plist.AddToList(&tmcam);
+    plist.AddToList(&badcam);
+    plist.AddToList(&job1.GetPedestalCam());
+
+    // Setup Tasklist
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    MReadMarsFile read("Events");
+    read.DisableAutoScheme();
+    read.AddFiles(iter);
+    //read.AddFiles(fnamein);
+
+    MGeomApply             apply; // Only necessary to craete geometry
+    MBadPixelsMerge        merge(&badpix);
+    MPedCalcFromLoGain     pedlo;
+    //MExtractSlidingWindow  extsignal;
+    MTaskEnv taskenv1("ExtractSignal");
+    taskenv1.SetDefault(extractor1);
+    //MExtractTimeFastSpline exttime;
+    MTaskEnv taskenv2("ExtractTime");
+    taskenv2.SetDefault(extractor2);
+    MCalibrateData         calib;
+    MCalibrateRelTimes     caltm;
+    MBadPixelsCalc         bpcal;
+    MBadPixelsTreat        treat;
+
+    MHCamEvent evt0("PedestalFLG");
+    MHCamEvent evt1("Extra'd");
+    MHCamEvent evt2("PedPhot");
+    MHCamEvent evt3("Interp'd");
+    MHCamEvent evt4("Unsuitable");
+    MHCamEvent evt5("Times");
+    evt0.SetType(0);
+    evt1.SetType(0);
+    evt2.SetType(0);
+    evt3.SetType(0);
+    evt4.SetType(2);
+    evt5.SetType(0);
+    MFillH fill0(&evt0, "MPedestalCam",        "FillPedestalFLG");
+    MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtracted");
+    MFillH fill2(&evt2, "MPedPhotCam",         "FillPedPhot");
+    MFillH fill3(&evt3, "MCerPhotEvt",         "FillInterpolated");
+    MFillH fill4(&evt4, "MBadPixelsCam",       "FillUnsuitable");
+    MFillH fill5(&evt5, "MArrivalTime",        "FillTimes");
+
+    MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fOutputPath.Data()), fOverwrite);
+    write.AddContainer("MCerPhotEvt",    "Events");
+    write.AddContainer("MPedPhotCam",    "Events");
+    write.AddContainer("MTime",          "Events");
+    write.AddContainer("MRawEvtHeader",  "Events");
+    write.AddContainer("MArrivalTime",   "Events");
+    write.AddContainer("MRawRunHeader",  "RunHeaders");
+    write.AddContainer("MBadPixelsCam",  "RunHeaders");
+    write.AddContainer("MGeomCam",       "RunHeaders");
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&apply);
+    tlist.AddToList(&merge);
+    tlist.AddToList(&pedlo);
+    tlist.AddToList(&fill0);
+    tlist.AddToList(&taskenv1);
+    tlist.AddToList(&taskenv2);
+    tlist.AddToList(&fill1);
+    tlist.AddToList(&calib);
+    tlist.AddToList(&caltm);
+    tlist.AddToList(&fill2);
+    tlist.AddToList(&bpcal);
+    tlist.AddToList(&treat);
+    tlist.AddToList(&fill3);
+    tlist.AddToList(&fill4);
+    tlist.AddToList(&fill5);
+    tlist.AddToList(&write);
+
+    // Create and setup the eventloop
+    MEvtLoop evtloop(fName);
+    evtloop.SetParList(&plist);
+    evtloop.SetDisplay(fDisplay);
+    evtloop.SetLogStream(fLog);
+    evtloop.ReadEnv(env);
+
+    // Execute first analysis
+    if (!evtloop.Eventloop(fMaxEvents))
+    {
+        *fLog << err << GetDescriptor() << ": Failed." << endl;
+        return kFALSE;
+    }
+
+    tlist.PrintStatistics();
+
+    if (!WriteResult(seq))
+        return kFALSE;
+
+    *fLog << all << GetDescriptor() << ": Done." << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 4723)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 4723)
@@ -0,0 +1,51 @@
+#ifndef MARS_MJCalibrateSignal
+#define MARS_MJCalibrateSignal
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class TEnv;
+
+class MTask;
+class MParList;
+class MSequence;
+class MBadPixelsCam;
+class MCalibrationCam;
+class MCalibrationQECam;
+class MCalibrationRelTimeCam;
+class MCalibrationChargeCam;
+
+class MJCalibrateSignal : public MParContainer
+{
+private:
+    TString fOutputPath;        // Directory to write signal*.root file to
+    TString fInputPath;         // Directory to read  calib*.root file from
+
+    Bool_t fOverwrite;          // Allow overwriting files
+    Int_t  fMaxEvents;          // Maximum number of events
+
+    void   CheckEnv(const char *env);
+    Bool_t WriteResult(const MSequence &seq);
+    Bool_t ReadCalibration(const MSequence &seq, const char *path, MCalibrationCam &calcam,
+                           MCalibrationCam &qecam, MCalibrationCam &tmcam,
+                           MBadPixelsCam &badpix, MTask* &ext1, MTask* &ext2) const;
+
+public:
+    MJCalibrateSignal(const char *name=NULL, const char *title=NULL);
+    ~MJCalibrateSignal();
+
+    Bool_t ProcessFile(const MSequence &seq, const char *env, const char *path=0);
+
+    void SetOutputPath(const char *path=".");
+    void SetInputPath(const char *path=".");
+    void SetMaxEvents(Int_t max) { fMaxEvents = max; }
+
+    void SetOverwrite(Bool_t b=kTRUE) { fOverwrite=b; }
+
+    MStatusDisplay *GetDisplay() { return fDisplay; }
+
+    ClassDef(MJCalibrateSignal, 0) // Tool to create a pedestal file (MPedestalCam)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4722)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4723)
@@ -1266,5 +1266,5 @@
         return;
 
-    TString e1 = fEnv->GetValue("MJCalibration.OutputPath", "");
+    TString e1 = fEnv->GetValue(Form("%s.OutputPath", fName.Data()), "");
     if (!e1.IsNull())
     {
@@ -1273,10 +1273,10 @@
     }
 
-    TString col = fEnv->GetValue("MJCalibration.Color", "");
+    TString col = fEnv->GetValue(Form("%s.Color", fName.Data()), "");
     if (!col.IsNull())
     {
     }
 
-    TString dis = fEnv->GetValue("MJCalibration.Display", "");
+    TString dis = fEnv->GetValue(Form("%s.Display", fName.Data()), "");
     if (dis.BeginsWith("Full", TString::kIgnoreCase))
         SetFullDisplay();
@@ -1286,12 +1286,12 @@
         SetNormalDisplay();
 
-    SetRelTimeCalibration(fEnv->GetValue("MJCalibration.RelTimeCalibration", fRelTimes));
-    SetDataCheck(fEnv->GetValue("MJCalibration.Datacheck", fDataCheck));
-    SetDebug(fEnv->GetValue("MJCalibration.Debug", fDebug));
-    SetUseBlindPixel(fEnv->GetValue("MJCalibration.UseBlindPixel", IsUseBlindPixel()));
-    SetUsePINDiode(fEnv->GetValue("MJCalibration.UsePINDiode", IsUsePINDiode()));
-
-    SetOverwrite(fEnv->GetValue("MJPedestal.AllowOverwrite", fOverwrite));
-    SetInputPath(fEnv->GetValue("MJPedestal.InputPath", fInputPath));
+    SetRelTimeCalibration(fEnv->GetValue(Form("%s.RelTimeCalibration", fName.Data()), fRelTimes));
+    SetDataCheck(fEnv->GetValue(Form("%s.Datacheck", fName.Data()), fDataCheck));
+    SetDebug(fEnv->GetValue(Form("%s.Debug", fName.Data()), fDebug));
+    SetUseBlindPixel(fEnv->GetValue(Form("%s.UseBlindPixel", fName.Data()), IsUseBlindPixel()));
+    SetUsePINDiode(fEnv->GetValue(Form("%s.UsePINDiode", fName.Data()), IsUsePINDiode()));
+
+    SetOverwrite(fEnv->GetValue(Form("%s.AllowOverwrite", fName.Data()), fOverwrite));
+    SetInputPath(fEnv->GetValue(Form("%s.InputPath", fName.Data()), fInputPath));
 }
 
@@ -1426,4 +1426,5 @@
     MTaskList tlist;
     plist.AddToList(&tlist);
+    plist.AddToList(this); // take care of fDisplay!
 
     MReadMarsFile read("Events");
@@ -1495,8 +1496,8 @@
     calcalc.SetPulserColor(fColor);
 
-    MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
-    MFillH fillbnd("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel");
-    MFillH fillcam("MHCalibrationChargeCam",      "MExtractedSignalCam");
-    MFillH filltme("MHCalibrationRelTimeCam",     "MArrivalTimeCam");
+    MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode",   "FillPINDiode");
+    MFillH fillbnd("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel", "FillBlindCam");
+    MFillH fillcam("MHCalibrationChargeCam",      "MExtractedSignalCam",        "FillChargeCam");
+    MFillH filltme("MHCalibrationRelTimeCam",     "MArrivalTimeCam",            "FillRelTime");
     fillpin.SetNameTab("PINDiode");
     fillbnd.SetNameTab("BlindPix");
@@ -1566,4 +1567,10 @@
         evtloop.ReadEnv(*fEnv);
 
+    //if (!WriteEventloop(evtloop))
+    //    return kFALSE;
+
+    if (!WriteTasks(taskenv.GetTask(), taskenv2.GetTask()))
+        return kFALSE;
+
     // Execute first analysis
     if (!evtloop.Eventloop())
@@ -1580,4 +1587,7 @@
     // the display. No idea where this comes from...
     //
+    // FIND THE REASON! THE NEXT CHANGE SOMEBODY DOES MIGHT RESULT
+    // IN __YOUR__ WORKAROUN NOT WORKING IF IT IS NOT CLEANLY DONE!
+    /*
     if (fDisplay)
     {
@@ -1607,5 +1617,5 @@
         }
     }
-    
+*/
     DisplayResult(plist);
 
@@ -1613,5 +1623,5 @@
         return kFALSE;
 
-    *fLog << inf << GetDescriptor() << ": Done." << endl;
+    *fLog << all << GetDescriptor() << ": Done." << endl;
 
     return kTRUE;
@@ -1716,4 +1726,59 @@
 }
 
+Bool_t MJCalibration::WriteEventloop(MEvtLoop &evtloop) const
+{
+    if (fOutputPath.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    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;
+    }
+
+    if (evtloop.Write(fName)<=0)
+    {
+        *fLog << err << "Unable to write MEvtloop to " << oname << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+Bool_t MJCalibration::WriteTasks(MTask *t1, MTask *t2) const
+{
+    if (fOutputPath.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    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;
+    }
+
+    if (t1->Write()<=0)
+    {
+        *fLog << err << "Unable to write " << t1->GetName() << " to " << oname << endl;
+        return kFALSE;
+    }
+    if (t2->Write()<=0)
+    {
+        *fLog << err << "Unable to write " << t2->GetName() << " to " << oname << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1736,5 +1801,5 @@
     *fLog << inf << "Writing to file: " << oname << endl;
 
-    TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCalibration", 9);
+    TFile file(oname, "UPDATE", "File created by MJCalibration", 9);
     if (!file.IsOpen())
     {
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 4722)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 4723)
@@ -22,4 +22,5 @@
 
 class TEnv;
+class MTask;
 class MRunIter;
 class MSequence;
@@ -28,4 +29,5 @@
 class MExtractor;
 class MExtractTime;
+class MEvtLoop;
 
 class MExtractBlindPixel;
@@ -56,4 +58,5 @@
 
   TString fOutputPath;                                 // Path to the output files
+  TString fInputPath;                                  // Path to get the data files from
   
   TEnv           *fEnv;                                // Input setup-file
@@ -89,8 +92,10 @@
   
   Byte_t fDevices;                                     // Bit-field for used devices for calibration
-  
+
+  // Combine these options into a single bit-files (TestBit/SetBit, etc)
   Bool_t fRelTimes;                                    // Flag if relative times have to be calibrated
   Bool_t fDataCheck;                                   // Flag if the data check is run on raw data
   Bool_t fDebug;                                       // Flag if debug option is passed onto cal. classes
+  Bool_t fOverwrite;                                   // Allow to overwite existing files
   
   void   DisplayResult        ( MParList &plist );
@@ -102,4 +107,6 @@
   
   Bool_t WriteResult();
+  Bool_t WriteEventloop(MEvtLoop &evtloop) const;
+  Bool_t WriteTasks(MTask *t1, MTask *t2) const;
   void   CheckEnv();
   
@@ -134,4 +141,6 @@
   void SetSequence(MSequence *seq) { fSequence=seq; }
   void SetOutputPath(const char *path=".");
+  void SetInputPath(const char *path=".");
+  void SetOverwrite(Bool_t b=kTRUE) { fOverwrite=b; }
   
   // Displays
@@ -156,4 +165,6 @@
   Bool_t ProcessFile(MPedestalCam &pedcam);
   Bool_t Process(MPedestalCam &pedcam);
+
+  MStatusDisplay *GetDisplay() { return fDisplay; }
   
   ClassDef(MJCalibration, 0) // Tool to run a calibration per pulser colour and intensity
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4722)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 4723)
@@ -440,7 +440,6 @@
 
 }
-
-
-Bool_t MJPedestal::WriteResult()
+/*
+Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const
 {
     if (fOutputPath.IsNull())
@@ -452,4 +451,29 @@
 
     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 (evtloop.Write(fName)<=0)
+    {
+        *fLog << err << "Unable to write MEvtloop to " << oname << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+*/
+Bool_t MJPedestal::WriteResult()
+{
+    if (fOutputPath.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
     if (!file.IsOpen())
     {
@@ -527,5 +551,5 @@
         return;
 
-    TString e1 = fEnv->GetValue("MJPedestal.OutputPath", "");
+    TString e1 = fEnv->GetValue(Form("%s.OutputPath", fName.Data()), "");
     if (!e1.IsNull())
     {
@@ -534,8 +558,8 @@
     }
 
-    SetMaxEvents(fEnv->GetValue("MJPedestal.MaxEvents", fMaxEvents));
-    SetOverwrite(fEnv->GetValue("MJPedestal.AllowOverwrite", fOverwrite));
-
-    fUseData = fEnv->GetValue("MJPedestal.UseData", fUseData);
+    SetMaxEvents(fEnv->GetValue(Form("%s.MaxEvents", fName.Data()), fMaxEvents));
+    SetOverwrite(fEnv->GetValue(Form("%s.AllowOverwrite", fName.Data()), fOverwrite));
+
+    fUseData = fEnv->GetValue(Form("%s.UseData", fName.Data()), fUseData);
 }
 
@@ -570,4 +594,5 @@
     MTaskList tlist;
     plist.AddToList(&tlist);
+    plist.AddToList(this); // take care of fDisplay!
 
     MReadMarsFile read("Events");
@@ -640,4 +665,7 @@
         evtloop.ReadEnv(*fEnv);
 
+    //    if (!WriteEventloop(evtloop))
+    //        return kFALSE;
+
     // Execute first analysis
     if (!evtloop.Eventloop(fMaxEvents))
@@ -654,5 +682,5 @@
         return kFALSE;
 
-    *fLog << inf << GetDescriptor() << ": Done." << endl;
+    *fLog << all << GetDescriptor() << ": Done." << endl;
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 4722)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 4723)
@@ -17,4 +17,5 @@
 class TH1D;
 class MExtractor;
+class MEvtLoop;
 
 class MJPedestal : public MParContainer
@@ -39,4 +40,5 @@
     
     TString fOutputPath;        // Directory where the F0-files get stored
+    TString fInputPath;         // Directory from which to read the data files
 
     TEnv       *fEnv;           // Input setup-file
@@ -55,4 +57,5 @@
     Bool_t fDataCheck;          // Flag if the data check is run on raw data
     Bool_t fUseData;            // Use data-runs from sequence instead of pedestal runs
+    Bool_t fOverwrite;          // Allow to overwite existing files
 
     Int_t fMaxEvents;           // Maximum number of events
@@ -60,4 +63,5 @@
     Bool_t ReadPedestalCam();
     Bool_t WriteResult();
+    //Bool_t WriteEventloop(MEvtLoop &evtloop) const;
 
     void   DisplayResult(MParList &plist);
@@ -86,5 +90,7 @@
     void SetSequence(const MSequence *seq, Bool_t usedata=kFALSE) { fSequence = seq; }
     void SetOutputPath(const char *path=".");
+    void SetInputPath(const char *path=".");
     void SetEnv(const char *env);
+    void SetOverwrite(Bool_t b=kTRUE) { fOverwrite=b; }
     void SetMaxEvents(Int_t max) { fMaxEvents = max; }
 
@@ -94,4 +100,6 @@
     void SetNormalDisplay()    { fDisplayType = kNormalDisplay;    }
 
+    MStatusDisplay *GetDisplay() { return fDisplay; }
+
     ClassDef(MJPedestal, 0) // Tool to create a pedestal file (MPedestalCam)
 };
Index: trunk/MagicSoft/Mars/mjobs/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mjobs/Makefile	(revision 4722)
+++ trunk/MagicSoft/Mars/mjobs/Makefile	(revision 4723)
@@ -28,4 +28,5 @@
 	   MJPedestal.cc \
            MJCalibration.cc \
+           MJCalibrateSignal.cc \
            MJExtractSignal.cc \
            MJExtractCalibTest.cc
