Changeset 16694
- Timestamp:
- 06/04/13 19:34:48 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilderWrapper.h
r16619 r16694 99 99 Queue<vector<char>> fQueueRawData; 100 100 Queue<tuple<Time,uint32_t,array<float,1440*4>>> fQueueEventData; 101 Queue<tuple<Time, array<uint32_t,40>, array<int16_t,160>>> fQueueTempRefClk; 101 102 102 103 string fPath; … … 206 207 "DNA of FAD boards" 207 208 "|DNA[hex]:Hex identifier of each FAD board"), 208 fDimTemperature ("FAD_CONTROL/TEMPERATURE", " F:82",209 fDimTemperature ("FAD_CONTROL/TEMPERATURE", "S:1;F:160", 209 210 "FADs temperatures" 210 "|temp[deg. C]:0 global min, 1-40 min, 41 global max, 42-81 max"), 211 "|cnt[uint16]:Counter of averaged values", 212 "|temp[deg C]:average temp of all DRS chips"), 211 213 fDimPrescaler ("FAD_CONTROL/PRESCALER", "S:42", 212 214 "Trigger generator prescaler of fad boards" 213 215 "|prescaler[int]:Trigger generator prescaler value, for each board"), 214 fDimRefClock ("FAD_CONTROL/REFERENCE_CLOCK", " I:42",216 fDimRefClock ("FAD_CONTROL/REFERENCE_CLOCK", "S:1;F:40", 215 217 "Reference clock of FAD boards" 216 "|refClocks[t]:ref clocks of FAD boards. 40=min, 41=max"), 218 "|cnt[uint16]:Counter of averaged values" 219 "|clk[Hz]:Averaged clock of ref clocks of FAD boards"), 217 220 fDimRoi ("FAD_CONTROL/REGION_OF_INTEREST", "S:2", "roi:|roi_rm:"), 218 221 fDimDac ("FAD_CONTROL/DAC", "S:336", … … 243 246 fQueueRawData( std::bind(&EventBuilderWrapper::UpdateDimRawData, this, placeholders::_1)), 244 247 fQueueEventData( std::bind(&EventBuilderWrapper::UpdateDimEventData, this, placeholders::_1)), 248 fQueueTempRefClk( std::bind(&EventBuilderWrapper::UpdateDimTempRefClk, this, placeholders::_1)), 245 249 fNightAsInt(0), fRunInProgress(-1), 246 250 fMaxEvent(make_pair(-FLT_MAX, array<float,1440*4>())) … … 641 645 } 642 646 647 void UpdateDimTempRefClk(const tuple<Time, array<uint32_t,40>, array<int16_t,160>> &dat) 648 { 649 const Time &tm = get<0>(dat); 650 651 const array<uint32_t,40> &clk = get<1>(dat); 652 const array<int16_t,160> &tmp = get<2>(dat); 653 654 // --------------- RefClock --------------- 655 656 // history, add current data to history 657 static list<pair<Time,array<uint32_t,40>>> listclk; 658 listclk.emplace_back(tm, clk); 659 660 // --------------- Temperatures --------------- 661 662 // history, add current data to history 663 static list<pair<Time,array<int16_t,160>>> listtmp; 664 listtmp.emplace_back(tm, tmp); 665 666 // ========== Update dim services once a second ========= 667 668 static Time oldt(boost::date_time::neg_infin); 669 Time newt; 670 671 if (newt<oldt+boost::posix_time::seconds(1)) 672 return; 673 674 oldt = newt; 675 676 // --------------- RefClock --------------- 677 678 // remove expired data from history 679 while (1) 680 { 681 auto it=listclk.begin(); 682 if (it==listclk.end() || it->first+boost::posix_time::seconds(1)>tm) 683 break; 684 listclk.pop_front(); 685 } 686 687 // Structure for dim service 688 struct Clock 689 { 690 uint16_t num; 691 float val[40]; 692 Clock() { memset(this, 0, sizeof(Clock)); } 693 } __attribute__((__packed__)); 694 695 // Calculate average and fll structure 696 vector<uint16_t> clknum(40); 697 698 Clock avgclk; 699 avgclk.num = listclk.size(); 700 for (auto it=listclk.begin(); it!=listclk.end(); it++) 701 for (int i=0; i<40; i++) 702 if (it->second[i]!=UINT32_MAX) 703 { 704 avgclk.val[i] += it->second[i]; 705 clknum[i]++; 706 } 707 for (int i=0; i<40; i++) 708 avgclk.val[i] *= 2.048/clknum[i]; 709 710 // Update dim service 711 fDimRefClock.setData(avgclk); 712 fDimRefClock.Update(tm); 713 714 // --------------- Temperatures --------------- 715 716 // remove expired data from history 717 while (1) 718 { 719 auto it=listtmp.begin(); 720 if (it==listtmp.end() || it->first+boost::posix_time::seconds(5)>tm) 721 break; 722 listtmp.pop_front(); 723 } 724 725 // Structure for dim service 726 struct Temp 727 { 728 uint16_t num; 729 float val[160]; 730 Temp() { memset(this, 0, sizeof(Temp)); } 731 } __attribute__((__packed__)); 732 733 // Calculate average and fll structure 734 vector<uint32_t> tmpnum(160); 735 736 Temp avgtmp; 737 avgtmp.num = listtmp.size(); 738 for (auto it=listtmp.begin(); it!=listtmp.end(); it++) 739 for (int i=0; i<160; i++) 740 if (it->second[i]!=INT16_MIN) 741 { 742 avgtmp.val[i] += it->second[i]; 743 tmpnum[i]++; 744 } 745 for (int i=0; i<160; i++) 746 avgtmp.val[i] /= tmpnum[i]*16; 747 748 // Update dim service 749 fDimTemperature.setData(avgtmp); 750 fDimTemperature.Update(tm); 751 } 752 643 753 bool eventCheck(const EVT_CTRL2 &evt) 644 754 { 645 755 const EVENT *event = evt.fEvent; 646 756 757 const Time tm(evt.time); 758 647 759 const array<uint16_t,2> roi = {{ event->Roi, event->RoiTM }}; 648 760 649 761 if (roi!=fVecRoi) 650 762 { 651 fQueueRoi.emplace( Time(), roi);763 fQueueRoi.emplace(tm, roi); 652 764 fVecRoi = roi; 653 765 } … … 657 769 658 770 // FIMXE: Compare with target configuration 771 772 // Copy data to array 773 array<uint32_t,40> clk; 774 array<int16_t,160> tmp; 775 776 for (int i=0; i<40; i++) 777 clk[i] = UINT32_MAX; 778 779 for (int i=0; i<160; i++) 780 tmp[i] = INT16_MIN; 781 782 //fill(clk.data(), clk.data()+ 40, UINT32_MAX); 783 //fill(tmp.data(), tmp.data()+160, INT16_MIN); 659 784 660 785 for (const FAD::EventHeader *ptr=beg; ptr!=end; ptr++) … … 667 792 continue; 668 793 } 794 795 clk[ptr->Id()] = ptr->fFreqRefClock; 796 for (int i=0; i<4; i++) 797 tmp[ptr->Id()*4+i] = ptr->fTempDrs[i]; 669 798 670 799 if (beg->fStatus != ptr->fStatus) … … 700 829 } 701 830 831 // FIXME: Check with first event! 702 832 if (beg->fAdcClockPhaseShift != ptr->fAdcClockPhaseShift) 703 833 { … … 706 836 } 707 837 838 // FIXME: Check with first event! 708 839 if (memcmp(beg->fDac, ptr->fDac, sizeof(beg->fDac))) 709 840 { … … 718 849 } 719 850 } 851 852 fQueueTempRefClk.emplace(tm, clk, tmp); 720 853 721 854 // check REFCLK_frequency … … 1171 1304 Update(fDimDac, dacs, t); 1172 1305 } 1173 1174 // -----------1175 1176 static Time oldt(boost::date_time::neg_infin);1177 Time newt;1178 1179 if (newt>oldt+boost::posix_time::seconds(1))1180 {1181 oldt = newt;1182 1183 // --- RefClock1184 1185 const array<uint32_t,42> clk = Compare(&fVecHeader[0], &fVecHeader[0].fFreqRefClock);1186 Update(fDimRefClock, clk, t);1187 1188 // --- Temperatures1189 1190 const array<int16_t,42> tmp[4] =1191 {1192 Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[0]), // 0-39:val, 40:min, 41:max1193 Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[1]), // 0-39:val, 40:min, 41:max1194 Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[2]), // 0-39:val, 40:min, 41:max1195 Compare(&fVecHeader[0], &fVecHeader[0].fTempDrs[3]) // 0-39:val, 40:min, 41:max1196 };1197 1198 vector<int16_t> data;1199 data.reserve(82);1200 data.push_back(tmp[0][40]); // min: 01201 data.insert(data.end(), tmp[0].data(), tmp[0].data()+40); // val: 1-401202 data.push_back(tmp[0][41]); // max: 411203 data.insert(data.end(), tmp[0].data(), tmp[0].data()+40); // val: 42-811204 1205 for (int j=1; j<=3; j++)1206 {1207 const array<int16_t,42> &ref = tmp[j];1208 1209 // Gloabl min1210 if (ref[40]<data[0]) // 40=min1211 data[0] = ref[40];1212 1213 // Global max1214 if (ref[41]>data[41]) // 41=max1215 data[41] = ref[41];1216 1217 for (int i=0; i<40; i++)1218 {1219 // min per board1220 if (ref[i]<data[i+1]) // data: 1-401221 data[i+1] = ref[i]; // ref: 0-391222 1223 // max per board1224 if (ref[i]>data[i+42]) // data: 42-811225 data[i+42] = ref[i]; // ref: 0-391226 }1227 }1228 1229 vector<float> deg(82); // 0: global min, 1-40: min1230 for (int i=0; i<82; i++) // 41: global max, 42-81: max1231 deg[i] = data[i]/16.;1232 1233 fDimTemperature.setData(deg.data(), 82*sizeof(float));1234 fDimTemperature.Update(t);1235 }1236 1306 } 1237 1307
Note:
See TracChangeset
for help on using the changeset viewer.