Index: /trunk/FACT++/src/DimDescriptionService.cc
===================================================================
--- /trunk/FACT++/src/DimDescriptionService.cc	(revision 11836)
+++ /trunk/FACT++/src/DimDescriptionService.cc	(revision 11837)
@@ -37,4 +37,5 @@
 
 #include "dis.hxx"
+#include "Time.h"
 
 using namespace std;
@@ -118,4 +119,6 @@
     fData += fDescription + '\n';
 
+    const Time t;
+    fService->setTimestamp(t.Time_t(), t.ms());
     fService->setData(const_cast<char*>(fData.c_str()));
     fService->updateService();
@@ -141,2 +144,34 @@
     fService=0;
 }
+
+void DimDescribedService::setTime(const Time &t)
+{
+    setTimestamp(t.Time_t(), t.ms());
+}
+
+void DimDescribedService::setTime()
+{
+    setTime(Time());
+}
+
+int DimDescribedService::Update(const Time &t)
+{
+    setTime(t);
+    return updateService();
+}
+
+int DimDescribedService::Update()
+{
+    return Update(Time());
+}
+
+int DimDescribedService::Update(const string &data)
+{
+    return Update(data.data());
+}
+
+int DimDescribedService::Update(const char *data)
+{
+    DimService::setData(const_cast<char*>(data));
+    return Update();
+}
Index: /trunk/FACT++/src/DimDescriptionService.h
===================================================================
--- /trunk/FACT++/src/DimDescriptionService.h	(revision 11836)
+++ /trunk/FACT++/src/DimDescriptionService.h	(revision 11837)
@@ -2,7 +2,9 @@
 #define FACT_DimDescriptionService
 
+#include <array>
 #include <string>
 #include <vector>
 
+class Time;
 class DimService;
 
@@ -45,22 +47,51 @@
     }
 
-    template<class T>
-    void Update(const T &data)
+    void setData(const void *ptr, size_t sz)
     {
-        //cout << "Update: " << svc.getName() << " (" << sizeof(T) << ")" << endl;
-        setData(const_cast<T*>(&data), sizeof(T));
-        updateService();
+        DimService::setData(const_cast<void*>(ptr), sz);
     }
 
     template<typename T>
-    void Update(const std::vector<T> &data)
+    void setData(const std::vector<T> &data)
     {
-        //std::cout << "Update: " << getName() << " " << data.size() << " " << sizeof(T) << std::endl;
-        setData(const_cast<T*>(data.data()), data.size()*sizeof(T));
-        updateService();
+        setData(data.data(), data.size()*sizeof(T));
+    }
+
+    template<class T, size_t N>
+    void setData(const std::array<T, N> &data)
+    {
+        setData(data.data(), N*sizeof(T));
+    }
+
+    void setTime(const Time &t);
+    void setTime();
+
+    int Update();
+    int Update(const Time &t);
+    int Update(const std::string &data);
+    int Update(const char *data);
+
+    template<class T>
+    int Update(const T &data)
+    {
+        setData(&data, sizeof(T));
+        return Update();
+    }
+
+    template<typename T>
+    int Update(const std::vector<T> &data)
+    {
+        setData(data);
+        return Update();
+    }
+
+    template<class T, size_t N>
+    int Update(const std::array<T, N> &data)
+    {
+        setData(data);
+        return Update();
     }
 
     // FIXME: Implement callback with boost::function instead of Pointer to this
-
 };
 
Index: /trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11836)
+++ /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11837)
@@ -197,10 +197,14 @@
         uint32_t maxevt;
 
+        string name;
+
         FAD::Configuration reference;
+
+        bool started;
     };
 
     map<uint32_t, RunDescription> fExpectedRuns;
 
-    uint32_t StartNewRun(int64_t maxtime, int64_t maxevt, const FAD::Configuration &ref)
+    uint32_t StartNewRun(int64_t maxtime, int64_t maxevt, const pair<string, FAD::Configuration> &ref)
     {
         if (maxtime<=0 || maxtime>24*60*60)
@@ -213,8 +217,12 @@
             uint32_t(maxtime),
             uint32_t(maxevt),
-            ref
+            ref.first,
+            ref.second,
+            false
         };
 
         // FIMXE: Maybe reset an event counter so that the mcp can count events?
+
+        fMsg.Info(" ==> TODO: Set a limit on the size of fExpectedRuns!");
 
         fExpectedRuns[fRunNumber] = descr;
@@ -484,4 +492,6 @@
     {
         fMsg.Info(" ==> TODO: Update run configuration in database!");
+        fMsg.Info(" ==> TODO: Remove run from fExpected runs in case of failure!");
+        fMsg.Info(" ==> TODO: Write information from fTargetConfig to header!");
 
         // Check if file already exists...
@@ -563,7 +573,10 @@
     }
 
+    virtual void CloseRun(uint32_t runid) { }
+
     int runClose(FileHandle_t handler, RUN_TAIL *tail, size_t)
     {
         fMsg.Info(" ==> TODO: Update run configuration in database!");
+        fMsg.Info(" ==> TODO: Remove run from fExpected runs!");
 
         DataProcessorImp *file = reinterpret_cast<DataProcessorImp*>(handler);
@@ -581,4 +594,5 @@
 
         fLastClosed = file->GetRunId();
+        CloseRun(fLastClosed);
         UpdateRuns();
 
@@ -710,4 +724,6 @@
         const FAD::EventHeader *end = reinterpret_cast<FAD::EventHeader*>(fadhd)+40;
 
+        // FIMXE: Compare with target configuration
+
         for (const FAD::EventHeader *ptr=beg; ptr!=end; ptr++)
         {
@@ -813,5 +829,6 @@
     bool IsRunStarted() const
     {
-        return fExpectedRuns.find(fRunNumber-1)==fExpectedRuns.end();
+        const map<uint32_t,RunDescription>::const_iterator it = fExpectedRuns.find(fRunNumber-1);
+        return it==fExpectedRuns.end();// ? true : it->second.started;
     }
 
@@ -834,4 +851,9 @@
         CloseRunFile(runnr, time(NULL)+it->second.maxtime, it->second.maxevt);
         // return: 0=close scheduled / >0 already closed / <0 does not exist
+
+        // FIXME: Move configuration from expected runs to runs which will soon
+        //        be opened/closed
+
+        it->second.started = true;
 
         fExpectedRuns.erase(it);
@@ -1056,5 +1078,5 @@
 //        svc.setQuality(vec[40]<=vec[41]);
         svc.setData(const_cast<T*>(data.data()), sizeof(T)*n);
-        svc.updateService();
+        svc.Update();
     }
 
Index: /trunk/FACT++/src/MessageDim.cc
===================================================================
--- /trunk/FACT++/src/MessageDim.cc	(revision 11836)
+++ /trunk/FACT++/src/MessageDim.cc	(revision 11837)
@@ -91,9 +91,7 @@
     // We have to use setData to make sure the DimService will
     // hold a local copy of the data.
-    setTimestamp(t.Time_t(), t.ms());
-    setData(const_cast<char*>(txt.c_str()));
     setQuality(qos);
 
-    const int rc = updateService();
+    const int rc = DimDescribedService::Update(txt);
 
     dim_unlock();
Index: /trunk/FACT++/src/StateMachineDim.cc
===================================================================
--- /trunk/FACT++/src/StateMachineDim.cc	(revision 11836)
+++ /trunk/FACT++/src/StateMachineDim.cc	(revision 11837)
@@ -112,6 +112,5 @@
         return;
 
-    fDescriptionStates.setData(const_cast<char*>((str0+str1+doc+'\n').c_str()));
-    fDescriptionStates.updateService();
+    fDescriptionStates.Update(str0+str1+doc+'\n');
 }
 
@@ -131,18 +130,25 @@
 
     fSrvState.setQuality(state);
-    fSrvState.setData(const_cast<char*>(msg.c_str()));
-    fSrvState.updateService();
+    fSrvState.Update(msg);
 
     return msg;
 }
 
+// --------------------------------------------------------------------------
+//
+//! In the case of dim this secures HandleEvent against dim's commandHandler
+//!
 void StateMachineDim::Lock()
 {
-//    dim_lock();
-}
-
+    dim_lock();
+}
+
+// --------------------------------------------------------------------------
+//
+//! In the case of dim this secures HandleEvent against dim's commandHandler
+//!
 void StateMachineDim::UnLock()
 {
-//    dim_unlock();
+    dim_unlock();
 }
 
Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 11836)
+++ /trunk/FACT++/src/datalogger.cc	(revision 11837)
@@ -1757,5 +1757,5 @@
     service->setData(reinterpret_cast<void*>(&fToDim), name.size()+1+sizeof(uint32_t));
     service->setQuality(0);
-    service->updateService();
+    service->Update();
 }
 // --------------------------------------------------------------------------
@@ -1862,5 +1862,5 @@
         NotifyOpenedFile(baseFileName, 7, fOpenedNightlyFiles);
         if (fNumSubAndFitsIsOn)
-            fNumSubAndFits->updateService();
+            fNumSubAndFits->Update();
     }
     //do the actual file open
@@ -1930,5 +1930,5 @@
 
         if (fNumSubAndFitsIsOn)
-            fNumSubAndFits->updateService();
+            fNumSubAndFits->Update();
     }
 }    
@@ -2219,5 +2219,5 @@
     NotifyOpenedFile("", 0, fOpenedRunFiles);
     if (fNumSubAndFitsIsOn)
-        fNumSubAndFits->updateService();
+        fNumSubAndFits->Update();
 
     while (fRunNumber.size() > 0)
@@ -2264,5 +2264,5 @@
         NotifyOpenedFile("", 0, fOpenedNightlyFiles);
         if (fNumSubAndFitsIsOn)
-            fNumSubAndFits->updateService();
+            fNumSubAndFits->Update();
     }
 #ifdef HAVE_FITS
Index: /trunk/FACT++/src/drivectrl.cc
===================================================================
--- /trunk/FACT++/src/drivectrl.cc	(revision 11836)
+++ /trunk/FACT++/src/drivectrl.cc	(revision 11837)
@@ -535,7 +535,6 @@
         void Update(DimDescribedService &svc, const Time &t, const array<double, N> &arr) const
     {
-        svc.setTimestamp(int(t.UnixTime()), t.ms());
-        svc.setData(const_cast<double*>(arr.data()), arr.size()*sizeof(double));
-        svc.updateService();
+        svc.setData(arr);
+        svc.Update(t);
     }
 
