Changeset 15510
- Timestamp:
- 05/06/13 19:01:18 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r15495 r15510 126 126 // We will return this amount of memory 127 127 tgb_inuse += MAX_TOT_MEM; 128 gj.bufTot++; 128 129 129 130 // No free slot available, allocate a new one … … 147 148 void TGB_free(void *mem) 148 149 { 150 if (!mem) 151 return; 152 149 153 // Add the last free slot to the stack 150 154 TGB_entry *entry = (TGB_entry*)malloc(sizeof(TGB_entry)); … … 565 569 566 570 567 int 568 mBufFree (int i) 569 { 570 TGB_free(evtCtrl[i].FADhead); 571 572 evtCtrl[i].fEvent = NULL; 573 evtCtrl[i].FADhead = NULL; 574 575 evtCtrl[i].evNum = evtCtrl[i].nRoi = -1; 576 evtCtrl[i].runNum = 0; 577 578 gj.usdMem = tgb_inuse; 579 580 gj.bufTot--; 581 582 return 0; 583 584 } /*-----------------------------------------------------------------*/ 571 void mBufFree (int i) 572 { 573 TGB_free(evtCtrl[i].FADhead); 574 575 evtCtrl[i].fEvent = NULL; 576 evtCtrl[i].FADhead = NULL; 577 578 evtCtrl[i].evNum = evtCtrl[i].nRoi = -1; 579 evtCtrl[i].runNum = 0; 580 581 gj.usdMem = tgb_inuse; 582 583 gj.bufTot--; 584 } 585 585 586 586 uint64_t reportIncomplete(int id, const char *txt) … … 1025 1025 1026 1026 // We have a valid entry, but no memory has yet been allocated 1027 if (idx >= 0 && evtCtrl[idx]. FADhead ==NULL)1027 if (idx >= 0 && evtCtrl[idx].evtStat==0 && evtCtrl[idx].FADhead==NULL) 1028 1028 { 1029 1029 // Try to get memory from the big buffer … … 1033 1033 // If this works properly, this is a hack which can be removed, or 1034 1034 // replaced by a signal or dim message 1035 if (rd[i].bufTyp== 2)1036 factPrintf(kError, 882, " malloc failed for event%d (run=%d)", evtCtrl[idx].evNum, evtCtrl[idx].runNum);1035 if (rd[i].bufTyp==1) 1036 factPrintf(kError, 882, "No free memory left for %d (run=%d)", evtCtrl[idx].evNum, evtCtrl[idx].runNum); 1037 1037 rd[i].bufTyp = 2; 1038 1038 continue; … … 1049 1049 1050 1050 gj.rateNew++; 1051 gj.bufTot++;1052 1051 if (gj.bufTot > gj.maxEvt) 1053 1052 gj.maxEvt = gj.bufTot; … … 1062 1061 if (idx < -1000) 1063 1062 continue; 1063 1064 if (evtCtrl[idx].evtStat==-1 || evtCtrl[idx].evtStat>=90) 1065 { 1066 factPrintf(kError, 882, "Received data of event %d [%d] (run=%d) has already been advanced (stat=%d)... skipping", evtCtrl[idx].evNum, i, evtCtrl[idx].runNum, evtCtrl[idx].evtStat); 1067 continue; 1068 } 1064 1069 1065 1070 //we have a valid entry in mBuffer[]; fill it … … 1153 1158 // the user has expressed that the old events are obsolste now 1154 1159 // and the run will be closed anyway 1155 if (evtCtrl[k].evtStat> =0 && evtCtrl[k].evtStat<90)1160 if (evtCtrl[k].evtStat>0 && evtCtrl[k].evtStat<90) 1156 1161 { 1157 1162 reportIncomplete(k, "expired"); … … 1185 1190 { 1186 1191 // Check the more likely case first: incomplete events 1187 if (evtCtrl[k0].evtStat> =0 && evtCtrl[k0].evtStat<100)1192 if (evtCtrl[k0].evtStat>0 && evtCtrl[k0].evtStat<100) 1188 1193 { 1189 1194 gj.bufNew++; //incomplete event in Buffer … … 1201 1206 //timeout for incomplete events 1202 1207 evtCtrl[k0].evtStat = 90; 1208 1203 1209 gj.evtSkip++; 1204 1210 … … 1209 1215 // evtState==0 can happen if the event was initialized (some data received) 1210 1216 // but the data did not make sense (e.g. inconsistent rois) 1211 if (evtCtrl[k0].evtStat== 0 || evtCtrl[k0].evtStat ==10000)1217 if (evtCtrl[k0].evtStat==10000) 1212 1218 { 1219 evtCtrl[k0].evtStat = -1; 1213 1220 mBufFree(k0); //event written--> free memory 1214 evtCtrl[k0].evtStat = -1;1215 1221 1216 1222 gj.evtWrite++; … … 1308 1314 // signals that the event can be deleted. (Note, that there are currently never 1309 1315 // two threads processing the same event at the same time) 1310 if ( (evtCtrl[k0].evtStat>0 && evtCtrl[k0].evtStat<90)|| evtCtrl[k0].evtStat==10000)1316 if (evtCtrl[k0].evtStat<90 || evtCtrl[k0].evtStat==10000) 1311 1317 { 1318 evtCtrl[k0].evtStat = -1; 1312 1319 mBufFree(k0); //event written--> free memory 1313 1320 evtCtrl_frstPtr = (evtCtrl_frstPtr+1) % MAX_EVT; 1314 evtCtrl[k0].evtStat = -1;1315 1321 } 1316 1322 … … 1493 1499 factPrintf(kError, 502, "procEvt: Could not open new file for run %d (idx=%d, evt=%d, runOpen failed)", irun, idx, ievt); 1494 1500 runCtrl[idx].fileId = 91; 1501 // FIXME: What happens to evtStat? Shell we really just try again? 1495 1502 continue; 1496 1503 } … … 1599 1606 } 1600 1607 1601 void checkAndCloseRun(int j, int irun, intcond, int where)1608 void checkAndCloseRun(int j, int cond, int where) 1602 1609 { 1603 1610 if (!cond && … … 1630 1637 { 1631 1638 factPrintf(kInfo, 503, "writeEvt-%d: Closed run %d (reason=%d)", 1632 where, irun, ii);1639 where, runCtrl[j].runId, ii); 1633 1640 runCtrl[j].fileId = 93+where*2; 1634 1641 } … … 1673 1680 1674 1681 const uint32_t irun = evtCtrl[k0].runNum; 1675 const int32_t ievt = evtCtrl[k0].evNum;1676 1682 1677 1683 const int idx = evtCtrl[k0].runCtrl_idx; … … 1697 1703 factPrintf(kError, 503, "writeEvt: Writing event for run %d failed (runWrite)", irun); 1698 1704 1699 checkAndCloseRun(idx, irun,rc<0, 1);1705 checkAndCloseRun(idx, rc<0, 1); 1700 1706 } 1701 1707 … … 1710 1716 //ETIENNE added the condition at this line. dunno what to do with run 0: skipping it 1711 1717 const int cond = /*runCtrl[j].lastTime < lastStartedTime &&*/ runCtrl[j].runId == 0; 1712 checkAndCloseRun(j, runCtrl[j].runId,cond, 2);1718 checkAndCloseRun(j, cond, 2); 1713 1719 } 1714 1720 } … … 1731 1737 { 1732 1738 if (runCtrl[j].fileId == 0) 1733 checkAndCloseRun(j, runCtrl[j].runId,1, 3);1739 checkAndCloseRun(j, 1, 3); 1734 1740 } 1735 1741
Note:
See TracChangeset
for help on using the changeset viewer.