Index: trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- trunk/FACT++/src/EventBuilderWrapper.h	(revision 11199)
+++ trunk/FACT++/src/EventBuilderWrapper.h	(revision 11200)
@@ -720,10 +720,9 @@
     uint32_t fNumEvts[2];
 
-    DimDescribedService fDimFiles;
     DimDescribedService fDimRuns;
     DimDescribedService fDimEvents;
-//    DimDescribedService fDimCurrentEvent;
     DimDescribedService fDimEventData;
     DimDescribedService fDimFwVersion;
+    DimDescribedService fDimRunNumber;
     DimDescribedService fDimStatus;
     DimDescribedService fDimDNA;
@@ -741,10 +740,9 @@
     EventBuilderWrapper(MessageImp &imp) : fMsg(imp),
         fFileFormat(kRaw), fMaxRun(0),
-        fDimFiles       ("FAD_CONTROL/FILES",            "X:1", ""),
-        fDimRuns        ("FAD_CONTROL/RUNS",             "I:1", ""),
+        fDimRuns        ("FAD_CONTROL/RUNS",             "I:3", ""),
         fDimEvents      ("FAD_CONTROL/EVENTS",           "I:2", ""),
-//        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:43", ""),
+        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", ""),
@@ -759,6 +757,4 @@
         memset(fNumEvts, 0, sizeof(fNumEvts));
 
-        fDimRuns.Update(uint32_t(0));
-//        fDimCurrentEvent.Update(uint32_t(0));
         fDimEvents.Update(fNumEvts);
 
@@ -944,4 +940,28 @@
     // -------------- Mapped event builder callbacks ------------------
 
+    void UpdateRuns()
+    {
+        uint32_t values[3] =
+        {
+            static_cast<uint32_t>(fFiles.size()),
+            0xffffffff,
+            0
+        };
+
+        for (vector<DataFileImp*>::const_iterator it=fFiles.begin();
+             it!=fFiles.end(); it++)
+        {
+            const DataFileImp *file = *it;
+
+            if (file->GetRunId()<values[1])
+                values[1] = file->GetRunId();
+
+            if (file->GetRunId()>values[2])
+                values[2] = file->GetRunId();
+        }
+
+        fDimRuns.Update(values);
+    }
+
     vector<DataFileImp*> fFiles;
 
@@ -970,15 +990,9 @@
         fFiles.push_back(file);
 
-        if (runid>fMaxRun)
-        {
-            fMaxRun = runid;
-            fNumEvts[kCurrent] = 0;
-
-            fDimRuns.Update(fMaxRun);
-            fDimEvents.Update(fNumEvts);
-//            fDimCurrentEvent.Update(uint32_t(0));
-        }
-
-        fDimFiles.Update(fFiles.size());
+        UpdateRuns();
+
+        fNumEvts[kCurrent] = 0;
+        fDimEvents.Update(fNumEvts);
+        // fDimCurrentEvent.Update(uint32_t(0));
 
         return reinterpret_cast<FileHandle_t>(file);
@@ -1037,5 +1051,5 @@
         fFiles.erase(it);
 
-        fDimFiles.Update(fFiles.size());
+        UpdateRuns();
 
         const bool rc = file->Close(tail);
@@ -1360,5 +1374,5 @@
 
     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)
+    boost::array<T, 42> Compare(const FAD::EventHeader *h, const T *t)
     {
         const int offset = reinterpret_cast<const char *>(t) - reinterpret_cast<const char *>(h);
@@ -1368,5 +1382,5 @@
         const T *max = NULL;
 
-        boost::array<T, 43> vec;
+        boost::array<T, 42> vec;
 
         bool rc = true;
@@ -1376,9 +1390,9 @@
             const T *ref = reinterpret_cast<const T*>(base+offset);
 
-            vec[i+3] = (*ref&mask)>>shift;
+            vec[i] = *ref;
 
             if (gi_NumConnect[i]!=7)
             {
-                vec[i+3] = -1;
+                vec[i] = 0;
                 continue;
             }
@@ -1397,16 +1411,12 @@
                 max = val;
 
-            if ((*val&mask)!=(*ref&mask))
+            if (*val!=*ref)
                 rc = false;
         }
 
-        if (!val)
-            return make_pair(false, vec);
-
-        vec[0] = (*min&mask)>>shift;
-        vec[1] = (*val&mask)>>shift;
-        vec[2] = (*max&mask)>>shift;
-
-        return make_pair(rc, vec);
+        vec[40] = val ? *min : 0xffffffff;
+        vec[41] = val ? *max : 0;
+
+        return vec;
     }
 
@@ -1453,8 +1463,8 @@
 
     template<typename T, size_t N>
-    void Update(DimDescribedService &svc, const pair<bool,boost::array<T, N>> &data)
-    {
-        svc.setQuality(data.first);
-        svc.setData(const_cast<T*>(data.second.data()), sizeof(T)*N);
+    void Update(DimDescribedService &svc, const boost::array<T, N> &data, int n=N)
+    {
+//        svc.setQuality(vec[40]<=vec[41]);
+        svc.setData(const_cast<T*>(data.data()), sizeof(T)*n);
         svc.updateService();
     }
@@ -1492,16 +1502,20 @@
         if (old.fVersion != h.fVersion || changed)
         {
-            const pair<bool, boost::array<uint16_t,43>> ver = Compare(&h, &h.fVersion);
-
-            pair<bool, boost::array<float,43>> data;
-            data.first = ver.first;
-
-            for (int i=0; i<43; i++)
+            const boost::array<uint16_t,42> ver = Compare(&h, &h.fVersion);
+
+            boost::array<float,42> data;
+            for (int i=0; i<42; i++)
             {
                 ostringstream str;
-                str << (ver.second[i]>>8) << '.' << (ver.second[i]&0xff);
-                data.second[i] = atof(str.str().c_str());
+                str << (ver[i]>>8) << '.' << (ver[i]&0xff);
+                data[i] = atof(str.str().c_str());
             }
             Update(fDimFwVersion, data);
+        }
+
+        if (old.fRunNumber != h.fRunNumber || changed)
+        {
+            const boost::array<uint32_t,42> run = Compare(&h, &h.fRunNumber);
+            fDimRunNumber.Update(run);
         }
 
@@ -1514,5 +1528,4 @@
          uint16_t fNumTriggersToGenerate;
          uint16_t fTriggerGeneratorPrescaler;
-         uint64_t fDNA; // Xilinx DNA
          uint32_t fTimeStamp;
          uint32_t fRunNumber;
@@ -1523,19 +1536,12 @@
         if (old.fTriggerType != h.fTriggerType || changed)
         {
-            const pair<bool, boost::array<uint16_t,43>> typ = Compare(&h, &h.fTriggerType);
-            Print("Typ", typ);
-        }
-
-        if (old.fRunNumber != h.fRunNumber || changed)
-        {
-            const pair<bool, boost::array<uint32_t,43>> run = Compare(&h, &h.fRunNumber);
-            Print("Run", run);
+            const boost::array<uint16_t,42> typ = Compare(&h, &h.fTriggerType);
+            //Print("Typ", typ);
         }
 
         if (old.fDNA != h.fDNA || changed)
         {
-            const pair<bool, boost::array<uint64_t,43>> dna = Compare(&h, &h.fDNA);
-            fDimDNA.setData(const_cast<uint64_t*>(dna.second.data())+3, 40*sizeof(uint64_t));
-            fDimDNA.updateService();
+            const boost::array<uint64_t,42> dna = Compare(&h, &h.fDNA);
+            Update(fDimDNA, dna, 40);
         }
 
@@ -1543,7 +1549,6 @@
         {
             const boost::array<uint16_t,42> sts = CompareBits(&h, &h.fStatus);
-            fDimStatus.setData(const_cast<uint16_t*>(sts.data()), 42*sizeof(uint16_t));
-            fDimStatus.updateService();
-	}
+            Update(fDimStatus, sts);
+        }
     }
 };
