Index: /trunk/FACT++/gui/FactGui.h
===================================================================
--- /trunk/FACT++/gui/FactGui.h	(revision 10984)
+++ /trunk/FACT++/gui/FactGui.h	(revision 10985)
@@ -334,4 +334,5 @@
     vector<int>  fPixelMapHW; // Software -> Hardware
     vector<int>  fPatchMapHW; // Software -> Hardware
+    vector<int> fPatchHW; // Maps the software(!) pixel id to the hardware(!) patch id
 
     bool fInChoosePatch; // FIXME. Find a better solution
@@ -1167,6 +1168,7 @@
         for (int i=0; i<1440; i++)
         {
-            const int isw = fPatch[i];
-            const int ihw = fPatchMapHW[isw];
+            const int ihw = fPatchHW[i];
+//            const int isw = fPatch[i];
+//            const int ihw = fPatchMapHW[isw];
             dat[i] = sdata.fRatePatch[ihw];
         }
@@ -1926,5 +1928,11 @@
             const int ihw = fPixelMapHW[isw];
 
-            const int idx = fPatch[isw];
+            const int idx = fPatchHW[isw];
+
+            int ii = 0;
+            for (; ii<160; ii++)
+                if (idx==fPatchMapHW[ii])
+                    break;
+
 
             const int patch =  ihw%4;
@@ -1933,5 +1941,5 @@
 
             ostringstream str;
-            str << " (hw=" << ihw << ")  Patch=" << idx << "  (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
+            str << " (hw=" << ihw << ")  Patch=" << ii << "  (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
 
             tipText += str.str().c_str();
@@ -1983,6 +1991,6 @@
 
         // Loop over the software idx of all pixels
-        for (unsigned int i=0; i<fPatch.size(); i++)
-            if (fPatch[i]==isw)
+        for (unsigned int i=0; i<1440; i++)
+            if (fPatchHW[i]==ihw)
                 cam.SetBold(i);
     }
@@ -1990,8 +1998,14 @@
     void ChoosePixel(Camera &cam, int isw)
     {
+        const int  ihw = fPixelMapHW[isw];
+
+        int ii = 0;
+        for (; ii<160; ii++)
+            if (fPatchHW[isw]==fPatchMapHW[ii])
+                break;
+
         cam.SetWhite(isw);
-        ChoosePatch(cam, fPatch[isw]);
-
-        const int  ihw = fPixelMapHW[isw];
+        ChoosePatch(cam, ii);
+
         const bool on  = fFtmStaticData.IsEnabled(ihw);
         fPixelEnable->setChecked(on);
@@ -2100,6 +2114,4 @@
     TGraph fGraphPatchRate[160];
     TGraph fGraphBoardRate[40];
-
-    map<int, int> fPatch;
 
 #ifdef HAVE_ROOT
@@ -2130,6 +2142,7 @@
 public:
     FactGui() :
-        fFtuStatus(40), fPixelMapHW(1440), fPatchMapHW(160),
-        fInChoosePatch(false),
+        fFtuStatus(40),
+        fPixelMapHW(1440), fPatchMapHW(160), fPatchHW(1440),
+        fInChoosePatch(false), 
         fDimDNS("DIS_DNS/VERSION_NUMBER", 1, int(0), this),
 
@@ -2166,5 +2179,5 @@
         // --------------------------------------------------------------------------
 
-        ifstream fin1("fact-trigger-all.txt");
+        ifstream fin1("Trigger-Patches.txt");
 
         int l = 0;
@@ -2180,8 +2193,11 @@
             for (int i=0; i<9; i++)
             {
-                int n;
+                unsigned int n;
                 str >> n;
 
-                fPatch[n] = l;
+                if (n>=fPatchHW.size())
+                    continue;
+
+                fPatchHW[n] = l;
             }
             l++;
@@ -2200,5 +2216,5 @@
                 continue;
 
-            int softid, hardid, dummy;
+            unsigned int softid, hardid, dummy;
 
             stringstream str(buf);
@@ -2208,4 +2224,7 @@
             str >> hardid;
 
+            if (softid>=fPixelMapHW.size())
+                continue;
+
             fPixelMapHW[softid] = hardid;
 
@@ -2225,5 +2244,5 @@
                 continue;
 
-            int softid, hardid;
+            unsigned int softid, hardid;
 
             stringstream str(buf);
@@ -2231,4 +2250,7 @@
             str >> softid;
             str >> hardid;
+
+            if (softid>=fPatchMapHW.size())
+                continue;
 
             fPatchMapHW[softid] = hardid-1;
