Index: trunk/MagicSoft/Mars/macros/readMagic.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readMagic.C	(revision 3140)
+++ trunk/MagicSoft/Mars/macros/readMagic.C	(revision 3141)
@@ -46,16 +46,73 @@
 }
 
+MHCamera display[4];
+
+TCanvas   *c;
+MParList  *fParList;
+MTaskList *fTaskList;
+
+Int_t PreProcess(MParList *plist)
+{
+    fParList = plist;
+    fTaskList = (MTaskList*)plist->FindObject("MTaskList");
+
+    MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
+
+    c = new TCanvas("Events", "Real Events", 600, 600);
+    c->SetBorderMode(0);
+    c->Divide(2,2);
+    for (int i=0; i<4; i++)
+    {
+        display[i].SetGeometry(*geomcam);
+        c->cd(i+1);
+        display[i].Draw();
+        gPad->cd(1);
+        plist->FindObject("MHillas")->Draw();
+    }
+    return kTRUE;
+}
+
+Int_t Process()
+{
+    MReadMarsFile *read = (MReadMarsFile*)fTaskList->FindObject("MRead");
+    MClone *clone = (MClone*)fTaskList->FindObject("MClone");
+    MImgCleanStd *clean = (MImgCleanStd*)fTaskList->FindObject("MImgCleanStd");
+    MGeomCam *geom = (MGeomCam*)fParList->FindObject("MGeomCam");
+
+    cout << "Event #" << read->GetNumEntry() << ":" << endl;
+
+    display[0].SetCamContent(*(MCerPhotEvt*)clone->GetClone());
+    display[1].SetCamContent(*(MCerPhotEvt*)fParList->FindObject("MCerPhotEvt"));
+    display[2].SetCamContent(*(MCameraData*)fParList->FindObject("MCameraData"));
+    display[3].SetCamContent(*(MCameraData*)fParList->FindObject("MCameraData"));
+
+    TArrayF lvl(2);
+    lvl[0] = clean->GetCleanLvl2();
+    lvl[1] = clean->GetCleanLvl1();
+    display[3].SetLevels(lvl);
+
+    for (int i=1; i<=4; i++)
+    {
+        c->GetPad(i)->GetPad(1)->Modified();
+        c->GetPad(i)->GetPad(1)->Update();
+    }
+
+    ((MHillas*)fParList->FindObject("MHillas"))->Print(*geom);
+    ((MHillasExt*)fParList->FindObject("MHillasExt"))->Print(*geom);
+    fParList->FindObject("MNewImagePar")->Print();
+
+    return HandleInput();
+}
+
+Int_t PostProcess()
+{
+    delete c;
+}
+
 void readMagic(const char *fname="../Proton*.root")
-{
-    MParList plist;
+{               
+    MParList  plist;
+    MTaskList tlist;
 
-    MHillas       hillas;
-    MHillasExt    hillasext;
-    MNewImagePar  newimgpar;
-    MTaskList     tlist;
-
-    plist.AddToList(&hillas);
-    plist.AddToList(&hillasext);
-    plist.AddToList(&newimgpar);
     plist.AddToList(&tlist);
 
@@ -71,5 +128,5 @@
     MMcPedestalCopy   pcopy;
     MMcPedestalNSBAdd pnsb;
-    MCerPhotCalc      ncalc;
+    MCerPhotAnal2     ncalc;
     MBlindPixelCalc   blind;
     blind.SetUseInterpolation();
@@ -77,4 +134,8 @@
     MImgCleanStd      clean;
     MHillasCalc       hcalc;
+    MTaskInteractive  mytask;
+
+    mytask.SetPreProcess(PreProcess);
+    mytask.SetProcess(Process);
 
     tlist.AddToList(&read);
@@ -89,58 +150,13 @@
     tlist.AddToList(&clean);
     tlist.AddToList(&hcalc);
+    tlist.AddToList(&mytask);
 
     MEvtLoop evtloop;
     evtloop.SetParList(&plist);
 
-    if (!evtloop.PreProcess())
+    if (!evtloop.Eventloop())
         return;
 
-    MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
-
-    MHCamera display[4];
-    TCanvas c("Events", "Real Events", 600, 600);
-    c.SetBorderMode(0);
-    c.Divide(2,2);
-    for (int i=0; i<4; i++)
-    {
-        display[i].SetGeometry(*geomcam);
-        c.cd(i+1);
-        display[i].Draw();
-        gPad->cd(1);
-        hillas.Draw();
-    }
-
-    // Use this if you don't want the event to be autoscaled
-    //display.SetMinimum(0);
-    //display.SetMaximum(100);
-
-    while (tlist.Process())
-    {
-        cout << "Event #" << read.GetNumEntry() ":" << endl;
-
-        display[0].SetCamContent(*(MCerPhotEvt*)clone.GetClone());
-        display[1].SetCamContent(*(MCerPhotEvt*)plist.FindObject("MCerPhotEvt"));
-        display[2].SetCamContent(*(MCamEvent*)plist.FindObject("MCameraData"));
-        display[3].SetCamContent(*(MCamEvent*)plist.FindObject("MCameraData"));
-        TArrayF lvl(2);
-        lvl[0] = clean.GetCleanLvl2();
-        lvl[1] = clean.GetCleanLvl1();
-        display[3].SetLevels(lvl);
-
-        for (int i=1; i<=4; i++)
-        {
-            c.GetPad(i)->GetPad(1)->Modified();
-            c.GetPad(i)->GetPad(1)->Update();
-        }
-
-        hillas.Print(*geomcam);
-        hillasext.Print(*geomcam);
-        newimgpar.Print();
-
-        if (!HandleInput())
-            break;
-    }
-
-    evtloop.PostProcess();
+    tlist.PrintStatistics();
 }
 
