Index: /trunk/FACT++/src/dataLogger.cc
===================================================================
--- /trunk/FACT++/src/dataLogger.cc	(revision 10967)
+++ /trunk/FACT++/src/dataLogger.cc	(revision 10968)
@@ -416,30 +416,29 @@
     if (path[path.size()-1] == '/')
         path = path.substr(0, path.size()-1);
+
     //create boost path
-    boost::filesystem::path fullPath =  boost::filesystem::system_complete(boost::filesystem::path(path));
+    const boost::filesystem::path fullPath =  boost::filesystem::system_complete(boost::filesystem::path(path));
 
     //if path does not exist, check if upper levels exist already
-    if (!boost::filesystem::exists(fullPath))
-    {
-        if (path.size() <= 1)
-        {//we're hitting "/", which SHOULD have existed...
-            Error("Something unexpected happened while creating a path");
-        }
-        CreateDirectory(path.substr(0, path.find_last_of('/')));
-    }
-    else
-    {//if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist)
-        if (!boost::filesystem::is_directory(fullPath))
-        {
-            Error("Path to be created contains a file name: '" + path + "'");
-            return false;
-        }
-
-        return true;
-    }
+    if (boost::filesystem::exists(fullPath))
+    {
+        //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist)
+        if (boost::filesystem::is_directory(fullPath))
+            return true;
+
+        Error("Path to be created contains a file name: '" + path + "'");
+        return false;
+    }
+
+    if (path.size() <= 1)
+    {//we're hitting "/", which SHOULD have existed...
+        Error("Something unexpected happened while creating a path");
+    }
+    CreateDirectory(path.substr(0, path.find_last_of('/')));
+
     //path does not exist, and upper level have been created already by recusrion.
-    mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes
-
-    int returnValue = mkdir(path.c_str(), rightsMask);
+    const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes
+
+    const int returnValue = mkdir(path.c_str(), rightsMask);
 
     if (returnValue != 0)
@@ -461,6 +460,5 @@
 bool DataLogger::DoesPathExist(string path)
 {
-    boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));
-
+    const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));
 
     if (!boost::filesystem::exists(fullPath))
@@ -596,8 +594,8 @@
     errno = 0;
     stream.open(name.c_str(), ios_base::out | ios_base::app);
-    if (errno != 0)
+    if (!stream)
     {
         ostringstream str;
-        str << "Unable to open file: " << name << ". Reason: " << strerror(errno) << " [" << errno << "]";
+        str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
         Error(str);
     }
@@ -793,7 +791,7 @@
             if (y->second.runFile.IsOpen())
             {
-                    fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize();
-                    if (isPrinting)
-                        Message("-> "+y->second.runFile.fFileName);
+                fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize();
+                if (isPrinting)
+                    Message("-> "+y->second.runFile.fFileName);
             }
             if (y->second.nightlyFile.IsOpen())
@@ -848,4 +846,5 @@
     return shouldWarn;
 }
+
 //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 ?
@@ -1130,5 +1129,5 @@
 
     //update the fits files sizes
-    Time cTime = Time();
+    const Time cTime = Time();
     if ((fStatsPeriodDuration != 0) && ((cTime.Mjd() - fPreviousStatsUpdateTime)*24*60*60 > fStatsPeriodDuration))
     {
@@ -1163,4 +1162,5 @@
     }
     run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log");
+
     errno = 0;
     run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app);
@@ -1168,5 +1168,5 @@
     {
         ostringstream str;
-        str << "Unable to open run Log " << run.logName << ". Reason: " << strerror(errno) << " [" << errno << "]";
+        str << "Unable to open log-file " << run.logName << ": " << strerror(errno) << " (errno=" << errno << ")";
         Error(str);
     }
@@ -1181,4 +1181,5 @@
         return -1;
     }
+
     errno = 0;
     run.reportFile->open(run.reportName.c_str(), ios_base::out | ios_base::app);
@@ -1186,5 +1187,5 @@
     {
         ostringstream str;
-        str << "Unable to open run report " << run.reportName << ". Reason: " << strerror(errno) << " [" << errno << "]";
+        str << "Unable to open rep-file " << run.reportName << ": " << strerror(errno) << " (errno=" << errno << ")";
         Error(str);
     }
@@ -1212,5 +1213,5 @@
 
     //TODO this notification scheme might be messed up now.... fix it !
-    string baseFileName = CompileFileName(fRunFilePath, run.runNumber, "", "");
+    const string baseFileName = CompileFileName(fRunFilePath, run.runNumber, "", "");
     NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles);
     run.openedFits.clear();
@@ -1653,6 +1654,7 @@
 int DataLogger::SetNumSubsAndFitsOnOff(const Event& evt)
 {
-    bool backupSubs = fNumSubAndFitsIsOn;
+    const bool backupSubs = fNumSubAndFitsIsOn;
     fNumSubAndFitsIsOn = evt.GetBool();
+
     if (fNumSubAndFitsIsOn == backupSubs)
         Warn("Warning: Number of subscriptions service mode was already in the requested state");
@@ -1700,17 +1702,19 @@
 int DataLogger::ConfigureRunFileName(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();
-        }
-        fRunFilePath = givenPath;
-        Message("New Run folder specified: " + fRunFilePath);
-    }
-    else
+    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();
@@ -1798,5 +1802,5 @@
 
     //notify that a new file has been opened.
-    string baseFileName = CompileFileName(fNightlyFilePath, "", "");
+    const string baseFileName = CompileFileName(fNightlyFilePath, "", "");
     NotifyOpenedFile(baseFileName, 3, fOpenedNightlyFiles);
 
@@ -1815,4 +1819,5 @@
 {
     string serviceName(sub.dimInfo->getName());
+
     //if run number has changed, reopen a new fits file with the correct run number.
      if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber)
@@ -1822,5 +1827,6 @@
          sub.runFile.Close();
      }
-      //we must check if we should group this service subscription to a single fits file before we replace the / by _
+
+     //we must check if we should group this service subscription to a single fits file before we replace the / by _
     bool hasGrouping = false;
     if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_Logging))
@@ -1847,7 +1853,7 @@
     if (!sub.nightlyFile.IsOpen())
     {
-        string fileNameOnly, partialName;
-        partialName = CompileFileName(fNightlyFilePath, serviceName, "fits");
-        fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
+        string partialName = CompileFileName(fNightlyFilePath, serviceName, "fits");
+
+        const string fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
         if (!sub.fitsBufferAllocated)
             AllocateFITSBuffers(sub);
@@ -1862,5 +1868,5 @@
         }
         //notify the opening
-        string baseFileName = CompileFileName(fNightlyFilePath, "", "");
+        const string baseFileName = CompileFileName(fNightlyFilePath, "", "");
         NotifyOpenedFile(baseFileName, 7, fOpenedNightlyFiles);
         if (fNumSubAndFitsIsOn)
@@ -1911,5 +1917,5 @@
             }
 
-        string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");
+        const string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");
         NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4);
         if (hasGrouping)
@@ -1946,6 +1952,4 @@
 void DataLogger::AllocateFITSBuffers(SubscriptionType& sub)
 {
-    int size = sub.dimInfo->getSize();
-     
     //Init the time columns of the file
     Description dateDesc(string("Time"), string("Modified Julian Date"), string("MjD"));
@@ -1967,4 +1971,6 @@
     //we've got a nice structure describing the format of this service's messages.
     //Let's create the appropriate FITS columns
+    int size = sub.dimInfo->getSize();
+
     vector<string> dataFormatsLocal;
     for (unsigned int i=0;i<flist.size()-1;i++)
@@ -2003,8 +2009,8 @@
              break;
              case 'S':
+                 size--;
                  //for strings, the number of elements I get is wrong. Correct it
                  dataQualifier.str(""); //clear
-                 dataQualifier << size-1 <<  "A";
-                 size = size-1;
+                 dataQualifier << size <<  "A";
              break;
              
@@ -2032,4 +2038,5 @@
                 SetCurrentState(kSM_WriteError);
          }
+
         if (sub.runFile.IsOpen())
         {
