Index: trunk/FACT++/src/datalogger.cc
===================================================================
--- trunk/FACT++/src/datalogger.cc	(revision 11307)
+++ trunk/FACT++/src/datalogger.cc	(revision 11308)
@@ -42,6 +42,6 @@
  //****************************************************************
 #include <unistd.h>      //for getting stat of opened files
-#include <sys/statvfs.h> //for getting disk free space
-#include <sys/stat.h>    //for getting files sizes
+//#include <sys/statvfs.h> //for getting disk free space
+//#include <sys/stat.h>    //for getting files sizes
 #include <fstream>
 
@@ -51,16 +51,10 @@
 #include "Dim.h"
 #include "Event.h"
-#include "Time.h"
 #include "StateMachineDim.h"
-#include "WindowLog.h"
 #include "Configuration.h"
-#include "ServiceList.h"
 #include "Converter.h"
-#include "MessageImp.h"
-#include "DimDescriptionService.h"
+#include "DimWriteStatistics.h"
 
 #include "Description.h"
-
-//#include "DimServiceInfoList.h"
 #include "DimNetwork.h"
 
@@ -68,6 +62,4 @@
 #include "Fits.h"
 #endif
-
-#include "FilesStatisticsService.h"
 
 //Dim structures
@@ -217,5 +209,5 @@
     list<RunNumberType> fRunNumber;
     ///old run numbers time-out delay (in seconds)
-    long fRunNumberTimeout;
+    uint32_t fRunNumberTimeout;
     ///previous run number. to check if changed while logging
     int fPreviousRunNumber;
@@ -238,5 +230,6 @@
     ///boolean to know whether we should close and reopen daily files or not
     bool fDailyFileDayChangedAlready;
-    FilesStatisticsService fFilesStats;
+
+    DimWriteStatistics fFilesStats;
 private:
     /***************************************************
@@ -907,5 +900,5 @@
 //
 DataLogger::DataLogger(ostream &out) : StateMachineDim(out, "DATA_LOGGER"),
-                                       fFilesStats("DATA_LOGGER", this)
+                                       fFilesStats("DATA_LOGGER", *this)
 {
     //initialize member data
@@ -1004,8 +997,8 @@
           "|Enable[bool]:Enable of disable debug mode (yes/no).");
 
-     AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
+     AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "S:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
          (boost::bind(&DataLogger::SetStatsPeriod, this, _1))
          ("Interval in which the data-logger statistics service (STATS) is updated."
-          "|Interval[s]:Floating point value in seconds.");
+          "|Interval[ms]:Value in milliseconds (<=0: no update).");
 
      AddEvent("ENABLE_FILENAME_SERVICES", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
@@ -1125,8 +1118,8 @@
     const Time cTime = Time();
 
-    if ((cTime - fPreviousOldRunNumberCheck).total_seconds() < fRunNumberTimeout)
+    if (cTime - fPreviousOldRunNumberCheck < boost::posix_time::milliseconds(fRunNumberTimeout))
         return;
 
-    while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::seconds(fRunNumberTimeout))
+    while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::milliseconds(fRunNumberTimeout))
     {
          RemoveOldestRunNumber();
@@ -1594,5 +1587,5 @@
     //timeout value
     str.str("");
-    str << "Timeout delay for old run numbers: " << fRunNumberTimeout << " seconds";
+    str << "Timeout delay for old run numbers: " << fRunNumberTimeout << " ms";
     Message(str);
 
@@ -1615,6 +1608,5 @@
     }
 
-    FileStatisticsData statVar;
-    fFilesStats.GetTotalSizeWritten(statVar);
+    const DimWriteStatistics::Stats statVar = fFilesStats.GetTotalSizeWritten();
  //   /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, true);
 #ifdef HAVE_FITS
@@ -1738,5 +1730,5 @@
     }
 */
-    fFilesStats.SetStatPeriod(evt.GetFloat());
+    fFilesStats.SetUpdateInterval(evt.GetShort());
     return GetCurrentState();
 }
@@ -1798,19 +1790,17 @@
 int DataLogger::SetRunTimeoutDelay(const Event& evt)
 {
-    const long backupTimeout = fRunNumberTimeout;
-    fRunNumberTimeout = evt.GetXtra();
-
-    if (fRunNumberTimeout == 0)
-    {
-        fRunNumberTimeout = backupTimeout;
-        Error("Timeout delays for old run numbers must be greater than 0. Ignored.");
+    if (evt.GetUInt() == 0)
+    {
+        Error("Timeout delays for old run numbers must be greater than 0... ignored.");
         return GetCurrentState();
     }
 
-    if (fRunNumberTimeout == backupTimeout)
+    if (fRunNumberTimeout == evt.GetUInt())
         Message("New timeout for old run numbers is same value as previous one.");
 
+    fRunNumberTimeout = evt.GetUInt();
+
     ostringstream str;
-    str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout << " seconds";
+    str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout << " ms";
     Message(str);
 
@@ -1959,5 +1949,5 @@
 //    fBaseSizeRun = 0;
 //    fPreviousSize = 0;
-    fFilesStats.Reset();
+//    fFilesStats.Reset();
     fFilesStats.FileOpened(fFullNightlyLogFileName);
     fFilesStats.FileOpened(fFullNightlyReportFileName);
@@ -2538,5 +2528,4 @@
     {
         const vector<string> vec = conf.Get<vector<string>>("block");
-
         fBlackList.insert(vec.begin(), vec.end());
     }
@@ -2557,10 +2546,10 @@
 
     //set the old run numbers timeout delay
-    if (conf.Has("runtimeout"))
-    {
-        const long timeout = conf.Get<long>("runtimeout");
-        if (timeout <= 0)
-        {
-            Error("Time out delay for old run numbers should be greater than 0 minute");
+    if (conf.Has("run-timeout"))
+    {
+        const uint32_t timeout = conf.Get<uint32_t>("run-timeout");
+        if (timeout == 0)
+        {
+            Error("Time out delay for old run numbers must not be 0.");
             return 1;
         }
@@ -2569,47 +2558,23 @@
 
     //configure the run files directory
-    if (conf.Has("run_folder"))
+    if (conf.Has("destination-folder"))
      {
-         const string folder = conf.Get<string>("run_folder");
-         if (fFilesStats.SetCurrentFolder(folder))
-             fRunFilePath = folder;
-         else
-             Error("Folder " + folder + " given through configuration seems invalid. Ignoring it");
-    }
-
-    //configure the nightly files directory
-    if (conf.Has("nightly_folder"))
-    {
-        const string folder = conf.Get<string>("nightly_folder");
-        if (fFilesStats.SetCurrentFolder(folder))
-            fNightlyFilePath = folder;
-        else
-            Error("Folder " + folder + " given through configuration seems invalid. Ignoring it");
-    }
-
-    //check if we have overwritten badly the directory being watched for free space
-    if (conf.Has("run_folder") && !conf.Has("nightly_folder"))
-    {//we've set the run folder for free space. we've decided it should be the nightly one. thus override it
-        fFilesStats.SetCurrentFolder(fNightlyFilePath);
+         const string folder = conf.Get<string>("destination-folder");
+         if (!fFilesStats.SetCurrentFolder(folder))
+             return 2;
+
+         fRunFilePath     = folder;
+         fNightlyFilePath = folder;
     }
 
     //configure the interval between statistics updates
-    if (conf.Has("stats_interval"))
-    {
-        const float interval = conf.Get<float>("stats_interval");
-        fFilesStats.SetStatPeriod(interval);
-    }
+    if (conf.Has("stats-interval"))
+        fFilesStats.SetUpdateInterval(conf.Get<int16_t>("stats-interval"));
 
     //configure if the filenames service is on or off
-    if (conf.Has("filename_service"))
-    {
-        fOpenedFilesIsOn = conf.Get<bool>("filename_service");
-    }
+    fOpenedFilesIsOn = !conf.Get<bool>("no-filename-service");
 
     //configure if the number of subscriptions and fits files is on or off.
-    if (conf.Has("numsubs_service"))
-    {
-        fNumSubAndFitsIsOn = conf.Get<bool>("numsubs_service");
-    }
+    fNumSubAndFitsIsOn = !conf.Get<bool>("no-numsubs-service");
 
     return -1;
@@ -2769,14 +2734,13 @@
     po::options_description configs("DataLogger options");
     configs.add_options()
-        ("block,b", vars<string>(), "Black-list of services")
-        ("allow,a", vars<string>(), "White-list of services")
-        ("debug",   po_bool(),      "Debug mode. Print clear text of received service reports to log-stream")
-        ("group,g", vars<string>(), "Grouping of services into a single run-Fits")
-        ("runtimeout", var<long>(), "Time out delay for old run numbers")
-        ("nightly_folder", var<string>(), "Base path for the nightly files")
-        ("run_folder", var<string>(), "Base path for the run files")
-        ("stats_interval", var<float>(), "Interval in seconds between two files statistics update")
-        ("filename_service", po_bool(), "Should the filename service be enabled?")
-        ("numsubs_service", po_bool(), "Should the number of subscriptions service be enabled?")
+        ("block,b",             vars<string>(),  "Black-list of services")
+        ("allow,a",             vars<string>(),  "White-list of services")
+        ("debug",               po_bool(),       "Debug mode. Print clear text of received service reports to log-stream")
+        ("group,g",             vars<string>(),  "Grouping of services into a single run-Fits")
+        ("run-timeout",         var<uint32_t>(), "Time out delay for old run numbers in milliseconds")
+        ("destination-folder",  var<string>(),   "Base path for the nightly files")
+        ("stats-interval",      var<int16_t>(),  "Interval in seconds between two files statistics update")
+        ("no-filename-service", po_bool(),       "Should the filename service be enabled?")
+        ("no-numsubs-service",  po_bool(),       "Should the number of subscriptions service be enabled?")
         ;
 
