Index: trunk/Mars/mdrs/MDrsCalibrationTime.cc
===================================================================
--- trunk/Mars/mdrs/MDrsCalibrationTime.cc	(revision 18154)
+++ trunk/Mars/mdrs/MDrsCalibrationTime.cc	(revision 18155)
@@ -59,22 +59,39 @@
     gSystem->ExpandPathName(fname);
 
-    string msg;
     try
     {
-        msg = DrsCalibrateTime::ReadFitsImp(fname.Data());
+        fits file(fname.Data());
+        if (!file)
+            throw runtime_error(strerror(errno));
+
+        if (file.GetStr("TELESCOP")!="FACT")
+        {
+            std::ostringstream msg;
+            msg << "Not a valid FACT file (TELESCOP not FACT in header)";
+            throw runtime_error(msg.str());
+        }
+
+        if (file.GetNumRows()!=1)
+            throw runtime_error("Number of rows in table is not 1.");
+
+        fNumSamples  = file.GetUInt("NROI");
+        fNumChannels = file.GetUInt("NCH");
+        fNumEntries  = file.GetUInt("NBTIME");
+
+        const double *d = reinterpret_cast<double*>(file.SetPtrAddress("CellOffset"));
+        if (!file.GetNextRow())
+            throw runtime_error("Read error.");
+
+        fOffsets.assign(d, d+fNumSamples*fNumChannels),
+        fDelays.resize(0);
     }
     catch (const exception &e)
     {
-        msg = e.what();
+        *fLog << err << "Error reading from " << fname << ": " << e.what() << endl;
+        return false;
     }
 
-    if (msg.empty())
-    {
-        *fLog << inf << "Read DRS calibration file " << fname << endl;
-        return true;
-    }
-
-    *fLog << err << "Error reading from " << fname << ": " << msg << endl;
-    return false;
+    *fLog << inf << "Read DRS calibration file " << fname << endl;
+    return true;
 }
 
@@ -88,21 +105,43 @@
     }
 
-    string msg;
     try
     {
-        msg = DrsCalibrateTime::WriteFitsImp(fname);
+        ofits file(fname.c_str());
+        if (!file)
+            throw runtime_error(strerror(errno));
+
+        file.SetDefaultKeys();
+        file.AddColumnDouble(fNumSamples*fNumChannels, "CellOffset", "samples", "Integral cell offset");
+
+        file.SetInt("ADCRANGE", 2000,    "Dynamic range of the ADC in mV");
+        file.SetInt("DACRANGE", 2500,    "Dynamic range of the DAC in mV");
+        file.SetInt("ADC",      12,      "Resolution of ADC in bits");
+        file.SetInt("DAC",      16,      "Resolution of DAC in bits");
+        file.SetInt("NPIX",     1440,    "Number of channels in the camera");
+        file.SetInt("NTM",      0,       "Number of time marker channels");
+        file.SetInt("NROI",     fNumSamples,  "Region of interest");
+        file.SetInt("NCH",      fNumChannels, "Number of chips");
+        file.SetInt("NBTIME",   fNumEntries,  "Num of entries for time calibration");
+
+        file.WriteTableHeader("DrsCellTimes");
+        //file.SetInt("NIGHT", night, "Night as int");
+
+        /*
+        file.SetStr("DATE-OBS", fDateObs, "First event of whole DRS calibration");
+        file.SetStr("DATE-END", fDateEnd, "Last event of whole DRS calibration");
+        file.SetStr("RUN-BEG", fDateRunBeg[0], "First event of run 0");
+        file.SetStr("RUN-END", fDateRunEnd[0], "Last event of run 0");
+        */
+
+        if (!file.WriteRow(fOffsets.data(), fOffsets.size()*sizeof(double)))
+            throw runtime_error("Write error.");
     }
     catch (const exception &e)
     {
-        msg = e.what();
+        *fLog << err << "Error writing to " << fname << ": " << e.what() << endl;
+        return false;
     }
 
-    if (msg.empty())
-    {
-        *fLog << inf << "Wrote DRS calibration file " << fname << endl;
-        return true;
-    }
-
-    *fLog << err << "Error writing to " << fname << ": " << msg << endl;
-    return false;
+    *fLog << inf << "Wrote DRS calibration file " << fname << endl;
+    return true;
 }
Index: trunk/Mars/mdrs/MDrsCalibrationTime.h
===================================================================
--- trunk/Mars/mdrs/MDrsCalibrationTime.h	(revision 18154)
+++ trunk/Mars/mdrs/MDrsCalibrationTime.h	(revision 18155)
@@ -12,6 +12,12 @@
 class TGraph;
 
-class MDrsCalibrationTime : public MParContainer, public DrsCalibrateTime
+class MDrsCalibrationTime : public MParContainer//, public DrsCalibrateTime
 {
+    int64_t fNumEntries;
+
+    size_t fNumSamples;
+    size_t fNumChannels;
+
+    std::vector<double> fOffsets;
     std::vector<double> fDelays;
 
@@ -19,5 +25,5 @@
     MDrsCalibrationTime(const char *name=0, const char *title=0)
     {
-        fName  = name ? name : "MDrsCalibrationTime";
+        fName  = name  ? name  : "MDrsCalibrationTime";
         fTitle = title ? title : "";
     }
@@ -25,13 +31,19 @@
     void InitSize(uint16_t channels, uint16_t samples)
     {
-        //fDelays.clear();
-        //fDelays.resize(channels);
-
-        DrsCalibrateTime::InitSize(channels, samples);
+        fNumSamples  = samples;
+        fNumChannels = channels;
     }
 
     void SetCalibration(const DrsCalibrateTime &cal)
     {
-        *static_cast<DrsCalibrateTime*>(this) = cal;
+        fNumEntries  = cal.fNumEntries,
+        fNumSamples  = cal.fNumSamples,
+        fNumChannels = cal.fNumChannels,
+
+        fOffsets.resize(fNumSamples*fNumChannels);
+
+        for (size_t c=0; c<fNumChannels; c++)
+            for (size_t s=0; s<fNumSamples; s++)
+                fOffsets[c*fNumSamples+s] = cal.Offset(c, s);
     }
 
@@ -39,7 +51,8 @@
     void SetDelays(const TGraph &g);
 
-    double GetOffset(int hw, int spos, float tm) const
+    double GetOffset(uint32_t hw, uint32_t spos, float tm) const
     {
-        return Offset(hw/9, fmod(tm+spos, 1024)) - Offset(hw/9, spos);
+        const uint32_t ch = (hw/9)*fNumSamples;
+        return fOffsets[ch + fmod(tm+spos, fNumSamples)] - fOffsets[ch + spos];
     }
 
@@ -52,5 +65,5 @@
     bool WriteFits(const std::string &fname) const;
 
-    ClassDef(MDrsCalibrationTime, 2) // A list of histograms storing the Fadc spektrum of one pixel
+    ClassDef(MDrsCalibrationTime, 3) // A list of histograms storing the Fadc spektrum of one pixel
 };
 
Index: trunk/Mars/mdrs/MHDrsCalibrationTime.cc
===================================================================
--- trunk/Mars/mdrs/MHDrsCalibrationTime.cc	(revision 18154)
+++ trunk/Mars/mdrs/MHDrsCalibrationTime.cc	(revision 18155)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 2013 <mailto:tbretz@phys.ethz.ch>
-!
-!   Copyright: MAGIC Software Development, 2000-2014
+!   Author(s): Thomas Bretz 2013 <mailto:tbretz@physik.rwth-aachen.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2015
 !
 !
@@ -37,4 +37,5 @@
 #include "MStatusDisplay.h"
 
+#include "MDrsCalibrationTime.h"
 #include "MPedestalSubtractedEvt.h"
 
Index: trunk/Mars/mdrs/MHDrsCalibrationTime.h
===================================================================
--- trunk/Mars/mdrs/MHDrsCalibrationTime.h	(revision 18154)
+++ trunk/Mars/mdrs/MHDrsCalibrationTime.h	(revision 18155)
@@ -2,6 +2,6 @@
 #define MARS_MHDrsCalibrationTime
 
-#ifndef MARS_DrsCalibrationTime
-#include "MDrsCalibrationTime.h"
+#ifndef MARS_DrsCalib
+#include "DrsCalib.h"
 #endif
 
@@ -23,5 +23,5 @@
     MDrsCalibrationTime    *fCal;     //!
 
-    MDrsCalibrationTime fData; //
+    DrsCalibrateTime fData; //
 
     void InitHistogram();
