Changeset 16381 for trunk/FACT++
- Timestamp:
- 05/28/13 13:48:41 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilderWrapper.h
r16108 r16381 332 332 return; 333 333 334 fRunInProgress = -1; 335 334 336 if (addr==tcp::endpoint()) 335 337 { 336 DisconnectSlot(i); 338 // In this order 339 g_port[i].sockDef = 0; 340 341 fDimIncomplete.setQuality(0); 342 fDimIncomplete.Update(uint64_t(0)); 337 343 return; 338 344 } … … 351 357 } 352 358 353 void DisconnectSlot(unsigned int i)354 {355 if (i>39)356 return;357 358 g_port[i].sockDef = 0;359 // In this order360 361 fDimIncomplete.setQuality(0);362 fDimIncomplete.Update(uint64_t(0));363 }364 359 void IgnoreSlot(unsigned int i) 365 360 { … … 448 443 } 449 444 450 virtual int CloseOpenFiles() { CloseRunFile(); return 0; }445 virtual int CloseOpenFiles() { CloseRunFile(); fRunInProgress = -1; return 0; } 451 446 452 447 … … 478 473 } 479 474 480 bool runOpen(const shared_ptr<EVT_CTRL2>&evt)481 { 482 const uint32_t night = evt ->runCtrl->night;483 const uint32_t runid = evt ->runNum>0 ? evt->runNum : time(NULL);475 bool runOpen(const EVT_CTRL2 &evt) 476 { 477 const uint32_t night = evt.runCtrl->night; 478 const uint32_t runid = evt.runNum>0 ? evt.runNum : time(NULL); 484 479 485 480 // If there is still an open file: close it … … 489 484 // Keep a copy of the currently valid drs calibration 490 485 // and associate it to the run control structure 491 evt ->runCtrl->calib = shared_ptr<DrsCalibration>(new DrsCalibration(DataCalib::GetCalibration()));486 evt.runCtrl->calib = shared_ptr<DrsCalibration>(new DrsCalibration(DataCalib::GetCalibration())); 492 487 493 488 // FIMXE: Check if file already exists... … … 509 504 // Try to open the file 510 505 FAD::RunDescription desc; 511 desc.name = evt ->runCtrl->runType;512 513 if (!file->Open( *evt, desc))506 desc.name = evt.runCtrl->runType; 507 508 if (!file->Open(evt, desc)) 514 509 return false; 515 510 } … … 532 527 fNumEvts[kTriggerId] = 0; 533 528 fNumEvts[kCurrent] = 0; 534 fDimQueue3. post(make_pair(Time(), fNumEvts));529 fDimQueue3.emplace(Time(), fNumEvts); 535 530 536 531 fDimWriteStats.FileOpened(file->GetFileName()); … … 543 538 } 544 539 545 bool runWrite(const shared_ptr<EVT_CTRL2>&e)546 { 547 const EVENT &evt = *e ->fEvent;540 bool runWrite(const EVT_CTRL2 &e) 541 { 542 const EVENT &evt = *e.fEvent; 548 543 if (!fFile->WriteEvt(evt)) 549 544 return false; … … 558 553 if (newt>oldt+boost::posix_time::seconds(1)) 559 554 { 560 fDimQueue3. post(make_pair(Time(), fNumEvts));555 fDimQueue3.emplace(Time(), fNumEvts); 561 556 oldt = newt; 562 557 } … … 594 589 595 590 // Time for update events before time for update runs 596 fDimQueue3. post(make_pair(Time(), fNumEvts));591 fDimQueue3.emplace(Time(), fNumEvts); 597 592 UpdateRuns(); 598 593 … … 609 604 } 610 605 611 bool eventCheck(const shared_ptr<EVT_CTRL2> &evt) 612 { 613 const PEVNT_HEADER *fadhd = evt->FADhead.get(); 614 const EVENT *event = evt->fEvent; 606 bool eventCheck(const EVT_CTRL2 &evt) 607 { 608 const EVENT *event = evt.fEvent; 615 609 616 610 const array<uint16_t,2> roi = {{ event->Roi, event->RoiTM }}; … … 618 612 if (roi!=fVecRoi) 619 613 { 620 fDimQueue4. post(make_pair(Time(), roi));614 fDimQueue4.emplace(Time(), roi); 621 615 fVecRoi = roi; 622 616 } 623 617 624 const FAD::EventHeader *beg = reinterpret_cast<const FAD::EventHeader*>( fadhd);625 const FAD::EventHeader *end = reinterpret_cast<const FAD::EventHeader*>( fadhd)+40;618 const FAD::EventHeader *beg = reinterpret_cast<const FAD::EventHeader*>(evt.FADhead); 619 const FAD::EventHeader *end = reinterpret_cast<const FAD::EventHeader*>(evt.FADhead)+40; 626 620 627 621 // FIMXE: Compare with target configuration … … 696 690 } 697 691 692 map<float,array<float, 1440*4>> evtList; 693 698 694 void applyCalib(const shared_ptr<EVT_CTRL2> &evt) 699 695 { 700 const PEVNT_HEADER *fadhd = evt->FADhead.get(); 701 const EVENT *event = evt->fEvent; 696 const EVENT *event = evt->fEvent; 697 const int16_t *start = event->StartPix; 698 699 // Get the reference to the run associated information 700 RUN_CTRL2 &run = *evt->runCtrl; 702 701 703 702 // Currently we send any event no matter what its trigger id is... 704 703 // To be changed. 705 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 706 709 Time newt; 707 708 static int skip = 0;709 710 // FIXME: Only send events if the have newer run-numbers711 if (newt<oldt+boost::posix_time::milliseconds(skip>0 ? 100 : 1000)) 712 return;713 oldt = newt;714 715 // Workaround to find a valid header..... 716 const FAD::EventHeader *beg = reinterpret_cast<const FAD::EventHeader*>(fadhd);717 const FAD::EventHeader *end = reinterpret_cast<const FAD::EventHeader*>(fadhd)+40;718 719 // FIMXE: Compare with target configuration720 const FAD::EventHeader *ptr=beg;721 for (; ptr!=end; ptr++)722 {723 if (ptr->fStartDelimiter!=0) 724 break;725 }726 if (ptr==end)727 return;728 729 730 vector<char> data(sizeof(EVENT)+event->Roi*sizeof(float)*(1440+160)); 731 memcpy(data.data(), event, sizeof(EVENT));732 733 float *vec = reinterpret_cast<float*>(data.data()+sizeof(EVENT)); 734 735 evt->runCtrl->calib->Apply(vec, event->Adc_Data, event->StartPix, event->Roi);736 DrsCalibrate::RemoveSpikes(vec, event->Roi);737 738 vector<float> data2(1440*4); // Mean, RMS, Max, Pos739 const double max = DrsCalibrate::GetPixelStats(data2.data(), vec, event->Roi);740 741 // Maximum above roughly 5pe742 if (ptr->IsTriggerPhys() && max<100 && skip<10) 743 {744 skip++;745 return;746 }747 748 skip = 0;749 750 fDimRawData.setQuality(ptr->fTriggerType);751 fDimRawData.Update(data);752 753 fDimEventData.setQuality(ptr->fTriggerType);754 fDimEventData.Update(data2);755 756 }757 758 /*759 void SendFeedbackData(PEVNT_HEADER *fadhd, EVENT *event) 760 {761 if (!DataCalib::IsValid())762 return;763 764 // Workaround to find a valid header..... 765 const FAD::EventHeader *beg = reinterpret_cast<FAD::EventHeader*>(fadhd);766 const FAD::EventHeader *end = reinterpret_cast<FAD::EventHeader*>(fadhd)+40;767 768 // FIMXE: Compare with target configuration769 770 const FAD::EventHeader *ptr=beg; 771 for (; ptr<end; ptr++)772 {773 if (ptr->fStartDelimiter!=0) 774 break;775 }776 777 if (ptr==end)778 return;779 780 if (!ptr->HasTriggerLPext() && !ptr->HasTriggerLPint())781 return;782 783 vector<float> data(event->Roi*1440);784 DataCalib::Apply(data.data(), event->Adc_Data, event->StartPix, event->Roi); 785 786 DrsCalibrate::RemoveSpikes(data.data(), event->Roi);787 788 vector<float> data2(1440); // Mean, RMS, Max, Pos, first, last789 DrsCalibrate::GetPixelMax(data2.data(), data.data(), event->Roi, 0, event->Roi-1);790 791 fDimFeedbackData.Update(data2);792 }793 */794 795 bool IsRunWaiting() // const710 if (newt>=oldt+boost::posix_time::milliseconds(100)) 711 { 712 // Keep the last update time 713 oldt = newt; 714 715 // ------------------- Copy event data to new memory -------------------- 716 // (to make it thread safe; a static buffer might improve memory handling) 717 const uint16_t roi = event->Roi; 718 719 // ------------------- Apply full DRS calibration ------------------------ 720 // (Is that necessray, or would a simple offset correct do well already?) 721 722 // There seems to be a problem using std::array... maybe the size is too big? 723 // array<float, (1440+160)*1024> vec2; 724 vector<float> vec((1440+160)*roi); 725 run.calib->Apply(vec.data(), event->Adc_Data, start, roi); 726 727 // ------------------- Appy DRS-step correction -------------------------- 728 for (auto it=run.prevStart.begin(); it!=run.prevStart.end(); it++) 729 { 730 DrsCalibrate::CorrectStep(vec.data(), 1440, roi, it->data(), start, roi+10); 731 DrsCalibrate::CorrectStep(vec.data(), 1440, roi, it->data(), start, 3); 732 } 733 734 // ------------------------- Remove spikes -------------------------------- 735 DrsCalibrate::RemoveSpikes3(vec.data(), roi); 736 737 // -------------- 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; 742 vector<char> data1(sizeof(EVENT)+vec.size()*sizeof(float)); 743 memcpy(data1.data(), event, sizeof(EVENT)); 744 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); 751 } 752 753 // ------------------------- Basic statistics ----------------------------- 754 DrsCalibrate::SlidingAverage(vec.data(), roi, 10); 755 756 array<float, 1440*4> stats; // Mean, RMS, Max, Pos 757 const double max = DrsCalibrate::GetPixelStats(stats.data(), vec.data(), roi); 758 759 // ------------------ 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(); 775 } 776 777 // === SendFeedbackData(PEVNT_HEADER *fadhd, EVENT *event) 778 // 779 // if (!ptr->HasTriggerLPext() && !ptr->HasTriggerLPint()) 780 // return; 781 // 782 // vector<float> data2(1440); // Mean, RMS, Max, Pos, first, last 783 // DrsCalibrate::GetPixelMax(data2.data(), data.data(), event->Roi, 0, event->Roi-1); 784 // 785 // fDimFeedbackData.Update(data2); 786 } 787 788 // Keep the start cells of the last five events for further corrections 789 // As a performance improvement we could also just store the 790 // pointers to the last five events... 791 // 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(); 796 } 797 798 bool IsRunWaiting() 796 799 { 797 800 const lock_guard<mutex> lock(mtx_newrun); … … 803 806 return fRunNumber; 804 807 } 805 806 /*807 bool IsRunFileOpen()808 {809 return fLastOpened==fRunNumber-1;810 }*/811 808 812 809 bool IncreaseRunNumber(uint32_t run) … … 953 950 void factStat(const GUI_STAT &stat) 954 951 { 955 fDimQueue1. post(make_pair(Time(), stat));952 fDimQueue1.emplace(Time(), stat); 956 953 } 957 954 … … 1212 1209 fNumConnected = con; 1213 1210 1214 fDimQueue2. post(make_tuple(Time(), changed, h));1211 fDimQueue2.emplace(Time(), changed, h); 1215 1212 } 1216 1213 }; … … 1219 1216 1220 1217 // ----------- Event builder callbacks implementation --------------- 1221 bool runOpen(const shared_ptr<EVT_CTRL2>&evt)1218 bool runOpen(const EVT_CTRL2 &evt) 1222 1219 { 1223 1220 return EventBuilderWrapper::This->runOpen(evt); 1224 1221 } 1225 1222 1226 bool runWrite(const shared_ptr<EVT_CTRL2>&evt)1223 bool runWrite(const EVT_CTRL2 &evt) 1227 1224 { 1228 1225 return EventBuilderWrapper::This->runWrite(evt); … … 1234 1231 } 1235 1232 1236 bool eventCheck(const shared_ptr<EVT_CTRL2>&evt)1233 bool eventCheck(const EVT_CTRL2 &evt) 1237 1234 { 1238 1235 return EventBuilderWrapper::This->eventCheck(evt);
Note:
See TracChangeset
for help on using the changeset viewer.