Index: /trunk/FACT++/src/fadctrl.cc
===================================================================
--- /trunk/FACT++/src/fadctrl.cc	(revision 10985)
+++ /trunk/FACT++/src/fadctrl.cc	(revision 10986)
@@ -523,5 +523,5 @@
 private:
     typedef pair<tcp::endpoint, ConnectionFAD*> Connection;
-    typedef vector<Connection>            BoardList;
+    typedef map<uint8_t, Connection>            BoardList;
 
     BoardList fBoards;
@@ -545,5 +545,5 @@
     {
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->Cmd(command);
+            i->second.second->Cmd(command);
 
         return T::GetCurrentState();
@@ -556,5 +556,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->Cmd(command, evt.GetBool());
+            i->second.second->Cmd(command, evt.GetBool());
 
         return T::GetCurrentState();
@@ -593,5 +593,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->CmdSetRegister(dat[0], dat[1]);
+            i->second.second->CmdSetRegister(dat[0], dat[1]);
 
         return T::GetCurrentState();
@@ -611,5 +611,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->CmdSetRoi(dat[0], dat[1]);
+            i->second.second->CmdSetRoi(dat[0], dat[1]);
 
         return T::GetCurrentState();
@@ -627,5 +627,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->CmdSetDacValue(dat[0], dat[1]);
+            i->second.second->CmdSetDacValue(dat[0], dat[1]);
 
         return T::GetCurrentState();
@@ -636,5 +636,5 @@
         for (int nn=0; nn<n; nn++)
             for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-                i->second->Cmd(FAD::kCmdSingleTrigger);
+                i->second.second->Cmd(FAD::kCmdSingleTrigger);
 
         return T::GetCurrentState();
@@ -657,5 +657,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->Cmd(FAD::kCmdRun, start);
+            i->second.second->Cmd(FAD::kCmdRun, start);
 
         return T::GetCurrentState();
@@ -668,5 +668,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->CmdPhaseShift(evt.GetShort());
+            i->second.second->CmdPhaseShift(evt.GetShort());
 
         return T::GetCurrentState();
@@ -687,5 +687,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->CmdSetTriggerRate(evt.GetUInt());
+            i->second.second->CmdSetTriggerRate(evt.GetUInt());
 
         return T::GetCurrentState();
@@ -708,5 +708,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->CmdSetRunNumber(num);
+            i->second.second->CmdSetRunNumber(num);
 
         return T::GetCurrentState();
@@ -731,5 +731,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->SetVerbose(evt.GetBool());
+            i->second.second->SetVerbose(evt.GetBool());
 
         return T::GetCurrentState();
@@ -742,5 +742,5 @@
 
         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->SetHexOutput(evt.GetBool());
+            i->second.second->SetHexOutput(evt.GetBool());
 
         return T::GetCurrentState();
@@ -753,5 +753,5 @@
 
        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            i->second->SetDataOutput(evt.GetBool());
+            i->second.second->SetDataOutput(evt.GetBool());
 
         return T::GetCurrentState();
@@ -768,5 +768,5 @@
         for (BoardList::const_iterator i=fBoards.begin(); i!=fBoards.end(); i++)
         {
-            if (i->first==endpoint)
+            if (i->second.first==endpoint)
             {
                T::Warn("Address "+addr+" already known.... ignored.");
@@ -787,5 +787,7 @@
         const int16_t slot = evt.GetShort();
 
-        if (fBoards[slot].first==tcp::endpoint())
+        const BoardList::iterator it = fBoards.find(slot);
+
+        if (it==fBoards.end())
         {
             ostringstream str;
@@ -795,6 +797,6 @@
         }
 
-        delete fBoards[slot].second;
-        fBoards[slot] = make_pair(tcp::endpoint(), (ConnectionFAD*)NULL);
+        delete it->second.second;
+        fBoards.erase(it);
 
         return T::GetCurrentState();
@@ -803,13 +805,13 @@
     int ListSlots()
     {
-        for (int i=0; i<40; i++)
-        {
-            if (fBoards[i].first==tcp::endpoint())
-                continue;
+        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
+        {
+            const int        &idx  = i->first;
+            const Connection &slot = i->second;
 
             ostringstream str;
-            str << "Slot " << setw(2) << i << ": " << fBoards[i].first;
-
-            const ConnectionFAD *c = fBoards[i].second;
+            str << "Slot " << setw(2) << idx << ": " << slot.first;
+
+            const ConnectionFAD *c = slot.second;
 
             if (c->IsConnecting())
@@ -823,9 +825,9 @@
             }
 
-            switch (fStatus2[i])
+            switch (fStatus2[idx])
             {
             case 0:  str << "1-7:not connected)"; break;
             case 7:  str << "1-7:connected)";     break;
-            default: str << "1-7:connecting [" << fStatus2[i] << "])"; break;
+            default: str << "1-7:connecting [" << fStatus2[idx] << "])"; break;
             }
 
@@ -843,10 +845,7 @@
     }
 
-    void EnableSlot(int i, bool enable=true)
-    {
-        if (fBoards[i].first==tcp::endpoint())
-            return;
-
-        ConnectionFAD* &ptr = fBoards[i].second;
+    void EnableSlot(Connection &c, bool enable=true)
+    {
+        ConnectionFAD *ptr = c.second;
         if (!ptr)
             return;
@@ -857,5 +856,5 @@
         {
             ostringstream str;
-            str << fBoards[i].first;
+            str << c.first;
             ptr->SetEndpoint(str.str());
             ptr->StartConnect();
@@ -865,6 +864,6 @@
     void EnableAll(bool enable=true)
     {
-        for (int i=0; i<40; i++)
-            EnableSlot(i, enable);
+        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
+            EnableSlot(i->second, enable);
     }
 
@@ -893,6 +892,6 @@
         vector<tcp::endpoint> addr(40);
 
-        for (int i=0; i<40; i++)
-            addr[i] = fBoards[i].first;
+        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
+            addr[i->first] = i->second.first;
 
         Start(addr);
@@ -929,7 +928,8 @@
         {
             // ----- Command socket -----
-            if (fBoards[idx].first!=tcp::endpoint())
+            const BoardList::const_iterator &slot = fBoards.find(idx);
+            if (slot!=fBoards.end())
             {
-                const ConnectionFAD *c = fBoards[idx].second;
+                const ConnectionFAD *c = slot->second.second;
                 if (c->IsConnecting())
                 {
@@ -986,5 +986,5 @@
         while (i<40)
         {
-            if (fBoards[i].first==tcp::endpoint())
+            if (fBoards.find(i)==fBoards.end())
                 break;
             i++;
@@ -1028,5 +1028,5 @@
     StateMachineFAD(ostream &out=cout) :
         T(out, "FAD_CONTROL"), EventBuilderWrapper(static_cast<MessageImp&>(*this)), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fBoards(40), fStatus1(40), fStatus2(40),
+        fStatus1(40), fStatus2(40),
         fDimConnection("FAD_CONTROL/CONNECTIONS", "C:41", "")
     {
@@ -1181,5 +1181,5 @@
     {
         for (BoardList::const_iterator i=fBoards.begin(); i!=fBoards.end(); i++)
-            delete i->second;
+            delete i->second.second;
         fBoards.clear();
     }
