Index: /trunk/FACT++/gui/FactGui.h
===================================================================
--- /trunk/FACT++/gui/FactGui.h	(revision 11606)
+++ /trunk/FACT++/gui/FactGui.h	(revision 11607)
@@ -396,4 +396,5 @@
     DimStampedInfo fDimFadPrescaler;
     DimStampedInfo fDimFadRefClock;
+    DimStampedInfo fDimFadRoi;
     DimStampedInfo fDimFadStatus;
     DimStampedInfo fDimFadStatistics1;
@@ -1069,5 +1070,29 @@
         SetLedColor(fFadLedRefClock, abs(diff)>3?kLedRed:kLedGreen, d.time);
 
-        handleFadToolTip(d.time, fFadLedRefClock, ptr+2);
+        handleFadToolTip(d.time, fFadLedRefClock, ptr);
+    }
+
+    void handleFadRoi(const DimData &d)
+    {
+        if (d.size()==0)
+        {
+            fFadRoi->setEnabled(false);
+            fFadRoiCh9->setEnabled(false);
+            SetLedColor(fFadLedRoi, kLedGray, d.time);
+            return;
+        }
+
+        if (!CheckSize(d, 2*sizeof(uint16_t)))
+            return;
+
+        const uint16_t *ptr = d.ptr<uint16_t>();
+
+        fFadRoi->setEnabled(true);
+	fFadRoiCh9->setEnabled(true);
+
+	fFadRoi->setValue(ptr[0]);
+	fFadRoiCh9->setValue(ptr[1]);
+
+        SetLedColor(fFadLedRoi, kLedGray, d.time);
     }
 
@@ -2294,4 +2319,7 @@
         if (getInfo()==&fDimFadRefClock)
             return PostInfoHandler(&FactGui::handleFadRefClock);
+
+	if (getInfo()==&fDimFadRoi)
+            return PostInfoHandler(&FactGui::handleFadRoi);
 
         if (getInfo()==&fDimFadPrescaler)
@@ -2739,18 +2767,19 @@
         fDimFtmCounter         ("FTM_CONTROL/COUNTER",          (void*)NULL, 0, this),
         //-
-        fDimFadWriteStats      ("FAD_CONTROL/STATS",            (void*)NULL, 0, this),
-        fDimFadRuns            ("FAD_CONTROL/RUNS",             (void*)NULL, 0, this),
-        fDimFadEvents          ("FAD_CONTROL/EVENTS",           (void*)NULL, 0, this),
-        fDimFadEventData       ("FAD_CONTROL/EVENT_DATA",       (void*)NULL, 0, this),
-        fDimFadConnections     ("FAD_CONTROL/CONNECTIONS",      (void*)NULL, 0, this),
-        fDimFadFwVersion       ("FAD_CONTROL/FIRMWARE_VERSION", (void*)NULL, 0, this),
-        fDimFadRunNumber       ("FAD_CONTROL/RUN_NUMBER",       (void*)NULL, 0, this),
-        fDimFadDNA             ("FAD_CONTROL/DNA",              (void*)NULL, 0, this),
-        fDimFadTemperature     ("FAD_CONTROL/TEMPERATURE",      (void*)NULL, 0, this),
-        fDimFadPrescaler       ("FAD_CONTROL/PRESCALER",        (void*)NULL, 0, this),
-        fDimFadRefClock        ("FAD_CONTROL/REFERENCE_CLOCK",  (void*)NULL, 0, this),
-        fDimFadStatus          ("FAD_CONTROL/STATUS",           (void*)NULL, 0, this),
-        fDimFadStatistics1     ("FAD_CONTROL/STATISTICS1",      (void*)NULL, 0, this),
-        fDimFadStatistics2     ("FAD_CONTROL/STATISTICS2",      (void*)NULL, 0, this),
+        fDimFadWriteStats      ("FAD_CONTROL/STATS",              (void*)NULL, 0, this),
+        fDimFadRuns            ("FAD_CONTROL/RUNS",               (void*)NULL, 0, this),
+        fDimFadEvents          ("FAD_CONTROL/EVENTS",             (void*)NULL, 0, this),
+        fDimFadEventData       ("FAD_CONTROL/EVENT_DATA",         (void*)NULL, 0, this),
+        fDimFadConnections     ("FAD_CONTROL/CONNECTIONS",        (void*)NULL, 0, this),
+        fDimFadFwVersion       ("FAD_CONTROL/FIRMWARE_VERSION",   (void*)NULL, 0, this),
+        fDimFadRunNumber       ("FAD_CONTROL/RUN_NUMBER",         (void*)NULL, 0, this),
+        fDimFadDNA             ("FAD_CONTROL/DNA",                (void*)NULL, 0, this),
+        fDimFadTemperature     ("FAD_CONTROL/TEMPERATURE",        (void*)NULL, 0, this),
+        fDimFadPrescaler       ("FAD_CONTROL/PRESCALER",          (void*)NULL, 0, this),
+        fDimFadRefClock        ("FAD_CONTROL/REFERENCE_CLOCK",    (void*)NULL, 0, this),
+        fDimFadRoi             ("FAD_CONTROL/REGION_OF_INTEREST", (void*)NULL, 0, this),
+        fDimFadStatus          ("FAD_CONTROL/STATUS",             (void*)NULL, 0, this),
+        fDimFadStatistics1     ("FAD_CONTROL/STATISTICS1",        (void*)NULL, 0, this),
+        fDimFadStatistics2     ("FAD_CONTROL/STATISTICS2",        (void*)NULL, 0, this),
         //-
         fEventData(0)
Index: /trunk/FACT++/gui/design.ui
===================================================================
--- /trunk/FACT++/gui/design.ui	(revision 11606)
+++ /trunk/FACT++/gui/design.ui	(revision 11607)
@@ -3175,5 +3175,5 @@
                      </item>
                      <item row="3" column="1">
-                      <widget class="QPushButton" name="fStatusDNSLed_3">
+                      <widget class="QPushButton" name="fFadLedRoi">
                        <property name="enabled">
                         <bool>true</bool>
@@ -3293,20 +3293,4 @@
                       </widget>
                      </item>
-                     <item row="3" column="2">
-                      <widget class="QSpinBox" name="spinBox_2">
-                       <property name="enabled">
-                        <bool>false</bool>
-                       </property>
-                       <property name="alignment">
-                        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-                       </property>
-                       <property name="readOnly">
-                        <bool>true</bool>
-                       </property>
-                       <property name="buttonSymbols">
-                        <enum>QAbstractSpinBox::NoButtons</enum>
-                       </property>
-                      </widget>
-                     </item>
                      <item row="0" column="2">
                       <widget class="QDoubleSpinBox" name="fFadFwVersion">
@@ -3335,14 +3319,4 @@
                       </widget>
                      </item>
-                     <item row="3" column="3">
-                      <widget class="QSpinBox" name="fFadRoiCmd">
-                       <property name="alignment">
-                        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-                       </property>
-                       <property name="maximum">
-                        <number>1024</number>
-                       </property>
-                      </widget>
-                     </item>
                      <item row="1" column="0">
                       <widget class="QLabel" name="label_145">
@@ -3416,5 +3390,5 @@
                       </widget>
                      </item>
-                     <item row="4" column="1">
+                     <item row="5" column="1">
                       <spacer name="verticalSpacer_26">
                        <property name="orientation">
@@ -3432,5 +3406,5 @@
                       </spacer>
                      </item>
-                     <item row="5" column="2">
+                     <item row="6" column="2">
                       <widget class="QLabel" name="label_128">
                        <property name="text">
@@ -3442,5 +3416,5 @@
                       </widget>
                      </item>
-                     <item row="5" column="3">
+                     <item row="6" column="3">
                       <widget class="QLabel" name="label_129">
                        <property name="text">
@@ -3452,5 +3426,5 @@
                       </widget>
                      </item>
-                     <item row="6" column="2">
+                     <item row="7" column="2">
                       <widget class="QDoubleSpinBox" name="fFadTempMin">
                        <property name="alignment">
@@ -3468,5 +3442,5 @@
                       </widget>
                      </item>
-                     <item row="6" column="3">
+                     <item row="7" column="3">
                       <widget class="QDoubleSpinBox" name="fFadTempMax">
                        <property name="alignment">
@@ -3484,5 +3458,5 @@
                       </widget>
                      </item>
-                     <item row="7" column="2">
+                     <item row="8" column="2">
                       <widget class="QDoubleSpinBox" name="fFadRefClockMin">
                        <property name="enabled">
@@ -3518,5 +3492,5 @@
                       </widget>
                      </item>
-                     <item row="7" column="3">
+                     <item row="8" column="3">
                       <widget class="QDoubleSpinBox" name="fFadRefClockMax">
                        <property name="sizePolicy">
@@ -3546,5 +3520,5 @@
                       </widget>
                      </item>
-                     <item row="6" column="0">
+                     <item row="7" column="0">
                       <widget class="QLabel" name="label_111">
                        <property name="text">
@@ -3553,5 +3527,5 @@
                       </widget>
                      </item>
-                     <item row="6" column="1">
+                     <item row="7" column="1">
                       <widget class="QPushButton" name="fFadLedTemp">
                        <property name="enabled">
@@ -3591,5 +3565,5 @@
                       </widget>
                      </item>
-                     <item row="7" column="0">
+                     <item row="8" column="0">
                       <widget class="QLabel" name="label_101">
                        <property name="text">
@@ -3598,5 +3572,5 @@
                       </widget>
                      </item>
-                     <item row="7" column="1">
+                     <item row="8" column="1">
                       <widget class="QPushButton" name="fFadLedRefClock">
                        <property name="enabled">
@@ -3636,5 +3610,5 @@
                       </widget>
                      </item>
-                     <item row="8" column="1">
+                     <item row="9" column="1">
                       <widget class="QPushButton" name="fFadLedRefClockTooLow">
                        <property name="enabled">
@@ -3674,5 +3648,5 @@
                       </widget>
                      </item>
-                     <item row="8" column="0">
+                     <item row="9" column="0">
                       <widget class="QLabel" name="label_103">
                        <property name="text">
@@ -3681,5 +3655,5 @@
                       </widget>
                      </item>
-                     <item row="9" column="0">
+                     <item row="10" column="0">
                       <widget class="QLabel" name="label_92">
                        <property name="text">
@@ -3688,5 +3662,5 @@
                       </widget>
                      </item>
-                     <item row="9" column="1">
+                     <item row="10" column="1">
                       <widget class="QPushButton" name="fFadLedPllLock">
                        <property name="enabled">
@@ -3726,18 +3700,85 @@
                       </widget>
                      </item>
+                     <item row="3" column="2">
+                      <widget class="QSpinBox" name="fFadRoi">
+                       <property name="enabled">
+                        <bool>false</bool>
+                       </property>
+                       <property name="alignment">
+                        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+                       </property>
+                       <property name="readOnly">
+                        <bool>true</bool>
+                       </property>
+                       <property name="buttonSymbols">
+                        <enum>QAbstractSpinBox::NoButtons</enum>
+                       </property>
+                       <property name="minimum">
+                        <number>-1</number>
+                       </property>
+                       <property name="maximum">
+                        <number>1024</number>
+                       </property>
+                       <property name="value">
+                        <number>-1</number>
+                       </property>
+                      </widget>
+                     </item>
+                     <item row="3" column="3">
+                      <widget class="QSpinBox" name="fFadRoiCmd">
+                       <property name="alignment">
+                        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+                       </property>
+                       <property name="maximum">
+                        <number>1024</number>
+                       </property>
+                      </widget>
+                     </item>
+                     <item row="4" column="2">
+                      <widget class="QSpinBox" name="fFadRoiCh9">
+                       <property name="enabled">
+                        <bool>false</bool>
+                       </property>
+                       <property name="alignment">
+                        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+                       </property>
+                       <property name="readOnly">
+                        <bool>true</bool>
+                       </property>
+                       <property name="buttonSymbols">
+                        <enum>QAbstractSpinBox::NoButtons</enum>
+                       </property>
+                       <property name="minimum">
+                        <number>-1</number>
+                       </property>
+                       <property name="maximum">
+                        <number>1024</number>
+                       </property>
+                       <property name="value">
+                        <number>-1</number>
+                       </property>
+                      </widget>
+                     </item>
+                     <item row="4" column="3">
+                      <widget class="QSpinBox" name="fFadRoiCh9Cmd">
+                       <property name="enabled">
+                        <bool>false</bool>
+                       </property>
+                       <property name="alignment">
+                        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+                       </property>
+                       <property name="maximum">
+                        <number>1024</number>
+                       </property>
+                      </widget>
+                     </item>
+                     <item row="4" column="0">
+                      <widget class="QLabel" name="label_161">
+                       <property name="text">
+                        <string>Region of interest (ch9)</string>
+                       </property>
+                      </widget>
+                     </item>
                     </layout>
-                   </item>
-                   <item row="1" column="2">
-                    <spacer name="horizontalSpacer_29">
-                     <property name="orientation">
-                      <enum>Qt::Horizontal</enum>
-                     </property>
-                     <property name="sizeHint" stdset="0">
-                      <size>
-                       <width>40</width>
-                       <height>20</height>
-                      </size>
-                     </property>
-                    </spacer>
                    </item>
                    <item row="1" column="0">
@@ -3760,4 +3801,17 @@
                      </property>
                     </widget>
+                   </item>
+                   <item row="1" column="2">
+                    <spacer name="horizontalSpacer_29">
+                     <property name="orientation">
+                      <enum>Qt::Horizontal</enum>
+                     </property>
+                     <property name="sizeHint" stdset="0">
+                      <size>
+                       <width>40</width>
+                       <height>20</height>
+                      </size>
+                     </property>
+                    </spacer>
                    </item>
                   </layout>
Index: /trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11606)
+++ /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
             };
 
