Changeset 15467 for trunk/FACT++/src
- Timestamp:
- 05/01/13 10:50:29 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r15463 r15467 123 123 GUI_STAT gj; 124 124 125 //int evtIdx[MAX_EVT * MAX_RUN]; //index from mBuffer to evtCtrl126 127 125 EVT_CTRL evtCtrl[MAX_EVT * MAX_RUN]; //control of events during processing 128 WRK_DATA mBuffer[MAX_EVT * MAX_RUN]; //local working space129 126 130 127 //#define MXSTR 1000 … … 502 499 // initialize mBuffer (mark all entries as unused\empty) 503 500 504 uint32_t actime = g_actTime + 50000000;501 //uint32_t actime = g_actTime + 50000000; 505 502 506 503 for (int i = 0; i < MAX_EVT * MAX_RUN; i++) { 507 mBuffer[i].evNum = mBuffer[i].nRoi = -1;508 mBuffer[i].runNum = 0;509 510 evtCtrl[i].mBuffer_idx = -1;504 evtCtrl[i].evNum = evtCtrl[i].nRoi = -1; 505 evtCtrl[i].runNum = 0; 506 507 //evtCtrl[i].mBuffer_idx = -1; 511 508 evtCtrl[i].evtStat = -1; 512 //evtCtrl[i].lastRecv = actime; //initiate to far future513 509 514 510 #ifdef ETIENNE_MALLOC … … 536 532 int checkRoiConsistency(int i, int roi[]); 537 533 538 int mBufEvt (int sk) 539 /*(int evID, uint runID, int nRoi[], int sk, int fadlen, int trgTyp, int trgNum, int fadNum)*/ 534 int mBufEvt(int sk) 540 535 { 541 536 // generate a new Event into mBuffer: … … 551 546 // size_t needmem = 0; 552 547 553 554 548 int nRoi[9]; 555 549 if (!checkRoiConsistency(sk, nRoi)) … … 560 554 const int evID = rd[sk].evtID; 561 555 const uint runID = rd[sk].runID; 562 const int fadlen = rd[sk].fadLen;563 556 const int trgTyp = rd[sk].ftmTyp; 564 557 const int trgNum = rd[sk].ftmID; 565 558 const int fadNum = rd[sk].evtID; 566 559 567 int i = evID % MAX_EVT;568 int e vFree = -1;569 570 for (int k = 0; k < MAX_RUN; k++)560 int beg = (evtCtrl_lastPtr + MAX_EVT*MAX_RUN - 1) % (MAX_EVT*MAX_RUN); 561 int end = (evtCtrl_frstPtr + MAX_EVT*MAX_RUN - 1) % (MAX_EVT*MAX_RUN); 562 563 for (int k=beg; k!=end; k--, k += MAX_EVT*MAX_RUN, k %= MAX_EVT*MAX_RUN) 571 564 { 572 //event is already registered; 573 if (mBuffer[i].evNum == evID && mBuffer[i].runNum == runID) 565 // If the run is different, go on searching. 566 // We cannot stop searching if a lower run-id is found as in 567 // the case of the events, because theoretically, there 568 // can be the same run on two different days. 569 if (runID != evtCtrl[k].runNum) 570 continue; 571 572 // The event in the control structure has an event id with 573 // a lower event id than the current one. All previous events 574 // should have an even lower event id, so there is no way it 575 // can be found in the structure. 576 if (evtCtrl[k].evNum < evID/* && runID == evtCtrl[k].runNum*/) 577 break; 578 579 if (evID != evtCtrl[k].evNum/* || runID != evtCtrl[k].runNum*/) 580 continue; 581 582 // is it ok ???? 583 if (evtCtrl[k].nRoi != nRoi[0] || evtCtrl[k].nRoiTM != nRoi[8]) 574 584 { 575 // is it ok ???? 576 if (mBuffer[i].nRoi != nRoi[0] || mBuffer[i].nRoiTM != nRoi[8]) 577 { 578 factPrintf(kError, 821, "Mismatch of roi within event. Expected roi=%d and roi_tm=%d, got %d and %d.", 579 mBuffer[i].nRoi, mBuffer[i].nRoiTM, nRoi[0], nRoi[8]); 580 return -8201; 581 } 582 583 // count for inconsistencies 584 if (mBuffer[i].trgNum != trgNum) 585 mBuffer[i].Errors[0]++; 586 if (mBuffer[i].fadNum != fadNum) 587 mBuffer[i].Errors[1]++; 588 if (mBuffer[i].trgTyp != trgTyp) 589 mBuffer[i].Errors[2]++; 590 591 //everything seems fine so far ==> use this slot .... 592 return i; 585 factPrintf(kError, 821, "Mismatch of roi within event. Expected roi=%d and roi_tm=%d, got %d and %d.", 586 evtCtrl[k].nRoi, evtCtrl[k].nRoiTM, nRoi[0], nRoi[8]); 587 return -8201; 593 588 } 594 589 595 if (evFree < 0 && mBuffer[i].evNum < 0) 596 evFree = i; 597 598 i += MAX_EVT; 590 // count for inconsistencies 591 if (evtCtrl[k].trgNum != trgNum) 592 evtCtrl[k].Errors[0]++; 593 if (evtCtrl[k].fadNum != fadNum) 594 evtCtrl[k].Errors[1]++; 595 if (evtCtrl[k].trgTyp != trgTyp) 596 evtCtrl[k].Errors[2]++; 597 598 //everything seems fine so far ==> use this slot .... 599 return k; 599 600 } 600 601 601 602 602 //event does not yet exist; create it 603 603 604 if (e vFree < 0) //no space available in ctrl604 if (end-beg==1 || (end==0 && beg==MAX_EVT*MAX_RUN-1)) //no space available in ctrl 605 605 { 606 factPrintf(kError, 881, "No control slot to keep event %d ", evID);606 factPrintf(kError, 881, "No control slot to keep event %d (run %d) %d %d", evID, runID, beg, end); 607 607 return -1; 608 608 } 609 610 i = evFree; //found free entry; use it ...611 609 612 610 // FIXME: This should be the time of the first receiped board … … 618 616 619 617 //check if runId already registered in runCtrl 620 evFree = -1;621 618 622 619 uint oldest = g_actTime + 1000; … … 629 626 // fileId>0: run closed 630 627 631 for (int k = 0; k <MAX_RUN; k++)628 for (int k=0; k<MAX_RUN; k++) 632 629 { 633 630 // Check if run already registered (old entries should have runId==-1) … … 653 650 jold = k; 654 651 } 655 /*656 // Empty slot already found?657 if (evFree>=0)658 continue;659 */660 661 /*662 if (runCtrl[k].fileId!=0)663 {664 evFree = k;665 continue;666 }*/667 668 /*669 // Slot not yet used670 if (runCtrl[k].fileId < 0)671 {672 evFree = k;673 continue;674 }675 676 // Slot already closed677 if (runCtrl[k].fileId > 0 && runCtrl[k].closeTime < oldest)678 {679 oldest = runCtrl[k].closeTime;680 jold = k;681 }*/682 652 } 683 653 684 654 if (!found) // Run not yet registered, register run 685 655 { 686 if ( evFree < 0 &&jold < 0)656 if (jold < 0) 687 657 { 688 658 factPrintf(kFatal, 883, "Not able to register the new run %d", runID); … … 690 660 } 691 661 692 if (evFree < 0) 693 evFree = jold; 662 int evFree = jold; 694 663 695 664 factPrintf(kInfo, 503, "New run %d (evID=%d, evFree=%d) registered with roi=%d and roi_tm=%d", … … 705 674 runCtrl[evFree].procEvt = 0; // Number of successfully checked events (checkEvent) 706 675 runCtrl[evFree].maxEvt = 999999999; // max number events allowed 707 //runCtrl[evFree].firstTime = tsec;708 //runCtrl[evFree].firstUsec = tusec;709 676 runCtrl[evFree].lastTime = tsec; // Time when the last event was written 710 677 runCtrl[evFree].closeTime = tsec + 3600 * 24; //max time allowed 711 /*712 runTail[evFree].nEventsOk = 0;713 runTail[evFree].nEventsRej = 0;714 runTail[evFree].nEventsBad = 0;715 runTail[evFree].PCtime0 = 0;716 runTail[evFree].PCtimeX = 0;717 */718 678 } 719 679 680 const int k = evtCtrl_lastPtr; 681 720 682 //flag all boards as unused 721 mBuffer[i].nBoard = 0; 722 for (int k = 0; k < NBOARDS; k++) 723 mBuffer[i].board[k] = -1; 724 725 mBuffer[i].pcTime[0] = tsec; 726 mBuffer[i].pcTime[1] = tusec; 727 mBuffer[i].nRoi = nRoi[0]; 728 mBuffer[i].nRoiTM = nRoi[8]; 729 mBuffer[i].evNum = evID; 730 mBuffer[i].runNum = runID; 731 mBuffer[i].fadNum = fadNum; 732 mBuffer[i].trgNum = trgNum; 733 mBuffer[i].trgTyp = trgTyp; 734 mBuffer[i].Errors[0] = 0; 735 mBuffer[i].Errors[1] = 0; 736 mBuffer[i].Errors[2] = 0; 737 mBuffer[i].Errors[3] = 0; 738 mBuffer[i].fEvent = NULL; 739 mBuffer[i].FADhead = NULL; 740 //mBuffer[i].buffer = NULL; 741 742 /* 743 #ifdef ETIENNE_MALLOC 744 mBuffer[i].FADhead = ETI_Malloc(evID, i); 745 mBuffer[i].buffer = NULL; 746 if (mBuffer[i].FADhead != NULL) 747 mBuffer[i].fEvent = (EVENT*)&(((char*)(mBuffer[i].FADhead))[MAX_HEAD_MEM]); 748 else 749 { 750 mBuffer[i].fEvent = NULL; 751 gj.usdMem = 0; 752 for (int k=0;k<numAllocatedChunks;k++) 753 gj.usdMem += EtiMemoryChunks[k].nSlots * MAX_SLOT_SIZE; 754 if (gj.usdMem > gj.maxMem) 755 gj.maxMem = gj.usdMem; 756 else 757 { 758 factPrintf(kDebug, 882, "No memory left to keep event %6d sock %3d", evID, sk); 759 } 760 return -11; 761 } 762 #endif 763 764 #ifdef STANDARD_MALLOC 765 mBuffer[i].FADhead = malloc (MAX_HEAD_MEM+MAX_EVT_MEM); 766 mBuffer[i].fEvent = NULL; 767 mBuffer[i].buffer = NULL; 768 if (mBuffer[i].FADhead == NULL) 769 { 770 factPrintf(kError, 882, "malloc header failed for event %d", evID); 771 return -12; 772 } 773 mBuffer[i].fEvent = (void*)((char*)mBuffer[i].FADhead+MAX_HEAD_MEM); 774 #endif 775 776 #ifdef ETIENNE_MALLOC 777 //ETIENNE 778 //gj.usdMem += needmem + headmem + gi_maxSize; 779 gj.usdMem = 0; 780 for (int k=0;k<numAllocatedChunks;k++) 781 gj.usdMem += EtiMemoryChunks[k].nSlots * MAX_SLOT_SIZE; 782 //END ETIENNE 783 #endif 784 */ 785 786 return i; 683 evtCtrl[k].nBoard = 0; 684 for (int b=0; b<NBOARDS; b++) 685 evtCtrl[k].board[b] = -1; 686 687 evtCtrl[k].pcTime[0] = tsec; 688 evtCtrl[k].pcTime[1] = tusec; 689 evtCtrl[k].nRoi = nRoi[0]; 690 evtCtrl[k].nRoiTM = nRoi[8]; 691 evtCtrl[k].evNum = evID; 692 evtCtrl[k].runNum = runID; 693 evtCtrl[k].fadNum = fadNum; 694 evtCtrl[k].trgNum = trgNum; 695 evtCtrl[k].trgTyp = trgTyp; 696 evtCtrl[k].Errors[0] = 0; 697 evtCtrl[k].Errors[1] = 0; 698 evtCtrl[k].Errors[2] = 0; 699 evtCtrl[k].Errors[3] = 0; 700 evtCtrl[k].fEvent = NULL; 701 evtCtrl[k].FADhead = NULL; 702 703 evtCtrl[k].evtStat = 0; 704 705 // This is dangerous, because theoretically, it can result is 706 // acessing invalid memory in another thread if this is split 707 // in two instructions. Must be done only _after_ the contents 708 // have been initialized 709 evtCtrl_lastPtr = (evtCtrl_lastPtr+1) % MAX_EVT * MAX_RUN; 710 711 return k; 787 712 788 713 } /*-----------------------------------------------------------------*/ 789 714 715 790 716 void initEvent(int i) 791 717 { 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);718 evtCtrl[i].fEvent = (EVENT*)((char*)evtCtrl[i].FADhead+MAX_HEAD_MEM); 719 memset(evtCtrl[i].fEvent->Adc_Data, 0, (NPIX+NTMARK)*2*evtCtrl[i].nRoi); 794 720 795 721 //flag all pixels as unused 796 722 for (int k = 0; k < NPIX; k++) 797 mBuffer[i].fEvent->StartPix[k] = -1;723 evtCtrl[i].fEvent->StartPix[k] = -1; 798 724 799 725 //flag all TMark as unused 800 726 for (int k = 0; k < NTMARK; k++) 801 mBuffer[i].fEvent->StartTM[k] = -1;802 803 mBuffer[i].fEvent->NumBoards = 0;804 mBuffer[i].fEvent->PCTime = mBuffer[i].pcTime[0];805 mBuffer[i].fEvent->PCUsec = mBuffer[i].pcTime[1];727 evtCtrl[i].fEvent->StartTM[k] = -1; 728 729 evtCtrl[i].fEvent->NumBoards = 0; 730 evtCtrl[i].fEvent->PCTime = evtCtrl[i].pcTime[0]; 731 evtCtrl[i].fEvent->PCUsec = evtCtrl[i].pcTime[1]; 806 732 } 807 733 … … 825 751 //ETIENNE 826 752 #ifdef THOMAS_MALLOC 827 TGB_free( mBuffer[i].FADhead);753 TGB_free(evtCtrl[i].FADhead); 828 754 #endif 829 755 … … 833 759 834 760 // free (mBuffer[i].fEvent); 835 mBuffer[i].fEvent = NULL;761 evtCtrl[i].fEvent = NULL; 836 762 837 763 // free (mBuffer[i].FADhead); 838 mBuffer[i].FADhead = NULL;764 evtCtrl[i].FADhead = NULL; 839 765 840 766 // free (mBuffer[i].buffer); … … 842 768 //END ETIENNE 843 769 // headmem = NBOARDS * sizeof (PEVNT_HEADER); 844 mBuffer[i].evNum = mBuffer[i].nRoi = -1;845 mBuffer[i].runNum = 0;770 evtCtrl[i].evNum = evtCtrl[i].nRoi = -1; 771 evtCtrl[i].runNum = 0; 846 772 847 773 #ifdef ETIENNE_MALLOC … … 910 836 { 911 837 factPrintf(kWarn, 601, "%5d skip incomplete evt %8d", 912 mBuffer[id].evNum, id);838 evtCtrl[id].evNum, id); 913 839 914 840 uint64_t report = 0; … … 922 848 str[ik++] = '|'; 923 849 924 const int jb = mBuffer[id].board[ib];850 const int jb = evtCtrl[id].board[ib]; 925 851 if (jb>=0) // data received from that board 926 852 { … … 1053 979 swapEventHeaderBytes(i); 1054 980 1055 memcpy(& mBuffer[evID].FADhead[boardId].start_package_flag,981 memcpy(&evtCtrl[evID].FADhead[boardId].start_package_flag, 1056 982 &rd[i].rBuf->S[0], sizeof(PEVNT_HEADER)); 1057 983 … … 1076 1002 src++; 1077 1003 1078 mBuffer[evID].fEvent->StartPix[pixS] = pixC;1004 evtCtrl[evID].fEvent->StartPix[pixS] = pixC; 1079 1005 1080 1006 const int dest1 = pixS * roi; 1081 memcpy(& mBuffer[evID].fEvent->Adc_Data[dest1],1007 memcpy(&evtCtrl[evID].fEvent->Adc_Data[dest1], 1082 1008 &rd[i].rBuf->S[src], roi * 2); 1083 1009 … … 1094 1020 1095 1021 const int srcT = src - roi; 1096 mBuffer[evID].fEvent->StartTM[tmS] = (pixC + pixR - roi) % 1024;1097 1098 memcpy(& mBuffer[evID].fEvent->Adc_Data[dest2],1022 evtCtrl[evID].fEvent->StartTM[tmS] = (pixC + pixR - roi) % 1024; 1023 1024 memcpy(&evtCtrl[evID].fEvent->Adc_Data[dest2], 1099 1025 &rd[i].rBuf->S[srcT], roi * 2); 1100 1026 } 1101 1027 else 1102 1028 { 1103 mBuffer[evID].fEvent->StartTM[tmS] = -1;1029 evtCtrl[evID].fEvent->StartTM[tmS] = -1; 1104 1030 1105 1031 //ETIENNE because the TM channels are always processed during drs calib, … … 1521 1447 1522 1448 // We have a valid entry, but no memory has yet been allocated 1523 if (evID >= 0 && mBuffer[evID].FADhead == NULL)1449 if (evID >= 0 && evtCtrl[evID].FADhead == NULL) 1524 1450 { 1525 1451 // Try to get memory from the big buffer 1526 mBuffer[evID].FADhead = (PEVNT_HEADER*)TGB_Malloc();1527 if ( mBuffer[evID].FADhead == NULL)1452 evtCtrl[evID].FADhead = (PEVNT_HEADER*)TGB_Malloc(); 1453 if (evtCtrl[evID].FADhead == NULL) 1528 1454 { 1529 1455 // If this works properly, this is a hack which can be removed, or … … 1550 1476 1551 1477 //register event in 'active list (reading)' 1552 mBuffer[evID].evtCtrl_idx = evtCtrl_lastPtr;1553 1554 evtCtrl[evtCtrl_lastPtr].mBuffer_idx = evID;1555 evtCtrl[evtCtrl_lastPtr].evtStat = 0;1478 //mBuffer[evID].evtCtrl_idx = evtCtrl_lastPtr; 1479 1480 //evtCtrl[evtCtrl_lastPtr].mBuffer_idx = evID; 1481 //evtCtrl[evtCtrl_lastPtr].evtStat = 0; 1556 1482 //evtCtrl[evtCtrl.lastPtr].pcTime = g_actTime; 1557 1483 1558 evtCtrl_lastPtr++;1559 evtCtrl_lastPtr %= MAX_EVT * MAX_RUN;1484 //evtCtrl_lastPtr++; 1485 //evtCtrl_lastPtr %= MAX_EVT * MAX_RUN; 1560 1486 } 1561 1487 … … 1579 1505 } 1580 1506 1581 if ( mBuffer[evID].board[board] != -1)1507 if (evtCtrl[evID].board[board] != -1) 1582 1508 { 1583 1509 factPrintf(kWarn, 501, "Got event %5d from board %3d (i=%3d, len=%5d) twice: Starts with %3d %3d - ends with %3d %3d", … … 1594 1520 // now we have stored a new board contents into Event structure 1595 1521 1596 mBuffer[evID].fEvent->NumBoards++; 1597 mBuffer[evID].board[board] = board; 1598 mBuffer[evID].nBoard++; 1599 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; 1522 evtCtrl[evID].fEvent->NumBoards++; 1523 evtCtrl[evID].board[board] = board; 1524 evtCtrl[evID].nBoard++; 1525 evtCtrl[evID].evtStat = evtCtrl[evID].nBoard; 1604 1526 1605 1527 // have we already reported first (partial) event of this run ??? 1606 if ( mBuffer[evID].nBoard==1 && mBuffer[evID].runNum != actrun)1528 if (evtCtrl[evID].nBoard==1 && evtCtrl[evID].runNum != actrun) 1607 1529 { 1608 1530 // Signal the fadctrl that a new run has been started 1609 gotNewRun( mBuffer[evID].runNum, NULL);1531 gotNewRun(evtCtrl[evID].runNum, NULL); 1610 1532 1611 1533 factPrintf(kInfo, 1, "gotNewRun called, prev run %d, new run %d, event %d", 1612 actrun, mBuffer[evID].runNum, mBuffer[evID].evNum);1534 actrun, evtCtrl[evID].runNum, evtCtrl[evID].evNum); 1613 1535 1614 1536 for (int j=0; j<MAX_RUN; j++) … … 1621 1543 // We got the first part of this event, so this is 1622 1544 // the number of events we expect for this run 1623 if (runCtrl[j].runId== mBuffer[evID].runNum)1545 if (runCtrl[j].runId==evtCtrl[evID].runNum) 1624 1546 runCtrl[j].lastEvt++; 1625 1547 } 1626 1548 1627 1549 // Change 'actrun' the the new runnumber 1628 actrun = mBuffer[evID].runNum;1550 actrun = evtCtrl[evID].runNum; 1629 1551 } 1630 1552 1631 1553 // event not yet complete 1632 if ( mBuffer[evID].nBoard < actBoards)1554 if (evtCtrl[evID].nBoard < actBoards) 1633 1555 continue; 1634 1556 … … 1643 1565 1644 1566 // Flag that the event is ready for processing 1645 evtCtrl[ iDx].evtStat = 99;1567 evtCtrl[evID].evtStat = 99; 1646 1568 1647 1569 } // end for loop over all sockets … … 1662 1584 for (int k0=evtCtrl_frstPtr; k0!=evtCtrl_lastPtr; k0++, k0 %= MAX_EVT*MAX_RUN) 1663 1585 { 1586 /* 1664 1587 if (k0==evtCtrl_frstPtr && evtCtrl[k0].evtStat<0) 1665 1588 { … … 1669 1592 // Continue because evtCtrl.evtStat[k0] must be <0 1670 1593 continue; 1671 } 1594 }*/ 1672 1595 1673 1596 // Check the more likely case first: incomplete events … … 1677 1600 1678 1601 // Event has not yet timed out or was reported already 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)1602 const int id = k0;//vtCtrl[k0].mBuffer_idx; 1603 1604 if (evtCtrl[k0].evtStat>=90 || evtCtrl[id].pcTime[0]/*evtCtrl[k0].lastRecv*/>=g_actTime - 30) 1682 1605 continue; 1683 1606 … … 1698 1621 if (evtCtrl[k0].evtStat==0 || evtCtrl[k0].evtStat >= 9000) 1699 1622 { 1700 const int id = evtCtrl[k0].mBuffer_idx;1623 const int id = k0;//evtCtrl[k0].mBuffer_idx; 1701 1624 #ifdef EVTDEBUG 1702 factPrintf(kDebug, -1, "%5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard);1625 factPrintf(kDebug, -1, "%5d free event buffer, nb=%3d", evtCtrl[id].evNum, evtCtrl[id].nBoard); 1703 1626 #endif 1704 1627 mBufFree (id); //event written--> free memory 1705 1628 evtCtrl[k0].evtStat = -1; 1629 1630 if (k0==evtCtrl_frstPtr) 1631 { 1632 evtCtrl_frstPtr++; 1633 evtCtrl_frstPtr %= MAX_EVT * MAX_RUN; 1634 } 1635 else 1636 factPrintf(kDebug, -1, "Freed a non-first slot"); 1637 1638 1706 1639 gj.evtWrite++; 1707 1640 gj.rateWrite++; … … 1819 1752 if (evtCtrl[k0].evtStat > minclear) 1820 1753 { 1821 const int id = evtCtrl[k0].mBuffer_idx;1754 const int id = k0;//evtCtrl[k0].mBuffer_idx; 1822 1755 #ifdef EVTDEBUG 1823 factPrintf(kDebug, -1, "ev %5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard);1756 factPrintf(kDebug, -1, "ev %5d free event buffer, nb=%3d", evtCtrl[id].evNum, evtCtrl[id].nBoard); 1824 1757 #endif 1825 1758 mBufFree (id); //event written--> free memory 1826 1759 evtCtrl[k0].evtStat = -1; 1760 1761 if (k0==evtCtrl_frstPtr) 1762 { 1763 evtCtrl_frstPtr++; 1764 evtCtrl_frstPtr %= MAX_EVT * MAX_RUN; 1765 } 1766 else 1767 factPrintf(kDebug, -1, "Freed a non-first slot"); 1827 1768 } 1828 1769 else … … 1830 1771 numclear++; //writing is still ongoing... 1831 1772 1773 /* 1832 1774 if (k0 == evtCtrl_frstPtr && evtCtrl[k0].evtStat < 0) 1833 1775 { 1834 1776 evtCtrl_frstPtr++; 1835 1777 evtCtrl_frstPtr %= MAX_EVT * MAX_RUN; 1836 } 1778 }*/ 1837 1779 } 1838 1780 … … 1903 1845 if (gi_resetR<=1) 1904 1846 { 1905 const int id = evtCtrl[k0].mBuffer_idx;1906 1907 jret = subProcEvt(threadID, mBuffer[id].FADhead,1908 mBuffer[id].fEvent, NULL/*mBuffer[id].buffer*/);1847 const int id = k0;//evtCtrl[k0].mBuffer_idx; 1848 1849 jret = subProcEvt(threadID, evtCtrl[id].FADhead, 1850 evtCtrl[id].fEvent, NULL/*mBuffer[id].buffer*/); 1909 1851 1910 1852 … … 2005 1947 //-------- it is better to open the run already here, so call can be used to initialize 2006 1948 //-------- buffers etc. needed to interprete run (e.g. DRS calibration) 2007 const int id = evtCtrl[k0].mBuffer_idx;2008 2009 const uint32_t irun = mBuffer[id].runNum;2010 const int32_t ievt = mBuffer[id].evNum;1949 const int id = k0;//evtCtrl[k0].mBuffer_idx; 1950 1951 const uint32_t irun = evtCtrl[id].runNum; 1952 const int32_t ievt = evtCtrl[id].evNum; 2011 1953 2012 1954 // Find entry in runCtrl which belongs to the event mBuffer[id] … … 2051 1993 actRun.Version = 1; 2052 1994 actRun.RunType = -1; //to be adapted 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;1995 actRun.Nroi = evtCtrl[id].nRoi; //runCtrl[lastRun].roi0; 1996 actRun.NroiTM = evtCtrl[id].nRoiTM; //runCtrl[lastRun].roi8; 1997 actRun.RunTime = evtCtrl[id].pcTime[0]; //runCtrl[lastRun].firstTime; 1998 actRun.RunUsec = evtCtrl[id].pcTime[1]; //runCtrl[lastRun].firstUsec; 2057 1999 actRun.NBoard = NBOARDS; 2058 2000 actRun.NPix = NPIX; 2059 2001 actRun.NTm = NTMARK; 2060 2002 2061 memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS*sizeof(PEVNT_HEADER));2003 memcpy(actRun.FADhead, evtCtrl[id].FADhead, NBOARDS*sizeof(PEVNT_HEADER)); 2062 2004 2063 2005 runCtrl[lastRun].fileHd = runOpen (irun, &actRun, sizeof (actRun)); … … 2126 2068 2127 2069 //and set correct event header ; also check for consistency in event (not yet) 2128 mBuffer[id].fEvent->Roi = mBuffer[id].nRoi;2129 mBuffer[id].fEvent->RoiTM = mBuffer[id].nRoiTM;2130 mBuffer[id].fEvent->EventNum = mBuffer[id].evNum;2131 mBuffer[id].fEvent->TriggerNum = mBuffer[id].trgNum;2132 mBuffer[id].fEvent->TriggerType = mBuffer[id].trgTyp;2133 mBuffer[id].fEvent->Errors[0] = mBuffer[id].Errors[0];2134 mBuffer[id].fEvent->Errors[1] = mBuffer[id].Errors[1];2135 mBuffer[id].fEvent->Errors[2] = mBuffer[id].Errors[2];2136 mBuffer[id].fEvent->Errors[3] = mBuffer[id].Errors[3];2137 mBuffer[id].fEvent->SoftTrig = 0;2070 evtCtrl[id].fEvent->Roi = evtCtrl[id].nRoi; 2071 evtCtrl[id].fEvent->RoiTM = evtCtrl[id].nRoiTM; 2072 evtCtrl[id].fEvent->EventNum = evtCtrl[id].evNum; 2073 evtCtrl[id].fEvent->TriggerNum = evtCtrl[id].trgNum; 2074 evtCtrl[id].fEvent->TriggerType = evtCtrl[id].trgTyp; 2075 evtCtrl[id].fEvent->Errors[0] = evtCtrl[id].Errors[0]; 2076 evtCtrl[id].fEvent->Errors[1] = evtCtrl[id].Errors[1]; 2077 evtCtrl[id].fEvent->Errors[2] = evtCtrl[id].Errors[2]; 2078 evtCtrl[id].fEvent->Errors[3] = evtCtrl[id].Errors[3]; 2079 evtCtrl[id].fEvent->SoftTrig = 0; 2138 2080 2139 2081 … … 2141 2083 { 2142 2084 // board is not read 2143 if ( mBuffer[id].board[ib] == -1)2085 if (evtCtrl[id].board[ib] == -1) 2144 2086 { 2145 mBuffer[id].FADhead[ib].start_package_flag = 0;2146 mBuffer[id].fEvent->BoardTime[ib] = 0;2087 evtCtrl[id].FADhead[ib].start_package_flag = 0; 2088 evtCtrl[id].fEvent->BoardTime[ib] = 0; 2147 2089 } 2148 2090 else 2149 2091 { 2150 mBuffer[id].fEvent->BoardTime[ib] = mBuffer[id].FADhead[ib].time;2092 evtCtrl[id].fEvent->BoardTime[ib] = evtCtrl[id].FADhead[ib].time; 2151 2093 } 2152 2094 } 2153 2095 2154 const int rc = eventCheck( mBuffer[id].runNum, mBuffer[id].FADhead,2155 mBuffer[id].fEvent);2096 const int rc = eventCheck(evtCtrl[id].runNum, evtCtrl[id].FADhead, 2097 evtCtrl[id].fEvent); 2156 2098 //gi.procTot++; 2157 2099 numProc++; … … 2331 2273 } 2332 2274 2333 const int id = evtCtrl[k0].mBuffer_idx;2334 2335 const uint32_t irun = mBuffer[id].runNum;2336 const int32_t ievt = mBuffer[id].evNum;2275 const int id = k0;//evtCtrl[k0].mBuffer_idx; 2276 2277 const uint32_t irun = evtCtrl[id].runNum; 2278 const int32_t ievt = evtCtrl[id].evNum; 2337 2279 2338 2280 // Find entry in runCtrl which belongs to the event mBuffer[id] … … 2362 2304 actRun.Version = 1; 2363 2305 actRun.RunType = -1; //to be adapted 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;2306 actRun.Nroi = evtCtrl[id].nRoi; //runCtrl[lastRun].roi0; 2307 actRun.NroiTM = evtCtrl[id].nRoiTM; //runCtrl[lastRun].roi8; 2308 actRun.RunTime = evtCtrl[id].pcTime[0];//runCtrl[lastRun].firstTime; 2309 actRun.RunUsec = evtCtrl[id].pcTime[1];//runCtrl[lastRun].firstUsec; 2368 2310 actRun.NBoard = NBOARDS; 2369 2311 actRun.NPix = NPIX; 2370 2312 actRun.NTm = NTMARK; 2371 2313 2372 memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS * sizeof (PEVNT_HEADER));2314 memcpy(actRun.FADhead, evtCtrl[id].FADhead, NBOARDS * sizeof (PEVNT_HEADER)); 2373 2315 2374 2316 runCtrl[lastRun].fileHd = runOpen (irun, &actRun, sizeof (actRun)); … … 2400 2342 if (runCtrl[lastRun].fileId==0) 2401 2343 { 2402 const int rc = runWrite(runCtrl[lastRun].fileHd, mBuffer[id].fEvent,2403 sizeof ( mBuffer[id]));2344 const int rc = runWrite(runCtrl[lastRun].fileHd, evtCtrl[id].fEvent, 2345 sizeof (evtCtrl[id])); 2404 2346 if (rc >= 0) 2405 2347 { -
trunk/FACT++/src/FAD.h
r15465 r15467 209 209 //--------------------------------------------------------------- 210 210 211 211 /* 212 212 typedef struct { 213 213 int32_t evNum ; … … 232 232 233 233 } WRK_DATA ; //internal to eventbuilder 234 234 */ 235 235 236 236 //--------------------------------------------------------------- … … 240 240 // int frstPtr ; //first used index 241 241 // int lastPtr ; //last used index 242 int mBuffer_idx;//[MAX_EVT*MAX_RUN] ; //index of event in mBuffer242 // int mBuffer_idx;//[MAX_EVT*MAX_RUN] ; //index of event in mBuffer 243 243 int evtStat;//[MAX_EVT*MAX_RUN] ; //status of event: 244 244 // -1=empty … … 253 253 //(TO BE REVISED) 254 254 255 // uint32_t lastRecv;//[MAX_EVT*MAX_RUN] ; //time when last action happened 255 // uint32_t lastRecv;//[MAX_EVT*MAX_RUN] ; //time when last action happened 256 257 258 // ==================================================== 259 260 int32_t evNum; 261 int32_t fadNum; 262 int32_t trgNum; 263 int32_t trgTyp; 264 uint32_t runNum; 265 int32_t fadLen; 266 int32_t nBoard; 267 int16_t board[NBOARDS]; 268 int16_t nRoi; 269 int16_t nRoiTM; 270 uint32_t pcTime[2] ; 271 uint8_t Errors[4] ; 272 273 uint32_t evtCtrl_idx; 274 275 EVENT *fEvent ; 276 PEVNT_HEADER *FADhead; // 277 278 // ==================================================== 279 280 256 281 } EVT_CTRL ; //internal to eventbuilder 257 282
Note:
See TracChangeset
for help on using the changeset viewer.