Index: trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- trunk/FACT++/src/EventBuilderWrapper.h	(revision 11605)
+++ trunk/FACT++/src/EventBuilderWrapper.h	(revision 11607)
@@ -801,4 +801,5 @@
     DimDescribedService fDimPrescaler;
     DimDescribedService fDimRefClock;
+    DimDescribedService fDimRoi;
     DimDescribedService fDimStatistics1;
     DimDescribedService fDimStatistics2;
@@ -841,16 +842,17 @@
         fFileFormat(kNone), fMaxRun(0), fLastOpened(0), fLastClosed(0),
         fDimWriteStats  ("FAD_CONTROL", imp),
-        fDimRuns        ("FAD_CONTROL/RUNS",             "I:5;C", ""),
-        fDimEvents      ("FAD_CONTROL/EVENTS",           "I:4", ""),
-        fDimEventData   ("FAD_CONTROL/EVENT_DATA",       "S:1;I:1;S:1;I:1;I:2;I:40;S:1440;S:160;S", ""),
-        fDimFwVersion   ("FAD_CONTROL/FIRMWARE_VERSION", "F:42", ""),
-        fDimRunNumber   ("FAD_CONTROL/RUN_NUMBER",       "I:42", ""),
-        fDimStatus      ("FAD_CONTROL/STATUS",           "S:42", ""),
-        fDimDNA         ("FAD_CONTROL/DNA",              "X:40", ""),
-        fDimTemperature ("FAD_CONTROL/TEMPERATURE",      "F:82", ""),
-        fDimPrescaler   ("FAD_CONTROL/PRESCALER",        "S:42", ""),
-        fDimRefClock    ("FAD_CONTROL/REFERENCE_CLOCK",  "I:42", ""),
-        fDimStatistics1 ("FAD_CONTROL/STATISTICS1",      "I:3;I:5;X:4;I:3;I:3;I:40;I:1;I:2;C:40;I:40;I:40;X:40", ""),
-        fDimStatistics2 ("FAD_CONTROL/STATISTICS2",      "I:1;I:280;X:40;I:40;I:4;I:4;I:2;I:2;I:3;C:40",  ""),
+        fDimRuns        ("FAD_CONTROL/RUNS",               "I:5;C", ""),
+        fDimEvents      ("FAD_CONTROL/EVENTS",             "I:4", ""),
+        fDimEventData   ("FAD_CONTROL/EVENT_DATA",         "S:1;I:1;S:1;I:1;I:2;I:40;S:1440;S:160;S", ""),
+        fDimFwVersion   ("FAD_CONTROL/FIRMWARE_VERSION",   "F:42", ""),
+        fDimRunNumber   ("FAD_CONTROL/RUN_NUMBER",         "I:42", ""),
+        fDimStatus      ("FAD_CONTROL/STATUS",             "S:42", ""),
+        fDimDNA         ("FAD_CONTROL/DNA",                "X:40", ""),
+        fDimTemperature ("FAD_CONTROL/TEMPERATURE",        "F:82", ""),
+        fDimPrescaler   ("FAD_CONTROL/PRESCALER",          "S:42", ""),
+        fDimRefClock    ("FAD_CONTROL/REFERENCE_CLOCK",    "I:42", ""),
+        fDimRoi         ("FAD_CONTROL/REGION_OF_INTEREST", "S:2",  ""),
+        fDimStatistics1 ("FAD_CONTROL/STATISTICS1",        "I:3;I:5;X:4;I:3;I:3;I:40;I:1;I:2;C:40;I:40;I:40;X:40", ""),
+        fDimStatistics2 ("FAD_CONTROL/STATISTICS2",        "I:1;I:280;X:40;I:40;I:4;I:4;I:2;I:2;I:3;C:40",  ""),
         fDebugStream(false), fDebugRead(false), fDebugLog(false)
     {
@@ -1355,4 +1357,6 @@
     }
 
+    array<uint16_t,2> fVecRoi;
+
     int eventCheck(PEVNT_HEADER *fadhd, EVENT *event)
     {
@@ -1368,4 +1372,9 @@
          geloescht (nicht an die write-routine weitergeleitet [mind. im Prinzip]
          */
+
+	const array<uint16_t,2> roi = {{ event->Roi, event->RoiTM }};
+
+        if (roi!=fVecRoi)
+	    Update(fDimRoi, roi);
 
         const FAD::EventHeader *beg = reinterpret_cast<FAD::EventHeader*>(fadhd);
@@ -1385,5 +1394,10 @@
                 //   * fTriggerGeneratorPrescaler
                 //   * fDac
-                // inconsistent
+	    // inconsistent
+
+	    // FIXME: Produce some output, only once per run or
+            //        minute
+
+            /*
             if (*ptr != *beg)
                 return -1;
@@ -1394,5 +1408,6 @@
                 return -1;
             if (ptr->fVersion     != beg->fVersion)
-                return -1;
+	    return -1;
+            */
         }
 
@@ -1564,8 +1579,8 @@
     array<FAD::EventHeader, 40> fVecHeader;
 
-    template<typename T>
-    array<T, 42> Compare(const FAD::EventHeader *h, const T *t)
-    {
-        const int offset = reinterpret_cast<const char *>(t) - reinterpret_cast<const char *>(h);
+    template<typename T, class S>
+    array<T, 42> Compare(const S *vec, const T *t)
+    {
+        const int offset = reinterpret_cast<const char *>(t) - reinterpret_cast<const char *>(vec);
 
         const T *min = NULL;
@@ -1573,17 +1588,17 @@
         const T *max = NULL;
 
-        array<T, 42> vec;
+        array<T, 42> arr;
 
         bool rc = true;
         for (int i=0; i<40; i++)
         {
-            const char *base = reinterpret_cast<const char*>(&fVecHeader[i]);
+            const char *base = reinterpret_cast<const char*>(vec+i);
             const T *ref = reinterpret_cast<const T*>(base+offset);
 
-            vec[i] = *ref;
+            arr[i] = *ref;
 
             if (gi_NumConnect[i]!=7)
             {
-                vec[i] = 0;
+                arr[i] = 0;
                 continue;
             }
@@ -1606,8 +1621,8 @@
         }
 
-        vec[40] = val ? *min : 1;
-        vec[41] = val ? *max : 0;
-
-        return vec;
+        arr[40] = val ? *min : 1;
+        arr[41] = val ? *max : 0;
+
+        return arr;
     }
 
@@ -1692,5 +1707,5 @@
         if (old.fVersion != h.fVersion || changed)
         {
-            const array<uint16_t,42> ver = Compare(&h, &h.fVersion);
+            const array<uint16_t,42> ver = Compare(&fVecHeader[0], &fVecHeader[0].fVersion);
 
             array<float,42> data;
@@ -1706,5 +1721,5 @@
         if (old.fRunNumber != h.fRunNumber || changed)
         {
-            const array<uint32_t,42> run = Compare(&h, &h.fRunNumber);
+            const array<uint32_t,42> run = Compare(&fVecHeader[0], &fVecHeader[0].fRunNumber);
             fDimRunNumber.Update(run);
         }
@@ -1712,5 +1727,5 @@
         if (old.fTriggerGeneratorPrescaler != h.fTriggerGeneratorPrescaler || changed)
         {
-            const array<uint16_t,42> pre = Compare(&h, &h.fTriggerGeneratorPrescaler);
+            const array<uint16_t,42> pre = Compare(&fVecHeader[0], &fVecHeader[0].fTriggerGeneratorPrescaler);
             fDimPrescaler.Update(pre);
         }
@@ -1718,5 +1733,5 @@
         if (old.fDNA != h.fDNA || changed)
         {
-            const array<uint64_t,42> dna = Compare(&h, &h.fDNA);
+            const array<uint64_t,42> dna = Compare(&fVecHeader[0], &fVecHeader[0].fDNA);
             Update(fDimDNA, dna, 40);
         }
@@ -1724,5 +1739,5 @@
         if (old.fStatus != h.fStatus || changed)
         {
-            const array<uint16_t,42> sts = CompareBits(&h, &h.fStatus);
+            const array<uint16_t,42> sts = CompareBits(&fVecHeader[0], &fVecHeader[0].fStatus);
             Update(fDimStatus, sts);
         }
@@ -1739,5 +1754,5 @@
             // --- RefClock
 
-            const array<uint32_t,42> clk = Compare(&h, &h.fFreqRefClock);
+            const array<uint32_t,42> clk = Compare(&fVecHeader[0], &fVecHeader[0].fFreqRefClock);
             Update(fDimRefClock, clk);
 
@@ -1746,8 +1761,8 @@
             const array<int16_t,42> tmp[4] =
             {
-                Compare(&h, &h.fTempDrs[0]),    // 0-39:val, 40:min, 41:max
-                Compare(&h, &h.fTempDrs[1]),    // 0-39:val, 40:min, 41:max
-                Compare(&h, &h.fTempDrs[2]),    // 0-39:val, 40:min, 41:max
-                Compare(&h, &h.fTempDrs[3])     // 0-39:val, 40:min, 41:max
+                Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[0]),    // 0-39:val, 40:min, 41:max
+                Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[1]),    // 0-39:val, 40:min, 41:max
+                Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[2]),    // 0-39:val, 40:min, 41:max
+                Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[3])     // 0-39:val, 40:min, 41:max
             };
 
