Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 11534)
+++ /trunk/FACT++/src/datalogger.cc	(revision 11535)
@@ -314,4 +314,5 @@
     void CreateFitsGrouping(map<string, vector<string> >& filesToGroup, int runNumber);
 
+    bool OpenStreamImp(ofstream &stream, const string &filename, bool mightbeopen);
     bool OpenStream(shared_ptr<ofstream> stream, const string &filename);
     ///Open the relevant text files related to a particular run
@@ -437,5 +438,5 @@
     {
         ostringstream str;
-        str << "Could not create directory " << path << " mkdir error code: " << errno;
+        str << "mkdir() failed for '" << path << "': " << strerror(errno) << " [errno=" << errno << "]";
         Error(str.str());
         return false;
@@ -524,7 +525,5 @@
             return;
 
-        ostringstream str;
-        str << "Subscription " << server << "/" << service << " could not be removed as it is not present";
-        Error(str.str());
+        Error("Subscription "+server+"/"+service+" could not be removed as it is not present");
         return;
     }
@@ -572,4 +571,39 @@
 }
 
+bool DataLogger::OpenStreamImp(ofstream &stream, const string &filename, bool mightbeopen)
+{
+    if (stream.is_open())
+    {
+        if (!mightbeopen)
+            Error(filename+" was already open when trying to open it.");
+        return mightbeopen;
+    }
+
+    errno = 0;
+    stream.open(filename.c_str(), ios_base::out | ios_base::app);
+    if (!stream /*|| errno!=0*/)
+    {
+        ostringstream str;
+        str << "ofstream::open() failed for '" << filename << "': " << strerror(errno) << " [errno=" << errno << "]";
+        Error(str);
+        return false;
+    }
+
+    if (!stream.is_open())
+    {
+        Error("File "+filename+" not open as it ought to be.");
+        return false;
+    }
+
+    Info("Opened: "+filename);
+
+    return true;
+}
+
+bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename)
+{
+    return OpenStreamImp(*stream, filename, false);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -580,20 +614,5 @@
 bool DataLogger::OpenTextFilePlease(ofstream& stream, const string& name)
 {
-    if (stream.is_open())
-        return true;
-
-    errno = 0;
-    stream.open(name.c_str(), ios_base::out | ios_base::app);
-    if (!stream.is_open())
-    {
-        ostringstream str;
-        str << "Trying to open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
-        Error(str);
-        return false;
-    }
-
-    Info("Opened: "+name);
-
-    return true;
+    return OpenStreamImp(stream, name, true);
 }
 
@@ -607,9 +626,6 @@
 {
     if (fDebugIsOn)
-    {
-        ostringstream str;
-        str << "Subscribing to service " << server << "/" << service;
-        Debug(str);
-    }
+        Debug("Subscribing to service "+server+"/"+service);
+
     return new DimStampedInfo((server + "/" + service).c_str(), (void*)NULL, 0, this);
 }
@@ -737,18 +753,7 @@
 off_t DataLogger::GetFileSize(const string& fileName)
 {
-    errno = 0;
-    struct stat st;
-    if (!stat(fileName.c_str(), &st))
-        return st.st_size;
-
-    if (errno != 0 && errno != 2)//ignoring error #2: no such file or directory is not an error for new files
-    {
-        ostringstream str;
-        str << "Unable to stat " << fileName << ". Reason: " << strerror(errno) << " [" << errno << "]";
-        Error(str);
-    }
-
-    return 0;
-}
+    return DimWriteStatistics::GetFileSizeOnDisk(fileName, *this);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1034,5 +1039,5 @@
     {
         ostringstream str;
-        str << "Format of " << I->getName() << " is empty. Ignoring it";
+        str << "Format of " << I->getName() << " is empty (ptr=" << I->getData() << ", size=" << I->getSize() << ")... ignoring it.";
         Error(str);
         return;
@@ -1055,37 +1060,4 @@
     //remove old run numbers
     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;
-    }
-
-    Info("Opened: "+filename);
-
-    return true;
 }
 
@@ -1146,5 +1118,5 @@
     {
         ostringstream str;
-        str << "Adding new run number " << newRun << " that was issued on " << time;
+        str << "Adding new run number " << newRun << " issued at " << time;
         Debug(str);
     }
@@ -1218,5 +1190,5 @@
     {
         ostringstream str;
-        str << "Logging " <<  I->getName() << " [" << I->getFormat() << "] (" << I->getSize() << ")";
+        str << "Logging " << I->getName() << " [" << I->getFormat() << "] (" << I->getSize() << ")";
         Debug(str);
     }
@@ -1264,8 +1236,8 @@
 
     //create the converter for that service
-    if (!sub.fConv.get())
+    if (!sub.fConv)
     {
         sub.fConv = shared_ptr<Converter>(new Converter(Out(), I->getFormat()));
-        if (!sub.fConv)
+        if (!sub.fConv->valid())
         {
             ostringstream str;
@@ -1304,12 +1276,10 @@
         if (rit == fRunNumber.rend() && fRunNumber.size() != 0)
         {
-            ostringstream str;
-            str << "Could not find an appropriate run number for info coming at time: " << cTime;
-            Error(str);
+            Error("Could not find an appropriate run number for info coming at time "+cTime.GetAsStr());
             Error("Active run numbers: ");
             for (rit=fRunNumber.rbegin(); rit != fRunNumber.rend(); rit++)
             {
-                str.str("");
-                str << rit->runNumber;
+                ostringstream str;
+                str << " -> " << rit->runNumber;
                 Error(str);
             }
@@ -2006,5 +1976,6 @@
         if (sub.nightlyFile.IsOpen())
         {
-            if (!sub.nightlyFile.Write(sub.fConv.get()))
+            const shared_ptr<Converter> ptr(sub.fConv);
+            if (!sub.nightlyFile.Write(*ptr))
             {
                 sub.nightlyFile.Close();
@@ -2017,5 +1988,6 @@
         if (sub.runFile.IsOpen())
         {
-            if (!sub.runFile.Write(sub.fConv.get()))
+            const shared_ptr<Converter> ptr(sub.fConv);
+            if (!sub.runFile.Write(*ptr))
             {
                 sub.runFile.Close();
@@ -2391,15 +2363,11 @@
          fFullNightlyLogFileName = CompileFileNameWithPath(fNightlyFilePath, "", "log");
          if (!OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName))
-             SetCurrentState(kSM_BadNightlyConfig);
-         else
-         {
-             fNightlyLogFile << endl;
-             NotifyOpenedFile(fFullNightlyLogFileName, 1, fOpenedNightlyFiles);
-             for (vector<string>::iterator it=backLogBuffer.begin();it!=backLogBuffer.end();it++)
-             {
-                 fNightlyLogFile << *it;
-             }
-         }
-    }
+             return 3;
+
+         fNightlyLogFile << endl;
+         NotifyOpenedFile(fFullNightlyLogFileName, 1, fOpenedNightlyFiles);
+         for (vector<string>::iterator it=backLogBuffer.begin();it!=backLogBuffer.end();it++)
+             fNightlyLogFile << *it;
+     }
 
     shouldBackLog = false;
