Changeset 11082 for trunk/FACT++/src
- Timestamp:
- 06/20/11 18:26:11 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r10979 r11082 10 10 #include <unistd.h> 11 11 #include <stdio.h> 12 #include < time.h>12 #include <sys/time.h> 13 13 #include <arpa/inet.h> 14 14 #include <string.h> … … 43 43 extern void factStat(int severity, int err, char* message ) ; 44 44 45 46 extern void debugRead(int isock, int ibyte, int32_t event, int state, 47 uint32_t tsec, uint32_t tusec ) ; 48 extern void debugStream(int isock, void *buf, int len) ; 49 50 51 45 52 int g_actTime = 0 ; 46 53 int g_runStat = 40 ; … … 129 136 int16_t S ; 130 137 } SHORT_BYTE ; 138 139 140 131 141 132 142 … … 395 405 int nokCnt[MAX_SOCK],loopCnt=0; 396 406 int sokCnt[MAX_SOCK]; 407 408 struct timeval *tv, atv; 409 tv=&atv; 410 uint32_t tsec, tusec ; 397 411 398 412 … … 466 480 467 481 head_len = sizeof(PEVNT_HEADER) ; 468 frst_len = head_len + 36 * 12 ; //fad_header plus 36*pix_header 482 //frst_len = head_len + 36 * 12 ; //fad_header plus 36*pix_header 483 frst_len = head_len ; //fad_header only, so each event must be longer, even for roi=0 484 469 485 470 486 numok = numok2 = 0 ; … … 490 506 491 507 for (i=0; i<gi_maxSocks; i++) { //check all sockets if something to read 508 509 gettimeofday( tv, NULL); 510 tsec = atv.tv_sec ; 511 tusec= atv.tv_usec ; 512 492 513 if (rd[i].sockStat <0 ) { //try to connect if not yet done 493 514 rd[i].sockStat=connect(rd[i].socket, … … 509 530 jrd=recv(rd[i].socket,&rd[i].rBuf->B[ rd[i].bufPos], rd[i].bufLen, MSG_DONTWAIT); 510 531 532 533 if (jrd >0 ) { 534 debugStream(i,&rd[i].rBuf->B[ rd[i].bufPos],jrd) ; 535 } 536 537 538 511 539 if (jrd == 0) { //connection has closed ... 512 540 rd[i].sockStat = -1 ; //flag (try to reopen next round) … … 528 556 rd[i].bufPos += jrd ; //==> prepare for continuation 529 557 rd[i].bufLen -= jrd ; 558 debugRead(i,jrd,rd[i].evtID, 0,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid; 0=reading data 530 559 } else { //full dataset read 531 560 rd[i].bufLen = rd[i].bufPos + j ; … … 539 568 540 569 } 570 debugRead(i,jrd,rd[i].evtID, 1,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid; 1=finished event 541 571 542 572 //we have a complete buffer, copy to WORK area … … 675 705 rd[i].bufLen = rd[i].fadLen - rd[i].bufPos ; 676 706 if (rd[i].bufLen <=0 ) rd[i].bufLen = 100000 ; 707 debugRead(i,jrd,rd[i].evtID,-1,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid;-1=start event 677 708 } 709 else { 710 debugRead(i,jrd,0,-2,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid; -2=start event, unknown id yet 711 } 712 678 713 } 714 715 else { 716 debugRead(i,jrd,0,-2,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid; -2=start event, unknown id yet 717 } 718 679 719 } //end interpreting last read 680 720 } //end of successful read anything … … 953 993 /* close run runId (all all runs if runId=0) */ 954 994 /* return: 0=close scheduled / >0 already closed / <0 does not exist */ 955 int j ;995 int i, j ; 956 996 957 997 if (runId == 0 ) { 958 998 for ( j=0; j<MAX_RUN; j++) { 959 999 if ( runCtrl[j].fileId == 0 ) { //run is open 1000 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1001 if (i<0) { 1002 snprintf(str,MXSTR,"error closing run %d %d",runCtrl[j].runId,i) ; 1003 factOut(kError,506, str ) ; 1004 runCtrl[j].fileId = 888 ; 1005 } else { 1006 snprintf(str,MXSTR,"closing run %d ok AAA",runCtrl[j].runId); 1007 factOut(kInfo,507, str ) ; 1008 runCtrl[j].fileId = 7777 ; 1009 } 960 1010 runCtrl[j].closeTime = closeTime ; 961 1011 } … … 968 1018 if ( runCtrl[j].runId == runId ) { 969 1019 if ( runCtrl[j].fileId == 0 ) { //run is open 1020 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1021 if (i<0) { 1022 snprintf(str,MXSTR,"error closing run %d %d",runCtrl[j].runId,i) ; 1023 factOut(kError,506, str ) ; 1024 runCtrl[j].fileId = 888 ; 1025 } else { 1026 snprintf(str,MXSTR,"closing run %d ok AAA",runCtrl[j].runId); 1027 factOut(kInfo,507, str ) ; 1028 runCtrl[j].fileId = 7777 ; 1029 } 970 1030 runCtrl[j].closeTime = closeTime ; 971 1031 return 0; 972 1032 } else if ( runCtrl[j].fileId <0 ) { //run not yet opened 973 1033 runCtrl[j].closeTime = closeTime ; 974 return 0;1034 return +1; 975 1035 } else { // run already closed 976 return + 1;1036 return +2; 977 1037 } 978 1038 } … … 1134 1194 factOut(kInfo,-1, str ) ; 1135 1195 for ( j=0; j<MAX_RUN; j++) 1136 if ( runCtrl[j]. runId >0 ) {1196 if ( runCtrl[j].fileId ==0 ) { 1137 1197 int i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1138 1198 if (i<0) { … … 1212 1272 1213 1273 1214 /* 1274 1215 1275 1216 1276 xwait.tv_sec = 20;; … … 1233 1293 1234 1294 1235 */ 1295 1236 1296 1237 1297 … … 1250 1310 } /*-----------------------------------------------------------------*/ 1251 1311 1312 1313 1314 1315 1316 /*-----------------------------------------------------------------*/ 1317 /*-----------------------------------------------------------------*/ 1318 /*-----------------------------------------------------------------*/ 1319 /*-----------------------------------------------------------------*/ 1320 /*-----------------------------------------------------------------*/ 1321 /*-----------------------------------------------------------------*/ 1322 /*-----------------------------------------------------------------*/ 1323 /*-----------------------------------------------------------------*/ 1324 /*-----------------------------------------------------------------*/ 1325 /*-----------------------------------------------------------------*/ 1326 1327 /* 1328 1329 1330 FileHandle_t runOpen(uint32_t irun, RUN_HEAD *runhd, size_t len ) 1331 { return 1; } ; 1332 1333 int runWrite(FileHandle_t fileHd , EVENT *event, size_t len ) 1334 { return 1; } ; 1335 1336 int runClose(FileHandle_t fileHd , RUN_TAIL *runth, size_t len ) 1337 { return 1; } ; 1338 1339 1340 void factStat(int severity, int err, char* message ) { 1341 printf("%3d %3d : %s\n",severity,err,message) ; 1342 } 1343 1344 1345 void debugRead(int isock, int ibyte, int32_t event, int state, uint32_t tsec, uint32_t tusec ) { 1346 printf("%3d %5d %9d %3d %12d\n",isock, ibyte, event, state, tusec) ; 1347 } 1348 1349 1350 1351 void debugStream(int isock, void *buf, int len) { 1352 } 1353 1354 1355 void factOut(int severity, int err, char* message ) { 1356 static FILE * fd ; 1357 static int file=0 ; 1358 1359 if (file==0) { 1360 printf("open file\n"); 1361 fd=fopen("x.out","w+") ; 1362 file=999; 1363 } 1364 1365 fprintf(fd,"%3d %3d | %s \n",severity,err,message) ; 1366 1367 if (severity != kDebug) 1368 printf("%3d %3d | %s\n",severity,err,message) ; 1369 } 1370 1371 1372 1373 int main() { 1374 int i,b,c,p ; 1375 char ipStr[100] ; 1376 struct in_addr IPaddr ; 1377 1378 g_maxMem = 1024*1024 ; //MBytes 1379 g_maxMem = g_maxMem * 1024 *10 ; //10GBytes 1380 1381 g_maxBoards = 40 ; 1382 1383 g_actBoards = g_maxBoards; 1384 1385 g_runStat = 40 ; 1386 1387 i=0 ; 1388 1389 // version for standard crates 1390 //for (c=0; c<4,c++) { 1391 // for (b=0; b<10; b++) { 1392 // sprintf(ipStr,"10.0.%d.%d",128+c,128+b) 1393 // 1394 // inet_pton(PF_INET, ipStr, &IPaddr) ; 1395 // 1396 // g_port[i].sockAddr.sin_family = PF_INET; 1397 // g_port[i].sockAddr.sin_port = htons(5000) ; 1398 // g_port[i].sockAddr.sin_addr = IPaddr ; 1399 // g_port[i].sockDef = 1 ; 1400 // i++ ; 1401 // } 1402 //} 1403 // 1404 //version for PC-test 1405 for (c=0; c<4; c++) { 1406 for (b=0; b<10; b++) { 1407 sprintf(ipStr,"10.0.%d.11",128+c) ; 1408 if (c==0) sprintf(ipStr,"10.0.100.11") ; 1409 1410 inet_pton(PF_INET, ipStr, &IPaddr) ; 1411 p = 31919+100*c+10*b; 1412 1413 1414 g_port[i].sockAddr.sin_family = PF_INET; 1415 g_port[i].sockAddr.sin_port = htons(p) ; 1416 g_port[i].sockAddr.sin_addr = IPaddr ; 1417 g_port[i].sockDef = 1 ; 1418 1419 i++ ; 1420 } 1421 } 1422 1423 1424 //g_port[17].sockDef =-1 ; 1425 //g_actBoards-- ; 1426 1427 StartEvtBuild() ; 1428 1429 return 0; 1430 1431 } 1432 1433 */ -
trunk/FACT++/src/EventBuilderWrapper.h
r11081 r11082 720 720 DimDescribedService fDimCurrentEvent; 721 721 722 bool fDebugStream; 723 bool fDebugRead; 724 722 725 int Write(const Time &time, const std::string &txt, int qos) 723 726 { … … 731 734 fDimRuns ("FAD_CONTROL/RUNS", "I:1", ""), 732 735 fDimEvents("FAD_CONTROL/EVENTS", "I:2", ""), 733 fDimCurrentEvent("FAD_CONTROL/CURRENT_EVENT", "I:1", "") 736 fDimCurrentEvent("FAD_CONTROL/CURRENT_EVENT", "I:1", ""), 737 fDebugStream(false), fDebugRead(false) 734 738 { 735 739 if (This) … … 847 851 bool IsIgnored(int i) const { return g_port[i].sockDef==0; } 848 852 853 void SetDebugStream(bool b) { fDebugStream = b; if (!b) for (int i=0; i<40; i++) fDumpStream[i].close(); } 854 void SetDebugRead(bool b) { fDebugRead = b; if (!b) fDumpRead.close(); } 855 849 856 size_t GetUsedMemory() const { return gi_usedMem; } 850 857 … … 984 991 return rc ? 0 : -1; 985 992 } 993 994 ofstream fDumpStream[40]; 995 996 void debugStream(int isock, void *buf, int len) 997 { 998 if (!fDebugStream) 999 return; 1000 1001 const int slot = isock/7; 1002 if (slot<0 || slot>39) 1003 return; 1004 1005 if (!fDumpStream[slot].is_open()) 1006 { 1007 ostringstream name; 1008 name << "socket_dump-" << setfill('0') << setw(2) << slot << ".bin"; 1009 1010 fDumpStream[slot].open(name.str().c_str(), ios::app); 1011 if (!fDumpStream[slot]) 1012 { 1013 //ostringstream str; 1014 //str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")"; 1015 //Error(str); 1016 1017 return; 1018 } 1019 } 1020 1021 fDumpStream[slot].write(reinterpret_cast<const char*>(buf), len); 1022 } 1023 1024 ofstream fDumpRead; // Stream to possibly dump docket events 1025 1026 void debugRead(int isock, int ibyte, int32_t event, int state, uint32_t tsec, uint32_t tusec) 1027 { 1028 // isock = socketID (0-279) 1029 // ibyte = #bytes gelesen 1030 // event = eventId (oder 0 wenn noch nicht bekannt) 1031 // state : 0=reading data 1032 // 1=finished reading data 1033 // -1=start reading data (header) 1034 // -2=start reading data, 1035 // eventId not known yet (too little data) 1036 // tsec, tusec = time when reading seconds, microseconds 1037 // 1038 if (!fDebugRead) 1039 return; 1040 1041 if (!fDumpRead.is_open()) 1042 { 1043 fDumpRead.open("socket_events.txt", ios::app); 1044 if (!fDumpRead) 1045 { 1046 //ostringstream str; 1047 //str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")"; 1048 //Error(str); 1049 1050 return; 1051 } 1052 } 1053 1054 fDumpRead 1055 << setw(2) << state << " " 1056 << setw(8) << tsec << " " 1057 << setw(9) << tusec << " " 1058 << setw(3) << isock << " " 1059 << setw(2) << isock/7 << " " 1060 << event << " " 1061 << ibyte << endl; 1062 } 1063 986 1064 }; 987 1065 … … 1039 1117 } 1040 1118 1119 void debugStream(int isock, void *buf, int len) 1120 { 1121 return EventBuilderWrapper::This->debugStream(isock, buf, len); 1122 } 1123 1124 void debugRead(int isock, int ibyte, int32_t event, int state, uint32_t tsec, uint32_t tusec) 1125 { 1126 return EventBuilderWrapper::This->debugRead(isock, ibyte, event, state, tsec, tusec); 1127 } 1128 1041 1129 /* 1042 1130 void message(int severity, const char *msg) -
trunk/FACT++/src/fadctrl.cc
r11080 r11082 947 947 for (int i=slot[0]; i<=slot[1]; i++) 948 948 SetIgnore(i, block); 949 950 return T::GetCurrentState(); 951 } 952 953 int SetDumpStream(const EventImp &evt) 954 { 955 if (!CheckEventSize(evt.GetSize(), "SetDumpStream", 1)) 956 return T::kSM_FatalError; 957 958 SetDebugStream(evt.Get<uint8_t>()); 959 960 return T::GetCurrentState(); 961 } 962 963 int SetDumpRecv(const EventImp &evt) 964 { 965 if (!CheckEventSize(evt.GetSize(), "SetDumpRecv", 1)) 966 return T::kSM_FatalError; 967 968 SetDebugRead(evt.Get<uint8_t>()); 949 969 950 970 return T::GetCurrentState(); … … 1334 1354 1335 1355 // Verbosity commands 1336 T::AddEvent("SET_VERBOSE", "B ")1356 T::AddEvent("SET_VERBOSE", "B:1") 1337 1357 (boost::bind(&StateMachineFAD::SetVerbosity, this, _1)) 1338 1358 ("set verbosity state" 1339 1359 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data"); 1340 1360 1341 T::AddEvent("SET_HEX_OUTPUT", "B ")1361 T::AddEvent("SET_HEX_OUTPUT", "B:1") 1342 1362 (boost::bind(&StateMachineFAD::SetHexOutput, this, _1)) 1343 1363 ("enable or disable hex output for received data" 1344 1364 "|hexout[bool]:disable or enable hex output for received data (yes/no)"); 1345 1365 1346 T::AddEvent("SET_DATA_OUTPUT", "B ")1366 T::AddEvent("SET_DATA_OUTPUT", "B:1") 1347 1367 (boost::bind(&StateMachineFAD::SetDataOutput, this, _1)) 1348 1368 (""); 1349 1369 1350 T::AddEvent("PRINT_EVENT", "I ")1370 T::AddEvent("PRINT_EVENT", "I:1") 1351 1371 (boost::bind(&StateMachineFAD::PrintEvent, this, _1)) 1352 1372 ("Print (last) event" 1353 1373 "|board[int]:slot from which the event should be printed (-1 for all)"); 1374 1375 T::AddEvent("DUMP_STREAM", "B:1") 1376 (boost::bind(&StateMachineFAD::SetDumpStream, this, _1)) 1377 ("For debugging purpose: the binary data stream read from the sockets 0-7 can be dumped to files." 1378 "|switch[bool]:Enable (yes) or disable (no)"); 1379 1380 T::AddEvent("DUMP_RECV", "B:1") 1381 (boost::bind(&StateMachineFAD::SetDumpRecv, this, _1)) 1382 ("For debugging purpose: the times when data has been receives are dumped to a file." 1383 "|switch[bool]:Enable (yes) or disable (no)"); 1354 1384 1355 1385 T::AddEvent("BLOCK_TRANSMISSION", "S:1;B:1")
Note:
See TracChangeset
for help on using the changeset viewer.