Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 4747)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 4748)
@@ -71,4 +71,9 @@
    * mfileio/MReadReports.h:
      - overwrote GetFileName - otherwise CINT refuses to create an object
+
+   * mbadpixels/MBadPixelsTreat.[h,cc]:
+     - added an primitive interpolation of arrival times which
+       tries to keep the random arrival time for pixels without
+       signal
 
 
Index: /trunk/MagicSoft/Mars/callisto.cc
===================================================================
--- /trunk/MagicSoft/Mars/callisto.cc	(revision 4747)
+++ /trunk/MagicSoft/Mars/callisto.cc	(revision 4748)
@@ -119,7 +119,7 @@
 
     const TString kInpathD    = arg.GetStringAndRemove("--ind=",  "");
-          TString kInpathY    = arg.GetStringAndRemove("--iny=",  ".");
-          TString kOutpathY   = arg.GetStringAndRemove("--outy=", ".");
-          TString kOutpathC   = arg.GetStringAndRemove("--outc=", ".");
+          TString kInpathY    = arg.GetStringAndRemove("--iny=",  "");
+          TString kOutpathY   = arg.GetStringAndRemove("--outy=", "");
+          TString kOutpathC   = arg.GetStringAndRemove("--outc=", "");
     const TString kOutpath    = arg.GetStringAndRemove("--out=",  "");
     const TString kPath       = arg.GetStringAndRemove("--path=", "");
@@ -139,4 +139,14 @@
         return 0;
     }
+
+    if (kModeC && kOutpathC.IsNull())
+        kOutpathC = ".";
+    if (kModeY)
+    {
+        if (kInpathY.IsNull())
+            kInpathY = ".";
+        if (kOutpathY.IsNull())
+            kOutpathY = ".";
+    }
     if (!kOutpath.IsNull())
     {
@@ -232,5 +242,5 @@
         else
             gLog << err << "ERROR";
-        gLog << " - " << n1 << " files in sequence defined, but " << n0 << "found in ";
+        gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
         gLog << (kInpathD.IsNull() ? "<defaultpath>" : kInpathD.Data()) << endl;
         if (!kForceExec)
@@ -316,5 +326,5 @@
         }
 
-        gLog << all << endl << endl;
+        gLog << flush << all << endl << endl;
     }
 
@@ -371,5 +381,5 @@
         }
 
-        gLog << all << endl << endl;
+        gLog << flush << all << endl << endl;
     }
 
Index: /trunk/MagicSoft/Mars/callisto.rc
===================================================================
--- /trunk/MagicSoft/Mars/callisto.rc	(revision 4747)
+++ /trunk/MagicSoft/Mars/callisto.rc	(revision 4748)
@@ -202,4 +202,5 @@
 MJCalibrateSignal.MBadPixelsTreat.UseInterpolation: yes
 MJCalibrateSignal.MBadPixelsTreat.ProcessPedestal:  yes
+MJCalibrateSignal.MBadPixelsTreat.ProcessTimes:     yes
 #MJCalibrateSignal.MBadPixelsTreat.UseCentralPixel:  no
 #MJCalibrateSignal.MBadPixelsTreat.HardTreatment:    no
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 4747)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 4748)
@@ -57,5 +57,6 @@
 
 #include <TEnv.h>
-#include <TArrayD.h>
+
+#include "MArrayD.h" // Used instead of TArrayD because operator[] has no range check
 
 #include "MLog.h"
@@ -76,4 +77,6 @@
 #include "MBadPixelsCam.h"
 
+#include "MArrivalTime.h"
+
 ClassImp(MBadPixelsTreat);
 
@@ -88,5 +91,5 @@
 //
 MBadPixelsTreat::MBadPixelsTreat(const char *name, const char *title)
-  : fFlags(0), fNumMinNeighbors(3), fNamePedPhotContainer("MPedPhotCam")
+  : fFlags(0), fNumMinNeighbors(3), fNamePedPhotCam("MPedPhotCam")
 {
     fName  = name  ? name  : gsDefName.Data();
@@ -118,19 +121,12 @@
     if (!fBadPixels)
     {
-        *fLog << err << "MBadPixelsCam not found... aborting." << endl;
+        *fLog << err << AddSerialNumber("MBadPixelsCam") << " not found... aborting." << endl;
         return kFALSE;
     }
 
-    fPedPhot = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotContainer), "MPedPhotCam");
-    if (!fPedPhot)
-    {
-        *fLog << err << "MPedPhotCam not found... aborting." << endl;
-        return kFALSE;
-    }
-    
     fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
     if (!fEvt)
     {
-        *fLog << err << "MCerPhotEvt not found... aborting." << endl;
+        *fLog << err << AddSerialNumber("MCerPhotEvt") << " not found... aborting." << endl;
         return kFALSE;
     }
@@ -139,6 +135,30 @@
     if (!fGeomCam && TESTBIT(fFlags, kUseInterpolation))
     {
-        *fLog << err << "MGeomCam not found... can't use interpolation." << endl;
+        *fLog << err << AddSerialNumber("MGeomCam") << " not found - can't use interpolation... abort." << endl;
         return kFALSE;
+    }
+
+    fPedPhot = 0;
+    if (IsProcessPedestal())
+    {
+        fPedPhot = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
+        if (!fPedPhot)
+        {
+            *fLog << err << AddSerialNumber("MPedPhotCam") << " not found... aborting." << endl;
+            return kFALSE;
+        }
+        *fLog << inf << "Processing Pedestals..." << endl;
+    }
+
+    fTimes = 0;
+    if (IsProcessTimes())
+    {
+        fTimes = (MArrivalTime*)pList->FindObject(AddSerialNumber("MArrivalTime"));
+        if (!fTimes)
+        {
+            *fLog << err << AddSerialNumber("MArrivalTime") << " not found... aborting." << endl;
+            return kFALSE;
+        }
+        *fLog << inf << "Processing Times..." << endl;
     }
 
@@ -160,6 +180,6 @@
     // Create arrays (FIXME: Check if its possible to create it only once)
     //
-    TArrayD nphot(entries);
-    TArrayD perr(entries);
+    MArrayD nphot(entries);
+    MArrayD perr(entries);
  
     //
@@ -269,6 +289,6 @@
 
     // Create arrays (FIXME: Check if its possible to create it only once)
-    TArrayD ped(entries);
-    TArrayD rms(entries);
+    MArrayD ped(entries);
+    MArrayD rms(entries);
 
     //
@@ -354,4 +374,51 @@
 
         (*fPedPhot)[i].Set(ped[i], rms[i]);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+void MBadPixelsTreat::InterpolateTimes() const
+{
+    Int_t n = fTimes->GetSize();
+
+    for (int i=0; i<n; i++)
+    {
+        //
+        // Check whether pixel with idx i is blind
+        //
+        if (!IsPixelBad(i))
+            continue;
+
+        //
+        // Get the corresponding geometry and pedestal
+        //
+        const MGeomPix &gpix = (*fGeomCam)[i];
+
+        const Int_t n0 = gpix.GetNumNeighbors();
+
+        MArrayD time(6);
+        for (int j=0; j<n0; j++)
+            time[j] = (*fTimes)[gpix.GetNeighbor(j)];
+
+        Int_t p0=0;
+        Int_t p1=0;
+
+        Double_t min=FLT_MAX;
+        for (int j=0; j<n0; j++)
+            for (int k=1; k<j+1; k++)
+            {
+                const Double_t diff = TMath::Abs(time[n0-k] - time[n0-k-j]);
+
+                if (diff>=min && diff<250)
+                    continue;
+
+                p0 = n0-k;
+                p1 = n0-k-j;
+                min = diff;
+            }
+
+        if (TMath::Abs(time[p0] - time[p1])<250)
+            fTimes->SetTime(i, (time[p0]+time[p1])/2);
     }
 }
@@ -557,4 +624,6 @@
         if (TESTBIT(fFlags, kProcessPedestal))
             InterpolatePedestals();
+        if (TESTBIT(fFlags, kProcessTimes))
+            InterpolateTimes();
     }
     else
@@ -582,4 +651,6 @@
     if (TESTBIT(fFlags, kProcessPedestal))
         out << "   " << GetUniqueName() << ".SetProcessPedestal();" << endl;
+    if (TESTBIT(fFlags, kProcessTimes))
+        out << "   " << GetUniqueName() << ".SetProcessTimes();" << endl;
     if (TESTBIT(fFlags, kHardTreatment))
         out << "   " << GetUniqueName() << ".SetHardTreatment();" << endl;
@@ -620,4 +691,9 @@
         SetProcessPedestal(GetEnvValue(env, prefix, "ProcessPedestal", IsProcessPedestal()));
     }
+    if (IsEnvDefined(env, prefix, "ProcessTimes", print))
+    {
+        rc = kTRUE;
+        SetProcessTimes(GetEnvValue(env, prefix, "ProcessTimes", IsProcessTimes()));
+    }
     if (IsEnvDefined(env, prefix, "NumMinNeighbors", print))
     {
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h	(revision 4747)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.h	(revision 4748)
@@ -9,4 +9,5 @@
 class MCerPhotEvt;
 class MPedPhotCam;
+class MArrivalTime;
 class MBadPixelsCam;
 
@@ -17,9 +18,11 @@
     MPedPhotCam   *fPedPhot;   //!
     MCerPhotEvt   *fEvt;       //!
+    MArrivalTime  *fTimes;     //!
     MBadPixelsCam *fBadPixels; //!
 
     Byte_t fFlags;       // flag for the method which is used
     Byte_t fNumMinNeighbors;
-    TString fNamePedPhotContainer; // name of the 'MPedPhotCam' container
+
+    TString fNamePedPhotCam; // name of the 'MPedPhotCam' container
 
     enum
@@ -28,9 +31,11 @@
         kUseCentralPixel  = 2,
         kProcessPedestal  = 3,
-        kHardTreatment    = 4
+        kProcessTimes     = 4,
+        kHardTreatment    = 5
     };
 
     static Double_t Pow2(Double_t x) { return x*x; }
 
+    void InterpolateTimes() const;
     void InterpolateSignal() const;
     void InterpolatePedestals() const;
@@ -60,4 +65,8 @@
         b ? SETBIT(fFlags, kProcessPedestal) : CLRBIT(fFlags, kProcessPedestal);
     }
+    void SetProcessTimes(Bool_t b=kTRUE)
+    {
+        b ? SETBIT(fFlags, kProcessTimes) : CLRBIT(fFlags, kProcessTimes);
+    }
     void SetHardTreatment(Bool_t b=kTRUE)
     {
@@ -67,10 +76,10 @@
     Bool_t IsHardTreatment() const    { return TESTBIT(fFlags, kHardTreatment); }
     Bool_t IsProcessPedestal() const  { return TESTBIT(fFlags, kProcessPedestal); }
+    Bool_t IsProcessTimes() const     { return TESTBIT(fFlags, kProcessTimes); }
     Bool_t IsUseCentralPixel() const  { return TESTBIT(fFlags, kUseCentralPixel); }
     Bool_t IsUseInterpolation() const { return TESTBIT(fFlags, kUseInterpolation); }
 
     void SetNumMinNeighbors(Byte_t num) { fNumMinNeighbors=num; }
-    void SetNamePedPhotContainer(const char *name)    { fNamePedPhotContainer = name; }
-
+    void SetNamePedPhotCam(const char *name)    { fNamePedPhotCam = name; }
 
     ClassDef(MBadPixelsTreat, 1) // Task to treat bad pixels (interpolation, unmapping)
Index: /trunk/MagicSoft/Mars/mbase/MArrayB.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MArrayB.cc	(revision 4747)
+++ /trunk/MagicSoft/Mars/mbase/MArrayB.cc	(revision 4748)
@@ -15,7 +15,7 @@
 ! *
 !
-!   Author(s): Thomas Bretz  12/2000 (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-2004
 !
 \* ======================================================================== */
@@ -23,11 +23,13 @@
 
 //////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-// MArrayB                                                                  //
-//                                                                          //
-// Array of Byte_t. It is almost the same than TArrayC, but it containes    //
-// Byte_t instead of Char_t and it can be stored with splitlevel=1 to a     //
-// a root-file because of it's derivement from MArray (TObject)             //                                                                       //
-//                                                                          //
+//
+// MArrayB
+//
+// Array of Byte_t. It is almost the same than TArrayC, but it containes
+// Byte_t instead of Char_t and it can be stored with splitlevel=1 to a
+// a root-file because of it's derivement from MArray (TObject)                                                                                    //
+//
+// Another advantage is: operator[] has no range check!
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MArrayB.h"
Index: /trunk/MagicSoft/Mars/mbase/MArrayS.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MArrayS.cc	(revision 4747)
+++ /trunk/MagicSoft/Mars/mbase/MArrayS.cc	(revision 4748)
@@ -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-2004
 !
 !
@@ -25,11 +25,13 @@
 
 //////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-// MArrayS                                                                  //
-//                                                                          //
-// Array of UShort_t. It is almost the same than TArrayS, but it containes  //
-// UShort_t instead of Short_t and it can be stored with splitlevel=1 to a  //
-// a root-file because of it's derivement from MArray (TObject)             //                                                                       //
-//                                                                          //
+//
+// MArrayS
+//
+// Array of UShort_t. It is almost the same than TArrayS, but it containes
+// UShort_t instead of Short_t and it can be stored with splitlevel=1 to a
+// a root-file because of it's derivement from MArray (TObject)                                                                                    //
+//
+// Another advantage is: operator[] has no range check!
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MArrayS.h"
Index: /trunk/MagicSoft/Mars/mbase/MGMap.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MGMap.cc	(revision 4747)
+++ /trunk/MagicSoft/Mars/mbase/MGMap.cc	(revision 4748)
@@ -135,7 +135,4 @@
 MGMap::~MGMap()
 {
-//    fToolTip->Hide();
-//    delete fToolTip;
-
     if (TestBit(kIsOwner))
         Delete();
@@ -164,8 +161,6 @@
     {
         delete (TObject*)(key);
-        if (!val)
-            continue;
-
-        delete (TString*)(val);
+        if (val)
+            delete (TString*)(val);
         /*
          Long_t key2, val2;
