Commit c4d1420e authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline
Browse files

Wait for last skipped frame before stopping detector acq.

parent 08d436fb
......@@ -195,6 +195,8 @@ private:
virtual void threadFunction();
private:
typedef std::pair<bool, bool> Status;
class ExceptionCleanUp : Thread::ExceptionCleanUp
{
DEB_CLASS_NAMESPC(DebModCamera,
......@@ -205,7 +207,7 @@ private:
virtual ~ExceptionCleanUp();
};
bool newFrameReady(FrameType frame);
Status newFrameReady(FrameType frame);
void startAcq();
void stopAcq();
void cleanUp();
......@@ -245,6 +247,9 @@ private:
bool checkLostPackets();
FrameType getLastReceivedFrame();
void waitLastSkippedFrame();
void processLastSkippedFrame(int port_idx);
void getSortedBadFrameList(IntList first_idx, IntList last_idx,
IntList& bad_frame_list );
void getSortedBadFrameList(IntList& bad_frame_list)
......@@ -285,6 +290,7 @@ private:
FrameType m_lima_nb_frames;
FrameType m_det_nb_frames;
FrameType m_skip_frame_freq;
SortedIntList m_missing_last_skipped_frame;
double m_exp_time;
double m_lat_time;
double m_frame_period;
......
......@@ -162,7 +162,7 @@ private:
int fileStartCallback(char *fpath, char *fname, uint64_t fidx,
uint32_t dsize);
void portCallback(FrameType frame, int port, char *dptr,
void portCallback(FrameType det_frame, int port, char *dptr,
uint32_t dsize);
void getNodeMaskList(const CPUAffinityList& listener,
......
......@@ -150,6 +150,7 @@ void Camera::AcqThread::threadFunction()
SeqFilter seq_filter;
bool had_frames = false;
bool cont_acq = true;
bool acq_end = false;
do {
while ((m_state != StopReq) && m_frame_queue.empty()) {
if (!m_cond.wait(m_cam->m_new_frame_timeout)) {
......@@ -168,7 +169,9 @@ void Camera::AcqThread::threadFunction()
int f = frames.first;
do {
DEB_TRACE() << DEB_VAR1(f);
cont_acq = newFrameReady(f);
Status status = newFrameReady(f);
cont_acq = status.first;
acq_end = status.second;
had_frames = true;
} while ((++f != frames.end()) && cont_acq);
}
......@@ -176,6 +179,11 @@ void Camera::AcqThread::threadFunction()
} while ((m_state != StopReq) && cont_acq);
State prev_state = m_state;
if (acq_end && m_cam->m_skip_frame_freq) {
AutoMutexUnlock u(l);
m_cam->waitLastSkippedFrame();
}
m_state = Stopping;
DEB_TRACE() << DEB_VAR2(prev_state, m_state);
{
......@@ -272,13 +280,15 @@ void Camera::AcqThread::stopAcq()
det->stopReceiver();
}
bool Camera::AcqThread::newFrameReady(FrameType frame)
Camera::AcqThread::Status Camera::AcqThread::newFrameReady(FrameType frame)
{
DEB_MEMBER_FUNCT();
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame;
bool cont_acq = m_cam->m_buffer_cb_mgr->newFrameReady(frame_info);
return cont_acq && (frame < m_cam->m_lima_nb_frames - 1);
bool acq_end = (frame == m_cam->m_lima_nb_frames - 1);
cont_acq &= !acq_end;
return Status(cont_acq, acq_end);
}
Camera::Camera(string config_fname)
......@@ -783,6 +793,11 @@ void Camera::prepareAcq()
RecvList::iterator it, end = m_recv_list.end();
for (it = m_recv_list.begin(); it != end; ++it)
(*it)->prepareAcq();
m_missing_last_skipped_frame.clear();
if (m_skip_frame_freq)
for (int i = 0; i < getTotNbPorts(); ++i)
m_missing_last_skipped_frame.insert(i);
}
m_model->prepareAcq();
......@@ -882,6 +897,25 @@ FrameType Camera::getLastReceivedFrame()
return last_frame;
}
void Camera::waitLastSkippedFrame()
{
DEB_MEMBER_FUNCT();
AutoMutex l = lock();
while (!m_missing_last_skipped_frame.empty())
m_cond.wait();
}
void Camera::processLastSkippedFrame(int port_idx)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(port_idx);
AutoMutex l = lock();
if (m_missing_last_skipped_frame.erase(port_idx) != 1)
DEB_ERROR() << "port " << port_idx << " already processed";
else
m_cond.broadcast();
}
int Camera::getFramesCaught()
{
DEB_MEMBER_FUNCT();
......
......@@ -409,9 +409,9 @@ void Receiver::portCallback(FrameType frame,
DEB_STATIC_FUNCT();
Receiver *recv = static_cast<Receiver *>(priv);
int port = (x % 2);
FrameType lima_frame = frame - 1;
DEB_PARAM() << DEB_VAR2(frame, lima_frame);
recv->portCallback(lima_frame, port, dptr, dsize);
FrameType det_frame = frame - 1;
DEB_PARAM() << DEB_VAR2(frame, det_frame);
recv->portCallback(det_frame, port, dptr, dsize);
}
int Receiver::fileStartCallback(char *fpath, char *fname, uint64_t fidx,
......@@ -451,14 +451,19 @@ void Receiver::portCallback(FrameType det_frame, int port, char *dptr,
FrameType skip_freq = m_cam->m_skip_frame_freq;
bool skip_frame = false;
FrameType lima_frame = det_frame;
int port_idx = recv_port.m_port_idx;
if (skip_freq) {
skip_frame = ((det_frame + 1) % (skip_freq + 1) == 0);
lima_frame -= det_frame / (skip_freq + 1);
DEB_TRACE() << DEB_VAR3(det_frame, skip_frame,
lima_frame);
DEB_TRACE() << DEB_VAR4(port_idx, det_frame,
skip_frame, lima_frame);
}
if (!skip_frame)
if (skip_frame) {
if (det_frame == m_cam->m_det_nb_frames - 1)
m_cam->processLastSkippedFrame(port_idx);
} else {
recv_port.processFrame(lima_frame, dptr, dsize);
}
} catch (Exception& e) {
ostringstream err_msg;
err_msg << "Receiver::portCallback: " << e << ": "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment