Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1324)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1325)
@@ -7,4 +7,20 @@
    * macros/tar.C:
      - implemented some sanity checks (existing files)
+
+   * mgui/MCamDisplay.[h,cc]:
+     - changed to use DeepSea palette in root versions newer than 3.01/05
+     - fixed a bug which caused the destructor to do strange thing
+       (the uncloned fGeomCam was deleted)
+     - implemented a more accurate deletion of the objects in the
+       TClonesArrays by using TClonesArray::Delete
+     - Implemented deletion of automatically created TCanvas
+     - Implemented a sanity check in Draw and DrawPhotNum
+
+   * macros/readCT1.C, macros/readMagic.C:
+     - changed to Handling of the gui and keyboard input
+     - implemented the filename as function argument
+
+   * manalysis/MCT1ReadAscii.cc:
+     - Expanded filename to support filnames containing '~'
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 1324)
+++ trunk/MagicSoft/Mars/NEWS	(revision 1325)
@@ -75,4 +75,5 @@
      by unfolding
 
+   - changed the color palette in the camera display to DeapSea.
 
 
Index: trunk/MagicSoft/Mars/macros/readCT1.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readCT1.C	(revision 1324)
+++ trunk/MagicSoft/Mars/macros/readCT1.C	(revision 1325)
@@ -23,6 +23,27 @@
 \* ======================================================================== */
 
+Bool_t HandleInput()
+{
+    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
+    while (1)
+    {
+        //
+        // While reading the input process gui events asynchronously
+        //
+        timer.TurnOn();
+        TString input = Getline("Type 'q' to exit, <return> to go on: ");
+        timer.TurnOff();
 
-void readCT1()
+        if (input=="q\n")
+            return kFALSE;
+
+        if (input=="\n")
+            return kTRUE;
+    };
+
+    return kFALSE;
+}
+
+void readCT1(const char *fname="~/data/CT1_97_on1.dat")
 {
     MParList plist;
@@ -36,5 +57,5 @@
     plist.AddToList(&tlist);
 
-    MCT1ReadAscii read("/home/tbretz/data/CT1_97_on1.dat");
+    MCT1ReadAscii read(fname);
     MClone        clone("MCerPhotEvt");
     MImgCleanStd  clean;
@@ -66,6 +87,6 @@
 
         display.DrawPhotNum(evt);
-        gClient->HandleInput();
-        if (getchar()=='q')
+
+        if (!HandleInput())
             break;
 
@@ -74,6 +95,5 @@
         display.DrawPhotNum((MCerPhotEvt*)plist.FindObject("MCerPhotEvt"));
 
-        gClient->HandleInput();
-        if (getchar()=='q')
+        if (!HandleInput())
             break;
     } 
Index: trunk/MagicSoft/Mars/macros/readMagic.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readMagic.C	(revision 1324)
+++ trunk/MagicSoft/Mars/macros/readMagic.C	(revision 1325)
@@ -24,5 +24,27 @@
 
 
-void readMagic()
+Bool_t HandleInput()
+{
+    TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
+    while (1)
+    {
+        //
+        // While reading the input process gui events asynchronously
+        //
+        timer.TurnOn();
+        TString input = Getline("Type 'q' to exit, <return> to go on: ");
+        timer.TurnOff();
+
+        if (input=="q\n")
+            return kFALSE;
+
+        if (input=="\n")
+            return kTRUE;
+    };
+
+    return kFALSE;
+}
+
+void readMagic(const char *fname="~/data/camera.root")
 {
     MParList plist;
@@ -36,5 +58,5 @@
     plist.AddToList(&tlist);
 
-    MReadMarsFile     read("Events", "~/data/camera.root");
+    MReadMarsFile     read("Events", fname);
 
     MMcPedestalCopy   pcopy;
@@ -71,6 +93,5 @@
         display.DrawPhotNum((MCerPhotEvt*)clone.GetClone());
 
-	gClient->HandleInput();
-        if(getchar()=='q')
+        if (!HandleInput())
             break;
 
@@ -80,14 +101,9 @@
         display.DrawPhotNum((MCerPhotEvt*)plist.FindObject("MCerPhotEvt"));
 
-        gClient->HandleInput();
-        if(getchar()=='q')
-	break;
+        if (!HandleInput())
+            break;
     } 
 
     evtloop.PostProcess();
-
 }
 
-
-
-
Index: trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc	(revision 1324)
+++ trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc	(revision 1325)
@@ -44,4 +44,5 @@
 
 #include <TList.h>
+#include <TSystem.h>
 
 #include "MLog.h"
@@ -124,5 +125,5 @@
     const char *name = file->GetName();
 
-    fIn = new ifstream(name);
+    fIn = new ifstream(gSystem->ExpandPathName(name));
 
     const Bool_t noexist = !(*fIn);
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1324)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1325)
@@ -27,7 +27,7 @@
 //
 MCamDisplay::MCamDisplay(MGeomCam *geom)
-    : fAutoScale(kTRUE), fMinPhe(-2), fMaxPhe(50), fW(0), fH(0), fDrawingPad(NULL)
-{
-    fGeomCam = geom; // FIXME: Clone doesn't work! (MGeomCam*)geom->Clone();
+    : fAutoScale(kTRUE), fMinPhe(-2), fMaxPhe(50), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
+{
+    fGeomCam = (MGeomCam*)geom; // FIXME: Clone doesn't work! (MGeomCam*)geom->Clone();
 
     //
@@ -53,5 +53,9 @@
     // set the color palette for the TBox elements
     //
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
     gStyle->SetPalette(1, 0);
+#else
+    gStyle->SetPalette(51, 0);
+#endif
 
     //
@@ -81,9 +85,16 @@
 MCamDisplay::~MCamDisplay()
 {
+    fPixels->Delete();
+    fLegend->Delete();
+    fLegText->Delete();
+
     delete fPixels;
     delete fLegend;
     delete fLegText;
 
-    delete fGeomCam;
+    // delete fGeomCam;
+
+    if (fIsAllocated)
+        delete fDrawingPad;
 }
 
@@ -157,11 +168,20 @@
     // gPad->SetFixedAspectRatio()
 
+    if (fDrawingPad)
+        return;
+
     //
     // if no canvas is yet existing to draw into, create a new one
     //
     if (!gPad)
+    {
         fDrawingPad = new TCanvas("CamDisplay", "Magic Camera Display", 0, 0, 750, 600);
+        fIsAllocated = kTRUE;
+    }
     else
+    {
         fDrawingPad = gPad;
+        fIsAllocated = kFALSE;
+    }
 
     fDrawingPad->SetBorderMode(0);
@@ -176,5 +196,9 @@
     // Setup the correct environment
     //
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
     gStyle->SetPalette(1, 0);
+#else
+    gStyle->SetPalette(51, 0);
+#endif
 
     gPad->SetFillColor(22);
@@ -220,4 +244,7 @@
 void MCamDisplay::DrawPhotNum(const MCerPhotEvt *event)
 {
+    if (!event)
+        return;
+
     if (!fDrawingPad)
         Draw();
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 1324)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 1325)
@@ -38,4 +38,5 @@
     UInt_t         fH;           // Height of canvas
     TVirtualPad   *fDrawingPad;  // pad in which we are drawing
+    Bool_t         fIsAllocated;
 
     TBox  *GetBox(Int_t i)  { return (TBox*) fLegend->At(i); }
