Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2416)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2438)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
@@ -78,5 +78,5 @@
 #include <TSystem.h>        // gSystem
 #include <TStopwatch.h>
-#include <TGProgressBar.h>
+#include <TGProgressBar.h>  
 
 #include "MLog.h"
@@ -191,5 +191,10 @@
         fProgress=NULL;
     else
+    {
         d->SetBit(kMustCleanup);
+
+        // Get pointer to update Progress bar
+        fProgress = fDisplay->GetBar();
+    }
 
     if (fParList)
@@ -237,6 +242,4 @@
         // Lock display to prevent user from deleting it
         fDisplay->Lock();
-        // Get pointer to update Progress bar
-        fProgress = fDisplay->GetBar();
         // Don't display context menus
         fDisplay->SetNoContextMenu();
@@ -267,5 +270,5 @@
 }
 
-Bool_t MEvtLoop::ProcessGuiEvents(Int_t num, Int_t entries)
+Bool_t MEvtLoop::ProcessGuiEvents(Int_t num)
 {
     if (gROOT->IsBatch())
@@ -347,7 +350,11 @@
             txt += " (";
             txt += speed;
-            txt += "Evts/s, est: ";
-            txt += (int)((long int)(t0-t2)*entries/(60000.*(num-start)));
-            txt += "m";
+            txt += "Evts/s";
+            if (fNumEvents>0)
+            {
+                txt += ", est: ";
+                txt += (int)((long int)(t0-t2)*fNumEvents/(60000.*(num-start)));
+                txt += "m";
+            }
             //txt += (int)fmod(entries/(1000.*(num-start)/(long int)(t0-t2)), 60);
             //txt += "s";
@@ -362,6 +369,6 @@
     // Set new progress bar position
     //
-    if (fProgress)
-        fProgress->SetPosition(num);
+    if (fProgress && fNumEvents>0)
+        fProgress->SetPosition(num/fNumEvents);
 
     //
@@ -409,8 +416,11 @@
 
     Int_t entries = INT_MAX;
+    fNumEvents = 0;
 
     if (fProgress && !gROOT->IsBatch())
     {
         fProgress->Reset();
+        fProgress->SetRange(0, 1);
+
 #ifdef __MARS__
         // limits.h
@@ -421,8 +431,8 @@
 
         if (maxcnt>0)
-            fProgress->SetRange(0, TMath::Min(maxcnt, entries));
+            fNumEvents = TMath::Min(maxcnt, entries);
         else
             if (entries!=INT_MAX)
-                fProgress->SetRange(0, entries);
+                fNumEvents = entries;
     }
 
@@ -454,5 +464,5 @@
         {
             numcnts++;
-            if (!ProcessGuiEvents(++dummy, entries))
+            if (!ProcessGuiEvents(++dummy))
                 break;
         }
@@ -462,5 +472,5 @@
         {
             numcnts++;
-            if (!ProcessGuiEvents(maxcnt - dummy, entries))
+            if (!ProcessGuiEvents(maxcnt - dummy))
                 break;
         }
@@ -473,5 +483,6 @@
     if (fProgress && !gROOT->IsBatch())
     {
-        fProgress->SetPosition(maxcnt>0 ? TMath::Min(maxcnt, entries) : entries);
+        //fProgress->SetPosition(maxcnt>0 ? TMath::Min(maxcnt, entries) : entries);
+        fProgress->SetPosition(1);
         // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents
         if (gApplication->InheritsFrom(TRint::Class()))
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 2416)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 2438)
@@ -30,4 +30,6 @@
     TGProgressBar *fProgress;  //!
 
+    ULong_t fNumEvents;        //!
+
     enum { kIsOwner = BIT(14) };
 
@@ -37,5 +39,5 @@
     void StreamPrimitive(ofstream &out) const;
 
-    Bool_t ProcessGuiEvents(Int_t num, Int_t entries);
+    Bool_t ProcessGuiEvents(Int_t num);
 
 public:
Index: trunk/MagicSoft/Mars/mbase/MReadSocket.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadSocket.cc	(revision 2416)
+++ trunk/MagicSoft/Mars/mbase/MReadSocket.cc	(revision 2438)
@@ -30,10 +30,4 @@
 //////////////////////////////////////////////////////////////////////////////
 #include "MReadSocket.h"
-
-/*
- #ifdef _REENTRANT
- #include <pthread.h>
- #endif
-*/
 
 #include <unistd.h>          // usleep
@@ -155,4 +149,10 @@
 int MReadSocket::underflow()
 {
+    if (fail())
+    {
+        setg(fBuffer, fBuffer, fBuffer+fMtu);
+        return 0;
+    }
+
     //
     // This simple trick should do its job, because the
@@ -161,11 +161,12 @@
     const TTime timeout = fTimeout+gSystem->Now();
 
-    Int_t l, len=-1;
+    Int_t len=-1;
     while (len<0 && gSystem->Now()<timeout)
     {
+        Int_t l;
         fRxSocket->GetOption(kBytesToRead, l);
         if (l==0)
         {
-            usleep(1);
+            gSystem->Sleep(1);
             continue;
         }
@@ -177,4 +178,6 @@
         cout << "MReadSocket: TSocket::RecvRaw - Connection timed out." << endl;
         setstate(ios::failbit);
+        memset(fBuffer, 0, fMtu);
+        len = fMtu;
     }
 
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 2416)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 2438)
@@ -76,4 +76,27 @@
     }
 
+    void SetTime(ULong_t t)
+    {
+        // t [millisec]
+        fNanoSec  = (t*1000000)%1000;
+        t /= 1000;
+        fSec      = t%60;
+        t /= 60;
+        fMin      = t%60;
+        t /= 60;
+        fHour     = t%24;
+    }
+
+    void SetTime(Double_t t)
+    {
+        // t [s]
+        fNanoSec  = (UInt_t)(fmod(t, 1)*1e9);
+        fSec      = (Byte_t)fmod(t, 60);
+        t /= 60;
+        fMin      = (Byte_t)fmod(t, 60);
+        t /= 60;
+        fHour     = (Byte_t)fmod(t, 24);
+    }
+
     void SetTime(Byte_t h, Byte_t m, Byte_t s, UShort_t ns)
     {
@@ -112,4 +135,8 @@
         return fNanoSec/1e9+(fHour*24*60*60+fMin*60+fSec);
     }
+    double operator()() const //[s]
+    {
+        return operator double();
+    }
 
     ClassDef(MTime, 1)	//A generalized MARS time stamp
@@ -118,30 +145,30 @@
 inline Double_t operator-(MTime &t1, MTime &t2)
 {
-    return (Double_t)t1.GetTimeLo()-(Double_t)t2.GetTimeLo();
+    return t1()-t2();
 }
 
 inline Bool_t operator<(MTime &t1, MTime &t2)
 {
-    return (t1.GetTimeHi()<=t2.GetTimeHi()) && (t1.GetTimeLo()<t2.GetTimeLo());
+    return t1()<t2();
 }
 
 inline Bool_t operator>(MTime &t1, MTime &t2)
 {
-    return (t1.GetTimeHi()>=t2.GetTimeHi()) && (t1.GetTimeLo()>t2.GetTimeLo());
+    return t1()>t2();
 }
 
 inline Bool_t operator<=(MTime &t1, MTime &t2)
 {
-    return (t1.GetTimeHi()<=t2.GetTimeHi()) && (t1.GetTimeLo()<=t2.GetTimeLo());
+    return t1<=t2();
 }
 
 inline Bool_t operator>=(MTime &t1, MTime &t2)
 {
-    return (t1.GetTimeHi()>=t2.GetTimeHi()) && (t1.GetTimeLo()>=t2.GetTimeLo());
+    return t1()>=t2();
 }
 
 inline Bool_t operator==(MTime &t1, MTime &t2)
 {
-    return (t1.GetTimeLo()==t2.GetTimeLo()) && (t1.GetTimeHi()==t2.GetTimeHi());
+    return t1()==t2();
 }
 
