3 #include "PipelineController.h"
4 #include "BaseController_p.h"
5 #include "ScopeController_p.h"
6 #include "helpers/SyncQueues.h"
7 #include "parameters/Scope.h"
8 #include "helpers/DaqChunk.h"
9 #include "helpers/DaqChunkResonance.h"
10 #include "helpers/ScopeMultiImage.h"
11 #include "scanmodes/PixelmapperBasic.h"
22 std::array<SynchronizedQueue<ScopeMessage<SCOPE_DAQCHUNKPTR_T>>, SCOPE_NAREAS>*
const input_queues;
31 std::array<ScannerVectorFrameBasicPtr, SCOPE_NAREAS>
scannervecs;
49 ATLTRACE(L
"PipelineController::Impl::Run beginning\n");
50 uint32_t framecount = 0;
51 uint32_t avgcount = 0;
53 std::unique_lock<std::mutex> online_update_lock(online_update_mutexe[_area], std::defer_lock);
54 online_updates[_area] =
false;
55 ControllerReturnStatus returnstatus(ControllerReturnStatus::none);
56 PixelmapperResult pixelmapper_result(Error);
61 const uint32_t requested_frames =
parameters.
areas[_area]->daq.requested_frames();
62 const uint32_t requested_averages =
parameters.
areas[ThisAreaOrMasterArea(_area)]->daq.averages();
66 SCOPE_MULTIIMAGEPTR_T current_frame = std::make_shared<SCOPE_MULTIIMAGE_T>(_area
70 SCOPE_MULTIIMAGEPTR_T next_frame = current_frame;
71 current_frame->SetAvgMax(requested_averages);
74 pixel_mapper->SetLookupVector(scannervecs[_area]->GetLookupVector());
75 pixel_mapper->SetParameters(scannervecs[_area]->GetSVParameters());
76 pixel_mapper->SetCurrentFrame(current_frame);
78 scope_controller.
FrameCounter[_area].SetWithLimits(0, 0, requested_frames);
82 while ( !sc->
IsSet() ) {
87 if ( msg.tag == ScopeMessageTag::abort ) {
88 returnstatus = stopped;
91 SCOPE_DAQCHUNKPTR_T chunk = msg.cargo;
94 chunk->Downsample(downsampling);
100 pixelmapper_result = pixel_mapper->LookupChunk(chunk, avgcount);
103 scope_controller.
SingleFrameProgress[_area] += 100.0 * chunk->PerChannel() / totalframepixels;
105 current_frame->SetAvgCount(avgcount+1);
106 current_frame->SetImageNumber(framecount+1);
110 outmsg.
cargo = current_frame;
113 if ( (pixelmapper_result & FrameComplete) != 0 ) {
114 current_frame->SetCompleteFrame(
true);
117 if ( ++avgcount == requested_averages ) {
119 current_frame->SetCompleteAvg(
true);
122 next_frame = std::make_shared<SCOPE_MULTIIMAGE_T>(*current_frame);
125 storage_queue->
Enqueue(outmsg);
132 next_frame->SetCompleteAvg(
false);
133 next_frame->SetAvgMax(requested_averages);
134 next_frame->SetCompleteFrame(
false);
135 next_frame->SetPercentComplete(0.0);
138 pixel_mapper->SetCurrentFrame(next_frame);
143 display_queue->
Enqueue(outmsg);
146 current_frame = next_frame;
149 }
while ( ((pixelmapper_result & EndOfChunk) != EndOfChunk) && !sc->
IsSet() );
153 online_update_lock.lock();
154 if ( online_updates[_area] && (requested_mode == DaqModeHelper::continuous) ) {
155 DBOUT(L
"PipelineController::Impl::Run online update\n");
157 pixel_mapper->SetLookupVector(scannervecs[_area]->GetLookupVector());
158 pixel_mapper->SetParameters(scannervecs[_area]->GetSVParameters());
159 online_updates[_area] =
false;
161 online_update_lock.unlock();
164 if ( (requested_mode == DaqModeHelper::nframes) && (requested_frames == framecount) ) {
165 returnstatus = finished;
167 DBOUT(L
"PipelineController all requested frames from area " << _area << L
" processed\n");
172 returnstatus = ControllerReturnStatus(returnstatus || ControllerReturnStatus::stopped);
174 DBOUT(L
"PipelineController::Impl::Run end\n");
185 , input_queues(_iqueues)
186 , storage_queue(_squeue)
187 , display_queue(_dqueue) {
200 input_queues->at(_a).Enqueue(stopmsg);
205 const uint32_t area = _areaparameters.
area();
206 std::lock_guard<std::mutex> lock(online_update_mutexe[area]);
209 online_updates[area] =
true;
214 scannervecs[_area] = _sv;
Main controller of microscope hardware and acquisition, also interface to the GUI.
Parameters for a whole area (includes a daq and a fpu)
parameters::Scope parameters
the Controller's own set of ScopeParameters
Thread-safe lock-free bool to signal a requested stop to the worker function currently executed in th...
void StopOne(const uint32_t &_a) override
Request one async worker function to stop by settings its StopCondition to true.
static std::array< ScopeNumber< double >, SCOPE_NAREAS > FrameCounter
Updated from PipelineControllerImpl::Run, connected to progress indicator in CTimeSeriesSettingsPage ...
The master parameters class.
std::array< std::unique_ptr< Area >, SCOPE_NAREAS > areas
holds AreaParameters for all areas.
SynchronizedQueue< ScopeMessage< SCOPE_MULTIIMAGEPTR_T > > *const display_queue
output queue to the DisplayController
void SetScannerVector(const uint32_t &_area, ScannerVectorFrameBasicPtr _sv)
Sets the pointers to the scanner vector.
Base class for all Scope datatypes here, provides a uniform interface (and saves typing...).
void Enqueue(const T &elem)
Enqueues an element and notifies one waiting operation that queue is not empty.
ControllerReturnStatus Run(StopCondition *const sc, const uint32_t &_area)
Main function for running pixel mapping.
SynchronizedQueue< ScopeMessage< SCOPE_MULTIIMAGEPTR_T > > *const storage_queue
output queue to the StorageController
std::array< std::mutex, SCOPE_NAREAS > online_update_mutexe
protection for online updates during live scanning
~Impl()
It is important that this is virtual, only by this the correct destructor for the pimpl is called in ...
Impl(const Impl &i)
disable copy
Impl operator=(const Impl &i)
disable assignment
ScopeValue< DaqMode > requested_mode
requested acquisition mode (see DaqModeHelper)
std::array< SynchronizedQueue< ScopeMessage< SCOPE_DAQCHUNKPTR_T > >, SCOPE_NAREAS > *const input_queues
input queue from the DaqController
Impl(std::array< SynchronizedQueue< ScopeMessage< SCOPE_DAQCHUNKPTR_T >>, SCOPE_NAREAS > *const _iqueues, SynchronizedQueue< ScopeMessage< SCOPE_MULTIIMAGEPTR_T >> *const _squeue, SynchronizedQueue< ScopeMessage< SCOPE_MULTIIMAGEPTR_T >> *const _dqueue, const parameters::Scope &_parameters)
Connect queues and get scanner vectors and parameters.
In here all declarations for all kinds of datatypes Scope needs.
virtual ControllerReturnStatus WaitForAll(const int32_t &_wait_time)
Wait for the futures of all async worker functions.
std::array< ScannerVectorFrameBasicPtr, SCOPE_NAREAS > scannervecs
array with the scanner vectors
virtual void StopAll()
Request all async worker function to stop.
virtual void StopOne(const uint32_t &_a)
Request one async worker function to stop by settings its StopCondition to true.
#define DBOUT(s)
A debug output to the debug console.
The implementation class of the PipelineController.
A synchronized, thread-safe queue was modeled after ringbuffer example from boost?! and/or a Herb Sutter column?!
void Set(const bool &_a=true)
ScopeNumber< uint32_t > area
the number of this area
std::array< bool, SCOPE_NAREAS > online_updates
trigger for online updates during live scanning
static std::array< ScopeNumber< double >, SCOPE_NAREAS > SingleFrameProgress
Updated from PipelineControllerImpl::Run.
Base class for all controllers.
static std::unique_ptr< PixelmapperBasic > Factory(const ScannerType &_scanner, const ScannerVectorType &_type)
A static factor method for pixelmappers.
void OnlineParameterUpdate(const parameters::Area &_areaparameters)
Handles update of parameters during scanning.