Changeset 11091
- Timestamp:
- 06/21/11 20:54:18 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r11090 r11091 43 43 extern void factStat(int severity, int err, char* message ) ; 44 44 45 extern int eventCheck( PEVNT_HEADER *fadhd, EVENT *event) ; 45 46 46 47 extern void debugRead(int isock, int ibyte, int32_t event, int state, … … 295 296 296 297 297 needmem = sizeof(EVENT) + NPIX*nRoi*2 + NTMARK*nRoi*2 ;298 needmem = sizeof(EVENT) + NPIX*nRoi*2 + NTMARK*nRoi*2; // 298 299 299 300 headmem = NBOARDS* sizeof(PEVNT_HEADER) ; … … 576 577 snprintf(str,MXSTR,"Socket %d closed by FAD",i); 577 578 factOut(kInfo,441, str ) ; 578 j =GenSock(1, i, 0,NULL, &rd[i]) ;579 GenSock(1, i, 0,NULL, &rd[i]) ; 579 580 gi_ErrCnt[i]++ ; 580 581 gi_NumConnect[ b ]-- ; … … 852 853 snprintf(str,MXSTR,"close all sockets ..."); 853 854 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 } 864 859 865 860 xwait.tv_sec = 0; … … 944 939 if (evtCtrl.evtStat[k0] > 90 && evtCtrl.evtStat[k0] <500) { 945 940 int id = evtCtrl.evtBuf[k0] ; 946 uint32_t irun = mBuffer[id].runNum ;947 941 int ievt = mBuffer[id].evNum ; 948 942 int roi = mBuffer[id].nRoi ; 943 // uint32_t irun = mBuffer[id].runNum ; 949 944 //snprintf(str,MXSTR,"P processing %d %d %d %d",ievt,k,id,evtCtrl.evtStat[k0]) ; 950 945 //factOut(kDebug,-1, str ) ; … … 964 959 } 965 960 } 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 } 977 976 } 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 978 982 numProc++ ; 979 983 evtCtrl.evtStat[k0] = 520 ; … … 1306 1310 1307 1311 1308 1312 /* 1309 1313 xwait.tv_sec = 20;; 1310 1314 xwait.tv_nsec= 0 ; // sleep for ~20sec … … 1324 1328 1325 1329 g_runStat = -1 ; 1326 1330 */ 1327 1331 1328 1332 … … 1371 1375 1372 1376 1377 1378 int 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 1373 1390 void factStat(int severity, int err, char* message ) { 1374 1391 printf("%3d %3d : %s\n",severity,err,message) ; … … 1377 1394 1378 1395 void 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) ; 1380 1397 } 1381 1398 -
trunk/FACT++/src/EventBuilderWrapper.h
r11082 r11091 747 747 Update(fDimCurrentEvent, uint32_t(0)); 748 748 Update(fDimEvents, fNumEvts); 749 750 for (size_t i=0; i<40; i++) 751 ConnectSlot(i, tcp::endpoint()); 749 752 } 750 753 ~EventBuilderWrapper() … … 777 780 } 778 781 779 void Start (const vector<tcp::endpoint> &addr)782 void StartThread(const vector<tcp::endpoint> &addr) 780 783 { 781 784 if (IsThreadRunning()) … … 785 788 } 786 789 787 int cnt = 0;788 790 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; 812 794 813 795 fMsg.Message("Starting EventBuilder thread"); … … 815 797 fThread = boost::thread(StartEvtBuild); 816 798 } 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 817 838 void Abort() 818 839 { … … 848 869 int GetNumConnected(int i) const { return gi_NumConnect[i]; } 849 870 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; } 852 873 853 874 void SetDebugStream(bool b) { fDebugStream = b; if (!b) for (int i=0; i<40; i++) fDumpStream[i].close(); } … … 1127 1148 } 1128 1149 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 } 1134 1153 } 1135 1154 -
trunk/FACT++/src/fadctrl.cc
r11083 r11091 1000 1000 const int16_t slot = evt.GetShort(); 1001 1001 1002 const BoardList::iterator it = fBoards.find(slot);1002 const BoardList::iterator it = GetSlot(slot); 1003 1003 1004 1004 if (it==fBoards.end()) 1005 {1006 ostringstream str;1007 str << "Slot " << slot << " not found.";1008 T::Warn(str.str());1009 1005 return T::GetCurrentState(); 1010 } 1006 1007 ConnectSlot(slot, tcp::endpoint()); 1011 1008 1012 1009 delete it->second.second; … … 1042 1039 case 0: str << "1-7:not connected)"; break; 1043 1040 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; 1045 1042 } 1046 1043 … … 1064 1061 } 1065 1062 1066 void Enable Slot(Connection &c, bool enable=true)1063 void EnableConnection(Connection &c, bool enable=true) 1067 1064 { 1068 1065 ConnectionFAD *ptr = c.second; … … 1071 1068 1072 1069 if (!enable) 1070 { 1073 1071 ptr->PostClose(false); 1072 } 1074 1073 else 1075 1074 { … … 1084 1083 { 1085 1084 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() 1090 1126 { 1091 1127 Exit(); … … 1094 1130 } 1095 1131 1096 int ForceDisconnect()1132 int AbortConnection() 1097 1133 { 1098 1134 Abort(); 1099 1135 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 1119 1136 return T::GetCurrentState(); 1120 1137 } … … 1134 1151 // ===== Evaluate connection status ===== 1135 1152 1153 uint16_t nclosed1 = 0; 1136 1154 uint16_t nconnecting1 = 0; 1137 1155 uint16_t nconnecting2 = 0; … … 1151 1169 { 1152 1170 const ConnectionFAD *c = slot->second.second; 1171 if (c->IsDisconnected()) 1172 { 1173 stat1[idx] = 0; 1174 nclosed1++; 1175 } 1153 1176 if (c->IsConnecting()) 1154 1177 { … … 1188 1211 // fadctrl: Always connecting if not disabled 1189 1212 // 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) 1193 1215 return FAD::kConnected; 1194 1216 1195 if (nconnect ed1!=0 || nconnected2!=0)1217 if (nconnecting1>0 || nconnecting2>0 || nconnected1!=nconnected2) 1196 1218 return FAD::kConnecting; 1219 1220 // cout << 1 << " " << nconnecting1 << " " << nconnected1 << " " << nclosed1 << endl; 1221 // cout << 2 << " " << nconnecting2 << " " << nconnected2 << endl; 1197 1222 1198 1223 // nconnected1 == nconnected2 == 0 … … 1248 1273 T(out, "FAD_CONTROL"), EventBuilderWrapper(*static_cast<MessageImp*>(this)), ba::io_service::work(static_cast<ba::io_service&>(*this)), 1249 1274 fStatus1(40), fStatus2(40), 1250 fDimConnection("FAD_CONTROL/CONNECTIONS", "C:4 1", "")1275 fDimConnection("FAD_CONTROL/CONNECTIONS", "C:40", "") 1251 1276 { 1252 1277 // ba::io_service::work is a kind of keep_alive for the loop. … … 1308 1333 (boost::bind(&StateMachineFAD::SendTriggers, this, _1)) 1309 1334 ("Issue software triggers"); 1310 T::AddEvent("START ", "")1335 T::AddEvent("START_RUN", "") 1311 1336 (boost::bind(&StateMachineFAD::StartRun, this, _1, true)) 1312 1337 ("Set FAD DAQ mode. when started, no configurations must be send."); 1313 T::AddEvent("STOP ")1338 T::AddEvent("STOP_RUN") 1314 1339 (boost::bind(&StateMachineFAD::StartRun, this, _1, false)) 1315 1340 (""); … … 1410 1435 1411 1436 // 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)) 1419 1439 (""); 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)) 1423 1442 (""); 1424 1443 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)) 1427 1454 (""); 1428 1455 … … 1503 1530 AddEndpoint(tcp::endpoint(endpoint.address(), endpoint.port()+8*i)); 1504 1531 1505 Connect();1532 StartConnection(); 1506 1533 return true; 1507 1534 } … … 1554 1581 } 1555 1582 1556 Connect();1583 StartConnection(); 1557 1584 1558 1585 return true;
Note:
See TracChangeset
for help on using the changeset viewer.