Index: trunk/FACT++/src/dataLogger.cc
===================================================================
--- trunk/FACT++/src/dataLogger.cc	(revision 10987)
+++ trunk/FACT++/src/dataLogger.cc	(revision 10990)
@@ -243,26 +243,5 @@
     ///boolean to know whether we should close and reopen daily files or not
     bool fDailyFileDayChangedAlready;
-public:
-    /***************************************************
-     * STATIC COMMAND NAMES
-     ***************************************************/
-    ///Define all the static names
-    static const char* fConfigDay;
-    static const char* fConfigRun;
-    static const char* fConfigRunNumber;
-    static const char* fConfigLog;
-    static const char* fTransStart;
-    static const char* fTransStop;
-    static const char* fTransStartRun;
-    static const char* fTransStopRun;
-    static const char* fTransReset;
-    static const char* fTransWait;
-    static const char* fRunNumberInfo; ///< This is the name of the dimInfo received to specify the run number. It must be updated once the final name will be defined
-    static const char* fPrintCommand;
-    static const char* fDebugOnOff;
-    static const char* fStatsPeriod;
-    static const char* fStartStopOpenedFiles;
-    static const char* fStartStopNumSubsAndFits;
-    static const char* fSetRunTimeOutDelay;
+
 private:
     /***************************************************
@@ -277,4 +256,6 @@
     ///Reporting method for the services info received
     void ReportPlease(DimInfo* I, SubscriptionType& sub);  
+
+    int ConfigureFileName(string &target, const string &type, const EventImp &evt);
     ///Configuration of the nightly file path
     int ConfigureNightlyFileName(const Event& evt); 
@@ -366,4 +347,6 @@
     ///creates a group fits file based on a list of files to be grouped
     void CreateFitsGrouping(map<string, vector<string> >& filesToGroup, int runNumber);
+
+    bool OpenStream(shared_ptr<ofstream> stream, const string &filename);
     ///Open the relevant text files related to a particular run
     int OpenRunFile(RunNumberType& run);
@@ -565,11 +548,11 @@
 void DataLogger::CheckForOfstreamError(ofstream& out)
 {
-    if (!out.good())
-    {
-        Error("An error occured while writing to a text file. Closing it");
-        if (out.is_open())
-            out.close();
-        SetCurrentState(kSM_WriteError);
-    }
+    if (out.good())
+        return;
+
+    Error("An error occured while writing to a text file. Closing it");
+    if (out.is_open())
+        out.close();
+    SetCurrentState(kSM_WriteError);
 }
 // --------------------------------------------------------------------------
@@ -858,24 +841,4 @@
 }
 
-//static members initialization
-//since I do not check the transition/config names any longer, indeed maybe these could be hard-coded... but who knows what will happen in the future ?
-const char* DataLogger::fConfigDay = "CONFIG_DAY";
-const char* DataLogger::fConfigRun = "CONFIG_RUN";
-const char* DataLogger::fConfigRunNumber = "CONFIG_RUN_NUMBER";
-const char* DataLogger::fConfigLog = "LOG";
-const char* DataLogger::fTransStart = "START";
-const char* DataLogger::fTransStop = "STOP";
-const char* DataLogger::fTransStartRun = "START_RUN";
-const char* DataLogger::fTransStopRun = "STOP_RUN";
-const char* DataLogger::fTransReset = "RESET";
-const char* DataLogger::fTransWait = "WAIT_RUN_NUMBER";
-const char* DataLogger::fRunNumberInfo = "RUN_NUMBER";
-const char* DataLogger::fPrintCommand = "PRINT";
-const char* DataLogger::fDebugOnOff = "DEBUG";
-const char* DataLogger::fStatsPeriod = "STATS_PERIOD";
-const char* DataLogger::fStartStopOpenedFiles = "OPENED_FILES_SRVC";
-const char* DataLogger::fStartStopNumSubsAndFits = "NUM_SUBS_SRVC";
-const char* DataLogger::fSetRunTimeOutDelay = "RUN_TIMEOUT";
-
 // --------------------------------------------------------------------------
 //
@@ -944,52 +907,50 @@
     AddStateName(kSM_BadNightlyConfig, "ErrNightlyFolder", "The folder for the nighly summary files is invalid.");
     AddStateName(kSM_BadRunConfig,     "ErrRunFolder",     "The folder for the run files is invalid.");
-    AddStateName(kSM_WriteError, "ErrWrite", "An error occured while writing to a file.");
-
-    /*Add the possible transitions for this machine*/
-    AddEvent(kSM_NightlyOpen, fTransStart, kSM_Ready, kSM_BadNightlyConfig)
-            (boost::bind(&DataLogger::StartPlease, this))
-            ("Start the nightly logging. Nightly file location must be specified already");
-
-    AddEvent(kSM_Ready, fTransStop, kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_WriteError)
-            (boost::bind(&DataLogger::GoToReadyPlease, this))
-            ("Stop all data logging, close all files.");
-
-    AddEvent(kSM_Logging, fTransStartRun, kSM_WaitingRun, kSM_BadRunConfig)
-            (boost::bind(&DataLogger::StartRunPlease, this))
-            ("Start the run logging. Run file location must be specified already.");
-
-    AddEvent(kSM_WaitingRun, fTransStopRun, kSM_Logging)
-            (boost::bind(&DataLogger::StopRunPlease, this))
-            ("Wait for a run to be started, open run-files as soon as a run number arrives.");
-
-    AddEvent(kSM_Ready, fTransReset, kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_WriteError)
-            (boost::bind(&DataLogger::GoToReadyPlease, this))
-            ("Transition to exit error states. Closes the nightly file if already opened.");
-
-    AddEvent(kSM_WaitingRun, fTransWait, kSM_NightlyOpen)
-            (boost::bind(&DataLogger::NightlyToWaitRunPlease, this));
-
-    /*Add the possible configurations for this machine*/
-    AddEvent(fConfigDay, "C", kSM_Ready, kSM_BadNightlyConfig)
-            (boost::bind(&DataLogger::ConfigureNightlyFileName, this, _1))
-            ("Configure the folder for the nightly files."
-             "|Path[string]:Absolute or relative path name where the nightly files should be stored.");
-
-    AddEvent(fConfigRun, "C", kSM_Ready, kSM_BadNightlyConfig, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig)
-            (boost::bind(&DataLogger::ConfigureRunFileName, this, _1))
-            ("Configure the folder for the run files."
-             "|Path[string]:Absolute or relative path name where the run files should be stored.");
-
-    AddEvent(fConfigRunNumber, "X", kSM_Ready, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig, kSM_Logging)
-            (boost::bind(&DataLogger::ConfigureRunNumber, this, _1))
-            ("Configure the run number. Cannot be done in logging state");
-
-     //Provide a print command
-     ostringstream str;
-     str <<     kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig << " " << kSM_WriteError;
-     str << " " << kSM_BadRunConfig;
-     AddEvent(fPrintCommand, str.str().c_str(), "")
-             (boost::bind(&DataLogger::PrintStatePlease, this, _1))
-             ("Print information about the internal status of the data logger.");
+    AddStateName(kSM_WriteError,       "ErrWrite",          "An error occured while writing to a file.");
+
+    // Add the possible transitions for this machine
+    AddEvent(kSM_NightlyOpen, "START", kSM_Ready, kSM_BadNightlyConfig)
+        (boost::bind(&DataLogger::StartPlease, this))
+        ("Start the nightly logging. Nightly file location must be specified already");
+
+    AddEvent(kSM_Ready, "STOP", kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_WriteError)
+        (boost::bind(&DataLogger::GoToReadyPlease, this))
+        ("Stop all data logging, close all files.");
+
+    AddEvent(kSM_Logging, "START_RUN", kSM_WaitingRun, kSM_BadRunConfig)
+        (boost::bind(&DataLogger::StartRunPlease, this))
+        ("Start the run logging. Run file location must be specified already.");
+
+    AddEvent(kSM_WaitingRun, "STOP_RUN", kSM_Logging)
+        (boost::bind(&DataLogger::StopRunPlease, this))
+        ("Wait for a run to be started, open run-files as soon as a run number arrives.");
+
+    AddEvent(kSM_Ready, "RESET", kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_WriteError)
+        (boost::bind(&DataLogger::GoToReadyPlease, this))
+        ("Transition to exit error states. Closes the any open file.");
+
+    AddEvent(kSM_WaitingRun, "WAIT_FOR_RUN_NUMBER", kSM_NightlyOpen)
+        (boost::bind(&DataLogger::NightlyToWaitRunPlease, this))
+        ("Go to waiting for run number state. In this state with any received run-number a new file is opened.");
+
+    // Add the possible configurations for this machine
+    AddEvent("SET_NIGHTLY_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig)
+        (boost::bind(&DataLogger::ConfigureNightlyFileName, this, _1))
+        ("Configure the base folder for the nightly files."
+         "|Path[string]:Absolute or relative path name where the nightly files should be stored.");
+
+    AddEvent("SET_RUN_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig)
+        (boost::bind(&DataLogger::ConfigureRunFileName, this, _1))
+        ("Configure the base folder for the run files."
+         "|Path[string]:Absolute or relative path name where the run files should be stored.");
+
+    AddEvent("SET_RUN_NUMBER", "X", kSM_Ready, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig, kSM_Logging)
+        (boost::bind(&DataLogger::ConfigureRunNumber, this, _1))
+        ("Configure the run number. Cannot be done in logging state");
+
+     // Provide a print command
+     AddEvent("PRINT")
+            (boost::bind(&DataLogger::PrintStatePlease, this, _1))
+            ("Print information about the internal status of the data logger.");
 
      OpenFileToDim fToDim;
@@ -1020,26 +981,29 @@
      fNumSubAndFitsIsOn = true;
 
-     //provide services control commands
-     AddEvent(fDebugOnOff, "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
-             (boost::bind(&DataLogger::SetDebugOnOff, this, _1))
-             ("Switch debug mode on off. Debug mode prints ifnormation about every service written to a file."
-              "|Enable[bool]:Enable of disable debug mode (yes/no).");
-
-     AddEvent(fStatsPeriod, "F", 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.");
-
-     AddEvent(fStartStopOpenedFiles, "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
-              (boost::bind(&DataLogger::SetOpenedFilesOnOff ,this, _1))
-              ("Switch off the service which distributes information about the open files.");
-
-     AddEvent(fStartStopNumSubsAndFits, "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
-             (boost::bind(&DataLogger::SetNumSubsAndFitsOnOff, this, _1))
-             ("Switch off the service which distributes information about the number of subscriptions and open files.");
-
-     AddEvent(fSetRunTimeOutDelay, "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
-             (boost::bind(&DataLogger::SetRunTimeoutDelay, this, _1))
-             ("Set the timeout delay for old run numbers.");
+     // provide services control commands
+     AddEvent("SET_DEUG_MODE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
+         (boost::bind(&DataLogger::SetDebugOnOff, this, _1))
+         ("Switch debug mode on or off. Debug mode prints ifnormation about every service written to a file."
+          "|Enable[bool]:Enable of disable debug mode (yes/no).");
+
+     AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "F", 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.");
+
+     AddEvent("ENABLE_FILENAME_SERVICES", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
+         (boost::bind(&DataLogger::SetOpenedFilesOnOff ,this, _1))
+         ("Switch service which distributes information about the open files on or off."
+          "|Enable[bool]:Enable of disable filename services (yes/no).");
+
+     AddEvent("ENABLE_NUMSUBS_SERVICE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
+         (boost::bind(&DataLogger::SetNumSubsAndFitsOnOff, this, _1))
+         ("Switch the service which distributes information about the number of subscriptions and open files on or off."
+          "|Enable[bool]:Enable of disable NUM_SUBS service (yes/no).");
+
+     AddEvent("SET_RUN_TIMEOUT", "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
+         (boost::bind(&DataLogger::SetRunTimeoutDelay, this, _1))
+         ("Set the timeout delay for old run numbers."
+          "|timeout[min]:Time out in minutes after which files for expired runs are closed.");
 
      fDestructing = false;
@@ -1197,5 +1161,9 @@
         return;
 
-    CheckForRunNumber(I);
+    // FIXME: Here we have to check if we have received the
+    //        service with the run-number.
+    //        CheckForRunNumber(I); has been removed because we have to
+    //        subscribe to this service anyway and hence we have the pointer
+    //        (no need to check for the name)
 
     ReportPlease(I, y->second);
@@ -1207,4 +1175,36 @@
     TrimOldRunNumbers();
 }
+
+bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename)
+{
+    if (stream->is_open())
+    {
+        ostringstream str;
+        str << filename << " was already open when trying to open it.";
+        Error(str);
+        return false;
+    }
+
+    errno = 0;
+    stream->open(filename.c_str(), ios_base::out | ios_base::app);
+    if (errno != 0)
+    {
+        ostringstream str;
+        str << "Unable to open " << filename << ": " << strerror(errno) << " (errno=" << errno << ")";
+        Error(str);
+        return false;
+    }
+
+    if (!stream->is_open())
+    {
+        ostringstream str;
+        str << "File " << filename << " not open as it ought to be.";
+        Error(str);
+        return false;
+    }
+
+    return true;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1215,56 +1215,15 @@
 {
 #ifdef RUN_LOGS
-    if (run.logFile->is_open())
-    {
-        ostringstream str;
-        str << "Log file " << run.logName << " was already open when trying to open it in OpenRunFile";
-        Error(str);
+    // open log file
+    run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log");
+    if (!OpenStream(run.logFile, run.logName))
         return -1;
-    }
-    run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log");
-
-    errno = 0;
-    run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app);
-    if (errno != 0)
-    {
-        ostringstream str;
-        str << "Unable to open log-file " << run.logName << ": " << strerror(errno) << " (errno=" << errno << ")";
-        Error(str);
-    }
 #endif
-    //open report file
+
+    // open report file
     run.reportName = CompileFileName(fRunFilePath, run.runNumber, "", "rep");
-    if (run.reportFile->is_open())
-    {
-        ostringstream str;
-        str << "Report file " << run.reportName << " was already open when trying to open it in OpenRunFile";
-        Error(str);
+    if (!OpenStream(run.reportFile, run.reportName))
         return -1;
-    }
-
-    errno = 0;
-    run.reportFile->open(run.reportName.c_str(), ios_base::out | ios_base::app);
-    if (errno != 0)
-    {
-        ostringstream str;
-        str << "Unable to open rep-file " << run.reportName << ": " << strerror(errno) << " (errno=" << errno << ")";
-        Error(str);
-    }
-
-#ifdef RUN_LOGS
-    if (!run.logFile->is_open() || !run.reportFile->is_open())
-#else
-    if (!run.reportFile->is_open())
-#endif
-    {
-        ostringstream str;
-        str << "Something went wrong while openning files ";
-#ifdef RUN_LOGS
-        str << run.logName << " and ";
-#endif
-        str << run.reportName;
-        Error(str);
-        return -1;
-    }
+
     //get the size of the newly opened file.
 #ifdef RUN_LOGS
@@ -1322,5 +1281,5 @@
 void DataLogger::CheckForRunNumber(DimInfo* I)
 {
-    if (strstr(I->getName(), fRunNumberInfo) != NULL)
+    if (strstr(I->getName(), "SET_RUN_NUMBER") != NULL)
     {//assumes that the run number is an integer
         //check if some run number entries can be deleted leave one so that two remain after adding the new one
@@ -1451,8 +1410,7 @@
         catch (const runtime_error &e)
         {
-            Out() << kRed << e.what() << endl;
             ostringstream str;
-            str << "Could not properly parse the data for service " << sub.dimInfo->getName();
-            str << " reason: " << e.what() << ". Entry ignored";
+            str << "Parsing service " << sub.dimInfo->getName();
+            str << " failed: " << e.what();
             Error(str);
             return;
@@ -1485,18 +1443,15 @@
     else
     {//write entry to both Nightly and run logs
-        string n = I->getName();
         ostringstream msg;
-        msg << n << ": " << I->getString();
+        msg << I->getName() << ": " << I->getString();
 
         if (fNightlyLogFile.is_open())
         {
-            MessageImp nightlyMess(fNightlyLogFile);
-            nightlyMess.Write(cTime, msg.str().c_str(), fQuality);
+            MessageImp(fNightlyLogFile).Write(cTime, msg.str().c_str(), fQuality);
             CheckForOfstreamError(fNightlyLogFile);
         }
         if (targetRunFile && targetRunFile->is_open())
         {
-            MessageImp runMess(*targetRunFile);
-            runMess.Write(cTime, msg.str().c_str(), fQuality);
+            MessageImp(*targetRunFile).Write(cTime, msg.str().c_str(), fQuality);
             CheckForOfstreamError(*targetRunFile);
         }
@@ -1635,14 +1590,15 @@
 int DataLogger::SetDebugOnOff(const Event& evt)
 {
-    bool backupDebug = fDebugIsOn;
+    const bool backupDebug = fDebugIsOn;
+
     fDebugIsOn = evt.GetBool();
+
     if (fDebugIsOn == backupDebug)
-        Warn("Warning: debug mode was already in the requested state");
-    else
-    {
-        ostringstream str;
-        str << "Debug mode is now " << fDebugIsOn;
-        Message(str);
-    }
+        Message("Debug mode was already in the requested state.");
+
+    ostringstream str;
+    str << "Debug mode is now " << fDebugIsOn;
+    Message(str);
+
     return GetCurrentState();
 }
@@ -1657,6 +1613,8 @@
 int DataLogger::SetStatsPeriod(const Event& evt)
 {
-    float backupDuration = fStatsPeriodDuration;
+    const float backupDuration = fStatsPeriodDuration;
+
     fStatsPeriodDuration = evt.GetFloat();
+
     if (fStatsPeriodDuration < 0)
     {
@@ -1667,21 +1625,20 @@
     if (!finite(fStatsPeriodDuration))// != fStatsPeriodDuration)
     {
-        Error("Provided duration does not appear to be a valid float. discarding it.");
+        Error("Provided duration does not appear to be a valid float. Discarding it.");
         fStatsPeriodDuration = backupDuration;
         return GetCurrentState();    
     }
     if (backupDuration == fStatsPeriodDuration)
-        Warn("Warning: statistics period was not modified: supplied value already in use");
+        Warn("Statistics period not modified. Supplied value already in use.");
+
+    if (fStatsPeriodDuration == 0.0f)
+        Message("Statistics are now OFF");
     else
     {
-        if (fStatsPeriodDuration == 0.0f)
-            Message("Statistics are now OFF");
-        else
-        {
-            ostringstream str;
-            str << "Statistics period is now " << fStatsPeriodDuration << " seconds";
-            Message(str);
-        }    
-    }
+        ostringstream str;
+        str << "Statistics period is now " << fStatsPeriodDuration << " seconds";
+        Message(str);
+    }
+
     return GetCurrentState();
 }
@@ -1696,17 +1653,18 @@
 int DataLogger::SetOpenedFilesOnOff(const Event& evt)
 {
-    bool backupOpened = fOpenedFilesIsOn;
+    const bool backupOpened = fOpenedFilesIsOn;
+
     fOpenedFilesIsOn = evt.GetBool();
+
     if (fOpenedFilesIsOn == backupOpened)
-        Warn("Warning: opened files service mode was already in the requested state");
-    else
-    {
-        ostringstream str;
-        str << "Opened files service mode is now " << fOpenedFilesIsOn;
-        Message(str);
-    }
+        Message("Opened files service mode was already in the requested state.");
+
+    ostringstream str;
+    str << "Opened files service mode is now " << fOpenedFilesIsOn;
+    Message(str);
+
     return GetCurrentState();
-    
-}
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1720,14 +1678,14 @@
 {
     const bool backupSubs = fNumSubAndFitsIsOn;
+
     fNumSubAndFitsIsOn = evt.GetBool();
 
     if (fNumSubAndFitsIsOn == backupSubs)
-        Warn("Warning: Number of subscriptions service mode was already in the requested state");
-    else
-    {
-        ostringstream str;
-        str << "Number of subscriptions service mode is now " << fNumSubAndFitsIsOn;
-        Message(str);
-    }
+        Message("Number of subscriptions service mode was already in the requested state");
+
+    ostringstream str;
+    str << "Number of subscriptions service mode is now " << fNumSubAndFitsIsOn;
+    Message(str);
+
     return GetCurrentState();
 }
@@ -1748,18 +1706,40 @@
     {
         fRunNumberTimeout = backupTimeout;
-        Error("timeout delays for old run numbers must be greater than 0. Ignored.");
+        Error("Timeout delays for old run numbers must be greater than 0. Ignored.");
         return GetCurrentState();
     }
 
     if (fRunNumberTimeout == backupTimeout)
-        Warn("Warning: given timeout for old run numbers is same value as previous one");
-    else
-    {
-        ostringstream str;
-        str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout;
-        Message(str);
-    }
+        Message("New timeout for old run numbers is same value as previous one.");
+
+    ostringstream str;
+    str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout;
+    Message(str);
+
     return GetCurrentState();
 }
+
+int DataLogger::ConfigureFileName(string &target, const string &type, const EventImp &evt)
+{
+    if (!evt.GetText())
+    {
+        Error("Empty "+type+" folder given. Please specify a valid path.");
+        return GetCurrentState();
+    }
+
+    const string givenPath = evt.GetText();
+    if (!DoesPathExist(givenPath))
+    {
+        Error("Provided "+type+" path '"+givenPath+"' is not a valid folder. Ignored");
+        return GetCurrentState();
+    }
+
+    Message("New "+type+" folder specified: "+givenPath);
+
+    target = givenPath;
+
+    return GetCurrentState();
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1772,20 +1752,7 @@
 int DataLogger::ConfigureNightlyFileName(const Event& evt)
 {
-    if (evt.GetText() != NULL)
-    {
-        string givenPath = string(evt.GetText());
-        if (!DoesPathExist(givenPath))
-        {
-            Error("Provided path is not a valid folder. Ignored");
-            return GetCurrentState();
-        }
-        fNightlyFilePath = givenPath;
-        Message("New Nightly folder specified: " + fNightlyFilePath);
-    }
-    else
-        Error("Empty Nightly folder given. Please specify a valid path.");
-
-    return GetCurrentState();
-}
+    return ConfigureFileName(fNightlyFilePath, "nightly", evt);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1797,22 +1764,7 @@
 int DataLogger::ConfigureRunFileName(const Event& evt)
 {
-    if (evt.GetText() == NULL)
-    {
-        Error("Empty Nightly folder given. Please specify a valid path");
-        return GetCurrentState();
-    }
-
-    const string givenPath = string(evt.GetText());
-    if (!DoesPathExist(givenPath))
-    {
-        Error("Provided path is not a valid folder. Ignored");
-        return GetCurrentState();
-    }
-
-    fRunFilePath = givenPath;
-    Message("New Run folder specified: " + fRunFilePath);
-
-    return GetCurrentState();
-}
+    return ConfigureFileName(fRunFilePath, "run", evt);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1852,5 +1804,6 @@
     if (name.size()+1 > FILENAME_MAX)
     {
-        Error("Provided file name '" + name + "' is longer than allowed file name length");
+        Error("Provided file name '" + name + "' is longer than allowed file name length.");
+        return;
     }
 
@@ -2435,8 +2388,10 @@
     {
         const long timeout = conf.Get<long>("runtimeout");
-        if (timeout != 0)
-            fRunNumberTimeout = timeout;
-        else
+        if (timeout <= 0)
+        {
             Error("Time out delay for old run numbers should be greater than 0 minute");
+            return false;
+        }
+        fRunNumberTimeout = timeout;
     }
     return true;
@@ -2547,21 +2502,7 @@
         "SERVICE_LIST services offered by any server and DIS_DNS/SERVICE_LIST "
         "will skip DIS_DNS/SERVICE_LIST.\n"
-        "\n"
-        "The commands offered by the dataLoger are the following: \n";
-    cout << setw(20) << DataLogger::fConfigDay << " : specify the path where to put the nightly files\n";
-    cout << setw(20) << DataLogger::fConfigRun << " : specify the path where to put the run files\n";
-    cout << setw(20) << DataLogger::fConfigRunNumber << " : specify the run number\n";
-    cout << setw(20) << DataLogger::fConfigLog << " : log a particular message\n";
-    cout << setw(20) << DataLogger::fTransStart << " : start the nightly logging\n";
-    cout << setw(20) << DataLogger::fTransStop << " : stop the nightly logging\n";
-    cout << setw(20) << DataLogger::fTransStartRun << " : start the run logging\n";
-    cout << setw(20) << DataLogger::fTransStopRun << " : stop the run logging\n";
-    cout << setw(20) << DataLogger::fTransReset << " : stop any logging and/or recover from an error state\n";
-    cout << setw(20) << DataLogger::fTransWait << " : go to the wait for run number state\n";
-    cout << setw(20) << DataLogger::fPrintCommand << " : print the current state of the logger to the shell\n";
-    cout << setw(20) << DataLogger::fDebugOnOff << " : turn on or off the debug mode\n";
-    cout << setw(20) << DataLogger::fStatsPeriod << " : set the periodicity of the statistics. 0 disable them\n";
-    cout << endl;
-}
+        << endl;
+}
+
 // --------------------------------------------------------------------------
 void SetupConfiguration(Configuration &conf)
