Commit a8f0779d authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

Fix issues in IntTrigMult and apply refactoring to Eiger::SavingCtrlObj

parent 1fc2e6b6
...@@ -174,7 +174,7 @@ class LIBEIGER Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGe ...@@ -174,7 +174,7 @@ class LIBEIGER Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGe
void _updateImageSize(); void _updateImageSize();
bool isAcquisitionFinished(); bool allFramesAcquired();
template <typename T> template <typename T>
struct Cache struct Cache
......
...@@ -55,6 +55,8 @@ namespace lima ...@@ -55,6 +55,8 @@ namespace lima
virtual void _start(int =0) override; virtual void _start(int =0) override;
virtual void _setActive(bool, int =0) override; virtual void _setActive(bool, int =0) override;
void _download_finished(std::string filename, bool ok, std::string error);
Camera& m_cam; Camera& m_cam;
int m_serie_id; int m_serie_id;
int m_nb_file_to_watch; int m_nb_file_to_watch;
......
...@@ -37,7 +37,6 @@ using namespace eigerapi; ...@@ -37,7 +37,6 @@ using namespace eigerapi;
typedef Requests::CommandReq CommandReq; typedef Requests::CommandReq CommandReq;
typedef Requests::ParamReq ParamReq; typedef Requests::ParamReq ParamReq;
typedef Requests::TransferReq TransferReq;
#define HANDLE_EIGERERROR(req, e) { \ #define HANDLE_EIGERERROR(req, e) { \
THROW_HW_ERROR(Error) << (req)->get_url() << ":" << (e).what(); \ THROW_HW_ERROR(Error) << (req)->get_url() << ":" << (e).what(); \
...@@ -845,22 +844,20 @@ void Camera::_trigger_finished(bool ok) ...@@ -845,22 +844,20 @@ void Camera::_trigger_finished(bool ok)
DEB_TRACE() << "Trigger end"; DEB_TRACE() << "Trigger end";
if(!ok) if(!ok)
DEB_ERROR() << "Error in trigger command"; DEB_ERROR() << "Error in trigger command";
else if(isAcquisitionFinished()) else if(allFramesAcquired())
try { disarm(); } try { disarm(); }
catch (...) { ok = false; } catch (...) { ok = false; }
AutoMutex lock(m_cond.mutex()); AutoMutex lock(m_cond.mutex());
m_trigger_state = ok ? IDLE : ERROR; m_trigger_state = ok ? IDLE : ERROR;
lock.unlock();
} }
bool Camera::isAcquisitionFinished() bool Camera::allFramesAcquired()
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
AutoMutex lock(m_cond.mutex()); AutoMutex lock(m_cond.mutex());
DEB_PARAM() << DEB_VAR2(m_trigger_state, m_image_number); DEB_PARAM() << DEB_VAR2(m_image_number, m_nb_frames);
bool finished = ((m_trig_mode != IntTrigMult) || bool finished = (m_image_number == m_nb_frames);
(m_image_number == m_nb_frames));
DEB_RETURN() << DEB_VAR1(finished); DEB_RETURN() << DEB_VAR1(finished);
return finished; return finished;
} }
......
...@@ -145,7 +145,9 @@ void Interface::getStatus(StatusType& status) ...@@ -145,7 +145,9 @@ void Interface::getStatus(StatusType& status)
{ {
case Camera::Ready: case Camera::Ready:
{ {
if (!m_cam.isAcquisitionFinished()) // missing frames in IntTrigMult TrigMode trig_mode;
m_cam.getTrigMode(trig_mode);
if ((trig_mode == IntTrigMult) && !m_cam.allFramesAcquired())
status.set(HwInterface::StatusType::Ready); status.set(HwInterface::StatusType::Ready);
else if (m_saving->isActive()) else if (m_saving->isActive())
{ {
......
...@@ -29,6 +29,10 @@ using namespace lima; ...@@ -29,6 +29,10 @@ using namespace lima;
using namespace lima::Eiger; using namespace lima::Eiger;
using namespace eigerapi; using namespace eigerapi;
typedef Requests::ParamReq ParamReq;
typedef Requests::TransferReq TransferReq;
typedef CurlLoop::FutureRequest::CallbackPtr CallbackPtr;
const int MAX_SIMULTANEOUS_DOWNLOAD = 4; const int MAX_SIMULTANEOUS_DOWNLOAD = 4;
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
HDF5 HEADER HDF5 HEADER
...@@ -122,7 +126,7 @@ void SavingCtrlObj::setCommonHeader(const HwSavingCtrlObj::HeaderMap& header) ...@@ -122,7 +126,7 @@ void SavingCtrlObj::setCommonHeader(const HwSavingCtrlObj::HeaderMap& header)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
std::list<std::shared_ptr<Requests::Param>> pending_request; std::list<ParamReq> pending_request;
for(HwSavingCtrlObj::HeaderMap::const_iterator i = header.begin(); for(HwSavingCtrlObj::HeaderMap::const_iterator i = header.begin();
i != header.end();++i) i != header.end();++i)
{ {
...@@ -135,13 +139,13 @@ void SavingCtrlObj::setCommonHeader(const HwSavingCtrlObj::HeaderMap& header) ...@@ -135,13 +139,13 @@ void SavingCtrlObj::setCommonHeader(const HwSavingCtrlObj::HeaderMap& header)
try try
{ {
for(std::list<std::shared_ptr<Requests::Param>>::iterator i = pending_request.begin(); for(std::list<ParamReq>::iterator i = pending_request.begin();
i != pending_request.end();++i) i != pending_request.end();++i)
(*i)->wait(); (*i)->wait();
} }
catch(const eigerapi::EigerException &e) catch(const eigerapi::EigerException &e)
{ {
for(std::list<std::shared_ptr<Requests::Param>>::iterator i = pending_request.begin(); for(std::list<ParamReq>::iterator i = pending_request.begin();
i != pending_request.end();++i) i != pending_request.end();++i)
m_cam.m_requests->cancel(*i); m_cam.m_requests->cancel(*i);
THROW_HW_ERROR(Error) << e.what(); THROW_HW_ERROR(Error) << e.what();
...@@ -188,9 +192,8 @@ void SavingCtrlObj::_setActive(bool active, int) ...@@ -188,9 +192,8 @@ void SavingCtrlObj::_setActive(bool active, int)
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
const char *active_str = active ? "enabled" : "disabled"; const char *active_str = active ? "enabled" : "disabled";
std::shared_ptr<Requests::Param> active_req = ParamReq active_req = m_cam.m_requests->set_param(Requests::FILEWRITER_MODE,
m_cam.m_requests->set_param(Requests::FILEWRITER_MODE, active_str);
active_str);
DEB_TRACE() << "FILEWRITER_MODE:" << DEB_VAR1(active_str); DEB_TRACE() << "FILEWRITER_MODE:" << DEB_VAR1(active_str);
active_req->wait(); active_req->wait();
} }
...@@ -200,12 +203,12 @@ void SavingCtrlObj::_prepare(int) ...@@ -200,12 +203,12 @@ void SavingCtrlObj::_prepare(int)
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
int frames_per_file = int(m_frames_per_file); int frames_per_file = int(m_frames_per_file);
std::shared_ptr<Requests::Param> nb_image_per_file_req = ParamReq nb_image_per_file_req =
m_cam.m_requests->set_param(Requests::NIMAGES_PER_FILE, m_cam.m_requests->set_param(Requests::NIMAGES_PER_FILE,
frames_per_file); frames_per_file);
DEB_TRACE() << "NIMAGES_PER_FILE:" << DEB_VAR1(frames_per_file); DEB_TRACE() << "NIMAGES_PER_FILE:" << DEB_VAR1(frames_per_file);
std::shared_ptr<Requests::Param> name_pattern_req = ParamReq name_pattern_req =
m_cam.m_requests->set_param(Requests::FILEWRITER_NAME_PATTERN,m_prefix); m_cam.m_requests->set_param(Requests::FILEWRITER_NAME_PATTERN,m_prefix);
DEB_TRACE() << "FILEWRITER_NAME_PATTERN" << DEB_VAR1(m_prefix); DEB_TRACE() << "FILEWRITER_NAME_PATTERN" << DEB_VAR1(m_prefix);
...@@ -304,8 +307,7 @@ void SavingCtrlObj::_PollingThread::threadFunction() ...@@ -304,8 +307,7 @@ void SavingCtrlObj::_PollingThread::threadFunction()
Requests::Param::Value files; Requests::Param::Value files;
//Ls request //Ls request
std::shared_ptr<Requests::Param> ls_req = ParamReq ls_req = m_requests->get_param(ls_name);
m_requests->get_param(ls_name);
try try
{ {
files = ls_req->get(); files = ls_req->get();
...@@ -332,7 +334,7 @@ void SavingCtrlObj::_PollingThread::threadFunction() ...@@ -332,7 +334,7 @@ void SavingCtrlObj::_PollingThread::threadFunction()
{ {
std::string master_file_name = prefix + "_master.h5"; std::string master_file_name = prefix + "_master.h5";
std::string dest_path = directory + "/" + master_file_name; std::string dest_path = directory + "/" + master_file_name;
std::shared_ptr<Requests::Transfer> master_file_req; TransferReq master_file_req;
try try
{ {
master_file_req = m_requests->start_transfer(src_file_name.str(),dest_path); master_file_req = m_requests->start_transfer(src_file_name.str(),dest_path);
...@@ -348,8 +350,7 @@ void SavingCtrlObj::_PollingThread::threadFunction() ...@@ -348,8 +350,7 @@ void SavingCtrlObj::_PollingThread::threadFunction()
m_saving.m_nb_file_to_watch = m_saving.m_nb_file_transfer_started = 0; m_saving.m_nb_file_to_watch = m_saving.m_nb_file_transfer_started = 0;
continue; continue;
} }
std::shared_ptr<CurlLoop::FutureRequest::Callback> CallbackPtr end_cbk(new _EndDownloadCallback(m_saving,src_file_name.str()));
end_cbk(new _EndDownloadCallback(m_saving,src_file_name.str()));
lock.unlock(); lock.unlock();
master_file_req->register_callback(end_cbk); master_file_req->register_callback(end_cbk);
lock.lock(); lock.lock();
...@@ -394,7 +395,7 @@ void SavingCtrlObj::_PollingThread::threadFunction() ...@@ -394,7 +395,7 @@ void SavingCtrlObj::_PollingThread::threadFunction()
DEB_TRACE() << "Start transfer file: " << DEB_VAR1(*file_name); DEB_TRACE() << "Start transfer file: " << DEB_VAR1(*file_name);
std::string dest_path = directory + "/" + src_file_name.str(); std::string dest_path = directory + "/" + src_file_name.str();
std::shared_ptr<Requests::Transfer> file_req; TransferReq file_req;
try try
{ {
file_req = m_requests->start_transfer(src_file_name.str(),dest_path); file_req = m_requests->start_transfer(src_file_name.str(),dest_path);
...@@ -412,8 +413,7 @@ void SavingCtrlObj::_PollingThread::threadFunction() ...@@ -412,8 +413,7 @@ void SavingCtrlObj::_PollingThread::threadFunction()
} }
++m_saving.m_nb_file_transfer_started,++m_saving.m_concurrent_download; ++m_saving.m_nb_file_transfer_started,++m_saving.m_concurrent_download;
std::shared_ptr<CurlLoop::FutureRequest::Callback> CallbackPtr end_cbk(new _EndDownloadCallback(m_saving,src_file_name.str()));
end_cbk(new _EndDownloadCallback(m_saving,src_file_name.str()));
lock.unlock(); lock.unlock();
file_req->register_callback(end_cbk); file_req->register_callback(end_cbk);
lock.lock(); lock.lock();
...@@ -442,6 +442,29 @@ void SavingCtrlObj::_PollingThread::threadFunction() ...@@ -442,6 +442,29 @@ void SavingCtrlObj::_PollingThread::threadFunction()
} }
} }
void SavingCtrlObj::_download_finished(std::string filename, bool ok,
std::string error)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR3(filename, ok, error);
m_cam.m_image_number++;
AutoMutex lock(m_cond.mutex());
if(!ok)
{
m_error_msg = "Failed to download file: ";
m_error_msg += filename;
DEB_ERROR() << m_error_msg << ": " << error;
//Stop the polling
m_poll_master_file = false;
m_nb_file_transfer_started = m_nb_file_to_watch = 0;
}
--m_concurrent_download;
m_cond.broadcast();
}
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
class _EndDownloadCallback class _EndDownloadCallback
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
...@@ -456,17 +479,7 @@ void SavingCtrlObj::_EndDownloadCallback:: ...@@ -456,17 +479,7 @@ void SavingCtrlObj::_EndDownloadCallback::
status_changed(CurlLoop::FutureRequest::Status status, std::string error) status_changed(CurlLoop::FutureRequest::Status status, std::string error)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
AutoMutex lock(m_saving.m_cond.mutex()); DEB_PARAM() << DEB_VAR2(status, error);
if(status != CurlLoop::FutureRequest::OK) bool ok = (status == CurlLoop::FutureRequest::OK);
{ m_saving._download_finished(m_filename, ok, error);
m_saving.m_error_msg = "Failed to download file: ";
m_saving.m_error_msg += m_filename;
DEB_ERROR() << m_saving.m_error_msg << ": " << error;
//Stop the polling
m_saving.m_poll_master_file = false;
m_saving.m_nb_file_transfer_started = m_saving.m_nb_file_to_watch = 0;
}
--m_saving.m_concurrent_download;
m_saving.m_cond.broadcast();
} }
Supports Markdown
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