Changeset 15463 for trunk/FACT++/src
- Timestamp:
- 05/01/13 09:46:42 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r15461 r15463 71 71 72 72 73 int evtCtrl_frstPtr; 74 int evtCtrl_lastPtr; 73 75 74 76 … … 116 118 //uint gp_EvtTot = 0 ; 117 119 118 PIX_MAP g_pixMap[NPIX];120 //PIX_MAP g_pixMap[NPIX]; 119 121 120 122 EVT_STAT gi; 121 123 GUI_STAT gj; 122 124 123 EVT_CTRL evtCtrl; //control of events during processing 124 int evtIdx[MAX_EVT * MAX_RUN]; //index from mBuffer to evtCtrl 125 126 WRK_DATA mBuffer[MAX_EVT * MAX_RUN]; 125 //int evtIdx[MAX_EVT * MAX_RUN]; //index from mBuffer to evtCtrl 126 127 EVT_CTRL evtCtrl[MAX_EVT * MAX_RUN]; //control of events during processing 128 WRK_DATA mBuffer[MAX_EVT * MAX_RUN]; //local working space 127 129 128 130 //#define MXSTR 1000 … … 322 324 323 325 RUN_CTRL runCtrl[MAX_RUN]; 324 RUN_TAIL runTail[MAX_RUN];326 //RUN_TAIL runTail[MAX_RUN]; 325 327 326 328 … … 506 508 mBuffer[i].runNum = 0; 507 509 508 evtCtrl .evtBuf[i]= -1;509 evtCtrl .evtStat[i]= -1;510 evtCtrl.pcTime[i]= actime; //initiate to far future510 evtCtrl[i].mBuffer_idx = -1; 511 evtCtrl[i].evtStat = -1; 512 //evtCtrl[i].lastRecv = actime; //initiate to far future 511 513 512 514 #ifdef ETIENNE_MALLOC … … 525 527 //actRun.FADhead = malloc (NBOARDS * sizeof (PEVNT_HEADER)); 526 528 527 evtCtrl .frstPtr = 0;528 evtCtrl .lastPtr = 0;529 evtCtrl_frstPtr = 0; 530 evtCtrl_lastPtr = 0; 529 531 530 532 return 0; … … 632 634 if (runCtrl[k].runId == runID) 633 635 { 636 // FIXME: Compare to previous event 634 637 if (runCtrl[k].roi0 != nRoi[0] || runCtrl[k].roi8 != nRoi[8]) 635 638 { … … 694 697 695 698 runCtrl[evFree].runId = runID; 696 runCtrl[evFree].roi0 = nRoi[0]; 697 runCtrl[evFree].roi8 = nRoi[8]; 699 runCtrl[evFree].roi0 = nRoi[0]; // FIXME: Make obsolete! 700 runCtrl[evFree].roi8 = nRoi[8]; // FIXME: Make obsolete! 698 701 runCtrl[evFree].fileId = -2; 699 702 runCtrl[evFree].procId = -2; … … 702 705 runCtrl[evFree].procEvt = 0; // Number of successfully checked events (checkEvent) 703 706 runCtrl[evFree].maxEvt = 999999999; // max number events allowed 704 runCtrl[evFree].firstTime = tsec;705 runCtrl[evFree].firstUsec = tusec;707 //runCtrl[evFree].firstTime = tsec; 708 //runCtrl[evFree].firstUsec = tusec; 706 709 runCtrl[evFree].lastTime = tsec; // Time when the last event was written 707 710 runCtrl[evFree].closeTime = tsec + 3600 * 24; //max time allowed 708 711 /* 709 712 runTail[evFree].nEventsOk = 0; 710 713 runTail[evFree].nEventsRej = 0; … … 712 715 runTail[evFree].PCtime0 = 0; 713 716 runTail[evFree].PCtimeX = 0; 717 */ 714 718 } 715 719 … … 733 737 mBuffer[i].Errors[3] = 0; 734 738 mBuffer[i].fEvent = NULL; 735 mBuffer[i].buffer = NULL;736 739 mBuffer[i].FADhead = NULL; 740 //mBuffer[i].buffer = NULL; 737 741 738 742 /* … … 787 791 { 788 792 mBuffer[i].fEvent = (EVENT*)((char*)mBuffer[i].FADhead+MAX_HEAD_MEM); 793 memset(mBuffer[i].fEvent->Adc_Data, 0, (NPIX+NTMARK)*2*mBuffer[i].nRoi); 789 794 790 795 //flag all pixels as unused … … 834 839 835 840 // free (mBuffer[i].buffer); 836 mBuffer[i].buffer = NULL;841 // mBuffer[i].buffer = NULL; 837 842 //END ETIENNE 838 843 // headmem = NBOARDS * sizeof (PEVNT_HEADER); … … 902 907 }*/ /*-----------------------------------------------------------------*/ 903 908 904 void reportIncomplete(int k0) 905 { 906 const int id = evtCtrl.evtBuf[k0]; 907 908 factPrintf(kWarn, 601, "%5d skip incomplete evt %8d %8d %2d", 909 mBuffer[id].evNum, evtCtrl.evtBuf[k0], k0, evtCtrl.evtStat[k0]); 909 void reportIncomplete(int id) 910 { 911 factPrintf(kWarn, 601, "%5d skip incomplete evt %8d", 912 mBuffer[id].evNum, id); 910 913 911 914 uint64_t report = 0; … … 1174 1177 1175 1178 START: 1176 evtCtrl .frstPtr = 0;1177 evtCtrl .lastPtr = 0;1179 evtCtrl_frstPtr = 0; 1180 evtCtrl_lastPtr = 0; 1178 1181 1179 1182 //time in seconds … … 1547 1550 1548 1551 //register event in 'active list (reading)' 1549 evtIdx[evID] = evtCtrl.lastPtr;1550 1551 evtCtrl .evtBuf[evtCtrl.lastPtr]= evID;1552 evtCtrl .evtStat[evtCtrl.lastPtr]= 0;1553 evtCtrl.pcTime[evtCtrl.lastPtr]= g_actTime;1554 1555 evtCtrl .lastPtr++;1556 evtCtrl .lastPtr %= MAX_EVT * MAX_RUN;1552 mBuffer[evID].evtCtrl_idx = evtCtrl_lastPtr; 1553 1554 evtCtrl[evtCtrl_lastPtr].mBuffer_idx = evID; 1555 evtCtrl[evtCtrl_lastPtr].evtStat = 0; 1556 //evtCtrl[evtCtrl.lastPtr].pcTime = g_actTime; 1557 1558 evtCtrl_lastPtr++; 1559 evtCtrl_lastPtr %= MAX_EVT * MAX_RUN; 1557 1560 } 1558 1561 … … 1591 1594 // now we have stored a new board contents into Event structure 1592 1595 1593 const int iDx = evtIdx[evID]; //index into evtCtrl1594 1595 1596 mBuffer[evID].fEvent->NumBoards++; 1596 1597 mBuffer[evID].board[board] = board; 1597 1598 mBuffer[evID].nBoard++; 1598 1599 1599 evtCtrl.evtStat[iDx] = mBuffer[evID].nBoard; 1600 evtCtrl.pcTime[iDx] = g_actTime; 1600 const int iDx = mBuffer[evID].evtCtrl_idx;//evtIdx[evID]; //index into evtCtrl 1601 1602 evtCtrl[iDx].evtStat = mBuffer[evID].nBoard; 1603 //evtCtrl[iDx].lastRecv = g_actTime; 1601 1604 1602 1605 // have we already reported first (partial) event of this run ??? … … 1640 1643 1641 1644 // Flag that the event is ready for processing 1642 evtCtrl .evtStat[iDx]= 99;1645 evtCtrl[iDx].evtStat = 99; 1643 1646 1644 1647 } // end for loop over all sockets … … 1657 1660 //loop over all active events and flag those older than read-timeout 1658 1661 //delete those that are written to disk .... 1659 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)1662 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 1660 1663 { 1661 if (k0==evtCtrl .frstPtr && evtCtrl.evtStat[k0]<0)1664 if (k0==evtCtrl_frstPtr && evtCtrl[k0].evtStat<0) 1662 1665 { 1663 evtCtrl .frstPtr++;1664 evtCtrl .frstPtr %= MAX_EVT * MAX_RUN;1666 evtCtrl_frstPtr++; 1667 evtCtrl_frstPtr %= MAX_EVT * MAX_RUN; 1665 1668 1666 1669 // Continue because evtCtrl.evtStat[k0] must be <0 … … 1669 1672 1670 1673 // Check the more likely case first: incomplete events 1671 if (evtCtrl .evtStat[k0]>0 && evtCtrl.evtStat[k0]<92)1674 if (evtCtrl[k0].evtStat>0 && evtCtrl[k0].evtStat<92) 1672 1675 { 1673 1676 gj.bufNew++; //incomplete event in Buffer 1674 1677 1675 1678 // Event has not yet timed out or was reported already 1676 if (evtCtrl.evtStat[k0]>=90 || evtCtrl.pcTime[k0]>=g_actTime - 30) 1679 const int id = evtCtrl[k0].mBuffer_idx; 1680 1681 if (evtCtrl[k0].evtStat>=90 || mBuffer[id].pcTime[0]/*evtCtrl[k0].lastRecv*/>=g_actTime - 30) 1677 1682 continue; 1678 1683 1679 reportIncomplete( k0);1684 reportIncomplete(id); 1680 1685 1681 1686 //timeout for incomplete events 1682 evtCtrl .evtStat[k0]= 91;1687 evtCtrl[k0].evtStat = 91; 1683 1688 gj.evtSkip++; 1684 1689 … … 1687 1692 1688 1693 // complete event in Buffer 1689 if (evtCtrl .evtStat[k0]>= 95)1694 if (evtCtrl[k0].evtStat >= 95) 1690 1695 gj.bufEvt++; 1691 1696 1692 1697 // Check the less likely case: 'useless' or 'delete' 1693 if (evtCtrl .evtStat[k0]==0 || evtCtrl.evtStat[k0]>= 9000)1698 if (evtCtrl[k0].evtStat==0 || evtCtrl[k0].evtStat >= 9000) 1694 1699 { 1695 const int id = evtCtrl .evtBuf[k0];1700 const int id = evtCtrl[k0].mBuffer_idx; 1696 1701 #ifdef EVTDEBUG 1697 1702 factPrintf(kDebug, -1, "%5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard); 1698 1703 #endif 1699 1704 mBufFree (id); //event written--> free memory 1700 evtCtrl .evtStat[k0]= -1;1705 evtCtrl[k0].evtStat = -1; 1701 1706 gj.evtWrite++; 1702 1707 gj.rateWrite++; … … 1782 1787 { 1783 1788 //flag all events as 'read finished' 1784 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)1789 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 1785 1790 { 1786 if (evtCtrl .evtStat[k0] > 0 && evtCtrl.evtStat[k0]< 90)1791 if (evtCtrl[k0].evtStat > 0 && evtCtrl[k0].evtStat < 90) 1787 1792 { 1788 evtCtrl .evtStat[k0]= 91;1793 evtCtrl[k0].evtStat = 91; 1789 1794 //gi.evtSkp++; 1790 1795 //gi.evtTot++; … … 1810 1815 numclear = 0; 1811 1816 1812 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)1817 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 1813 1818 { 1814 if (evtCtrl .evtStat[k0]> minclear)1819 if (evtCtrl[k0].evtStat > minclear) 1815 1820 { 1816 const int id = evtCtrl .evtBuf[k0];1821 const int id = evtCtrl[k0].mBuffer_idx; 1817 1822 #ifdef EVTDEBUG 1818 1823 factPrintf(kDebug, -1, "ev %5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard); 1819 1824 #endif 1820 1825 mBufFree (id); //event written--> free memory 1821 evtCtrl .evtStat[k0]= -1;1826 evtCtrl[k0].evtStat = -1; 1822 1827 } 1823 1828 else 1824 if (evtCtrl .evtStat[k0]> 0)1829 if (evtCtrl[k0].evtStat > 0) 1825 1830 numclear++; //writing is still ongoing... 1826 1831 1827 if (k0 == evtCtrl .frstPtr && evtCtrl.evtStat[k0]< 0)1832 if (k0 == evtCtrl_frstPtr && evtCtrl[k0].evtStat < 0) 1828 1833 { 1829 evtCtrl .frstPtr++;1830 evtCtrl .frstPtr %= MAX_EVT * MAX_RUN;1834 evtCtrl_frstPtr++; 1835 evtCtrl_frstPtr %= MAX_EVT * MAX_RUN; 1831 1836 } 1832 1837 } … … 1882 1887 int numProc = 0; 1883 1888 1884 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)1889 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 1885 1890 { 1886 if ( !(evtCtrl.evtStat[k0] == 1000 + threadID))1891 if (evtCtrl[k0].evtStat != 1000 + threadID) 1887 1892 { 1888 if (evtCtrl .evtStat[k0]< 1000 + threadID)1893 if (evtCtrl[k0].evtStat < 1000 + threadID) 1889 1894 numWait++; 1890 1895 … … 1898 1903 if (gi_resetR<=1) 1899 1904 { 1900 const int id = evtCtrl .evtBuf[k0];1905 const int id = evtCtrl[k0].mBuffer_idx; 1901 1906 1902 1907 jret = subProcEvt(threadID, mBuffer[id].FADhead, 1903 mBuffer[id].fEvent, mBuffer[id].buffer);1908 mBuffer[id].fEvent, NULL/*mBuffer[id].buffer*/); 1904 1909 1905 1910 … … 1915 1920 } 1916 1921 1917 evtCtrl .evtStat[k0]= jret;1922 evtCtrl[k0].evtStat = jret; 1918 1923 numProc++; 1919 1924 } … … 1981 1986 int numProc = 0; 1982 1987 1983 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)1988 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 1984 1989 { 1985 if (evtCtrl .evtStat[k0] <= 90 || evtCtrl.evtStat[k0]>= 1000)1990 if (evtCtrl[k0].evtStat <= 90 || evtCtrl[k0].evtStat >= 1000) 1986 1991 { 1987 if (evtCtrl .evtStat[k0] >= 0 && evtCtrl.evtStat[k0]< 90)1992 if (evtCtrl[k0].evtStat >= 0 && evtCtrl[k0].evtStat< 90) 1988 1993 numWait++; 1989 1994 … … 1994 1999 if (gi_resetR > 1) 1995 2000 { 1996 evtCtrl .evtStat[k0]= 9991;2001 evtCtrl[k0].evtStat = 9991; 1997 2002 continue; 1998 2003 } … … 2000 2005 //-------- it is better to open the run already here, so call can be used to initialize 2001 2006 //-------- buffers etc. needed to interprete run (e.g. DRS calibration) 2002 const int id = evtCtrl .evtBuf[k0];2007 const int id = evtCtrl[k0].mBuffer_idx; 2003 2008 2004 2009 const uint32_t irun = mBuffer[id].runNum; … … 2044 2049 2045 2050 RUN_HEAD actRun; 2046 2047 actRun.Version = 1; 2051 actRun.Version = 1; 2048 2052 actRun.RunType = -1; //to be adapted 2049 2050 actRun.Nroi = runCtrl[lastRun].roi0; 2051 actRun.NroiTM = runCtrl[lastRun].roi8; 2052 //ETIENNE don't reset it to zero as it is taken care of in DataWriteFits 2053 // if (actRun.Nroi == actRun.NroiTM) 2054 // actRun.NroiTM = 0; 2055 actRun.RunTime = runCtrl[lastRun].firstTime; 2056 actRun.RunUsec = runCtrl[lastRun].firstUsec; 2053 actRun.Nroi = mBuffer[id].nRoi; //runCtrl[lastRun].roi0; 2054 actRun.NroiTM = mBuffer[id].nRoiTM; //runCtrl[lastRun].roi8; 2055 actRun.RunTime = mBuffer[id].pcTime[0]; //runCtrl[lastRun].firstTime; 2056 actRun.RunUsec = mBuffer[id].pcTime[1]; //runCtrl[lastRun].firstUsec; 2057 2057 actRun.NBoard = NBOARDS; 2058 2058 actRun.NPix = NPIX; 2059 2059 actRun.NTm = NTMARK; 2060 actRun.Nroi = mBuffer[id].nRoi;2061 2060 2062 2061 memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS*sizeof(PEVNT_HEADER)); … … 2093 2092 if (runCtrl[lastRun].procId != 0) 2094 2093 { 2095 evtCtrl .evtStat[k0]= 9091;2094 evtCtrl[k0].evtStat = 9091; 2096 2095 continue; 2097 2096 } … … 2100 2099 //-------- 2101 2100 2102 const int roi = mBuffer[id].nRoi;2101 //const int roi = mBuffer[id].nRoi; 2103 2102 //const int roiTM = mBuffer[id].nRoiTM; 2104 2103 … … 2107 2106 // if (roiTM == roi) 2108 2107 // roiTM = 0; 2108 /* 2109 2109 for (int ip=0; ip<NPIX; ip++) 2110 2110 { … … 2123 2123 memset(&mBuffer[id].fEvent->Adc_Data[dest], 0, roi * 2); 2124 2124 } 2125 } 2125 }*/ 2126 2126 2127 2127 //and set correct event header ; also check for consistency in event (not yet) … … 2159 2159 if (rc < 0) 2160 2160 { 2161 evtCtrl .evtStat[k0]= 9999; //flag event to be skipped2161 evtCtrl[k0].evtStat = 9999; //flag event to be skipped 2162 2162 //gi.procErr++; 2163 2163 } 2164 2164 else 2165 2165 { 2166 evtCtrl .evtStat[k0]= 1000;2166 evtCtrl[k0].evtStat = 1000; 2167 2167 runCtrl[lastRun].procEvt++; 2168 2168 } … … 2194 2194 } 2195 2195 2196 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)2196 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 2197 2197 { 2198 if (evtCtrl .evtStat[k0] >= 0 && evtCtrl.evtStat[k0]< 1000)2199 evtCtrl .evtStat[k0]= 9800; //flag event as 'processed'2198 if (evtCtrl[k0].evtStat >= 0 && evtCtrl[k0].evtStat < 1000) 2199 evtCtrl[k0].evtStat = 9800; //flag event as 'processed' 2200 2200 } 2201 2201 … … 2271 2271 runCtrl[j].closeTime = g_actTime - 1; 2272 2272 2273 const int rc = runClose(runCtrl[j].fileHd, &runTail[j], sizeof(runTail[j]));2273 const int rc = runClose(runCtrl[j].fileHd, NULL, 0);//&runTail[j], sizeof(runTail[j])); 2274 2274 if (rc<0) 2275 2275 { … … 2314 2314 int numWait = 0; 2315 2315 2316 for (int k0=evtCtrl .frstPtr; k0!=evtCtrl.lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN)2316 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 2317 2317 { 2318 if (evtCtrl .evtStat[k0] <= 5000 || evtCtrl.evtStat[k0]>= 9000)2318 if (evtCtrl[k0].evtStat <= 5000 || evtCtrl[k0].evtStat >= 9000) 2319 2319 { 2320 if (evtCtrl .evtStat[k0] > 0 && evtCtrl.evtStat[k0]< 9000)2320 if (evtCtrl[k0].evtStat > 0 && evtCtrl[k0].evtStat < 9000) 2321 2321 numWait++; 2322 2322 … … 2327 2327 if (gi_resetR > 1) 2328 2328 { 2329 evtCtrl .evtStat[k0]= 9904;2329 evtCtrl[k0].evtStat = 9904; 2330 2330 continue; 2331 2331 } 2332 2332 2333 const int id = evtCtrl .evtBuf[k0];2333 const int id = evtCtrl[k0].mBuffer_idx; 2334 2334 2335 2335 const uint32_t irun = mBuffer[id].runNum; … … 2360 2360 { 2361 2361 RUN_HEAD actRun; 2362 2363 actRun.Version = 1; 2362 actRun.Version = 1; 2364 2363 actRun.RunType = -1; //to be adapted 2365 2366 actRun.Nroi = runCtrl[lastRun].roi0; 2367 actRun.NroiTM = runCtrl[lastRun].roi8; 2368 //ETIENNE don't reset it to zero as it is taken care of in DataWriteFits 2369 // if (actRun.Nroi == actRun.NroiTM) 2370 // actRun.NroiTM = 0; 2371 actRun.RunTime = runCtrl[lastRun].firstTime; 2372 actRun.RunUsec = runCtrl[lastRun].firstUsec; 2364 actRun.Nroi = mBuffer[id].nRoi; //runCtrl[lastRun].roi0; 2365 actRun.NroiTM = mBuffer[id].nRoiTM; //runCtrl[lastRun].roi8; 2366 actRun.RunTime = mBuffer[id].pcTime[0];//runCtrl[lastRun].firstTime; 2367 actRun.RunUsec = mBuffer[id].pcTime[1];//runCtrl[lastRun].firstUsec; 2373 2368 actRun.NBoard = NBOARDS; 2374 2369 actRun.NPix = NPIX; 2375 2370 actRun.NTm = NTMARK; 2376 actRun.Nroi = mBuffer[id].nRoi;2377 2371 2378 2372 memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS * sizeof (PEVNT_HEADER)); … … 2400 2394 }*/ 2401 2395 2402 evtCtrl .evtStat[k0]= 9903;2396 evtCtrl[k0].evtStat = 9903; 2403 2397 } 2404 2398 … … 2413 2407 runCtrl[lastRun].lastTime = g_actTime; 2414 2408 runCtrl[lastRun].actEvt++; 2415 evtCtrl.evtStat[k0] = 9901; 2409 2410 evtCtrl[k0].evtStat = 9901; 2416 2411 } 2417 2412 else 2418 2413 { 2419 2414 factPrintf(kError, 503, "writeEvt: Writing event for run %d failed (runWrite)", irun); 2420 evtCtrl .evtStat[k0]= 9902;2415 evtCtrl[k0].evtStat = 9902; 2421 2416 } 2422 2417 … … 2543 2538 } 2544 2539 //partially initialize event control logics 2545 evtCtrl .frstPtr = 0;2546 evtCtrl .lastPtr = 0;2540 evtCtrl_frstPtr = 0; 2541 evtCtrl_lastPtr = 0; 2547 2542 2548 2543 //start all threads (more to come) when we are allowed to ....
Note:
See TracChangeset
for help on using the changeset viewer.