Changeset 11091 for trunk


Ignore:
Timestamp:
06/21/11 20:54:18 (13 years ago)
Author:
tbretz
Message:
Added new connection/disconnection scheme; added eventCheck stub
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/EventBuilder.c

    r11090 r11091  
    4343extern void factStat(int severity, int err, char* message ) ;
    4444
     45extern int  eventCheck( PEVNT_HEADER *fadhd, EVENT *event) ;
    4546
    4647extern void debugRead(int isock, int ibyte, int32_t event, int state,
     
    295296
    296297   
    297    needmem = sizeof(EVENT) + NPIX*nRoi*2 + NTMARK*nRoi*2 ;
     298   needmem = sizeof(EVENT) + NPIX*nRoi*2 + NTMARK*nRoi*2; //
    298299
    299300   headmem = NBOARDS* sizeof(PEVNT_HEADER) ;
     
    576577           snprintf(str,MXSTR,"Socket %d closed by FAD",i);
    577578           factOut(kInfo,441, str ) ;
    578            j = GenSock(1, i, 0,NULL, &rd[i]) ;
     579           GenSock(1, i, 0,NULL, &rd[i]) ;
    579580           gi_ErrCnt[i]++ ;
    580581           gi_NumConnect[ b ]-- ;
     
    852853 snprintf(str,MXSTR,"close all sockets ...");
    853854 factOut(kInfo,-1, str ) ;
    854  for (i=0; i<MAX_SOCK; i++)   
    855     if (rd[i].sockStat ==0 ) { 
    856        j=close(rd[i].socket) ;
    857        if (j>0) {
    858           snprintf(str,MXSTR,"Error closing socket %d | %m",i);
    859           factOut(kFatal,771, str ) ;
    860        }
    861        rd[i].sockStat = -1 ;        //flag (try to reopen next round)
    862        gi_NumConnect[ i/7 ]-- ;
    863     }
     855 for (i=0; i<MAX_SOCK; i++) { 
     856    GenSock(-1, i, 0, NULL, &rd[i]) ; //close and destroy socket   
     857    gi_NumConnect[ i/7 ]-- ;
     858 }
    864859
    865860 xwait.tv_sec = 0;
     
    944939        if (evtCtrl.evtStat[k0] > 90 && evtCtrl.evtStat[k0] <500) {
    945940           int      id   = evtCtrl.evtBuf[k0] ;
    946            uint32_t irun = mBuffer[id].runNum ;
    947941           int      ievt = mBuffer[id].evNum ;
    948942           int      roi  = mBuffer[id].nRoi ;
     943//         uint32_t irun = mBuffer[id].runNum ;
    949944//snprintf(str,MXSTR,"P processing %d %d %d %d",ievt,k,id,evtCtrl.evtStat[k0]) ;
    950945//factOut(kDebug,-1, str ) ;
     
    964959             }
    965960           }
    966 //and set correct event header ; also check for consistency in event
    967           mBuffer[id].fEvent->Roi = roi ;
    968           mBuffer[id].fEvent->EventNum = ievt ;
    969           mBuffer[id].fEvent->TriggerType = 0 ; // TBD
    970           mBuffer[id].fEvent->SoftTrig = 0 ;
    971           for (ib=0; ib<NBOARDS; ib++) {
    972              mBuffer[id].fEvent->BoardTime[ib] = 123 ;
    973 
    974 
    975 
    976 
     961
     962
     963//and set correct event header ; also check for consistency in event (not yet)
     964           mBuffer[id].fEvent->Roi = roi ;
     965           mBuffer[id].fEvent->EventNum = ievt ;
     966           mBuffer[id].fEvent->TriggerType = 0 ; // TBD
     967           mBuffer[id].fEvent->SoftTrig = 0 ;
     968           for (ib=0; ib<NBOARDS; ib++) {
     969              if (mBuffer[id].board[ib] == -1 ) {  //board is not read
     970                 mBuffer[id].FADhead[ib].start_package_flag = 0 ;
     971                 mBuffer[id].fEvent->BoardTime[ib] = 0 ;
     972              } else {
     973                 mBuffer[id].fEvent->BoardTime[ib] =
     974                 ntohl(mBuffer[id].FADhead[ib].time) ;
     975              }
    977976           }
     977
     978           int i=eventCheck(mBuffer[id].FADhead,mBuffer[id].fEvent) ;
     979           
     980           if (i<0) evtCtrl.evtStat[k0] = 999 ; //flag event to be skipped
     981
    978982           numProc++ ;
    979983           evtCtrl.evtStat[k0] = 520 ;
     
    13061310
    13071311
    1308 
     1312/*
    13091313     xwait.tv_sec = 20;;
    13101314     xwait.tv_nsec= 0 ;  // sleep for ~20sec
     
    13241328
    13251329     g_runStat = -1 ;
    1326 
     1330*/
    13271331
    13281332
     
    13711375
    13721376
     1377
     1378int  eventCheck( PEVNT_HEADER *fadhd, EVENT *event)
     1379{
     1380   int i=0;
     1381
     1382   printf("------------%d\n",ntohl(fadhd[7].fad_evt_counter) );
     1383   for (i=0; i<NBOARDS; i++) {
     1384      printf("b=%2d,=%5d\n",i,fadhd[i].board_id);
     1385   }
     1386   return 0;
     1387}
     1388
     1389
    13731390void factStat(int severity, int err, char* message ) {
    13741391  printf("%3d %3d : %s\n",severity,err,message) ;
     
    13771394
    13781395void debugRead(int isock, int ibyte, int32_t event, int state, uint32_t tsec, uint32_t tusec ) {
    1379   printf("%3d %5d %9d %3d %12d\n",isock, ibyte, event, state, tusec) ;
     1396//  printf("%3d %5d %9d %3d %12d\n",isock, ibyte, event, state, tusec) ;
    13801397}
    13811398
  • trunk/FACT++/src/EventBuilderWrapper.h

    r11082 r11091  
    747747        Update(fDimCurrentEvent, uint32_t(0));
    748748        Update(fDimEvents,       fNumEvts);
     749
     750        for (size_t i=0; i<40; i++)
     751            ConnectSlot(i, tcp::endpoint());
    749752    }
    750753    ~EventBuilderWrapper()
     
    777780    }
    778781
    779     void Start(const vector<tcp::endpoint> &addr)
     782    void StartThread(const vector<tcp::endpoint> &addr)
    780783    {
    781784        if (IsThreadRunning())
     
    785788        }
    786789
    787         int cnt = 0;
    788790        for (size_t i=0; i<40; i++)
    789         {
    790             if (addr[i]==tcp::endpoint())
    791             {
    792                 g_port[i].sockDef = -1;
    793                 continue;
    794             }
    795 
    796             // -1:  if entry shell not be used
    797             //  0:  event builder will connect but ignore the events
    798             //  1:  event builder will connect and build events
    799             g_port[i].sockDef                  = 1;
    800 
    801             g_port[i].sockAddr.sin_family      = AF_INET;
    802             g_port[i].sockAddr.sin_addr.s_addr = htonl(addr[i].address().to_v4().to_ulong());
    803             g_port[i].sockAddr.sin_port        = htons(addr[i].port());
    804 
    805             cnt++;
    806         }
    807 
    808 //        g_maxBoards = cnt;
    809         g_actBoards = cnt;
    810 
    811         g_runStat   = kModeRun;
     791            ConnectSlot(i, addr[i]);
     792
     793        g_runStat = kModeRun;
    812794
    813795        fMsg.Message("Starting EventBuilder thread");
     
    815797        fThread = boost::thread(StartEvtBuild);
    816798    }
     799    void ConnectSlot(unsigned int i, const tcp::endpoint &addr)
     800    {
     801        if (i>39)
     802            return;
     803
     804        if (addr==tcp::endpoint())
     805        {
     806            DisconnectSlot(i);
     807            return;
     808        }
     809
     810        g_port[i].sockAddr.sin_family      = AF_INET;
     811        g_port[i].sockAddr.sin_addr.s_addr = htonl(addr.address().to_v4().to_ulong());
     812        g_port[i].sockAddr.sin_port        = htons(addr.port());
     813        // In this order
     814        g_port[i].sockDef = 1;
     815    }
     816    void DisconnectSlot(unsigned int i)
     817    {
     818        if (i>39)
     819            return;
     820
     821        g_port[i].sockDef = 0;
     822        // In this order
     823        g_port[i].sockAddr.sin_family      = AF_INET;
     824        g_port[i].sockAddr.sin_addr.s_addr = 0;
     825        g_port[i].sockAddr.sin_port        = 0;
     826    }
     827    void IgnoreSlot(unsigned int i)
     828    {
     829        if (i>39)
     830            return;
     831        if (g_port[i].sockAddr.sin_port==0)
     832            return;
     833
     834        g_port[i].sockDef = -1;
     835    }
     836
     837
    817838    void Abort()
    818839    {
     
    848869    int  GetNumConnected(int i) const { return gi_NumConnect[i]; }
    849870
    850     void SetIgnore(int i, bool b) const { if (g_port[i].sockDef>=0) g_port[i].sockDef=b?0:1; }
    851     bool IsIgnored(int i) const { return g_port[i].sockDef==0; }
     871    void SetIgnore(int i, bool b) const { if (g_port[i].sockDef!=0) g_port[i].sockDef=b?-1:1; }
     872    bool IsIgnored(int i) const { return g_port[i].sockDef==-1; }
    852873
    853874    void SetDebugStream(bool b) { fDebugStream = b; if (!b) for (int i=0; i<40; i++) fDumpStream[i].close(); }
     
    11271148    }
    11281149
    1129     /*
    1130     void message(int severity, const char *msg)
    1131     {
    1132         EventBuilderWrapper::This->Update(msg, severity);
    1133     }*/
     1150    int eventCheck(PEVNT_HEADER *fadhd, EVENT *event)
     1151    {
     1152    }
    11341153}
    11351154
  • trunk/FACT++/src/fadctrl.cc

    r11083 r11091  
    10001000        const int16_t slot = evt.GetShort();
    10011001
    1002         const BoardList::iterator it = fBoards.find(slot);
     1002        const BoardList::iterator it = GetSlot(slot);
    10031003
    10041004        if (it==fBoards.end())
    1005         {
    1006             ostringstream str;
    1007             str << "Slot " << slot << " not found.";
    1008             T::Warn(str.str());
    10091005            return T::GetCurrentState();
    1010         }
     1006
     1007        ConnectSlot(slot, tcp::endpoint());
    10111008
    10121009        delete it->second.second;
     
    10421039            case 0:  str << "1-7:not connected)"; break;
    10431040            case 7:  str << "1-7:connected)";     break;
    1044             default: str << "1-7:connecting [" << fStatus2[idx] << "])"; break;
     1041            default: str << "1-7:connecting [" << (int)fStatus2[idx] << "])"; break;
    10451042            }
    10461043
     
    10641061    }
    10651062
    1066     void EnableSlot(Connection &c, bool enable=true)
     1063    void EnableConnection(Connection &c, bool enable=true)
    10671064    {
    10681065        ConnectionFAD *ptr = c.second;
     
    10711068
    10721069        if (!enable)
     1070        {
    10731071            ptr->PostClose(false);
     1072        }
    10741073        else
    10751074        {
     
    10841083    {
    10851084        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
    1086             EnableSlot(i->second, enable);
    1087     }
    1088 
    1089     int Disconnect()
     1085            EnableConnection(i->second, enable);
     1086    }
     1087
     1088    int CloseOpenFiles()
     1089    {
     1090        EventBuilderWrapper::CloseOpenFiles();
     1091        return T::GetCurrentState();
     1092    }
     1093
     1094    int EnableSlot(const EventImp &evt, bool enable)
     1095    {
     1096        if (!CheckEventSize(evt.GetSize(), "EnableSlot", 2))
     1097            return T::kSM_FatalError;
     1098
     1099        const int16_t slot = evt.GetShort();
     1100
     1101        const BoardList::iterator it = GetSlot(slot);
     1102
     1103        if (it==fBoards.end())
     1104            return T::GetCurrentState();
     1105
     1106        EnableConnection(it->second, enable);
     1107        ConnectSlot(it->first, enable ? it->second.first : tcp::endpoint());
     1108
     1109        return T::GetCurrentState();
     1110    }
     1111
     1112    int StartConnection()
     1113    {
     1114        vector<tcp::endpoint> addr(40);
     1115
     1116        for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
     1117            addr[i->first] = i->second.first;
     1118
     1119        StartThread(addr);
     1120        EnableAll(true);
     1121
     1122        return T::GetCurrentState();
     1123    }
     1124
     1125    int StopConnection()
    10901126    {
    10911127        Exit();
     
    10941130    }
    10951131
    1096     int ForceDisconnect()
     1132    int AbortConnection()
    10971133    {
    10981134        Abort();
    10991135        EnableAll(false);
    1100         return T::GetCurrentState();
    1101     }
    1102 
    1103     int CloseOpenFiles()
    1104     {
    1105         EventBuilderWrapper::CloseOpenFiles();
    1106         return T::GetCurrentState();
    1107     }
    1108 
    1109     int Connect()
    1110     {
    1111         vector<tcp::endpoint> addr(40);
    1112 
    1113         for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++)
    1114             addr[i->first] = i->second.first;
    1115 
    1116         Start(addr);
    1117         EnableAll(true);
    1118 
    11191136        return T::GetCurrentState();
    11201137    }
     
    11341151        // ===== Evaluate connection status =====
    11351152
     1153        uint16_t nclosed1     = 0;
    11361154        uint16_t nconnecting1 = 0;
    11371155        uint16_t nconnecting2 = 0;
     
    11511169            {
    11521170                const ConnectionFAD *c = slot->second.second;
     1171                if (c->IsDisconnected())
     1172                {
     1173                    stat1[idx] = 0;
     1174                    nclosed1++;
     1175                }
    11531176                if (c->IsConnecting())
    11541177                {
     
    11881211        // fadctrl:       Always connecting if not disabled
    11891212        // event builder:
    1190 
    1191        // FIXME: Evaluate event builder status
    1192          if (nconnected1==cnt && nconnected2==cnt && cnt>0)
     1213        if (nconnecting1==0 && nconnected1>0 &&
     1214            nconnected2==nconnected1)
    11931215            return FAD::kConnected;
    11941216
    1195         if (nconnected1!=0 || nconnected2!=0)
     1217        if (nconnecting1>0 || nconnecting2>0 || nconnected1!=nconnected2)
    11961218            return FAD::kConnecting;
     1219
     1220//        cout << 1 << " " << nconnecting1 << " " << nconnected1 << " " << nclosed1 << endl;
     1221//        cout << 2 << " " << nconnecting2 << " " << nconnected2 << endl;
    11971222
    11981223        // nconnected1 == nconnected2 == 0
     
    12481273        T(out, "FAD_CONTROL"), EventBuilderWrapper(*static_cast<MessageImp*>(this)), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    12491274        fStatus1(40), fStatus2(40),
    1250         fDimConnection("FAD_CONTROL/CONNECTIONS", "C:41", "")
     1275        fDimConnection("FAD_CONTROL/CONNECTIONS", "C:40", "")
    12511276    {
    12521277        // ba::io_service::work is a kind of keep_alive for the loop.
     
    13081333            (boost::bind(&StateMachineFAD::SendTriggers, this, _1))
    13091334            ("Issue software triggers");
    1310         T::AddEvent("START", "")
     1335        T::AddEvent("START_RUN", "")
    13111336            (boost::bind(&StateMachineFAD::StartRun, this, _1, true))
    13121337            ("Set FAD DAQ mode. when started, no configurations must be send.");
    1313         T::AddEvent("STOP")
     1338        T::AddEvent("STOP_RUN")
    13141339            (boost::bind(&StateMachineFAD::StartRun, this, _1, false))
    13151340            ("");
     
    14101435
    14111436        // Conenction commands
    1412         /*
    1413         T::AddEvent("ENABLE", "S:1;B:1", FAD::kDisconnected)
    1414             (boost::bind(&StateMachineFAD::Enable, this, _1))
    1415             ("");*/
    1416 
    1417         T::AddEvent("CONNECT", FAD::kOffline)
    1418             (boost::bind(&StateMachineFAD::Connect, this))
     1437        T::AddEvent("START", FAD::kOffline)
     1438            (boost::bind(&StateMachineFAD::StartConnection, this))
    14191439            ("");
    1420 
    1421         T::AddEvent("DISCONNECT", FAD::kDisconnected, FAD::kConnecting, FAD::kConnected)
    1422             (boost::bind(&StateMachineFAD::Disconnect, this))
     1440        T::AddEvent("STOP",  FAD::kDisconnected, FAD::kConnecting, FAD::kConnected)
     1441            (boost::bind(&StateMachineFAD::StopConnection, this))
    14231442            ("");
    14241443
    1425         T::AddEvent("FORCE_DISCONNECT", FAD::kDisconnected, FAD::kConnecting, FAD::kConnected)
    1426             (boost::bind(&StateMachineFAD::ForceDisconnect, this))
     1444        T::AddEvent("ABORT", FAD::kDisconnected, FAD::kConnecting, FAD::kConnected)
     1445            (boost::bind(&StateMachineFAD::AbortConnection, this))
     1446            ("");
     1447
     1448        T::AddEvent("CONNECT", "S:1", FAD::kConnecting, FAD::kConnected)
     1449            (boost::bind(&StateMachineFAD::EnableSlot, this, _1, true))
     1450            ("");
     1451
     1452        T::AddEvent("DISCONNECT", "S:1", FAD::kConnecting, FAD::kConnected)
     1453            (boost::bind(&StateMachineFAD::EnableSlot, this, _1, false))
    14271454            ("");
    14281455
     
    15031530                AddEndpoint(tcp::endpoint(endpoint.address(), endpoint.port()+8*i));
    15041531
    1505             Connect();
     1532            StartConnection();
    15061533            return true;
    15071534        }
     
    15541581        }
    15551582
    1556         Connect();
     1583        StartConnection();
    15571584
    15581585        return true;
Note: See TracChangeset for help on using the changeset viewer.