Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 11718)
+++ /trunk/FACT++/src/datalogger.cc	(revision 11719)
@@ -964,6 +964,8 @@
 //    dim_lock();
 
-     //now clear the services subscriptions
+    //now clear the services subscriptions
+    dim_lock();
     fServiceSubscriptions.clear();
+    dim_unlock();
 
     //clear any remaining run number (should remain only one)
@@ -1805,5 +1807,5 @@
      {
          sub.runFile.Close();
-         Info("Closed: "+sub.runFile.fFileName+" (new run number)");
+         Info("Closed: "+sub.runFile.GetName()+" (new run number)");
      }
 
@@ -1841,5 +1843,5 @@
             fOpenedNightlyFits[fileNameOnly].push_back(serviceName);
 
-        if (!sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0))
+        if (!sub.nightlyFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, 0))
         {
             GoToRunWriteErrorState();
@@ -1865,11 +1867,12 @@
         {
             partialName = CompileFileNameWithPath(fRunFilePath, sub.runNumber, "", "fits");
-            fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
         }
         else
         {
             partialName = CompileFileNameWithPath(fRunFilePath, sub.runNumber, serviceName, "fits");
-            fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
-        }
+        }
+
+        fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
+
         //get the size of the file we're about to open
         if (fFilesStats.FileOpened(partialName))
@@ -1902,5 +1905,5 @@
         if (hasGrouping)
         {
-            if (!sub.runFile.Open(partialName, serviceName, (cRunNumber->runFitsFile).get(), &fNumSubAndFitsData.numOpenFits, this, sub.runNumber))
+            if (!sub.runFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber, cRunNumber->runFitsFile.get()))
             {
                 GoToRunWriteErrorState();
@@ -1910,5 +1913,5 @@
         else
         {
-            if (!sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber))
+            if (!sub.runFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber))
             {
                 GoToRunWriteErrorState();
@@ -1941,5 +1944,4 @@
     sub.runFile.AddStandardColumn(QoSDesc, "1J", &fQuality, sizeof(int));
 
-    const Converter::FormatList flist = sub.fConv->GetList();
     // Compilation failed
     if (!sub.fConv->valid())
@@ -1951,34 +1953,9 @@
     //we've got a nice structure describing the format of this service's messages.
     //Let's create the appropriate FITS columns
-    int size = 0;
-
-    vector<string> dataFormatsLocal;
-    for (unsigned int i=0;i<flist.size()-1;i++)
-    {
-         ostringstream dataQualifier;
-
-         dataQualifier << flist[i].second.first;
-         switch (flist[i].first.first->name()[0])
-         {
-         case 'c': dataQualifier << 'B'; break;
-         case 's': dataQualifier << 'I'; break;
-         case 'i': dataQualifier << 'J'; break;
-         case 'l': dataQualifier << 'J'; break;
-         case 'f': dataQualifier << 'E'; break;
-         case 'd': dataQualifier << 'D'; break;
-         case 'x': dataQualifier << 'K'; break;
-         case 'S': //we skip the variable length strings
-             continue;
-
-         default:
-             Fatal("THIS SHOULD NEVER BE REACHED.");
-         };
-
-         size += flist[i].first.second * flist[i].second.first;
-         dataFormatsLocal.push_back(dataQualifier.str());
-     }
-     sub.nightlyFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), size);
-     sub.runFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), size);
-     sub.fitsBufferAllocated = true;
+    const vector<string> dataFormatsLocal = sub.fConv->GetFitsFormat();
+
+    sub.nightlyFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData());
+    sub.runFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData());
+    sub.fitsBufferAllocated = true;
 }
 // --------------------------------------------------------------------------
