Index: branches/Mars_use_drstimefiles/mcore/DrsCalib.h
===================================================================
--- branches/Mars_use_drstimefiles/mcore/DrsCalib.h	(revision 17989)
+++ branches/Mars_use_drstimefiles/mcore/DrsCalib.h	(revision 17995)
@@ -947,4 +947,119 @@
     {
     }
+
+    // DN: To be done:
+    //      include also reading of fStat[i].second into the file
+    //      not done, because it's not yet written into the file.
+    DrsCalibrateTime(const char* fits_file_path) : fNumEntries(0), fNumSamples(0), fNumChannels(0)
+    {
+        fits drs_time_file(fits_file_path);
+
+        fNumSamples = drs_time_file.GetInt("NCHIPS");
+        fNumChannels = drs_time_file.GetInt("NCELLS");
+        fNumEntries = drs_time_file.GetInt("NENTRIES"); // the number of events, that were in the original file.
+        InitSize(fNumChannels, fNumSamples);
+        
+        double *drs_sampling_time_deviations = new double[fNumChannels * fNumSamples];
+        drs_time_file.SetPtrAddress("SamplingTimeDeviation", drs_sampling_time_deviations);
+        drs_time_file.GetNextRow();
+        for (size_t i=0; i<fNumChannels * fNumSamples; i++){
+            fStat[i].first = drs_sampling_time_deviations[i];
+        }
+        drs_time_file.close();
+        // if deleting drs_sampling_time_deviations, before closing the file, 
+        // I get a seg fault. So apparently fits accesses this array not only
+        // in the call to GetNextRow() Why? is that so?
+        delete[] drs_sampling_time_deviations;
+        drs_sampling_time_deviations = NULL;
+    }
+
+    // DN: To be done:
+    //      include also writing of fStat[i].second into the file
+    //      not done, because I don't know how.
+    void WriteToFits(const char* fits_file_path)
+    {
+        ofits drstimeFile(fits_file_path);
+        drstimeFile.SetDefaultKeys();
+        drstimeFile.AddColumnDouble(
+            fNumChannels*fNumSamples,
+            "SamplingTimeDeviation", "nominal slices",
+            "see following COMMENT."
+        );
+        drstimeFile.SetInt("NCHIPS", fNumChannels, "number of drs chips");
+        drstimeFile.SetInt("NCELLS", fNumSamples, "number of cells of each chip");
+        drstimeFile.SetInt("NENTRIES", fNumEntries, "number of events in raw file");
+
+        drstimeFile.AddComment(
+    "The SamplingTimeDeviation specifies the deviation of the actual ");
+        drstimeFile.AddComment(
+    "sampling time of a certain cell, from its nominal sampling time.");
+        drstimeFile.AddComment(
+    "It is measured in nominal slices.");
+        drstimeFile.AddComment(
+    "In order to convert the sample index into the actual sampling time");
+        drstimeFile.AddComment(
+    "just do: ");
+        drstimeFile.AddComment(
+    "     cell_index + td(cell_index) - td(stop_cell_index)");
+        drstimeFile.AddComment(
+    "where td(i) refers to the SamplingTimeDeviation of cell i of the ");
+        drstimeFile.AddComment(
+    "current DRS4 chip.");
+        drstimeFile.AddComment(
+    "This gives you the actual sampling time of the cell measured in ");
+        drstimeFile.AddComment(
+    "nominal slices [nsl] with respect to the stop cells sampling time.");
+        drstimeFile.AddComment(
+    "Convert it to ns, simply by multiplication ");
+        drstimeFile.AddComment(
+    "with 0.5 ns/nsl.");
+        drstimeFile.AddComment(
+    "");
+
+        drstimeFile.AddComment(
+    "In FACT it became common practice to measure un-time-calibrated ");
+        drstimeFile.AddComment(
+    " DRS4 data in 'time slices' or simply 'samples', while ");
+        drstimeFile.AddComment(
+    " time-calibrated DRS4 data usually measured in ns. Since the method,");
+        drstimeFile.AddComment(
+    " that is emplyed to measure the DRS4 time calibration constants has ");
+        drstimeFile.AddComment(
+    " no possibility to assert the actual length of a slice is really half");
+        drstimeFile.AddComment(
+    " a nanosecond, this practice is not advisable.");
+        drstimeFile.AddComment(
+    " I propose instead to call un-time-calibrated data 'samples',");
+        drstimeFile.AddComment(
+    " since this is what they are. If one wants to stress the fact,");
+        drstimeFile.AddComment(
+    " that no drs time calibration has been applied one should refer to ");
+        drstimeFile.AddComment(
+    "'uncalibrated slices'. Since it *should* be common practice to apply");
+
+        drstimeFile.AddComment(
+    " the drs4 time calibration in all cases, I also propose to use the");
+        drstimeFile.AddComment(
+    " short term of 'slices' or 'sl'. If one wants to stress, that the");
+        drstimeFile.AddComment(
+    " drs4 time calibration has actually been applied to the data,");
+        drstimeFile.AddComment(
+    " the term 'calibrated slices' or 'nominal slices' or short 'nsl'.");
+
+        drstimeFile.WriteTableHeader("DRS_CELL_TIMES");
+
+        double *drs_sampling_time_deviations = new double[fNumChannels * fNumSamples];
+        for (size_t chip = 0; chip < fNumChannels; chip++){
+            for (size_t cell = 0; cell < fNumSamples; cell++){
+                drs_sampling_time_deviations[chip*fNumChannels + cell] = 
+                    fStat[chip*fNumChannels + cell].first;
+            }
+        }
+
+        drstimeFile.WriteRow(drs_sampling_time_deviations, sizeof(double) * fNumChannels * fNumSamples);
+        drstimeFile.close();
+
+    }
+
     virtual ~DrsCalibrateTime()
     {
