Index: /trunk/FACT++/src/dataLogger.cc
===================================================================
--- /trunk/FACT++/src/dataLogger.cc	(revision 10991)
+++ /trunk/FACT++/src/dataLogger.cc	(revision 10992)
@@ -370,5 +370,5 @@
     DimStampedInfo* SubscribeToPlease(const string& server, const string& service);
     ///Open a text file and checks for ofstream status
-    void OpenTextFilePlease(ofstream& stream, const string& name);
+    bool OpenTextFilePlease(ofstream& stream, const string& name);
     ///Check if a dir is . and returns the actual string corresponding to .
 //    string CheckIfDirIsDot(const string& dir);
@@ -582,6 +582,8 @@
 //! @name the file name
 //
-void DataLogger::OpenTextFilePlease(ofstream& stream, const string& name)
-{
+bool DataLogger::OpenTextFilePlease(ofstream& stream, const string& name)
+{
+    Info("Opening: "+name);
+
     errno = 0;
     stream.open(name.c_str(), ios_base::out | ios_base::app);
@@ -589,8 +591,12 @@
     {
         ostringstream str;
-        str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
+        str << "Trying to open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
         Error(str);
-    }
-}
+        return false;
+    }
+
+    return true;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -740,11 +746,7 @@
             if (y->second.runFile.fRunNumber == fRunNumber.front().runNumber && y->second.runFile.IsOpen())
             {
-                if (fDebugIsOn)
-                {
-                    ostringstream str;
-                    str << "Closing Fits run file " << y->second.runFile.fFileName;
-                    Debug(str);
-                }
                 y->second.runFile.Close();
+
+                Info("Closed: "+y->second.runFile.fFileName);
             }
     //if a grouping file is on, decrease the number of opened fits manually
@@ -1178,4 +1180,6 @@
 bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename)
 {
+    Info("Opening: "+filename);
+
     if (stream->is_open())
     {
@@ -1323,9 +1327,14 @@
         fNightlyReportFile.close();
 
+        Info("Closed: "+fFullNightlyLogFileName);
+        Info("Closed: "+fFullNightlyReportFileName);
+
         fFullNightlyLogFileName = CompileFileName(fNightlyFilePath, "", "log");
         OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName);
+        //FIXME: Handle return code properly!
 
         fFullNightlyReportFileName = CompileFileName(fNightlyFilePath, "", "rep");
         OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName);
+        //FIXME: Handle return code properly!
 
         fDailyFileDayChangedAlready = true;
@@ -1735,5 +1744,5 @@
     }
 
-    Message("New "+type+" folder specified: "+givenPath);
+    Message("New "+type+" folder: "+givenPath);
 
     target = givenPath;
@@ -1830,16 +1839,12 @@
     }
     fFullNightlyLogFileName = CompileFileName(fNightlyFilePath, "", "log");
-    OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName);
+    if (!OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName))
+        return kSM_BadNightlyConfig;
+
 
     fFullNightlyReportFileName = CompileFileName(fNightlyFilePath, "", "rep");
-    OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName);
-
-    if (!fNightlyLogFile.is_open() || !fNightlyReportFile.is_open())
-    {    
-        ostringstream str;
-        str << "Something went wrong while openning nightly files " << fFullNightlyLogFileName << " and " << fFullNightlyReportFileName;
-        Error(str);
+    if (!OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName))
         return kSM_BadNightlyConfig;
-    }
+
     //get the size of the newly opened file.
     fBaseSizeNightly = GetFileSize(fFullNightlyLogFileName);
@@ -1871,7 +1876,6 @@
      if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber)
      {
-         if (fDebugIsOn)
-             Debug("Run number changed. Closing " + sub.runFile.fFileName);
          sub.runFile.Close();
+         Info("Closed: "+sub.runFile.fFileName+" (new run number)");
      }
 
@@ -1910,4 +1914,8 @@
             fOpenedNightlyFits[fileNameOnly].push_back(serviceName);
 
+        ostringstream str;
+        str << "Opening: " << partialName << " (Nfits=" << fNumSubAndFitsData.numOpenFits << ")";
+        Info(str);
+
         if (!sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0))
         {
@@ -1920,10 +1928,4 @@
         if (fNumSubAndFitsIsOn)
             fNumSubAndFits->updateService();
-        if (fDebugIsOn)
-        {
-            ostringstream str;
-            str << "Opened Nightly FITS: " << partialName << " and table: " << serviceName << ".current number of opened FITS: " << fNumSubAndFitsData.numOpenFits;
-            Debug(str);
-        }
     }
     //do the actual file open
@@ -1934,5 +1936,5 @@
         if (hasGrouping)
         {
-            partialName = CompileFileName(fRunFilePath, sub.runNumber, "group", "fits");
+            partialName = CompileFileName(fRunFilePath, sub.runNumber, "", "fits");
             fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
         }
@@ -1960,5 +1962,5 @@
             {
                 ostringstream str;
-                str << "Could not open FITS Run file " << partialName << " reason: " << e.message();
+                str << "Open FITS file " << partialName << ": " << e.message();
                 Error(str);
                 cRunNumber->runFitsFile = shared_ptr<CCfits::FITS>();//NULL;
@@ -1967,4 +1969,9 @@
         const string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");
         NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4);
+
+        ostringstream str;
+        str << "Opening: " << partialName << " (Nfits=" << fNumSubAndFitsData.numOpenFits << ")";
+        Info(str);
+
         if (hasGrouping)
         {
@@ -1983,12 +1990,6 @@
             }
         }
-       if (fNumSubAndFitsIsOn)
-           fNumSubAndFits->updateService();
-           if (fDebugIsOn)
-        {
-            ostringstream str;
-            str << "Opened Run FITS: " << partialName << " and table: " << serviceName << ".current number of opened FITS: " << fNumSubAndFitsData.numOpenFits;
-            Debug(str);
-        }
+        if (fNumSubAndFitsIsOn)
+            fNumSubAndFits->updateService();
     }
 }    
@@ -2165,4 +2166,6 @@
         groupName = CompileFileName(fNightlyFilePath, "", "fits");
 
+    Info("Creating FITS group in: "+groupName);
+
     CCfits::Table* groupTable;
     int maxCharLength = 50;//FILENAME_MAX;
@@ -2190,5 +2193,5 @@
      {
          ostringstream str;
-         str << "Could not open or create FITS table GROUPING in  file " << groupName << " reason: " << e.message();
+         str << "Creating FITS table GROUPING in " << groupName << ": " << e.message();
          Error(str);
          return;
@@ -2232,7 +2235,10 @@
             if (status)
             {
+                char text[30];//max length of cfitsio error strings (from doc)
+                fits_get_errstatus(status, text);
                 ostringstream str;
-                str << "Could not write row #" << i << "In the fits grouping file " << groupName << ". Cfitsio error code: " << status;
+                str << "Writing FITS row " << i << " in " << groupName << ": " << text << " (file_write_tblbytes, rc=" << status << ")";
                 Error(str);
+                // FIXME: What to do in case of error?
             }
         }
