Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2496)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2497)
@@ -84,4 +84,20 @@
      - added MGMenu
      - added MProgressBar
+
+   * mona.cc:
+     - added ChangeContextMenus
+     - adapted to new MRawSocketRead interface
+     - assigned names to different tasks
+     - swiched off progress bar (temporarily)
+     - moved status display into thread
+     - exit thread by Exit() (seems to be necessary)
+     - added preliminary workaround for mssing RootPlugin
+
+   * mmain/MAnalysis.cc:
+     - removed external display
+     - added MStatusDisplay
+     
+   * mmain/MMonteCarlo.cc:
+     - old workaround (MMcEvt) obsolete
 
 
Index: trunk/MagicSoft/Mars/mmain/MAnalysis.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MAnalysis.cc	(revision 2496)
+++ trunk/MagicSoft/Mars/mmain/MAnalysis.cc	(revision 2497)
@@ -61,5 +61,5 @@
     //
     TGCompositeFrame *frame = CreateNewTab("Setup");
-
+ /*
     TGGroupFrame *grp = new TGGroupFrame(frame, "Setup Display");
     fList->Add(grp);
@@ -87,9 +87,10 @@
     grp->AddFrame(fCheckButton1, laybut);
     grp->AddFrame(fCheckButton2, laybut);
-
+ */
     TGLayoutHints *laygrp = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 20, 20, 20);
     fList->Add(laygrp);
-
+ /*
     frame->AddFrame(grp, laygrp);
+  */
 
     /*
@@ -120,4 +121,5 @@
 // ======================================================================
 
+#include "MStatusDisplay.h"
 #include "MParList.h"
 #include "MTaskList.h"
@@ -138,4 +140,5 @@
 #include "MEvtLoop.h"
 #include "MHillas.h"
+#include "MGeomApply.h"
 
 void MAnalysis::CalculateHillas()
@@ -145,6 +148,6 @@
     // parameter out of a Magic root file.
 
-    const Bool_t displhillas  = fCheckButton1->GetState();
-    const Bool_t displstarmap = fCheckButton2->GetState();
+    const Bool_t displhillas  = kTRUE;//fCheckButton1->GetState();
+    const Bool_t displstarmap = kTRUE;//fCheckButton2->GetState();
 
     //
@@ -193,5 +196,7 @@
     //
     MReadMarsFile read("Events", fInputFile);
-
+    read.DisableAutoScheme();
+
+    MGeomApply         apply;
     MMcPedestalCopy    pcopy;
     MMcPedestalNSBAdd  pdnsb;
@@ -216,4 +221,5 @@
 
     tlist.AddToList(&read);
+    tlist.AddToList(&apply);
     tlist.AddToList(&pcopy);
     tlist.AddToList(&pdnsb);
@@ -245,17 +251,29 @@
     // Add ProgressBar to window
     //
-    TGProgressBar *bar = CreateProgressBar(fTop2);
-    evtloop.SetProgressBar(bar);
+    TGProgressBar *bar = NULL;
+    if (displhillas || displstarmap)
+    {
+        MStatusDisplay *d=new MStatusDisplay;
+        evtloop.SetDisplay(d);
+    }
+    else
+    {
+        bar = CreateProgressBar(fTop2);
+        evtloop.SetProgressBar(bar);
+    }
+
 
     //
     // Execute your analysis
     //
-    Bool_t rc = evtloop.Eventloop();
+    /*Bool_t rc =*/ evtloop.Eventloop();
 
     //
     // Remove progressbar from window
     //
-    DestroyProgressBar(bar);
-
+    if (bar)
+        DestroyProgressBar(bar);
+
+ /*
     if (!rc)
         return;
@@ -270,8 +288,4 @@
         plist.FindObject("MHHillasSrc")->DrawClone();
         plist.FindObject("MHNewImagePar")->DrawClone();
-        /*
-         plist.FindObject("HistSource")->DrawClone();
-         plist.FindObject("HistAntiSrc")->DrawClone();
-         */
     }
 
@@ -281,4 +295,5 @@
     cout << endl;
     cout << "Calculation of Hillas Parameters finished without error!" << endl;
+ */
 }
 
Index: trunk/MagicSoft/Mars/mmain/MMonteCarlo.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MMonteCarlo.cc	(revision 2496)
+++ trunk/MagicSoft/Mars/mmain/MMonteCarlo.cc	(revision 2497)
@@ -197,5 +197,7 @@
 #include "MMcCollectionAreaCalc.h"
 
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
 #include "../mmc/MMcTrig.hxx" // FIXME: see FIXME below
+#endif
 
 Int_t MMonteCarlo::GetDim() const
@@ -228,4 +230,5 @@
     plist.AddToList(&tlist);
 
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
     //
     // FIXME: This line is needed that root finds the MMc-classes in the
@@ -235,4 +238,5 @@
     //
     MMcTrig trig;
+#endif
 
     //
@@ -326,4 +330,5 @@
     plist.AddToList(&hists);
 
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
     //
     // FIXME: This line is needed that root finds the MMc-classes in the
@@ -333,4 +338,5 @@
     //
     MMcTrig trig;
+#endif
 
     //
@@ -412,4 +418,5 @@
     plist.AddToList(&hists);
 
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
     //
     // FIXME: This line is needed that root finds the MMc-classes in the
@@ -419,4 +426,5 @@
     //
     MMcTrig trig;
+#endif
 
     //
Index: trunk/MagicSoft/Mars/mona.cc
===================================================================
--- trunk/MagicSoft/Mars/mona.cc	(revision 2496)
+++ trunk/MagicSoft/Mars/mona.cc	(revision 2497)
@@ -1,6 +1,6 @@
-#include <TROOT.h>
 #include <TApplication.h>
 
 #include <TThread.h>
+#include <TMethod.h>          // GetMenuItems
 
 #include "MParList.h"
@@ -17,4 +17,5 @@
 #include "MOnlineDump2.h"
 #include "MHTriggerLvl0.h"
+#include "MHCamera.h"         // ::Class()
 
 #include "MStatusDisplay.h"
@@ -39,4 +40,37 @@
 }
 
+void Remove(TMethod *m, const char *name)
+{
+    if (TString(m->GetName()).BeginsWith(name))
+        m->SetMenuItem(kMenuNoMenu);
+}
+
+void ChangeContextMenus()
+{
+    TList l;
+    MHCamera::Class()->GetMenuItems(&l);
+    TIter Next(&l);
+    TMethod *m=NULL;
+    while ((m=(TMethod*)Next()))
+    {
+        Remove(m, "DrawClone");
+        Remove(m, "SetName");
+        Remove(m, "Delete");
+        Remove(m, "DrawClass");
+        Remove(m, "Dump");
+        Remove(m, "Inspect");
+        Remove(m, "Smooth");
+        Remove(m, "Fit");
+        Remove(m, "Divide");
+        Remove(m, "Add");
+        Remove(m, "Multiply");
+        Remove(m, "Delete");
+        Remove(m, "SetLineAttributes");
+        Remove(m, "SetFillAttributes");
+        Remove(m, "SetMarkerAttributes");
+        Remove(m, "SetDrawOption");
+    }
+}
+
 Bool_t Loop(MStatusDisplay *display)
 {
@@ -47,4 +81,5 @@
     //
     MRawSocketRead reader;
+    reader.SetPort(7000);
 
     //
@@ -57,7 +92,4 @@
     plist.AddToList(&tasks);
     tasks.AddToList(&reader);
-
-    //MParList &plist = *(MParList*)ptr;
-    //MTaskList &tasks = *(MTaskList*)plist.FindObject("MTaskList");
 
     MGeomApply geomapl;
@@ -66,20 +98,16 @@
     tasks.AddToList(&ncalc);
 
-    MFillH fill1("MHCamEvent", "MCerPhotEvt");
-    MFillH fill2("MHEvent",    "MCerPhotEvt");
+    MFillH fill1("MHEvent",    "MCerPhotEvt", "MFillEvent");
+    MFillH fill2("MHCamEvent", "MCerPhotEvt", "MFillCamEvent");
+
+    MFRealTimePeriod filter;
+    fill1.SetFilter(&filter);
 
     MHTriggerLvl0 trigmap(128, "Above 128");
-    MFillH fill3(&trigmap, "MRawEvtData");
-
-    MFRealTimePeriod filter;
-    fill2.SetFilter(&filter);
-
-    fill1.SetName("MFillCamEvent");
-    fill2.SetName("MFillEvent");
-    fill3.SetName("MFillTriggerLvl0");
-
-    tasks.AddToList(&fill2);
+    MFillH fill3(&trigmap, "MRawEvtData", "MFillTriggerLvl0");
+
     tasks.AddToList(&filter);
     tasks.AddToList(&fill1);
+    tasks.AddToList(&fill2);
     tasks.AddToList(&fill3);
 
@@ -91,17 +119,17 @@
     MHillasCalc       hcalc;
     MHillasSrcCalc    scalc; // !!Preliminary!! Will be removed later!
-    MFillH hfill3("MHHillas", "MHillas");
-    MFillH hfill6("MHHillasSrc","MHillasSrc");
+    MFillH hfill3("MHHillas",   "MHillas",    "MFillHillas");
+    MFillH hfill4("MHHillasSrc","MHillasSrc", "MFillHillasSrc");
     tasks.AddToList(&clean);
     tasks.AddToList(&hcalc);
     tasks.AddToList(&scalc);
     tasks.AddToList(&hfill3);
-    tasks.AddToList(&hfill6);
+    tasks.AddToList(&hfill4);
 
     MEvtLoop magic;
-    //plist.AddToList(&magic);
     magic.SetParList(&plist);
 
     magic.SetDisplay(display);
+    magic.SetProgressBar((TGProgressBar*)NULL);
 
     if (!magic.Eventloop())
@@ -115,10 +143,14 @@
 }
 
+//
+// By defining the function return type 'void' instead of
+// 'void*' we tell TThread to create a detached thread,
+// but calling Exit() in a detached thread results in a crash
+// when the TGApplication is terminated.
+//
 void *thread(void *ptr)
 {
-    // TThread::SetCancelAsynchronous();
-    // TThread::SetCancelOn();
-    MStatusDisplay *display=(MStatusDisplay*)ptr;
-//    display->Lock();
+    MStatusDisplay d;
+    d.Resize(740, 600);
 
     //
@@ -126,6 +158,6 @@
     // user requested to exit the program.
     //
-    while (display->CheckStatus()!=MStatusDisplay::kFileExit)
-        Loop(display);
+    while (d.CheckStatus()!=MStatusDisplay::kFileExit)
+        Loop(&d);
 
     gLog << dbg << "Exit System Loop... " << flush;
@@ -133,13 +165,52 @@
     gLog << "done." << endl;
 
+    TThread::Self()->Exit();
     return 0;
 }
 
+/*
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
+#include <TRootGuiFactory.h>
+#include <TPluginManager.h>
+void InitGuiFactory()
+{
+   if (gROOT->IsBatch())
+       gROOT->SetBatch(kFALSE);
+
+    //
+    // Must be loaded by hand, because it is not loaded by TGApplication.
+    // We could also use TApplication instead, but TApplication doesn't
+    // deal with the DISPLAY variable in a convient way.
+    //
+    TPluginHandler *h;
+    if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", "root")))
+    {
+        if (h->LoadPlugin() == -1)
+            return;
+        gGuiFactory = (TGuiFactory*)h->ExecPlugin(0);
+    }
+}
+#endif
+*/
+
 int main(int argc, char **argv)
 {
-    TROOT simple("mona", "Magic ONline Analysis");
-    TApplication app("MonaApp", &argc, argv);
-
     StartUpMessage();
+
+    TApplication app("Mars", &argc, argv);
+    if (gROOT->IsBatch() || !gClient)
+    {
+        gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
+        return 1;
+    }
+    /*
+    TGApplication app("Mona", &argc, argv);
+
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
+    InitGuiFactory();
+#endif
+    */
+
+    ChangeContextMenus();
 
     //
@@ -147,12 +218,9 @@
     // if the thread is terminated (by return)
     //
-    MStatusDisplay d;
-    d.Resize(740, 600);
-
     gLog << dbg << "Starting Thread..." << endl;
-    TThread t(thread, &d);
+    TThread t(thread);
     t.Run();
 
-    gLog << dbg << "Starting System loop..." << endl;
+    gLog << dbg << "Starting System loop... " << endl;
     app.Run(kTRUE);
     gLog << dbg << "System loop stopped." << endl;
