Changeset 11282 for trunk/FACT++/src/EventBuilder.c
- Timestamp:
- 07/07/11 19:52:05 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r11191 r11282 35 35 36 36 #define MIN_LEN 32 // min #bytes needed to interpret FADheader 37 #define MAX_LEN 64*1024 // size of read-buffer per socket37 #define MAX_LEN 256*1024 // size of read-buffer per socket 38 38 39 39 extern FileHandle_t runOpen(uint32_t irun, RUN_HEAD *runhd, size_t len ) ; … … 41 41 extern int runClose(FileHandle_t fileHd , RUN_TAIL *runth, size_t len ) ; 42 42 extern void factOut(int severity, int err, char* message ) ; 43 extern void factStat(int64_t *array , int len ) ; 43 44 extern void factStat(GUI_STAT gj) ; 45 46 extern void factStatNew(EVT_STAT gi) ; 44 47 45 48 extern int eventCheck( PEVNT_HEADER *fadhd, EVENT *event) ; 46 49 47 48 extern void debugHead(int i, void *buf); 49 50 extern void debugRead(int isock, int ibyte, int32_t event,int32_t ftmevt, int32_t runnr, int state, 51 uint32_t tsec, uint32_t tusec ) ; 50 extern void debugHead(int i, int j, void *buf); 51 52 extern void debugRead(int isock, int ibyte, int32_t event,int32_t ftmevt, 53 int32_t runnr, int state, uint32_t tsec, uint32_t tusec ) ; 52 54 extern void debugStream(int isock, void *buf, int len) ; 53 55 54 56 55 57 56 int g_actTime = 0;57 int g_runStat = 40;58 int g_actTime ; 59 int g_runStat ; 58 60 size_t g_maxMem ; //maximum memory allowed for buffer 59 61 … … 66 68 67 69 68 int gi_runStat ; 69 int gp_runStat ; 70 int gw_runStat ; 71 72 73 uint gi_SecRate[MAX_SOCK] ; 74 uint gi_S10Rate[MAX_SOCK] ; 75 uint gi_MinRate[MAX_SOCK] ; 76 uint gi_ErrCnt[MAX_SOCK] ; 70 int gi_runStat ; 71 int gp_runStat ; 72 int gw_runStat ; 73 int32_t gi_myRun ; 74 75 77 76 78 77 uint gi_NumConnect[NBOARDS]; //4 crates * 10 boards 79 78 80 uint gi_SecTime, gi_S10Time, gi_MinTime ; 81 uint gi_EvtStart= 0 ; 82 uint gi_EvtRead = 0 ; 83 uint gi_EvtBad = 0 ; 84 uint gi_EvtTot = 0 ; 85 size_t gi_usedMem = 0 ; 86 87 uint gw_EvtTot = 0 ; 88 uint gp_EvtTot = 0 ; 79 //uint gi_EvtStart= 0 ; 80 //uint gi_EvtRead = 0 ; 81 //uint gi_EvtBad = 0 ; 82 //uint gi_EvtTot = 0 ; 83 //size_t gi_usedMem = 0 ; 84 85 //uint gw_EvtTot = 0 ; 86 //uint gp_EvtTot = 0 ; 89 87 90 88 PIX_MAP g_pixMap[NPIX] ; 89 90 EVT_STAT gi ; 91 GUI_STAT gj ; 91 92 92 93 EVT_CTRL evtCtrl ; //control of events during processing … … 305 306 headmem = NBOARDS* sizeof(PEVNT_HEADER) ; 306 307 307 if ( g i_usedMem + needmem + headmem > g_maxMem) {308 if ( gj.usdMem + needmem + headmem > g_maxMem) { 308 309 snprintf(str,MXSTR,"no memory left to keep event %d",evID) ; 309 310 factOut(kError,882, str ) ; … … 349 350 mBuffer[i].evtLen = needmem ; 350 351 351 gi_usedMem += needmem + headmem; 352 gj.usdMem += needmem + headmem; 353 if (gj.usdMem > gj.maxMem ) gj.maxMem = gj.usdMem ; 352 354 353 355 //register event in 'active list (reading)' … … 357 359 evtCtrl.pcTime[ evtCtrl.lastPtr] = g_actTime ; 358 360 evtIdx[i] = evtCtrl.lastPtr ; 361 362 gj.readEvt++ ; //#events read 363 gj.evtBuf++ ; 364 365 359 366 snprintf(str,MXSTR,"%5d start new evt %8d %8d %2d",evID,i,evtCtrl.lastPtr,0); 360 367 factOut(kDebug,-11, str ) ; … … 363 370 364 371 365 366 367 gi_EvtStart++ ; 372 gi.evtGet++ ; 368 373 369 374 //check if runId already registered in runCtrl … … 379 384 } else { 380 385 runCtrl[evFree].runId = runID ; 386 runCtrl[evFree].fileId = -2 ; 387 runCtrl[evFree].nextEvt= 0; 388 runCtrl[evFree].actEvt = 0; 389 runCtrl[evFree].maxEvt = 999999999 ; //max number events allowed 390 runCtrl[evFree].lastTime=g_actTime ; 391 runCtrl[evFree].closeTime=g_actTime + 3600*24 ; //max time allowed 392 runCtrl[evFree].lastTime = 0 ; 393 394 runTail[evFree].nEventsOk = 395 runTail[evFree].nEventsRej = 396 runTail[evFree].nEventsBad = 397 runTail[evFree].PCtime0 = 398 runTail[evFree].PCtimeX = 0 ; 381 399 } 382 400 … … 384 402 385 403 } /*-----------------------------------------------------------------*/ 404 405 386 406 387 407 … … 405 425 mBuffer[i].evNum = mBuffer[i].runNum = mBuffer[i].nRoi= -1; 406 426 407 g i_usedMem = gi_usedMem - freemem - headmem;408 427 gj.usdMem = gj.usdMem - freemem - headmem; 428 gj.evtBuf-- ; 409 429 410 430 return 0 ; … … 413 433 414 434 415 /*-----------------------------------------------------------------*/ 435 void resetEvtStat() { 436 int i ; 437 438 for (i=0; i<MAX_SOCK; i++) gi.numRead[i] = 0 ; 439 440 for (i=0; i<NBOARDS; i++ ) { 441 gi.gotByte[i] = 0 ; 442 gi.gotErr[i] = 0 ; 443 } 444 445 gi.evtGet = 0 ; //#new Start of Events read 446 gi.evtTot = 0 ; //#complete Events read 447 gi.evtErr = 0 ; //#Events with Errors 448 gi.evtSkp = 0 ; //#Events incomplete (timeout) 449 450 gi.procTot = 0 ; //#Events processed 451 gi.procErr = 0 ; //#Events showed problem in processing 452 gi.procTrg = 0 ; //#Events accepted by SW trigger 453 gi.procSkp = 0 ; //#Events rejected by SW trigger 454 455 gi.feedTot = 0 ; //#Events used for feedBack system 456 gi.feedErr = 0 ; //#Events rejected by feedBack 457 458 gi.wrtTot = 0 ; //#Events written to disk 459 gi.wrtErr = 0 ; //#Events with write-error 460 461 gi.runOpen = 0 ; //#Runs opened 462 gi.runClose= 0 ; //#Runs closed 463 gi.runErr = 0 ; //#Runs with open/close errors 464 465 return ; 466 } /*-----------------------------------------------------------------*/ 416 467 417 468 … … 428 479 int actBoards = 0, minLen ; 429 480 int32_t jrd ; 430 int 32_t myRun;481 int64_t stat[9] ; 431 482 int boardId, roi,drs,px,src,pixS,pixH,pixC,pixR,tmS ; 432 483 uint qtot = 0, qread = 0, qconn = 0 ; 484 485 int goodhed = 0 ; 433 486 int errcnt0 = 0 ; 434 487 435 int goodhed=0;436 437 488 struct timespec xwait ; 438 489 439 int nokCnt[MAX_SOCK],loopCnt=0;440 int sokCnt[MAX_SOCK];441 int sockDef[NBOARDS];442 490 443 491 struct timeval *tv, atv; … … 470 518 rd[i].sockStat = 99 ; 471 519 } 520 521 int sockDef[NBOARDS]; //internal state of sockets 472 522 for (i=0; i<NBOARDS; i++) sockDef[i]= 0 ; 473 523 474 524 475 g_actTime = time(NULL) ;476 for (k=0; k<MAX_SOCK; k++)477 gi_SecRate[k]=gi_S10Rate[k]=gi_MinRate[k]=gi_ErrCnt[k]= 0 ;478 479 for (k=0; k<NBOARDS; k++) 525 resetEvtStat(); 526 gj.usdMem = gj.maxMem = 0 ; 527 gj.evtBuf = 0 ; 528 529 for (k=0; k<NBOARDS; k++) { 480 530 gi_NumConnect[k]=0; 481 482 483 gi_SecTime= gi_S10Time= gi_MinTime= g_actTime ; 531 gi.numConn[k] =0; 532 } 533 534 535 uint gi_SecTime ; //time in seconds 536 gi_SecTime= g_actTime ; 484 537 485 538 mBufInit() ; //initialize buffers … … 489 542 490 543 491 for (k=0; k<MAX_SOCK; k++) sokCnt[k]=nokCnt[k]=0 ;492 544 493 545 head_len = sizeof(PEVNT_HEADER) ; … … 503 555 stop.S= 0x04FE; 504 556 505 myRun = g_actTime ; 506 557 gi_myRun = g_actTime ; 507 558 gi_runStat = g_runStat ; 559 gj.readStat= g_runStat ; 508 560 509 561 510 562 while (g_runStat >=0) { //loop until global variable g_runStat claims stop 511 563 512 gi_runStat = g_runStat ; 564 gi_runStat = g_runStat; 565 gj.readStat= g_runStat; 566 gj.totMem = g_maxMem ; 567 // if (gi.totMem < 50000000 ) gi.totMem = 500000000 ; 513 568 514 569 int b,p,p0,s0,nch; … … 519 574 nch++ ; 520 575 gi_NumConnect[ b ] = 0 ; //must close all connections 576 gi.numConn[ b ] = 0; 521 577 if ( sockDef[b] == 0) s0= 0 ; //sockets to be defined and opened 522 578 else if (g_port[b].sockDef == 0) s0=-1 ; //sockets to be destroyed … … 542 598 543 599 544 g_actTime = time(NULL) ; 545 nokCnt[numok]++; 546 547 loopCnt++ ; 600 548 601 549 602 numok = 0 ; //count number of succesfull actions … … 555 608 556 609 gettimeofday( tv, NULL); 557 tsec = atv.tv_sec ;610 g_actTime = tsec = atv.tv_sec ; 558 611 tusec= atv.tv_usec ; 559 612 … … 572 625 rd[i].skip = 0 ; // start empty 573 626 gi_NumConnect[ b ]++ ; 574 numok++ ; //make sure next round will execute575 snprintf(str,MXSTR,"+++connect %d %d",b,gi _NumConnect[ b ]);627 gi.numConn[ b ]++ ; 628 snprintf(str,MXSTR,"+++connect %d %d",b,gi.numConn[ b ]); 576 629 factOut(kInfo,-1, str ) ; 577 630 } … … 581 634 if (rd[i].bufLen > 0) { //might be nothing to read [buffer full] 582 635 numok++ ; 583 sokCnt[i]++;584 636 jrd=recv(rd[i].socket,&rd[i].rBuf->B[ rd[i].bufPos], rd[i].bufLen, MSG_DONTWAIT); 585 637 … … 593 645 factOut(kInfo,441, str ) ; 594 646 GenSock(s0, i, 0,NULL, &rd[i]) ; 595 gi _ErrCnt[i]++ ;647 gi.gotErr[ b ]++ ; 596 648 gi_NumConnect[ b ]-- ; 649 gi.numConn[ b ]-- ; 597 650 598 651 } else if ( jrd<0 ) { //did not read anything … … 600 653 snprintf(str,MXSTR,"Error Reading from %d | %m",i); 601 654 factOut(kError,442, str ) ; 602 gi _ErrCnt[i]++ ;655 gi.gotErr[ b ]++ ; 603 656 } else numok-- ; //else nothing waiting to be read 604 657 jrd = 0 ; 605 658 } 606 659 } else jrd = 0 ; //did read nothing as requested 660 661 gi.gotByte[ b ] += jrd ; 607 662 608 663 if ( rd[i].bufTyp <0 ) { // we are skipping this board ... … … 619 674 if ( rd[i].rBuf->B[ rd[i].bufPos-1] != stop.B[0] 620 675 && rd[i].rBuf->B[ rd[i].bufPos ] != stop.B[1]) { 621 gi _ErrCnt[i]++ ;676 gi.evtErr++ ; 622 677 snprintf(str,MXSTR,"wrong end of buffer found %d",rd[i].bufPos); 623 678 factOut(kError,301, str ) ; … … 628 683 629 684 //we have a complete buffer, copy to WORK area 630 gi_SecRate[i]++ ;631 632 685 roi = ntohs(rd[i].rBuf->S[ head_len/2 + 2 ]) ; 633 686 //get index into mBuffer for this event (create if needed) … … 651 704 snprintf(str,MXSTR,"wrong Board ID %d %d %d",fadCrate,fadBoard%256,boardId) ; 652 705 if (errcnt0++ < 99 ) factOut(kWarn,301, str ) ; //print only few times 653 // } else {654 // snprintf(str,MXSTR,"correct Board ID %d %d %d",fadCrate,fadBoard%256,boardId) ;655 // if (errcnt0++ < 99 ) factOut(kWarn,301, str ) ; //print only few times656 706 } 657 707 if ( mBuffer[evID].board[ boardId ] != -1) { … … 703 753 } else { 704 754 snprintf(str,MXSTR,"wrong roi %d %d %d %d",px,pixR,roi,src-2); 755 gi.evtErr++ ; 705 756 factOut(kError,202, str ) ; 706 757 goto EndBuf ; … … 708 759 } 709 760 }// now we have stored a new board contents into Event structure 761 710 762 mBuffer[evID].board[ boardId ] = boardId ; 711 763 evtCtrl.evtStat[ iDx ]++ ; … … 717 769 //complete event read ---> flag for next processing 718 770 evtCtrl.evtStat[ iDx ] = 99; 719 gi_EvtRead++ ; 720 gi_EvtTot++ ; 771 gi.evtTot++ ; 721 772 } 722 773 … … 763 814 rd[i].ftmID = ntohl(rd[i].rBuf->I[5]) ; //(FTMevt) 764 815 rd[i].runID = ntohl(rd[i].rBuf->I[11]) ; 765 if (rd[i].runID ==0 ) rd[i].runID = myRun ;816 if (rd[i].runID ==0 ) rd[i].runID = gi_myRun ; 766 817 rd[i].bufTyp = 1 ; //ready to read full record 767 818 rd[i].bufLen = rd[i].fadLen - rd[i].bufPos ; 768 819 if (rd[i].bufLen <=0 ) rd[i].bufLen = 100000 ; //? 769 debugHead(i,rd[i].rBuf); 820 int fadBoard = ntohs(rd[i].rBuf->S[12] ) ; 821 debugHead(i,fadBoard,rd[i].rBuf); 770 822 debugRead(i,jrd,rd[i].evtID,rd[i].ftmID,rd[i].runID,-1,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid;-1=start event 771 823 } else { … … 780 832 } //finished trying to read all sockets 781 833 834 gi.numRead[ numok ] ++ ; 835 782 836 int qwait=0, qdel=0, qskip=0 ; 783 837 g_actTime = time(NULL) ; … … 806 860 factOut(kWarn,601, str ) ; 807 861 evtCtrl.evtStat[k0] = 91 ; //timeout for incomplete events 808 gi_EvtBad++ ; 809 gi_EvtTot++ ; 862 gi.evtSkp++ ; 863 gi.evtTot++ ; 864 gj.skipEvt++; 810 865 qskip++; 811 866 } … … 831 886 int ib ; 832 887 for (ib=0; ib<NBOARDS; ib++) qconn+=gi_NumConnect[ib] ; 833 int64_t stat[9] ;834 888 stat[0]= qwait; 835 889 stat[1]= qskip; 836 890 stat[2]= qdel ; 837 891 stat[3]= qtot ; 838 stat[4]= g i_usedMem ;892 stat[4]= gj.usdMem ; 839 893 stat[5]= qread; 840 894 stat[6]= qconn; 841 895 842 factStat(stat,7);843 896 qread=0 ; 897 gj.deltaT = 1000 ; //temporary, must be improved 898 899 factStat(gj); 900 factStatNew(gi) ; 901 902 gj.readEvt = gj.procEvt = gj.writEvt = gj.skipEvt = 0 ; 844 903 } 845 904 … … 876 935 && evtCtrl.evtStat[k0] < 90 ) { 877 936 evtCtrl.evtStat[k0] = 91 ; 878 gi _EvtBad++ ;879 gi _EvtTot++ ;937 gi.evtSkp++ ; 938 gi.evtTot++ ; 880 939 } 881 940 } … … 885 944 factOut(kInfo,-1, str ) ; 886 945 for (i=0; i<MAX_SOCK; i++) { 887 GenSock(-1, i, 0, NULL, &rd[i]) ; //close and destroy socket 888 if (gi_NumConnect[ i/7 ]>0) 889 gi_NumConnect[ i/7 ]-- ; 946 if (rd[i].sockStat ==0 ) { 947 GenSock(-1, i, 0, NULL, &rd[i]) ; //close and destroy socket 948 gi_NumConnect[ i/7 ]-- ; 949 gi.numConn[ i/7 ]-- ; 950 } 890 951 } 891 952 … … 894 955 nanosleep( &xwait , NULL ) ; 895 956 gi_runStat = -11 ; //inform all that no update to happen any more 957 gj.readStat= -11 ; //inform all that no update to happen any more 896 958 897 959 … … 930 992 factOut(kInfo,-1, str ) ; 931 993 gi_runStat = -99 ; 994 gj.readStat= -99 ; 995 factStat(gj); 996 factStatNew(gi) ; 932 997 return 0; 933 998 … … 1009 1074 1010 1075 int i=eventCheck(mBuffer[id].FADhead,mBuffer[id].fEvent) ; 1011 1012 if (i<0) evtCtrl.evtStat[k0] = 999 ; //flag event to be skipped 1013 1076 gj.procEvt++ ; 1077 gi.procTot++ ; 1014 1078 numProc++ ; 1015 1079 evtCtrl.evtStat[k0] = 520 ; 1016 gp_EvtTot++ ; 1080 1081 if (i<0) { 1082 evtCtrl.evtStat[k0] = 999 ; //flag event to be skipped 1083 gi.procErr++ ; 1084 } 1017 1085 } else if ( evtCtrl.evtStat[k0] >=0 && evtCtrl.evtStat[k0] < 90 ) { 1018 1086 numWait++ ; … … 1020 1088 } 1021 1089 1022 if ( g i_runStat < -10 && numWait == 0) { //nothing left to do1090 if ( gj.readStat < -10 && numWait == 0) { //nothing left to do 1023 1091 snprintf(str,MXSTR,"Exit Processing Process ..."); 1024 1092 factOut(kInfo,-1, str ) ; 1025 1093 gp_runStat = -22 ; //==> we should exit 1094 gj.procStat= -22 ; //==> we should exit 1026 1095 return 0 ; 1027 1096 } … … 1034 1103 } 1035 1104 gp_runStat = gi_runStat ; 1105 gj.procStat= gj.readStat ; 1036 1106 1037 1107 } … … 1054 1124 1055 1125 gp_runStat = -99 ; 1126 gj.procStat= -99 ; 1056 1127 1057 1128 return 0; … … 1059 1130 } /*-----------------------------------------------------------------*/ 1060 1131 1061 int CloseRunFile(uint32_t runId, uint32_t closeTime ) {1132 int CloseRunFile(uint32_t runId, uint32_t closeTime, uint32_t maxEvt) { 1062 1133 /* close run runId (all all runs if runId=0) */ 1063 1134 /* return: 0=close scheduled / >0 already closed / <0 does not exist */ 1064 int i, j ; 1065 1066 if (runId == 0 ) { 1135 int j ; 1136 1137 1138 if ( runId == 0 ) { 1067 1139 for ( j=0; j<MAX_RUN; j++) { 1068 1140 if ( runCtrl[j].fileId == 0 ) { //run is open 1069 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) );1070 if (i<0) {1071 snprintf(str,MXSTR,"error closing run %d %d",runCtrl[j].runId,i) ;1072 factOut(kError,506, str ) ;1073 runCtrl[j].fileId = 888 ;1074 } else {1075 snprintf(str,MXSTR,"closing run %d ok AAA",runCtrl[j].runId);1076 factOut(kInfo,507, str ) ;1077 runCtrl[j].fileId = 7777 ;1078 }1079 1141 runCtrl[j].closeTime = closeTime ; 1142 runCtrl[j].maxEvt = maxEvt ; 1080 1143 } 1081 1144 } 1082 return 0 ; 1083 } 1084 1145 return 0; 1146 } 1085 1147 1086 1148 for ( j=0; j<MAX_RUN; j++) { 1087 1149 if ( runCtrl[j].runId == runId ) { 1088 1150 if ( runCtrl[j].fileId == 0 ) { //run is open 1089 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) );1090 if (i<0) {1091 snprintf(str,MXSTR,"error closing run %d %d",runCtrl[j].runId,i) ;1092 factOut(kError,506, str ) ;1093 runCtrl[j].fileId = 888 ;1094 } else {1095 snprintf(str,MXSTR,"closing run %d ok AAA",runCtrl[j].runId);1096 factOut(kInfo,507, str ) ;1097 runCtrl[j].fileId = 7777 ;1098 }1099 1151 runCtrl[j].closeTime = closeTime ; 1152 runCtrl[j].maxEvt = maxEvt ; 1100 1153 return 0; 1101 1154 } else if ( runCtrl[j].fileId <0 ) { //run not yet opened 1102 1155 runCtrl[j].closeTime = closeTime ; 1156 runCtrl[j].maxEvt = maxEvt ; 1103 1157 return +1; 1104 1158 } else { // run already closed … … 1116 1170 1117 1171 int numWrite, numWait ; 1118 int k,j ;1172 int k,j,i ; 1119 1173 struct timespec xwait ; 1120 1174 char str[MXSTR] ; … … 1152 1206 int ievt = mBuffer[id].evNum ; 1153 1207 1208 gi.wrtTot++ ; 1154 1209 if (runCtrl[lastRun].runId == irun ) { 1155 1210 j = lastRun ; … … 1162 1217 snprintf(str,MXSTR,"W error: can not find run %d for event %d in %d", irun,ievt,id); 1163 1218 factOut(kFatal,901, str ) ; 1219 gi.wrtErr++ ; 1164 1220 for ( j=0; j<MAX_RUN; j++) printf("j %d run.j %d run %d\n",j,runCtrl[j].runId,irun ); 1165 1221 exit(111); … … 1176 1232 actRun.Nroi = mBuffer[id].nRoi ; 1177 1233 // actRun.FADhead = mBuffer[id].FADhead ; //to be corrected 1178 runCtrl[j].nextEvt= 0; 1179 runCtrl[j].lastTime=g_actTime ; 1234 1180 1235 runCtrl[j].fileHd = runOpen(irun, &actRun, sizeof(actRun) ) ; 1181 1236 if (runCtrl[j].fileHd == NULL ) { … … 1191 1246 } 1192 1247 1193 if (runCtrl[j].fileId >0 ) {1248 if (runCtrl[j].fileId != 0 ) { 1194 1249 snprintf(str,MXSTR,"W no open file for this run %d",irun) ; 1195 factOut(k Debug,123,str) ;1250 factOut(kWarn,123,str) ; 1196 1251 evtCtrl.evtStat[k0] = 902 ; 1252 gi.wrtErr++ ; 1197 1253 } else { 1198 int i=runWrite(runCtrl[j].fileHd, mBuffer[id].fEvent, sizeof(mBuffer[id]) ); 1199 if (i<0) { 1254 i=runWrite(runCtrl[j].fileHd, mBuffer[id].fEvent, sizeof(mBuffer[id]) ); 1255 if ( i>=0 ) { 1256 runCtrl[j].lastTime = g_actTime; 1257 runCtrl[j].actEvt++ ; 1258 evtCtrl.evtStat[k0] = 901 ; 1259 snprintf(str,MXSTR,"%5d successfully wrote for run %d id %5d",ievt,irun,k0); 1260 factOut(kDebug,504, str ) ; 1261 gj.writEvt++ ; 1262 } else { 1200 1263 snprintf(str,MXSTR,"W error writing event for run %d",irun) ; 1201 1264 factOut(kError,503, str ) ; 1202 1265 evtCtrl.evtStat[k0] = 901 ; 1203 //close run 1266 gi.wrtErr++ ; 1267 } 1268 1269 if ( i < 0 1270 || runCtrl[j].closeTime < g_actTime 1271 || runCtrl[j].lastTime < g_actTime-300 1272 || runCtrl[j].maxEvt < runCtrl[j].actEvt ) { 1273 int ii =0 ; 1274 if ( i < 0 ) ii=1 ; 1275 else if (runCtrl[j].closeTime < g_actTime ) ii=2 ; 1276 else if (runCtrl[j].lastTime < g_actTime-300 ) ii=3 ; 1277 else if (runCtrl[j].maxEvt < runCtrl[j].actEvt ) ii=4 ; 1278 1279 1280 1281 //close run for whatever reason 1282 if (runCtrl[j].runId == gi_myRun) gi_myRun = g_actTime ; 1204 1283 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1205 1284 if (i<0) { 1206 snprintf(str,MXSTR," W error closing run %d",irun) ;1285 snprintf(str,MXSTR,"error closing run %d %d AAA",runCtrl[j].runId,i) ; 1207 1286 factOut(kError,503, str ) ; 1287 runCtrl[j].fileId = 9001 ; 1208 1288 } else { 1209 snprintf(str,MXSTR,"W closed run %d because of write error",irun) ;1289 snprintf(str,MXSTR,"W closed run %d AAA %d",irun,ii) ; 1210 1290 factOut(kInfo,503, str ) ; 1291 runCtrl[j].fileId = 901 ; 1211 1292 } 1212 runCtrl[j].fileId = 9999 ;1213 } else {1214 runCtrl[j].lastTime = g_actTime;1215 evtCtrl.evtStat[k0] = 901 ;1216 snprintf(str,MXSTR,"%5d successfully wrote for run %d id %5d",ievt,irun,k0);1217 factOut(kDebug,504, str ) ;1218 1293 } 1219 1294 } … … 1221 1296 } 1222 1297 1223 //check if we should close a run ...1298 //check if we should close a run (mainly when no event pending) 1224 1299 for ( j=0; j<MAX_RUN; j++) { 1225 1300 if ( runCtrl[j].fileId==0 1226 1301 && ( runCtrl[j].closeTime < g_actTime 1227 ||runCtrl[j].lastTime < g_actTime-120) ) { 1228 int i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1302 ||runCtrl[j].lastTime < g_actTime-300 1303 ||runCtrl[j].maxEvt < runCtrl[j].actEvt ) ) { 1304 if (runCtrl[j].runId == gi_myRun) gi_myRun = g_actTime ; 1305 int ii =0 ; 1306 if ( i < 0 ) ii=1 ; 1307 else if (runCtrl[j].closeTime < g_actTime ) ii=2 ; 1308 else if (runCtrl[j].lastTime < g_actTime-300 ) ii=3 ; 1309 else if (runCtrl[j].maxEvt < runCtrl[j].actEvt ) ii=4 ; 1310 1311 1312 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1229 1313 if (i<0) { 1230 snprintf(str,MXSTR,"error closing run %d %d ",runCtrl[j].runId,i) ;1314 snprintf(str,MXSTR,"error closing run %d %d BBB",runCtrl[j].runId,i) ; 1231 1315 factOut(kError,506, str ) ; 1232 runCtrl[j].fileId = 888;1316 runCtrl[j].fileId = 9011 ; 1233 1317 } else { 1234 snprintf(str,MXSTR," closing run %d ok BBB",runCtrl[j].runId);1318 snprintf(str,MXSTR,"W closed run %d BBB %d",runCtrl[j].runId,ii) ; 1235 1319 factOut(kInfo,507, str ) ; 1236 runCtrl[j].fileId = 7777;1320 runCtrl[j].fileId = 911 ; 1237 1321 } 1238 1322 } … … 1246 1330 } 1247 1331 1248 if ( g i_runStat < -10 && numWait == 0) { //nothing left to do1332 if ( gj.readStat < -10 && numWait == 0) { //nothing left to do 1249 1333 snprintf(str,MXSTR,"Finish Write Process ..."); 1250 1334 factOut(kInfo,-1, str ) ; 1251 1335 gw_runStat = -22 ; //==> we should exit 1336 gj.writStat= -22 ; //==> we should exit 1252 1337 goto closerun ; 1253 1338 } 1254 1339 gw_runStat = gi_runStat ; 1340 gj.writStat= gj.readStat ; 1255 1341 1256 1342 } … … 1264 1350 for ( j=0; j<MAX_RUN; j++) 1265 1351 if ( runCtrl[j].fileId ==0 ) { 1266 int i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1352 if (runCtrl[j].runId == gi_myRun) gi_myRun = g_actTime ; 1353 i=runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]) ); 1354 int ii =0 ; 1355 if ( i < 0 ) ii=1 ; 1356 else if (runCtrl[j].closeTime < g_actTime ) ii=2 ; 1357 else if (runCtrl[j].lastTime < g_actTime-300 ) ii=3 ; 1358 else if (runCtrl[j].maxEvt < runCtrl[j].actEvt ) ii=4 ; 1267 1359 if (i<0) { 1268 snprintf(str,MXSTR,"error closing run %d %d ",runCtrl[j].runId,i) ;1360 snprintf(str,MXSTR,"error closing run %d %d CCC",runCtrl[j].runId,i) ; 1269 1361 factOut(kError,506, str ) ; 1270 runCtrl[j].fileId = 888;1362 runCtrl[j].fileId = 9021 ; 1271 1363 } else { 1272 snprintf(str,MXSTR," closing run %d ok AAA",runCtrl[j].runId);1364 snprintf(str,MXSTR,"W closed run %d CCC %d",runCtrl[j].runId,ii) ; 1273 1365 factOut(kInfo,507, str ) ; 1274 runCtrl[j].fileId = 7777;1366 runCtrl[j].fileId = 921 ; 1275 1367 } 1276 1368 } 1277 1369 1278 1370 gw_runStat = -99; 1371 gj.writStat= -99; 1279 1372 snprintf(str,MXSTR,"Exit Writing Process ..."); 1280 1373 factOut(kInfo,-1, str ) ; … … 1297 1390 1298 1391 gi_runStat = gp_runStat = gw_runStat = 0 ; 1392 gj.readStat= gj.procStat= gj.writStat= 0 ; 1393 1299 1394 1300 1395 snprintf(str,MXSTR,"Starting EventBuilder"); … … 1309 1404 for (i=0; i<MAX_RUN; i++) { 1310 1405 runCtrl[i].runId = 0 ; 1311 runCtrl[i].lastTime = 0 ;1312 runCtrl[i].closeTime = time(NULL) + 3600*24*7;1313 1314 runCtrl[i].nextEvt = 0 ;1315 1406 runCtrl[i].fileId = -2 ; 1316 1317 runTail[i].nEventsOk = 1318 runTail[i].nEventsRej=1319 runTail[i].nEventsBad=1320 runTail[i].PCtime0=1321 runTail[i].PCtimeX = 0 ;1322 }1407 } 1408 1409 gj.evtBuf = 1410 gj.readEvt = 1411 gj.procEvt = 1412 gj.writEvt = 1413 gj.skipEvt = 0 ; 1323 1414 1324 1415 //start all threads (more to come) when we are allowed to .... … … 1338 1429 imax=i ; 1339 1430 1340 1341 1342 1343 1344 /* 1431 #ifdef BILAND 1345 1432 xwait.tv_sec = 20;; 1346 1433 xwait.tv_nsec= 0 ; // sleep for ~20sec 1347 1434 nanosleep( &xwait , NULL ) ; 1348 1435 1349 1350 1436 printf("close all runs in 2 seconds\n"); 1351 1437 1352 1353 CloseRunFile( 0, time(NULL)+2) ; 1438 CloseRunFile( 0, time(NULL)+2, 0) ; 1354 1439 1355 1440 xwait.tv_sec = 5;; … … 1360 1445 1361 1446 g_runStat = -1 ; 1362 */ 1363 1364 1365 1366 1367 1368 1369 1370 1371 1447 #endif 1372 1448 1373 1449 … … 1378 1454 1379 1455 } /*-----------------------------------------------------------------*/ 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1380 1466 1381 1467 … … 1388 1474 /*-----------------------------------------------------------------*/ 1389 1475 /*-----------------------------------------------------------------*/ 1476 1477 1478 #ifdef BILAND 1479 1480 1390 1481 /*-----------------------------------------------------------------*/ 1391 1482 /*-----------------------------------------------------------------*/ … … 1395 1486 1396 1487 1397 /* 1488 1398 1489 1399 1490 FileHandle_t runOpen(uint32_t irun, RUN_HEAD *runhd, size_t len ) … … 1420 1511 1421 1512 1422 void factStat(int64_t *array, int len ) { 1423 printf("stat: bfr%5lu skp%4lu free%4lu (tot%7lu) mem%12lu rd%12lu %3lu\n", 1424 array[0],array[1],array[2],array[3],array[4],array[5],array[6]); 1513 void factStatNew(EVT_STAT gi) { 1514 int i ; 1515 1516 for (i=0;i<MAX_SOCK;i++) { 1517 printf("%4d",gi.numRead[i]); 1518 if (i%20 == 0 ) printf("\n"); 1519 } 1520 } 1521 1522 1523 void factStat(GUI_STAT gj) { 1524 // printf("stat: bfr%5lu skp%4lu free%4lu (tot%7lu) mem%12lu rd%12lu %3lu\n", 1525 // array[0],array[1],array[2],array[3],array[4],array[5],array[6]); 1425 1526 } 1426 1527 … … 1435 1536 } 1436 1537 1437 void debugHead(int i, void *buf) {1538 void debugHead(int i, int j, void *buf) { 1438 1539 } 1439 1540 … … 1485 1586 //} 1486 1587 // 1487 //version for PC-test 1588 //version for PC-test * 1488 1589 for (c=0; c<4; c++) { 1489 1590 for (b=0; b<10; b++) { … … 1513 1614 1514 1615 } 1515 */ 1616 #endif
Note:
See TracChangeset
for help on using the changeset viewer.