Changeset 11082 for trunk/FACT++/src/EventBuilder.c
- Timestamp:
- 06/20/11 18:26:11 (13 years ago)
- File:
-
- 1 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 */
Note:
See TracChangeset
for help on using the changeset viewer.