Changeset 16530
- Timestamp:
- 05/31/13 14:31:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilderWrapper.h
r16469 r16530 93 93 DimDescribedService fDimIncomplete; 94 94 95 Queue<pair<Time,GUI_STAT>> fDimQueue1; 96 Queue<tuple<Time,bool,FAD::EventHeader>> fDimQueue2; 97 Queue<pair<Time,array<uint32_t,4>>> fDimQueue3; 98 Queue<pair<Time,array<uint16_t,2>>> fDimQueue4; 95 Queue<pair<Time,GUI_STAT>> fQueueStatistics1; 96 Queue<tuple<Time,bool,FAD::EventHeader>> fQueueProcHeader; 97 Queue<pair<Time,array<uint32_t,4>>> fQueueEvents; 98 Queue<pair<Time,array<uint16_t,2>>> fQueueRoi; 99 Queue<vector<char>> fQueueRawData; 100 Queue<tuple<Time,uint32_t,array<float,1440*4>>> fQueueEventData; 99 101 100 102 string fPath; … … 104 106 105 107 array<uint16_t,2> fVecRoi; 108 pair<float,array<float, 1440*4>> fMaxEvent; // Maximum event from applyCalib 106 109 107 110 protected: … … 224 227 "|roi:Region of interest of secondary baseline" 225 228 "|run:Run numbers of DRS runs (0=none)"), 226 fDimStatistics1 ("FAD_CONTROL/STATISTICS1", "I: 3;I:5;X:4;I:3;I:3;I:40;I:1;I:2;C:40;I:40;X:40",229 fDimStatistics1 ("FAD_CONTROL/STATISTICS1", "I:5;X:3;I:1;I:2;C:40;I:40;X:40", 227 230 "Event Builder status for GUI display" 228 "|threadInfo[int]:Number of read, proc and writes" 229 "|bufferInfo[int]:Events in buffer, incomp., comp., tot., max past cycle, total" 230 "|memInfo[int]:total buf. mem, used mem, max used, max past cycle" 231 "|EvtCnt[int]:Number of events skipped, written, with errors" 232 "|badRoi[int]:Num boards with wrong ROI in event, run or board" 233 "|badRoiBoard[int]:Num boards with wrong ROI" 231 "|bufferInfo[int]:Events in buffer, incomp., comp., write, proc., tot." 232 "|memInfo[int]:total mem allocated, used mem, max memory" 234 233 "|deltaT[ms]:Time in ms for rates" 235 234 "|rateNew[int]:Number of new start events received" … … 240 239 fDimIncomplete("FAD_CONTROL/INCOMPLETE", "X:1", "|incomplete[bits]:One bit per board"), 241 240 // It is important to instantiate them after the DimServices 242 fDimQueue1(std::bind(&EventBuilderWrapper::factStatSend, this, placeholders::_1)), 243 fDimQueue2(std::bind(&EventBuilderWrapper::procHeader, this, placeholders::_1)), 244 fDimQueue3(std::bind(&EventBuilderWrapper::updateEvents, this, placeholders::_1)), 245 fDimQueue4(std::bind(&EventBuilderWrapper::updateRoi, this, placeholders::_1)), 246 fNightAsInt(0), fRunInProgress(-1) 241 fQueueStatistics1(std::bind(&EventBuilderWrapper::UpdateDimStatistics1, this, placeholders::_1)), 242 fQueueProcHeader( std::bind(&EventBuilderWrapper::procHeader, this, placeholders::_1)), 243 fQueueEvents( std::bind(&EventBuilderWrapper::UpdateDimEvents, this, placeholders::_1)), 244 fQueueRoi( std::bind(&EventBuilderWrapper::UpdateDimRoi, this, placeholders::_1)), 245 fQueueRawData( std::bind(&EventBuilderWrapper::UpdateDimRawData, this, placeholders::_1)), 246 fQueueEventData( std::bind(&EventBuilderWrapper::UpdateDimEventData, this, placeholders::_1)), 247 fNightAsInt(0), fRunInProgress(-1), 248 fMaxEvent(make_pair(-FLT_MAX, array<float,1440*4>())) 247 249 { 248 250 if (This) … … 467 469 shared_ptr<DataProcessorImp> fFile; 468 470 469 void updateEvents(const pair<Time,array<uint32_t,4>> &stat)471 void UpdateDimEvents(const pair<Time,array<uint32_t,4>> &stat) 470 472 { 471 473 fDimEvents.setData(stat.second.data(), sizeof(uint32_t)*4); … … 485 487 // and associate it to the run control structure 486 488 evt.runCtrl->calib = shared_ptr<DrsCalibration>(new DrsCalibration(DataCalib::GetCalibration())); 489 490 /* 491 evt.runCtrl->calibInt.resize(1024*1440); 492 493 const int16_t *off = evt.runCtrl->zcalib.data(); 494 int32_t *ptr = evt.runCtrl->calib.data(); 495 496 const uint64_t num = evt.runCtrl->calib.fNumOffset; 497 for (int i=0; i<1024*1440) 498 ptr[i] = off[i]/num; 499 */ 487 500 488 501 // FIMXE: Check if file already exists... … … 527 540 fNumEvts[kTriggerId] = 0; 528 541 fNumEvts[kCurrent] = 0; 529 f DimQueue3.emplace(Time(), fNumEvts);542 fQueueEvents.emplace(Time(), fNumEvts); 530 543 531 544 fDimWriteStats.FileOpened(file->GetFileName()); … … 540 553 bool runWrite(const EVT_CTRL2 &e) 541 554 { 555 /* 556 const size_t size = sizeof(EVENT)+1440*(evt.Roi+evt.RoiTM)*2; 557 vector evt(e.fEvent, e.fEvent+size); 558 559 const EVENT &evt = *reinterpret_cast<EVENT*>(evt.data()); 560 561 int16_t *val = evt.Adc_Data; 562 const int16_t *off = e.runCtrl->zcalib.data(); 563 for (const int16_t *start=evt.StartPix; start<evt.StartPix+1440; val+=1024, off+=1024, start++) 564 { 565 if (*start<0) 566 continue; 567 568 for (size_t i=0; i<roi; i++) 569 val[i] -= offset[(*start+i)%1024]; 570 }*/ 571 542 572 const EVENT &evt = *e.fEvent; 543 573 if (!fFile->WriteEvt(evt)) … … 553 583 if (newt>oldt+boost::posix_time::seconds(1)) 554 584 { 555 f DimQueue3.emplace(Time(), fNumEvts);585 fQueueEvents.emplace(Time(), fNumEvts); 556 586 oldt = newt; 557 587 } … … 589 619 590 620 // Time for update events before time for update runs 591 f DimQueue3.emplace(Time(), fNumEvts);621 fQueueEvents.emplace(Time(), fNumEvts); 592 622 UpdateRuns(); 593 623 … … 598 628 virtual void CloseRun(uint32_t /*runid*/) { } 599 629 600 void updateRoi(const pair<Time, array<uint16_t,2>> &roi)630 void UpdateDimRoi(const pair<Time, array<uint16_t,2>> &roi) 601 631 { 602 632 fDimRoi.setData(roi.second.data(), sizeof(uint16_t)*2); … … 612 642 if (roi!=fVecRoi) 613 643 { 614 f DimQueue4.emplace(Time(), roi);644 fQueueRoi.emplace(Time(), roi); 615 645 fVecRoi = roi; 616 646 } … … 690 720 } 691 721 692 map<float,array<float, 1440*4>> evtList; 693 694 void applyCalib(const shared_ptr<EVT_CTRL2> &evt) 695 { 696 const EVENT *event = evt->fEvent; 722 Time fLastDimRawData; 723 Time fLastDimEventData; 724 725 void UpdateDimRawData(const vector<char> &v) 726 { 727 const EVENT *evt = reinterpret_cast<const EVENT*>(v.data()); 728 729 fDimRawData.setData(v.data()); 730 fDimRawData.setQuality(evt->TriggerType); 731 fDimRawData.Update(Time(evt->PCTime, evt->PCUsec)); 732 } 733 void UpdateDimEventData(const tuple<Time,uint32_t,array<float, 1440*4>> &tup) 734 { 735 fDimEventData.setQuality(get<1>(tup)); 736 fDimEventData.setData(get<2>(tup)); 737 fDimEventData.Update(get<0>(tup)); 738 } 739 740 void applyCalib(const EVT_CTRL2 &evt, const size_t &size) 741 { 742 const EVENT *event = evt.fEvent; 697 743 const int16_t *start = event->StartPix; 698 744 699 745 // Get the reference to the run associated information 700 RUN_CTRL2 &run = *evt->runCtrl; 701 702 // Currently we send any event no matter what its trigger id is... 703 // To be changed. 704 static Time oldt(boost::date_time::neg_infin); 705 706 static uint64_t cnt = 0; 707 708 // In case of a need of more performance this cold be split to several threads 709 Time newt; 710 if (newt>=oldt+boost::posix_time::milliseconds(100)) 711 { 712 // Keep the last update time 713 oldt = newt; 746 RUN_CTRL2 &run = *evt.runCtrl; 747 748 if (size==1) // If there is more than one event waiting (including this one), throw them away 749 { 750 Time now; 714 751 715 752 // ------------------- Copy event data to new memory -------------------- … … 736 773 737 774 // -------------- Update raw data dim sevice (VERY SLOW) ----------------- 738 const Time tm = evt->time; 739 if (++cnt%50==0) // Once every 5s 740 { 741 //array<char,sizeof(EVENT)+(1440+160)*1024*sizeof(float)> data1; 775 if (fQueueRawData.empty() && now>fLastDimRawData+boost::posix_time::seconds(5)) 776 { 742 777 vector<char> data1(sizeof(EVENT)+vec.size()*sizeof(float)); 743 778 memcpy(data1.data(), event, sizeof(EVENT)); 744 779 memcpy(data1.data()+sizeof(EVENT), vec.data(), vec.size()*sizeof(float)); 745 746 // This needs to be decoupled for optimum performance! 747 // Make a queue which does not overfill by maintaining queue size! 748 fDimRawData.setQuality(evt->trgTyp); 749 fDimRawData.setData(data1.data(), sizeof(EVENT)+vec.size()*sizeof(float)); 750 fDimRawData.Update(tm); 780 fQueueRawData.emplace(data1); 781 782 fLastDimRawData = now; 751 783 } 752 784 … … 754 786 DrsCalibrate::SlidingAverage(vec.data(), roi, 10); 755 787 788 // If this is a cosmic event 756 789 array<float, 1440*4> stats; // Mean, RMS, Max, Pos 757 const double max = DrsCalibrate::GetPixelStats(stats.data(), vec.data(), roi); 790 const float max = DrsCalibrate::GetPixelStats(stats.data(), vec.data(), roi); 791 if (evt.trgTyp==0 && max>fMaxEvent.first) 792 fMaxEvent = make_pair(max, stats); 758 793 759 794 // ------------------ Update dim service (statistics) --------------------- 760 if (evt->trgTyp==0) 761 evtList[max] = stats; 762 763 if (cnt%50==0) 764 { 765 if (!evtList.empty()) 766 stats = evtList.rbegin()->second; 767 768 // This needs to be decoupled for optimum performance! 769 // Make a queue which does not overfill by maintaining queue size! 770 fDimEventData.setQuality(evtList.empty() ? evt->trgTyp : 0); 771 fDimEventData.setData(stats.data(), 1440*4*sizeof(float)); 772 fDimEventData.Update(tm); 773 774 evtList.clear(); 795 796 if (fQueueEventData.empty() && now>fLastDimEventData+boost::posix_time::seconds(3)) 797 { 798 fQueueEventData.emplace(evt.time, evt.trgTyp, evt.trgTyp==0 ? fMaxEvent.second : stats); 799 if (evt.trgTyp==0) 800 fMaxEvent.first = -FLT_MAX; 801 802 fLastDimEventData = now; 775 803 } 776 804 … … 790 818 // pointers to the last five events... 791 819 // What if a new run is started? Do we mind? 792 run.prevStart.emplace_front(); 793 memcpy(run.prevStart.front().data(), start, 1440*sizeof(int16_t)); 794 if (run.prevStart.size()>5) 795 run.prevStart.pop_back(); 820 auto &l = run.prevStart; // History for start cells of previous events (for step calibration) 821 822 if (l.size()<5) 823 l.emplace_front(); 824 else 825 { 826 auto it = l.end(); 827 l.splice(l.begin(), l, --it); 828 } 829 830 memcpy(l.front().data(), start, 1440*sizeof(int16_t)); 796 831 } 797 832 … … 942 977 */ 943 978 944 void factStatSend(const pair<Time,GUI_STAT> &stat)979 void UpdateDimStatistics1(const pair<Time,GUI_STAT> &stat) 945 980 { 946 981 fDimStatistics1.setData(&stat.second, sizeof(GUI_STAT)); … … 950 985 void factStat(const GUI_STAT &stat) 951 986 { 952 f DimQueue1.emplace(Time(), stat);987 fQueueStatistics1.emplace(Time(), stat); 953 988 } 954 989 … … 1209 1244 fNumConnected = con; 1210 1245 1211 f DimQueue2.emplace(Time(), changed, h);1246 fQueueProcHeader.emplace(Time(), changed, h); 1212 1247 } 1213 1248 }; … … 1246 1281 } 1247 1282 1248 void applyCalib(const shared_ptr<EVT_CTRL2> &evt)1283 void applyCalib(const EVT_CTRL2 &evt, const size_t &size) 1249 1284 { 1250 EventBuilderWrapper::This->applyCalib(evt );1285 EventBuilderWrapper::This->applyCalib(evt, size); 1251 1286 } 1252 1287 … … 1256 1291 } 1257 1292 1258 void factStat( GUI_STATstat)1293 void factStat(const GUI_STAT &stat) 1259 1294 { 1260 1295 EventBuilderWrapper::This->factStat(stat);
Note:
See TracChangeset
for help on using the changeset viewer.