Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2437)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2438)
@@ -1,19 +1,58 @@
                                                  -*-*- END OF LINE -*-*-
 
+  2003/10/28: Thomas Bretz
+  
+   * macros/readCT1.C:
+     - fixed to work with the correct geometry
+     
+   * macros/readMagic.C:
+     - fixed - was crashing
+     
+   * macros/tar.C:
+     - exclude 'Tag' files from tar
+     
+   * manalysis/MGeomApply.[h,cc]:
+     - replaced constructor by SetGeometry (constructor was
+       not unique)
+
+   * mbase/MEvtLoop.[h,cc]:
+     - set fProgress already when setting fDisplay (gives the
+       possibility to overwrite fProgress)
+     - removed 'entries' from ProcessGuiEvents (moved to fNumEvents)
+     - Set ProgressBar position in percent instead of event number
+     - Set progress bar range from 0 to 1
+     
+   * mbase/MReadSocket.cc:
+     - fixed to treat timeout correctly
+     - replaces usleep() by gSystem->Sleep()
+
+   * mbase/MTime.h:
+     - added SetTime(ULong_t) (support for gSystem->Now())
+     - added SetTime(Double_t)
+     - added operator()
+     - fixed all comparison operators to use time instead of
+       time lo/hi - will be removed soon
+       
+   * mimage/MHHillasSrc.cc:
+     - delete 3rd Pad
+     
+   * mraw/MRawEvtData.cc:
+     - when drawing print gPad
+
+
+
   2003/10/28: Wolfgang Wittek
 
-  * manalysis/MCT1PadONOFF.cc
-    - replace GetMeanRms() by GetPedestalRms()
-    - replace SetMeanRms() by SetPedestalRms()
-    - reactivate code which was commented out by tgb
-                     (no compilation errors on Alpha OSF)
-
-  * manalysis/AnalysisLinkDef.h
-             /Makefile
-    - put back MCT1PadONOFF
-
-  * macros/CT1Analysis.C
-          /ONOFFCT1Analysis.C
-    - current versions of macros for the analysis of CT1 data
+   * manalysis/MCT1PadONOFF.cc
+     - replace GetMeanRms() by GetPedestalRms()
+     - replace SetMeanRms() by SetPedestalRms()
+     - reactivate code which was commented out by tgb
+       (no compilation errors on Alpha OSF)
+
+   * manalysis/AnalysisLinkDef.h, manalysis/Makefile
+     - put back MCT1PadONOFF
+
+   * macros/CT1Analysis.C, macros/ONOFFCT1Analysis.C
+     - current versions of macros for the analysis of CT1 data
 
 
@@ -25,4 +64,6 @@
        that goes with the same value to both FADC gains (fDigitalNoise)
      - Class version has been changed from 2 to 3.
+
+
 
   2003/10/24: Abelardo Moralejo
@@ -37,4 +78,6 @@
        class would produce wrong results.
 
+
+
   2003/10/23: Abelardo Moralejo
 
@@ -44,4 +87,5 @@
        we had in 3.02, and the graphics output had become unreadable. 
        Replacing some Draw() calls by DrawCopy() has solved the problem.
+
 
 
Index: trunk/MagicSoft/Mars/macros/readCT1.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readCT1.C	(revision 2437)
+++ trunk/MagicSoft/Mars/macros/readCT1.C	(revision 2438)
@@ -49,5 +49,4 @@
     MParList plist;
 
-    MGeomCamCT1  geomcam;
     MHillas      hillas;
     MHillasExt   hillasext;
@@ -67,4 +66,6 @@
     MHillasCalc   hcalc;
 
+    geomapl.SetGeometry("MGeomCamCT1");
+
     tlist.AddToList(&read);
     tlist.AddToList(&clone);
@@ -77,4 +78,6 @@
     if (!evtloop.PreProcess())
         return;
+
+    MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
 
     Int_t icount = 0;
Index: trunk/MagicSoft/Mars/macros/readMagic.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readMagic.C	(revision 2437)
+++ trunk/MagicSoft/Mars/macros/readMagic.C	(revision 2438)
@@ -96,6 +96,8 @@
         return;
 
-    MHCamera display1(geomcam);
-    MHCamera display2(geomcam);
+    MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
+
+    MHCamera display1(*geomcam);
+    MHCamera display2(*geomcam);
 
     TCanvas c("Events", "Real Events", 300, 600);
Index: trunk/MagicSoft/Mars/macros/tar.C
===================================================================
--- trunk/MagicSoft/Mars/macros/tar.C	(revision 2437)
+++ trunk/MagicSoft/Mars/macros/tar.C	(revision 2438)
@@ -21,5 +21,5 @@
     gSystem->cd("..");
 
-    TString cmd = "tar cvf "+name+".tar --exclude=Root "+name+"/.rootrc "+name+"/*";
+    TString cmd = "tar cvf "+name+".tar --exclude=Root Tag "+name+"/.rootrc "+name+"/*";
 
     cout << "Executing: " << cmd << endl;
Index: trunk/MagicSoft/Mars/manalysis/MGeomApply.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MGeomApply.cc	(revision 2437)
+++ trunk/MagicSoft/Mars/manalysis/MGeomApply.cc	(revision 2438)
@@ -74,14 +74,4 @@
 // --------------------------------------------------------------------------
 //
-//  Give the name of the geometry you want to have, eg. MGeomCamCT1
-//
-MGeomApply::MGeomApply(const TString cam, const char *name, const char *title) : fGeomName(cam)
-{
-    fName  = name  ? name  : "MGeomApply";
-    fTitle = title ? title : "Task to apply geometry settings";
-}
-
-// --------------------------------------------------------------------------
-//
 //  Try to find 'MGeomCam' in the Parameter List. If it is not found,
 //  try to create a fGeomName object.
Index: trunk/MagicSoft/Mars/manalysis/MGeomApply.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MGeomApply.h	(revision 2437)
+++ trunk/MagicSoft/Mars/manalysis/MGeomApply.h	(revision 2438)
@@ -20,5 +20,6 @@
 public:
     MGeomApply(const char *name=NULL, const char *title=NULL);
-    MGeomApply(const TString name, const char *name=NULL, const char *title=NULL);
+
+    void SetGeometry(TString geom) { fGeomName = geom; }
 
     ClassDef(MGeomApply, 0) // Task to apply geometry settings
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2437)
+++ 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 2437)
+++ 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 2437)
+++ 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 2437)
+++ 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();
 }
 
Index: trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 2437)
+++ trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 2438)
@@ -217,4 +217,6 @@
     fDist->Draw();
 
+    delete pad->GetPad(3);
+
     pad->cd(4);
     gPad->SetBorderMode(0);
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 2437)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 2438)
@@ -215,4 +215,5 @@
 //     <index>      The pixel with the given index is drawn
 //
+#include <TVirtualPad.h>
 void MRawEvtData::Draw(Option_t *opt)
 {
@@ -300,5 +301,5 @@
     {
         // FIXME: Add Legend
-        *fLog << inf << "Drawing Histogram of Pixel with Idx #" << dec << pix.GetPixelId() << endl;
+        *fLog << inf << "Drawing Histogram of Pixel with Idx #" << dec << pix.GetPixelId() << " to " << gPad << endl;
 
         TH1F *histh = new TH1F(name, "FADC Samples", nh, -0.5, nh-.5);
