Index: /trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11161)
+++ /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11162)
@@ -739,5 +739,5 @@
         fDimCurrentEvent("FAD_CONTROL/CURRENT_EVENT", "I:1", ""),
 	fDimEventData("FAD_CONTROL/EVENT_DATA", "S:1;I:1;S:1;I:2;S:1;S", ""),
-        fDimFwVersion("FAD_CONTROL/FIRMWARE_VERSION", "F:40", ""),
+        fDimFwVersion("FAD_CONTROL/FIRMWARE_VERSION", "F:43", ""),
         fDimStatistics("FAD_CONTROL/STATISTICS", "X:8", ""),
         fDebugStream(false), fDebugRead(false)
@@ -1191,5 +1191,5 @@
         bool     ok_runno;
        // uint16_t ok_bitmask;
-
+/*
         const vector<uint16_t> verno = CheckVals(fadhd, &fadhd->version_no, ok_verno);
         const vector<uint32_t> runno = CheckVals(fadhd, &fadhd->runnumber,  ok_runno);
@@ -1210,5 +1210,5 @@
             fStoreVersion=verno;
         }
-
+*/
         /*
          uint16_t start_package_flag;
@@ -1332,7 +1332,186 @@
     }
 
+    boost::array<FAD::EventHeader, 40> fVecHeader;
+
+    template<typename T>
+    pair<bool,boost::array<T, 43>> Compare(const FAD::EventHeader *h, const T *t, const uint64_t mask=~0, const uint8_t shift=0)
+    {
+        const int offset = reinterpret_cast<const char *>(t) - reinterpret_cast<const char *>(h);
+
+        const T *min = NULL;
+        const T *val = NULL;
+        const T *max = NULL;
+
+        boost::array<T, 43> vec;
+
+        bool rc = true;
+        for (int i=0; i<40; i++)
+        {
+            const char *base = reinterpret_cast<const char*>(&fVecHeader[i]);
+            const T *ref = reinterpret_cast<const T*>(base+offset);
+
+            vec[i+3] = *ref;
+
+            if (gi_NumConnect[i/7]!=7)
+                continue;
+
+            if (!val)
+            {
+                min = ref;
+                val = ref;
+                max = ref;
+            }
+
+            if (*val<*min)
+                min = val;
+
+            if (*val>*max)
+                max = val;
+
+            if ((*val&mask)!=(*ref&mask))
+                rc = false;
+        }
+
+        if (!val)
+            return make_pair(false, vec);
+
+        vec[0] =  *min;
+        vec[1] = (*val&mask)>>shift;
+        vec[2] =  *max;
+
+        return make_pair(rc, vec);
+    }
+
+    template<typename T>
+    void Update(DimDescribedService &svc, const pair<bool,boost::array<T, 43>> &data)
+    {
+        svc.setQuality(data.first);
+        svc.setData(const_cast<T*>(data.second.data()), sizeof(T)*43);
+        svc.updateService();
+    }
+
+    template<typename T>
+        void Print(const char *name, const pair<bool,boost::array<T, 43>> &data)
+    {
+        cout << name << "|" << data.first << "|" << data.second[1] << "|" << data.second[0] << "<x<" << data.second[1] << ":";
+        for (int i=0; i<40;i++)
+            cout << " " << data.second[i+3];
+        cout << endl;
+    }
+
     void debugHead(int socket, const FAD::EventHeader &h)
     {
-        cout << h;
+        const uint16_t id = h.Id();
+        if (id>39) // WARNING
+            return;
+
+        const FAD::EventHeader old = fVecHeader[id];
+
+        fVecHeader[id] = h;
+
+        if (old.fVersion != h.fVersion)
+        {
+            const pair<bool, boost::array<uint16_t,43>> ver = Compare(&h, &h.fVersion);
+            //Print("Ver", ver);
+
+            pair<bool, boost::array<float,43>> data;
+            data.first = ver.first;
+
+            for (int i=0; i<43; i++)
+            {
+                ostringstream str;
+                str << (ver.second[i]>>8) << '.' << (ver.second[i]&0xff);
+                data.second[i] = atof(str.str().c_str());
+            }
+            Update(fDimFwVersion, data);
+        }
+
+        if (old.fTriggerType != h.fTriggerType)
+        {
+            const pair<bool, boost::array<uint16_t,43>> typ = Compare(&h, &h.fTriggerType);
+            Print("Typ", typ);
+        }
+
+        if (old.fRunNumber != h.fRunNumber)
+        {
+            const pair<bool, boost::array<uint32_t,43>> run = Compare(&h, &h.fRunNumber);
+            Print("Run", run);
+        }
+
+        if (old.PLLLCK() != h.PLLLCK())
+        {
+            const pair<bool, boost::array<uint16_t,43>> pll = Compare(&h, &h.fStatus, 0xf<<12, 12);
+            Print("Pll", pll);
+        }
+
+        if (old.HasDenable() != h.HasDenable())
+        {
+            const pair<bool, boost::array<uint16_t,43>> drs = Compare(&h, &h.fStatus, FAD::EventHeader::kDenable);
+            Print("Drs", drs);
+        }
+
+        if (old.HasDwrite() != h.HasDwrite())
+        {
+            const pair<bool, boost::array<uint16_t,43>> wri = Compare(&h, &h.fStatus, FAD::EventHeader::kDwrite);
+            Print("Wri", wri);
+        }
+
+        if (old.IsRefClockTooLow() != h.IsRefClockTooLow())
+        {
+            const pair<bool, boost::array<uint16_t,43>> owf = Compare(&h, &h.fStatus, FAD::EventHeader::kRefClkTooLow);
+            Print("Owf", owf);
+        }
+
+        if (old.IsDcmLocked() != h.IsDcmLocked())
+        {
+            const pair<bool, boost::array<uint16_t,43>> lck = Compare(&h, &h.fStatus, FAD::EventHeader::kDcmLocked);
+            Print("Lck", lck);
+        }
+
+        if (old.IsDcmReady() != h.IsDcmReady())
+        {
+            const pair<bool, boost::array<uint16_t,43>> rdy = Compare(&h, &h.fStatus, FAD::EventHeader::kDcmReady);
+            Print("Rdy", rdy);
+        }
+
+        if (old.HasSpiSclk() != h.HasSpiSclk())
+        {
+            const pair<bool, boost::array<uint16_t,43>> spi = Compare(&h, &h.fStatus, FAD::EventHeader::kSpiSclk);
+            Print("Spi", spi);
+        }
+
+        if (old.HasBusy() != h.HasBusy())
+        {
+            const pair<bool, boost::array<uint16_t,43>> bsy = Compare(&h, &h.fStatus, FAD::EventHeader::kBusy);
+            Print("Bsy", bsy);
+        }
+
+        if (old.HasTriggerEnabled() != h.HasTriggerEnabled())
+        {
+            const pair<bool, boost::array<uint16_t,43>> trg = Compare(&h, &h.fStatus, FAD::EventHeader::kTriggerLine);
+            Print("Trg", trg);
+        }
+
+        if (old.HasContTriggerEnabled() != h.HasContTriggerEnabled())
+        {
+            const pair<bool, boost::array<uint16_t,43>> cnt = Compare(&h, &h.fStatus, FAD::EventHeader::kContTrigger);
+            Print("Cnt", cnt);
+        }
+
+        if (old.IsInSock17Mode() != h.IsInSock17Mode())
+        {
+            const pair<bool, boost::array<uint16_t,43>> sck = Compare(&h, &h.fStatus, FAD::EventHeader::kSock17);
+            Print("Sck", sck);
+        }
+
+
+
+        //Update(fDimFwVersion, ver);
+        //Update(fDimFwVersion, trg);
+        //Update(fDimFwVersion, run);
+        // frq send only min/max
+
+        //const pair<bool, boost::array<uint32_t,43>> frq = Compare(&h, &h.fFreqRefClock);
+        //Print("Frq", frq);
     }
 };
