- Timestamp:
- 07/11/11 16:04:50 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r11335 r11343 60 60 int g_runStat ; 61 61 int g_reset ; 62 int gi_reset, gi_resetR, gi_resetS, gi_resetW, gi_resetX ; 62 63 size_t g_maxMem ; //maximum memory allowed for buffer 63 64 … … 76 77 int gi_memStat = +1 ; 77 78 78 int32_t gi_myRun ;79 uint32_t gi_myRun ; 79 80 80 81 … … 248 249 249 250 for (i=0; i<MAX_EVT*MAX_RUN; i++) { 250 mBuffer[i].evNum = mBuffer[i].runNum = -1; 251 mBuffer[i].evNum = mBuffer[i].nRoi = -1; 252 mBuffer[i].runNum= 0 ; 251 253 252 254 evtCtrl.evtBuf[ i] = -1 ; … … 268 270 269 271 270 int mBufEvt( uint evID, uint runID, uint nRoi) {272 int mBufEvt( int evID, uint runID, int nRoi) { 271 273 // generate a new Event into mBuffer: 272 274 // make sure only complete Event are possible, so 'free' will always work … … 278 280 size_t needmem = 0 ; 279 281 280 if (nRoi < =0 || nRoi > 1024) {282 if (nRoi <0 || nRoi > 1024) { 281 283 snprintf(str,MXSTR,"illegal nRoi: %d",nRoi) ; 282 284 factOut(kError, 1, str ) ; … … 419 421 size_t freemem = 0 ; 420 422 421 if ( mBuffer[i].nRoi > 0) { //have an fEvent structure generated ... 422 freemem = mBuffer[i].evtLen ; 423 free(mBuffer[i].fEvent ) ; 424 mBuffer[i].fEvent = NULL ; 425 426 free(mBuffer[i].FADhead ) ; 427 mBuffer[i].FADhead = NULL ; 428 429 } 423 freemem = mBuffer[i].evtLen ; 424 425 free(mBuffer[i].fEvent ) ; 426 mBuffer[i].fEvent = NULL ; 427 428 free(mBuffer[i].FADhead ) ; 429 mBuffer[i].FADhead = NULL ; 430 430 431 headmem = NBOARDS* sizeof(PEVNT_HEADER) ; 431 mBuffer[i].evNum = mBuffer[i].runNum = mBuffer[i].nRoi= -1; 432 mBuffer[i].evNum = mBuffer[i].nRoi= -1; 433 mBuffer[i].runNum = 0; 432 434 433 435 gj.usdMem = gj.usdMem - freemem - headmem; … … 495 497 int errcnt0 = 0 ; 496 498 497 int reset, resetR, resetS, resetW, resetX ;498 499 int sockDef[NBOARDS]; //internal state of sockets 499 500 … … 538 539 runCtrl[i].fileId = -2 ; 539 540 } 540 resetS =resetR = 9;541 541 gi_resetS = gi_resetR = 9; 542 for (i=0; i<NBOARDS; i++) sockDef[i]= 0 ; 542 543 543 544 START: … … 551 552 numok = numok2 = 0 ; 552 553 553 if ( resetS > 0) {554 if ( gi_resetS > 0) { 554 555 //make sure all sockets are preallocated as 'not exist' 555 556 for (i=0; i<MAX_SOCK; i++) { … … 557 558 rd[i].sockStat = 99 ; 558 559 } 559 560 for (i=0; i<NBOARDS; i++) sockDef[i]= 0 ;561 562 }563 564 565 if ( resetR > 0) {566 resetEvtStat();567 gj.usdMem = gj.maxMem = gj.xxxMem = 0 ;568 gj.totMem = g_maxMem ;569 gj.bufNew = gj.bufEvt = 0 ;570 gj.evtSkip= gj.evtWrite = gj.evtErr = 0 ;571 560 572 561 for (k=0; k<NBOARDS; k++) { … … 579 568 } 580 569 570 } 571 572 573 if ( gi_resetR > 0) { 574 resetEvtStat(); 575 gj.usdMem = gj.maxMem = gj.xxxMem = 0 ; 576 gj.totMem = g_maxMem ; 577 gj.bufNew = gj.bufEvt = 0 ; 578 gj.evtSkip= gj.evtWrite = gj.evtErr = 0 ; 579 580 581 581 mBufInit() ; //initialize buffers 582 582 … … 586 586 587 587 588 reset = resetR = resetS =resetW = 0 ;589 590 while (g_runStat >=0 ||g_reset ==0 ) { //loop until global variable g_runStat claims stop588 gi_reset = gi_resetR = gi_resetS = gi_resetW = 0 ; 589 590 while (g_runStat >=0 && g_reset ==0 ) { //loop until global variable g_runStat claims stop 591 591 592 592 gi_runStat = g_runStat; … … 893 893 gj.evtSkip++; 894 894 } 895 } else if (evtCtrl.evtStat[k0] >= 900 ) { 895 } else if (evtCtrl.evtStat[k0] >= 900 //'delete' 896 || evtCtrl.evtStat[k0] == 0 ) { //'useless' 896 897 897 898 int id =evtCtrl.evtBuf[k0] ; … … 945 946 946 947 if (g_reset >0 ) { 947 reset = g_reset ;948 resetR =reset%10 ; //shall we stop reading ?949 resetS = (reset/10)%10 ; //shall we close sockets ?950 resetW = (reset/100)%10 ; //shall we close files ?951 resetX =reset/1000 ; //shall we simply wait resetX seconds ?948 gi_reset = g_reset ; 949 gi_resetR = gi_reset%10 ; //shall we stop reading ? 950 gi_resetS = (gi_reset/10)%10 ; //shall we close sockets ? 951 gi_resetW = (gi_reset/100)%10 ; //shall we close files ? 952 gi_resetX = gi_reset/1000 ; //shall we simply wait resetX seconds ? 952 953 g_reset= 0; 953 954 } else { 954 reset = 0;955 if ( g_runStat==-1 ) resetR = 1 ;956 else resetR = 7 ;957 resetS = 7 ; //close all sockets958 resetW = 7 ; //close all files959 resetX = 0 ;955 gi_reset = 0; 956 if ( g_runStat==-1 ) gi_resetR = 1 ; 957 else gi_resetR = 7 ; 958 gi_resetS = 7 ; //close all sockets 959 gi_resetW = 7 ; //close all files 960 gi_resetX = 0 ; 960 961 961 962 //inform others we have to quit .... … … 964 965 } 965 966 966 if ( resetS > 0) {967 if (gi_resetS > 0) { 967 968 //must close all open sockets ... 968 969 snprintf(str,MXSTR,"close all sockets ..."); … … 979 980 980 981 981 if ( resetR > 0) {982 if (gi_resetR > 0) { 982 983 //flag all events as 'read finished' 983 984 int kd = evtCtrl.lastPtr - evtCtrl.frstPtr ; … … 1001 1002 //and clear all buffers (might have to wait until all others are done) 1002 1003 int minclear ; 1003 if ( resetR == 1) {1004 if (gi_resetR == 1) { 1004 1005 minclear = 900 ; 1005 1006 snprintf(str,MXSTR,"drain all buffers ..."); … … 1035 1036 } 1036 1037 1037 if ( reset > 0) {1038 if ( resetW > 0) {1038 if (gi_reset > 0) { 1039 if (gi_resetW > 0) { 1039 1040 CloseRunFile(0,0,0) ; //ask all Runs to be closed 1040 1041 } 1041 if ( resetX > 0) {1042 xwait.tv_sec = resetX;1042 if (gi_resetX > 0) { 1043 xwait.tv_sec = gi_resetX; 1043 1044 xwait.tv_nsec= 0 ; 1044 1045 nanosleep( &xwait , NULL ) ; … … 1047 1048 snprintf(str,MXSTR,"Continue read Process ..."); 1048 1049 factOut(kInfo,-1, str ) ; 1049 reset = 0 ;1050 gi_reset = 0 ; 1050 1051 goto START ; 1051 1052 } … … 1099 1100 //would be better to use bitmaps for evtStat (allow '&' instead of multi-if) 1100 1101 if (evtCtrl.evtStat[k0] > 90 && evtCtrl.evtStat[k0] <500) { 1102 1103 if ( gi_resetR > 1 ) { //we are asked to flush buffers asap 1104 evtCtrl.evtStat[k0] = 991 ; 1105 } else { 1106 1101 1107 int id = evtCtrl.evtBuf[k0] ; 1102 1108 int ievt = mBuffer[id].evNum ; … … 1141 1147 gi.procTot++ ; 1142 1148 numProc++ ; 1143 evtCtrl.evtStat[k0] = 520 ;1144 1149 1145 1150 if (i<0) { 1146 1151 evtCtrl.evtStat[k0] = 999 ; //flag event to be skipped 1147 1152 gi.procErr++ ; 1153 } else { 1154 evtCtrl.evtStat[k0] = 520 ; 1148 1155 } 1156 } 1149 1157 } else if ( evtCtrl.evtStat[k0] >=0 && evtCtrl.evtStat[k0] < 90 ) { 1150 1158 numWait++ ; … … 1266 1274 //would be better to use bitmaps for evtStat (allow '&' instead of multi-if) 1267 1275 if (evtCtrl.evtStat[k0] > 500 && evtCtrl.evtStat[k0] < 900) { 1276 1277 if ( gi_resetR > 1 ) { //we must drain the buffer asap 1278 evtCtrl.evtStat[k0] = 904 ; 1279 } else { 1280 1281 1268 1282 int id = evtCtrl.evtBuf[k0] ; 1269 1283 uint32_t irun = mBuffer[id].runNum ; … … 1313 1327 snprintf(str,MXSTR,"W no open file for this run %d",irun) ; 1314 1328 factOut(kWarn,123,str) ; 1315 evtCtrl.evtStat[k0] = 90 2;1329 evtCtrl.evtStat[k0] = 903 ; 1316 1330 gi.wrtErr++ ; 1317 1331 } else { … … 1327 1341 snprintf(str,MXSTR,"W error writing event for run %d",irun) ; 1328 1342 factOut(kError,503, str ) ; 1329 evtCtrl.evtStat[k0] = 90 1;1343 evtCtrl.evtStat[k0] = 902 ; 1330 1344 gi.wrtErr++ ; 1331 1345 } 1332 1346 1333 1347 if ( i < 0 1348 || runCtrl[j].lastTime < g_actTime-300 1334 1349 || runCtrl[j].closeTime < g_actTime 1335 || runCtrl[j].lastTime < g_actTime-3001336 1350 || runCtrl[j].maxEvt < runCtrl[j].actEvt ) { 1337 1351 int ii =0 ; … … 1357 1371 } 1358 1372 } 1359 } else if (evtCtrl.evtStat[k0] > 0 ) numWait++ ; 1373 } 1374 } else if (evtCtrl.evtStat[k0] > 0 1375 && evtCtrl.evtStat[k0] < 900 ) numWait++ ; 1360 1376 } 1361 1377 … … 1408 1424 snprintf(str,MXSTR,"Abort Writing Process ..."); 1409 1425 factOut(kInfo,-1, str ) ; 1426 1410 1427 closerun: 1411 1428 snprintf(str,MXSTR,"Close all open files ..."); … … 1456 1473 factOut(kInfo,-1, str ) ; 1457 1474 1475 /* initialize run control logics */ 1476 for (i=0; i<MAX_RUN; i++) { 1477 runCtrl[i].runId = 0 ; 1478 runCtrl[i].fileId = -2 ; 1479 } 1480 1481 /* partially initialize event control logics */ 1482 evtCtrl.frstPtr = 0 ; 1483 evtCtrl.lastPtr = 0 ; 1484 1458 1485 //start all threads (more to come) when we are allowed to .... 1459 1486 while (g_runStat == 0 ) { -
trunk/FACT++/src/FAD.h
r11333 r11343 199 199 200 200 typedef struct { 201 int32_tevNum ;201 int32_t evNum ; 202 202 uint32_t runNum ; 203 int32_t fadLen ;204 int32_t nBoard ;205 int16_t board[ NBOARDS ];206 int32_t nRoi ;203 int32_t fadLen ; 204 int32_t nBoard ; 205 int16_t board[ NBOARDS ]; 206 int32_t nRoi ; 207 207 uint32_t pcTime ; 208 int32_t evtLen ;209 EVENT *fEvent 208 int32_t evtLen ; 209 EVENT *fEvent ; 210 210 PEVNT_HEADER *FADhead; // 211 211 … … 232 232 //(TO BE REVISED) 233 233 234 int pcTime[MAX_EVT*MAX_RUN] ; //time when last action happened234 uint32_t pcTime[MAX_EVT*MAX_RUN] ; //time when last action happened 235 235 } EVT_CTRL ; //internal to eventbuilder 236 236
Note:
See TracChangeset
for help on using the changeset viewer.