Changeset 15459
- Timestamp:
- 04/30/13 10:47:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r15441 r15459 626 626 int found = 0; 627 627 628 // fileId==-2: not yet used or run assigned but not open 629 // fileId== 0: file open 630 // fileId>0: run closed 631 628 632 for (int k = 0; k < MAX_RUN; k++) 629 633 { 634 // Check if run already registered (old entries should have runId==-1) 630 635 if (runCtrl[k].runId == runID) 631 636 { 632 637 if (runCtrl[k].roi0 != nRoi[0] || runCtrl[k].roi8 != nRoi[8]) 633 638 { 634 factPrintf(kError, 931, "Mismatch of roi within run. Expected roi=%d and roi_tm=%d, got %d and %d .",635 runCtrl[k].roi0, runCtrl[k].roi8, nRoi[0], nRoi[8] );639 factPrintf(kError, 931, "Mismatch of roi within run. Expected roi=%d and roi_tm=%d, got %d and %d (runID=%d, evID=%d)", 640 runCtrl[k].roi0, runCtrl[k].roi8, nRoi[0], nRoi[8], runID, evID); 636 641 return -9301; 637 642 } … … 641 646 } 642 647 648 // This is just for sanity. We use the oldest free entry (until 649 // we have understood the concept and can use "just" a free entry 650 if (runCtrl[k].runId==0 && runCtrl[k].closeTime < oldest) 651 { 652 oldest = runCtrl[k].closeTime; 653 jold = k; 654 } 655 /* 656 // Empty slot already found? 643 657 if (evFree>=0) 644 658 continue; 645 646 //not yet used 659 */ 660 661 /* 662 if (runCtrl[k].fileId!=0) 663 { 664 evFree = k; 665 continue; 666 }*/ 667 668 /* 669 // Slot not yet used 647 670 if (runCtrl[k].fileId < 0) 648 671 { … … 651 674 } 652 675 653 // already closed676 // Slot already closed 654 677 if (runCtrl[k].fileId > 0 && runCtrl[k].closeTime < oldest) 655 678 { 656 679 oldest = runCtrl[k].closeTime; 657 680 jold = k; 658 } 681 }*/ 659 682 } 660 683 661 if (!found) 684 if (!found) // Run not yet registered, register run 662 685 { 663 686 if (evFree < 0 && jold < 0) … … 670 693 evFree = jold; 671 694 672 factPrintf(kInfo, 503, "New run %d (ev Free=%d) registered with roi=%d and roi_tm=%d", runID,673 evFree, nRoi[0], nRoi[8]);695 factPrintf(kInfo, 503, "New run %d (evID=%d, evFree=%d) registered with roi=%d and roi_tm=%d", 696 runID, evID, evFree, nRoi[0], nRoi[8]); 674 697 675 698 runCtrl[evFree].runId = runID; … … 678 701 runCtrl[evFree].fileId = -2; 679 702 runCtrl[evFree].procId = -2; 680 runCtrl[evFree].lastEvt = -1; 681 runCtrl[evFree].nextEvt = 0; 682 runCtrl[evFree].actEvt = 0; 683 runCtrl[evFree].procEvt = 0; 684 runCtrl[evFree].maxEvt = 999999999; //max number events allowed 703 runCtrl[evFree].lastEvt = 1; // Number of events partially started to read 704 runCtrl[evFree].actEvt = 0; // Number of written events (write) 705 runCtrl[evFree].procEvt = 0; // Number of successfully checked events (checkEvent) 706 runCtrl[evFree].maxEvt = 999999999; // max number events allowed 685 707 runCtrl[evFree].firstTime = tsec; 686 708 runCtrl[evFree].firstUsec = tusec; 687 runCtrl[evFree].lastTime = tsec; 709 runCtrl[evFree].lastTime = tsec; // Time when the last event was written 688 710 runCtrl[evFree].closeTime = tsec + 3600 * 24; //max time allowed 689 711 … … 695 717 } 696 718 697 // FIXME: Why is that done if FOUND?698 699 719 //flag all boards as unused 700 720 mBuffer[i].nBoard = 0; … … 702 722 mBuffer[i].board[k] = -1; 703 723 704 mBuffer[i].pcTime[0] 705 mBuffer[i].pcTime[1] 706 mBuffer[i].nRoi 707 mBuffer[i].nRoiTM 708 mBuffer[i].evNum 709 mBuffer[i].runNum 710 mBuffer[i].fadNum 711 mBuffer[i].trgNum 712 mBuffer[i].trgTyp 713 mBuffer[i].Errors[0] 714 mBuffer[i].Errors[1] 715 mBuffer[i].Errors[2] 716 mBuffer[i].Errors[3] 717 mBuffer[i].fEvent 718 mBuffer[i].buffer 719 mBuffer[i].FADhead 724 mBuffer[i].pcTime[0] = tsec; 725 mBuffer[i].pcTime[1] = tusec; 726 mBuffer[i].nRoi = nRoi[0]; 727 mBuffer[i].nRoiTM = nRoi[8]; 728 mBuffer[i].evNum = evID; 729 mBuffer[i].runNum = runID; 730 mBuffer[i].fadNum = fadNum; 731 mBuffer[i].trgNum = trgNum; 732 mBuffer[i].trgTyp = trgTyp; 733 mBuffer[i].Errors[0] = 0; 734 mBuffer[i].Errors[1] = 0; 735 mBuffer[i].Errors[2] = 0; 736 mBuffer[i].Errors[3] = 0; 737 mBuffer[i].fEvent = NULL; 738 mBuffer[i].buffer = NULL; 739 mBuffer[i].FADhead = NULL; 720 740 721 741 /* … … 1147 1167 /* initialize run control logics */ 1148 1168 for (int i = 0; i < MAX_RUN; i++) { 1149 runCtrl[i].runId =0;1169 runCtrl[i].runId = 0; 1150 1170 runCtrl[i].fileId = -2; 1151 1171 runCtrl[i].procId = -2; … … 1491 1511 const int iDx = evtIdx[evID]; //index into evtCtrl 1492 1512 1493 evtCtrl.evtStat[iDx]++;1513 //evtCtrl.evtStat[iDx]++; 1494 1514 evtCtrl.pcTime[iDx] = g_actTime; 1495 1515 … … 1499 1519 1500 1520 // have we already reported first (partial) event of this run ??? 1501 if (mBuffer[evID].nBoard >0&& mBuffer[evID].runNum != actrun)1521 if (mBuffer[evID].nBoard==1 && mBuffer[evID].runNum != actrun) 1502 1522 { 1523 // Signal the fadctrl that a new run has been started 1524 gotNewRun(mBuffer[evID].runNum, NULL); 1525 1526 factPrintf(kInfo, 1, "gotNewRun called, prev run %d, new run %d, event %d", 1527 actrun, mBuffer[evID].runNum, mBuffer[evID].evNum); 1528 1529 for (int j=0; j<MAX_RUN; j++) 1530 { 1531 // Since we have started a new run, we know already when to close the 1532 // previous run in terms of number of events 1533 if (runCtrl[j].runId==actrun) 1534 runCtrl[j].maxEvt = runCtrl[j].lastEvt; 1535 1536 // We got the first part of this event, so this is 1537 // the number of events we expect for this run 1538 if (runCtrl[j].runId==mBuffer[evID].runNum) 1539 runCtrl[j].lastEvt++; 1540 } 1541 1542 // Change 'actrun' the the new runnumber 1503 1543 actrun = mBuffer[evID].runNum; 1504 1505 for (int ir = 0; ir < MAX_RUN; ir++)1506 {1507 if (runCtrl[ir].runId == actrun)1508 {1509 if (++runCtrl[ir].lastEvt == 0)1510 {1511 gotNewRun (actrun, NULL);1512 factPrintf(kInfo, 1, "gotNewRun called for run %d, event %d",1513 mBuffer[evID].runNum, mBuffer[evID].evNum);1514 break;1515 }1516 }1517 }1518 1544 } 1519 1545 … … 1521 1547 if (mBuffer[evID].nBoard >= actBoards) 1522 1548 { 1549 // This is a non-ideal hack to lower the probability that 1550 // in mBufEvt the search for correct entry in runCtrl 1551 // will not return a super-old entry 1552 for (int ir=0; ir<MAX_RUN; ir++) 1553 { 1554 if (runCtrl[ir].runId != actrun && runCtrl[ir].fileId>0) 1555 runCtrl[ir].runId = 0; 1556 } 1557 1558 // Flag that the event is ready for processing 1523 1559 evtCtrl.evtStat[iDx] = 99; 1524 //gi.evtTot++;1525 1560 } 1526 1561 … … 1604 1639 rd[i].ftmID = rd[i].rBuf->I[3]; //(FTMevt) 1605 1640 rd[i].evtID = rd[i].rBuf->I[4]; //(FADevt) 1606 rd[i].runID = rd[i].rBuf->I[11] ;1641 rd[i].runID = rd[i].rBuf->I[11]==0 ? (int)g_actTime : rd[i].rBuf->I[11]; 1607 1642 rd[i].bufTyp = 1; //ready to read full record 1608 1643 rd[i].bufLen = rd[i].fadLen - rd[i].bufPos; 1609 1610 if (rd[i].runID == 0)1611 rd[i].runID = g_actTime;1612 1644 1613 1645 const int fadBoard = rd[i].rBuf->S[12]; … … 1655 1687 reportIncomplete(k0); 1656 1688 1657 evtCtrl.evtStat[k0] = 91; //timeout for incomplete events 1658 //gi.evtSkp++; 1659 //gi.evtTot++; 1689 //timeout for incomplete events 1690 evtCtrl.evtStat[k0] = 91; 1660 1691 gj.evtSkip++; 1661 1692 … … 1665 1696 // complete event in Buffer 1666 1697 if (evtCtrl.evtStat[k0] >= 95) 1667 gj.bufEvt++; 1698 gj.bufEvt++; 1668 1699 1669 1700 // Check the less likely case: 'useless' or 'delete' … … 1968 1999 } 1969 2000 1970 /*** if (evtCtrl.evtStat[k0] > 90 && evtCtrl.evtStat[k0] < 1000) ***/1971 1972 2001 //we are asked to flush buffers asap 1973 2002 if (gi_resetR > 1) 1974 { 2003 { 1975 2004 evtCtrl.evtStat[k0] = 9991; 1976 2005 continue; … … 1984 2013 const int32_t ievt = mBuffer[id].evNum; 1985 2014 1986 int j = lastRun; 2015 // Find entry in runCtrl which belongs to the event mBuffer[id] 2016 // (only check if there is a need to check) 1987 2017 if (runCtrl[lastRun].runId != irun) 1988 2018 { 1989 2019 //check which fileID to use (or open if needed) 1990 for (j = 0; j < MAX_RUN; j++) { 2020 int j; 2021 for (j=0;j<MAX_RUN; j++) 1991 2022 if (runCtrl[j].runId == irun) 1992 2023 break; 1993 } 1994 if (j >= MAX_RUN) { 1995 factPrintf(kFatal, 901, "procEvt: Can not find run %d for event %d in %d", irun, ievt, id); 1996 // FIXME: The event has to be flagged such that it will be deleted! Although that should never happen 2024 2025 if (j>=MAX_RUN) 2026 { 2027 factPrintf(kFatal, 901, "writeEvt: Can not find run %d for event %d in %d", irun, ievt, id); 2028 // FIXME: What is the right action? (Flag event for deletion?) 1997 2029 continue; 1998 2030 } 2031 1999 2032 lastRun = j; 2000 2033 } 2001 2034 2002 if (runCtrl[j].fileId < 0) 2035 // File not yet open 2036 if (runCtrl[lastRun].fileId < 0) 2003 2037 { 2004 2038 //---- we need to open a new run ==> make sure all older runs are 2005 2039 //---- finished and marked to be closed .... 2006 int j1; 2007 for (j1 = 0; j1 < MAX_RUN; j1++) { 2008 if (runCtrl[j1].fileId == 0) { 2009 runCtrl[j1].procId = 2; //--> do no longer accept events for processing 2040 // This loop is unique to procEvt 2041 for (int j=0; j<MAX_RUN; j++) 2042 { 2043 if (runCtrl[j].fileId == 0) 2044 { 2045 runCtrl[j].procId = 2; //--> do no longer accept events for processing 2046 2010 2047 //---- problem: processing still going on ==> must wait for closing .... 2011 factPrintf(kInfo, -1, "procEvt: Finished run since new one opened %d", runCtrl[j 1].runId);2012 runFinish1(runCtrl[j 1].runId);2048 factPrintf(kInfo, -1, "procEvt: Finished run since new one opened %d", runCtrl[j].runId); 2049 runFinish1(runCtrl[j].runId); 2013 2050 } 2014 2051 } … … 2017 2054 actRun.RunType = -1; //to be adapted 2018 2055 2019 actRun.Nroi = runCtrl[j].roi0;2020 actRun.NroiTM = runCtrl[ j].roi8;2056 actRun.Nroi = runCtrl[lastRun].roi0; 2057 actRun.NroiTM = runCtrl[lastRun].roi8; 2021 2058 //ETIENNE don't reset it to zero as it is taken care of in DataWriteFits 2022 2059 // if (actRun.Nroi == actRun.NroiTM) 2023 2060 // actRun.NroiTM = 0; 2024 actRun.RunTime = runCtrl[ j].firstTime;2025 actRun.RunUsec = runCtrl[ j].firstUsec;2061 actRun.RunTime = runCtrl[lastRun].firstTime; 2062 actRun.RunUsec = runCtrl[lastRun].firstUsec; 2026 2063 actRun.NBoard = NBOARDS; 2027 2064 actRun.NPix = NPIX; … … 2031 2068 memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS*sizeof(PEVNT_HEADER)); 2032 2069 2033 runCtrl[ j].fileHd = runOpen (irun, &actRun, sizeof (actRun));2034 if (runCtrl[ j].fileHd == NULL)2070 runCtrl[lastRun].fileHd = runOpen (irun, &actRun, sizeof (actRun)); 2071 if (runCtrl[lastRun].fileHd == NULL) 2035 2072 { 2036 2073 factPrintf(kError, 502, "procEvt: Could not open a file for run %d (runOpen failed)", irun); 2037 runCtrl[j].fileId = 91; 2038 runCtrl[j].procId = 91; 2074 runCtrl[lastRun].fileId = 91; 2075 runCtrl[lastRun].procId = 91; // Is not set in writeEvt 2076 continue; 2039 2077 } 2040 else 2078 2079 runCtrl[lastRun].fileId = 0; 2080 runCtrl[lastRun].procId = 0; // Is not set in writeEvt 2081 2082 factPrintf(kInfo, -1, "procEvt: Opened new file for run %d (evt=%d)", irun, ievt); 2083 } 2084 2085 //-------- also check if run shall be closed (==> skip event, but do not close the file !!! ) 2086 if (runCtrl[lastRun].procId == 0) 2087 { 2088 if (runCtrl[lastRun].closeTime < g_actTime || 2089 runCtrl[lastRun].lastTime < g_actTime - 300 || 2090 runCtrl[lastRun].maxEvt <= runCtrl[lastRun].procEvt) 2041 2091 { 2042 factPrintf(kInfo, -1, "procEvt: Opened new file for run %d (evt=%d)", irun, ievt);2043 run Ctrl[j].fileId = 0;2044 runCtrl[ j].procId = 0;2092 factPrintf(kInfo, 502, "procEvt: Reached end of run condition for run %d", irun); 2093 runFinish1 (runCtrl[lastRun].runId); 2094 runCtrl[lastRun].procId = 1; 2045 2095 } 2046 2096 } 2047 2097 2048 // -------- also check if run shall be closed (==> skip event, but do not close the file !!! )2049 if (runCtrl[ j].procId == 0)2098 // Skip event because of no active run 2099 if (runCtrl[lastRun].procId != 0) 2050 2100 { 2051 if (runCtrl[j].closeTime < g_actTime ||2052 runCtrl[j].lastTime < g_actTime - 300 ||2053 runCtrl[j].maxEvt <= runCtrl[j].procEvt)2054 {2055 factPrintf(kInfo, 502, "procEvt: Reached end of run condition for run %d", irun);2056 runFinish1 (runCtrl[j].runId);2057 runCtrl[j].procId = 1;2058 }2059 }2060 if (runCtrl[j].procId != 0) {2061 #ifdef EVTDEBUG2062 factPrintf(kDebug, 502, "procEvt: Skip event %d because no active run %d", ievt, irun);2063 #endif2064 2101 evtCtrl.evtStat[k0] = 9091; 2065 2102 continue; … … 2134 2171 { 2135 2172 evtCtrl.evtStat[k0] = 1000; 2136 runCtrl[ j].procEvt++;2173 runCtrl[lastRun].procEvt++; 2137 2174 } 2138 2175 } … … 2293 2330 } 2294 2331 2295 /*** if (evtCtrl.evtStat[k0] > 5000 && evtCtrl.evtStat[k0] < 9000) ***/2296 2297 2332 //we must drain the buffer asap 2298 2333 if (gi_resetR > 1) … … 2307 2342 const int32_t ievt = mBuffer[id].evNum; 2308 2343 2309 //gi.wrtTot++; 2310 2311 int j = lastRun; 2312 2344 // Find entry in runCtrl which belongs to the event mBuffer[id] 2345 // (only check if there is a need to check) 2313 2346 if (runCtrl[lastRun].runId != irun) 2314 2347 { 2315 2348 //check which fileID to use (or open if needed) 2316 for (j = 0; j < MAX_RUN; j++)2317 {2349 int j; 2350 for (j=0;j<MAX_RUN; j++) 2318 2351 if (runCtrl[j].runId == irun) 2319 2352 break; 2320 } 2321 2322 if (j >= MAX_RUN) 2353 2354 if (j>=MAX_RUN) 2323 2355 { 2324 2356 factPrintf(kFatal, 901, "writeEvt: Can not find run %d for event %d in %d", irun, ievt, id); 2325 //gi.wrtErr++; 2357 // FIXME: What is the right action? 2358 continue; 2326 2359 } 2327 2360 … … 2329 2362 } 2330 2363 2331 if (runCtrl[j].fileId < 0) { 2364 // File not yet open 2365 if (runCtrl[lastRun].fileId < 0) 2366 { 2332 2367 actRun.Version = 1; 2333 2368 actRun.RunType = -1; //to be adapted 2334 2369 2335 actRun.Nroi = runCtrl[j].roi0;2336 actRun.NroiTM = runCtrl[ j].roi8;2370 actRun.Nroi = runCtrl[lastRun].roi0; 2371 actRun.NroiTM = runCtrl[lastRun].roi8; 2337 2372 //ETIENNE don't reset it to zero as it is taken care of in DataWriteFits 2338 2373 // if (actRun.Nroi == actRun.NroiTM) 2339 2374 // actRun.NroiTM = 0; 2340 actRun.RunTime = runCtrl[ j].firstTime;2341 actRun.RunUsec = runCtrl[ j].firstUsec;2342 actRun.NBoard = NBOARDS;2343 actRun.NPix = NPIX;2344 actRun.NTm = NTMARK;2345 actRun.Nroi = mBuffer[id].nRoi;2346 memcpy (actRun.FADhead, mBuffer[id].FADhead, 2347 2348 2349 runCtrl[ j].fileHd =2350 runOpen (irun, &actRun, sizeof (actRun));2351 if (runCtrl[j].fileHd == NULL){2375 actRun.RunTime = runCtrl[lastRun].firstTime; 2376 actRun.RunUsec = runCtrl[lastRun].firstUsec; 2377 actRun.NBoard = NBOARDS; 2378 actRun.NPix = NPIX; 2379 actRun.NTm = NTMARK; 2380 actRun.Nroi = mBuffer[id].nRoi; 2381 2382 memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS * sizeof (PEVNT_HEADER)); 2383 2384 runCtrl[lastRun].fileHd = runOpen (irun, &actRun, sizeof (actRun)); 2385 if (runCtrl[lastRun].fileHd == NULL) 2386 { 2352 2387 factPrintf(kError, 502, "writeEvt: Could not open a file for run %d (runOpen failed)", irun); 2353 runCtrl[j].fileId = 91; 2354 } else { 2355 factPrintf(kInfo, -1, "writeEvt: Opened new file for run %d (evt %d)", irun, ievt); 2356 runCtrl[j].fileId = 0; 2388 runCtrl[lastRun].fileId = 91; 2389 continue; 2357 2390 } 2358 2391 2392 runCtrl[lastRun].fileId = 0; 2393 factPrintf(kInfo, -1, "writeEvt: Opened new file for run %d (evt %d)", irun, ievt); 2359 2394 } 2360 2395 2361 if (runCtrl[j].fileId != 0) { 2362 if (runCtrl[j].fileId < 0) { 2363 factPrintf(kError, 123, "writeEvt: Never opened file for run %d", irun); 2364 } else if (runCtrl[j].fileId < 100) { 2396 if (runCtrl[lastRun].fileId > 0) 2397 { 2398 // There is an event but file is already closed 2399 /* 2400 if (runCtrl[j].fileId < 100) 2401 { 2365 2402 factPrintf(kWarn, 123, "writeEvt: File for run %d is closed", irun); 2366 2403 runCtrl[j].fileId += 100; 2367 } else { 2368 #ifdef EVTDEBUG 2369 factPrintf(kDebug, 123, "writeEvt: File for run %d is closed", irun); 2370 #endif 2404 }*/ 2405 2406 evtCtrl.evtStat[k0] = 9903; 2407 } 2408 2409 // File is open 2410 if (runCtrl[lastRun].fileId==0) 2411 { 2412 const int rc = runWrite(runCtrl[lastRun].fileHd, mBuffer[id].fEvent, 2413 sizeof (mBuffer[id])); 2414 if (rc >= 0) 2415 { 2416 // Sucessfully wrote event 2417 runCtrl[lastRun].lastTime = g_actTime; 2418 runCtrl[lastRun].actEvt++; 2419 evtCtrl.evtStat[k0] = 9901; 2371 2420 } 2372 evtCtrl.evtStat[k0] = 9903; 2373 //gi.wrtErr++; 2374 } else { 2375 // snprintf (str, MXSTR,"write event %d size %d",ievt,sizeof (mBuffer[id])); 2376 // factOut (kInfo, 504, str); 2377 const int rc = runWrite (runCtrl[j].fileHd, mBuffer[id].fEvent, 2378 sizeof (mBuffer[id])); 2379 if (rc >= 0) { 2380 runCtrl[j].lastTime = g_actTime; 2381 runCtrl[j].actEvt++; 2382 evtCtrl.evtStat[k0] = 9901; 2383 #ifdef EVTDEBUG 2384 factPrintf(kDebug, 504, "%5d successfully wrote for run %d id %5d", ievt, irun, k0); 2385 #endif 2386 // gj.writEvt++ ; 2387 } else { 2421 else 2422 { 2388 2423 factPrintf(kError, 503, "writeEvt: Writing event for run %d failed (runWrite)", irun); 2389 2424 evtCtrl.evtStat[k0] = 9902; 2390 //gi.wrtErr++;2391 2425 } 2392 2426 2393 checkAndCloseRun( j, irun, rc<0, 1);2427 checkAndCloseRun(lastRun, irun, rc<0, 1); 2394 2428 } 2395 2429 } 2396 2397 //check if we should close a run (mainly when no event pending) 2398 //ETIENNE but first figure out which one is the latest run with a complete event. 2399 //i.e. max run Id and lastEvt >= 0 2400 //this condition is sufficient because all pending events were written already in the loop just above 2401 //actrun 2402 uint32_t lastStartedTime = 0; 2403 uint32_t runIdFound = 0; 2404 if (actrun != 0) 2405 {//If we have an active run, look for its start time 2406 for (int j=0;j<MAX_RUN;j++) 2407 { 2408 if (runCtrl[j].runId == actrun) 2409 { 2410 lastStartedTime = runCtrl[j].lastTime; 2411 runIdFound = 1; 2412 } 2413 } 2414 } 2415 else 2416 runIdFound = 1; 2430 /* 2431 //check if we should close a run (mainly when no event pending) 2432 //ETIENNE but first figure out which one is the latest run with a complete event. 2433 //i.e. max run Id and lastEvt >= 0 2434 //this condition is sufficient because all pending events were written already in the loop just above 2435 //actrun 2436 uint32_t lastStartedTime = 0; 2437 uint32_t runIdFound = 1; 2438 2439 //If we have an active run, look for its start time 2440 if (actrun != 0) 2441 { 2442 runIdfound = 0; 2443 for (int j=0;j<MAX_RUN;j++) 2444 { 2445 if (runCtrl[j].runId == actrun) 2446 { 2447 lastStartedTime = runCtrl[j].lastTime; 2448 runIdFound = 1; 2449 } 2450 } 2451 } 2417 2452 2418 2453 if (runIdFound == 0) … … 2420 2455 factPrintf(kInfo, 0, "An Active run (number %u) has been registered, but it could not be found in the runs list", actrun); 2421 2456 } 2422 // snprintf(str, MXSTR, "Maximum runId: %d", maxStartedRun); 2423 // factOut(kInfo, 000, str); 2424 //Also check if some files will never be opened 2425 //EDIT: this is completely useless, because as run Numbers are taken from FADs board, 2426 //I will never get run numbers for which no file is to be opened 2427 for (int j=0;j<MAX_RUN;j++) 2428 { 2429 if ((runCtrl[j].fileId < 0) && 2430 (runCtrl[j].lastTime < lastStartedTime) && 2431 (runCtrl[j].runId != 0)) 2432 { 2433 factPrintf(kInfo, 0, "writeEvt: No file will be opened for run %u. Last run: %u (started)", runCtrl[j].runId, actrun); 2434 ;//TODO notify that this run will never be opened 2435 } 2436 } 2437 for (int j=0; j<MAX_RUN; j++) 2438 { 2439 if (runCtrl[j].fileId == 0) 2440 { 2441 //ETIENNE added the condition at this line. dunno what to do with run 0: skipping it 2442 const int cond = runCtrl[j].lastTime < lastStartedTime && runCtrl[j].runId != 0; 2443 checkAndCloseRun(j, runCtrl[j].runId, cond, 2); 2444 } 2445 } 2457 2458 //Also check if some files will never be opened 2459 //EDIT: this is completely useless, because as run Numbers are taken from FADs board, 2460 //I will never get run numbers for which no file is to be opened 2461 for (int j=0;j<MAX_RUN;j++) 2462 { 2463 if ((runCtrl[j].fileId < 0) && 2464 (runCtrl[j].lastTime < lastStartedTime) && 2465 (runCtrl[j].runId != 0)) 2466 { 2467 factPrintf(kInfo, 0, "writeEvt: No file will be opened for run %u. Last run: %u (started)", runCtrl[j].runId, actrun); 2468 ;//TODO notify that this run will never be opened 2469 } 2470 } 2471 */ 2472 2473 // Although the are no pending events, we have to check if a run should be closed (timeout) 2474 for (int j=0; j<MAX_RUN; j++) 2475 { 2476 if (runCtrl[j].fileId == 0) 2477 { 2478 //ETIENNE added the condition at this line. dunno what to do with run 0: skipping it 2479 const int cond = /*runCtrl[j].lastTime < lastStartedTime &&*/ runCtrl[j].runId == 0; 2480 checkAndCloseRun(j, runCtrl[j].runId, cond, 2); 2481 } 2482 } 2446 2483 2447 2484 //seems we have nothing to do, so sleep a little … … 2449 2486 usleep(1); 2450 2487 2451 if (gj.readStat < -10 && numWait == 0) { //nothing left to do 2452 factPrintf(kInfo, -1, "Finish Write Process ..."); 2453 gw_runStat = -22; //==> we should exit 2454 gj.writStat = -22; //==> we should exit 2455 goto closerun; 2456 } 2457 gw_runStat = gi_runStat; 2458 gj.writStat = gj.readStat; 2459 2460 } 2461 2462 //must close all open files .... 2463 factPrintf(kInfo, -1, "Abort Writing Process ..."); 2464 2465 closerun: 2488 //nothing left to do 2489 if (gj.readStat < -10 && numWait == 0) 2490 { 2491 factPrintf(kInfo, -1, "Finish Write Process ..."); 2492 gw_runStat = -22; //==> we should exit 2493 gj.writStat = -22; //==> we should exit 2494 break; 2495 } 2496 2497 gw_runStat = gi_runStat; 2498 gj.writStat = gj.readStat; 2499 } 2500 2466 2501 factPrintf(kInfo, -1, "Close all open files ..."); 2467 2502 for (int j=0; j<MAX_RUN; j++) … … 2473 2508 gw_runStat = -99; 2474 2509 gj.writStat = -99; 2510 2475 2511 factPrintf(kInfo, -1, "Exit Writing Process ..."); 2512 2476 2513 return 0; 2477 2478 2479 2480 2481 2514 } /*-----------------------------------------------------------------*/ 2482 2515
Note:
See TracChangeset
for help on using the changeset viewer.