Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 2377)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 2386)
@@ -14,4 +14,5 @@
 
 #pragma link C++ class MLog+;
+#pragma link C++ class MReadSocket+;
 
 #pragma link C++ class MIter+;
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2377)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2386)
@@ -168,5 +168,6 @@
 {
     fProgress = bar;
-    fProgress->SetBit(kMustCleanup);
+    if (fProgress)
+        fProgress->SetBit(kMustCleanup);
 }
 
@@ -187,10 +188,8 @@
     MParContainer::SetDisplay(d);
     if (!d)
-    {
         fProgress=NULL;
-        return;
-    }
-
-    d->SetBit(kMustCleanup);
+    else
+        d->SetBit(kMustCleanup);
+
     if (fParList)
         fParList->SetDisplay(d);
@@ -269,5 +268,5 @@
 Bool_t MEvtLoop::ProcessGuiEvents(Int_t num, Int_t entries)
 {
-    if (!fProgress || gROOT->IsBatch())
+    if (gROOT->IsBatch())
         return kTRUE;
 
@@ -286,6 +285,33 @@
             fDisplay->ClearStatus();
             break;
+        //
+        // If the display is not on the heap (means: not created
+        // with the new operator) the object is deleted somewhere
+        // else in the code. It is the responsibility of the
+        // application which instantiated the object to make
+        // sure that the correct action is taken. This can be
+        // done by calling MStatusDisplay::CheckStatus()
+        //
+        // Because we are synchronous we can safely delete it here!
+        //
+        // Close means: Close the display but leave analysis running
+        // Exit means: Close the display and stop analysis
+        //
+        case MStatusDisplay::kFileClose:
+        case MStatusDisplay::kFileExit:
+            rc = fDisplay->CheckStatus() == MStatusDisplay::kFileClose;
+
+            if (fDisplay->IsOnHeap())
+                delete fDisplay;
+
+            //
+            // This makes the display really disappear physically on
+            // the screen in case of MStatusDisplay::kFileClose
+            //
+            gSystem->ProcessEvents();
+
+            return rc;
         default:
-            *fLog << warn << "MEvtloop: fDisplay->ChecStatus() has returned unknown status #" << fDisplay->CheckStatus() << "... cleared." << endl;
+            *fLog << warn << "MEvtloop: fDisplay->CheckStatus() has returned unknown status #" << fDisplay->CheckStatus() << "... cleared." << endl;
             fDisplay->ClearStatus();
             break;
@@ -293,8 +319,8 @@
 
     //
-    // Check System time (don't loose too much time by updates)
-    //
-
-    // FIXME: Not thread safe
+    // Check System time (don't loose too much time by updating the GUI)
+    //
+
+    // FIXME: Not thread safe (if you have more than one eventloop running)
     static Int_t start = num;
     static TTime t1 = gSystem->Now();
@@ -335,5 +361,6 @@
     // Set new progress bar position
     //
-    fProgress->SetPosition(num);
+    if (fProgress)
+        fProgress->SetPosition(num);
 
     //
@@ -346,5 +373,6 @@
         gSystem->ProcessEvents();
     else
-        gClient->ProcessEventsFor(fProgress);
+        if (fProgress)
+            gClient->ProcessEventsFor(fProgress);
 #endif
 
Index: trunk/MagicSoft/Mars/mbase/MFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MFilter.cc	(revision 2377)
+++ trunk/MagicSoft/Mars/mbase/MFilter.cc	(revision 2386)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  07/2001 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz, 07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
Index: trunk/MagicSoft/Mars/mbase/MReadSocket.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadSocket.cc	(revision 2386)
+++ trunk/MagicSoft/Mars/mbase/MReadSocket.cc	(revision 2386)
@@ -0,0 +1,184 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MReadSocket
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MReadSocket.h"
+
+/*
+ #ifdef _REENTRANT
+ #include <pthread.h>
+ #endif
+*/
+
+#include <unistd.h>          // usleep
+
+#include <TMath.h>           // TMath::Min
+#include <TTime.h>           // TTime
+#include <TDatime.h>         // TDatime
+#include <TSystem.h>         // gSystem
+#include <TSocket.h>         // TSocket
+#include <TServerSocket.h>   // TServerSocket
+
+ClassImp(MReadSocket);
+
+using namespace std;
+
+MReadSocket::MReadSocket(int port, int mtu) : istream(this), fMtu(mtu), fTimeout(2500), fServSock(NULL), fRxSocket(NULL)
+{
+    fBuffer = new char[mtu];
+
+    setg(fBuffer, fBuffer, fBuffer+1);
+
+    cout << "Starting server socket on port 7000..." << endl;
+
+    while (1)
+    {
+        fServSock=new TServerSocket(port, kTRUE);
+        if (fServSock->IsValid())
+            break;
+
+        cout << "ServerSocket not valid: ";
+        switch (fServSock->GetErrorCode())
+        {
+        case 0: cout << "No error." << endl; break;
+        case -1: cout << "low level socket() call failed." << endl; break;
+        case -2: cout << "low level bind() call failed." << endl; break;
+        case -3: cout << "low level listen() call failed." << endl; break;
+        default: cout << "Unknown." << endl; break;
+        }
+
+        delete fServSock;
+        fServSock=NULL;
+        break;
+    }
+    if (!fServSock)
+    {
+        cout << "MReadSocket: TServerSocket - Connection timed out." << endl;
+        setstate(ios::failbit);
+        return;
+    }
+
+    fServSock->SetOption(kNoBlock, 1);
+
+    while (1)
+    {
+        const TTime timeout = gSystem->Now() + TTime(5000);
+
+        TDatime now;
+        cout << now.AsString() << ": Waiting for conntection on port 7000..." << endl;
+        fRxSocket = NULL;
+        while ((Long_t)fRxSocket<=0 && gSystem->Now()<timeout)
+        {
+            fRxSocket = fServSock->Accept();
+            if (fRxSocket==0)
+                cout << "Error: TServerSock::Accept" << endl;
+            usleep(1);
+        }
+
+        if ((Long_t)fRxSocket<=0)
+            continue;
+
+        if (fRxSocket->IsValid())
+            break;
+
+        cout << "TSocket: Connection not valid..." << endl;
+        delete fRxSocket;
+    }
+
+    if ((Long_t)fRxSocket<=0)
+    {
+        cout << "MReadSocket: TServerSocket::Accept - Connection timed out." << endl;
+        fRxSocket=NULL;
+        setstate(ios::failbit);
+        return;
+    }
+
+    cout << "Connection established..." << endl;
+
+    fRxSocket->SetOption(kNoBlock, 1);
+
+    underflow();
+}
+
+// --------------------------------------------------------------------------
+//
+//  Destructor, destroying the gui mutex.
+//
+MReadSocket::~MReadSocket()
+{
+    if (fRxSocket)
+        delete fRxSocket;
+    if (fServSock)
+        delete fServSock;
+
+    delete fBuffer;
+
+    cout << "Connection on Port 7000 closed." << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// This is called to flush the buffer of the streaming devices
+//
+int MReadSocket::sync()
+{
+    cout << "sync" << endl;
+    return 0;
+}
+
+int MReadSocket::underflow()
+{
+    //
+    // This simple trick should do its job, because the
+    // TCP/IP stream is buffered already
+    //
+    const TTime timeout = fTimeout+gSystem->Now();
+
+    Int_t l, len=-1;
+    while (len<0 && gSystem->Now()<timeout)
+    {
+        fRxSocket->GetOption(kBytesToRead, l);
+        if (l==0)
+        {
+            usleep(1);
+            continue;
+        }
+        len = fRxSocket->RecvRaw(fBuffer, TMath::Min(fMtu, l));
+    }
+
+    if (len<0)
+    {
+        cout << "MReadSocket: TSocket::RecvRaw - Connection timed out." << endl;
+        setstate(ios::failbit);
+    }
+
+    setg(fBuffer, fBuffer, fBuffer+len);
+    return 0;
+}
+
Index: trunk/MagicSoft/Mars/mbase/MReadSocket.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadSocket.h	(revision 2386)
+++ trunk/MagicSoft/Mars/mbase/MReadSocket.h	(revision 2386)
@@ -0,0 +1,42 @@
+#ifndef MARS_MReadSocket
+#define MARS_MReadSocket
+
+#ifndef ROOT_TROOT
+#include <TROOT.h>
+#endif
+#ifndef ROOT_TTime
+#include <TTime.h>
+#endif
+
+#include <iostream>  // base classes for MReadSocket
+
+class TSocket;
+class TServerSocket;
+
+class MReadSocket : public std::streambuf, public std::istream
+{
+private:
+    char *fBuffer; //!
+
+    int   fMtu;
+    TTime fTimeout;
+
+    TServerSocket  *fServSock;
+    TSocket        *fRxSocket;
+
+    int underflow();
+    int sync();
+
+public:
+    MReadSocket(int port, int mtu=1500);
+    MReadSocket(MReadSocket const& log) : istream((std::streambuf*)&log)
+    {
+    }
+    ~MReadSocket();
+
+    void SetTimeout(UInt_t millisec) { fTimeout = millisec; }
+
+    ClassDef(MReadSocket, 0) // This is what we call 'The logging system'
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 2377)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 2386)
@@ -108,4 +108,9 @@
     }
 
+    operator double() const //[s]
+    {
+        return fNanoSec/1e9+(fHour*24*60*60+fMin*60+fSec);
+    }
+
     ClassDef(MTime, 1)	//A generalized MARS time stamp
 };
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 2377)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 2386)
@@ -44,4 +44,5 @@
            MEvtLoop.cc \
            MIter.cc \
+           MReadSocket.cc \
            MDirIter.cc \
            MGList.cc \
