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

Cache frequently-used Eiger acq. params; issue requests only when changed:

* EXPOSURE, FRAME_TIME, NIMAGES, NTRIGGER, TRIGGER_MODE
parent 31deb1d3
...@@ -90,7 +90,7 @@ namespace lima ...@@ -90,7 +90,7 @@ namespace lima
void setTrigMode(TrigMode mode); void setTrigMode(TrigMode mode);
void getTrigMode(TrigMode& mode); void getTrigMode(TrigMode& mode);
void setExpTime(double exp_time); void setExpTime(double exp_time, bool force = false);
void getExpTime(double& exp_time); void getExpTime(double& exp_time);
void setLatTime(double lat_time); void setLatTime(double lat_time);
...@@ -161,19 +161,41 @@ namespace lima ...@@ -161,19 +161,41 @@ namespace lima
friend class InitCallback; friend class InitCallback;
void initialiseController(); /// Used during plug-in initialization void initialiseController(); /// Used during plug-in initialization
void _acquisition_finished(bool); void _acquisition_finished(bool);
template <typename T>
struct Cache
{
T val;
Cache() = default;
Cache(T v) : val(v) {}
operator T&() { return val; }
Cache& operator =(T new_val)
{ val = new_val; return *this; }
bool changed(T new_val)
{ std::swap(val, new_val); return (val != new_val); }
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//- lima stuff //- lima stuff
int m_nb_frames; int m_nb_frames;
Cache<unsigned int> m_nb_images;
Cache<unsigned int> m_nb_triggers;
int m_image_number; int m_image_number;
double m_latency_time; double m_latency_time;
TrigMode m_trig_mode; Cache<TrigMode> m_trig_mode;
//- camera stuff //- camera stuff
ApiGeneration m_api; ApiGeneration m_api;
std::string m_detector_model; std::string m_detector_model;
std::string m_detector_type; std::string m_detector_type;
unsigned int m_maxImageWidth, m_maxImageHeight; unsigned int m_maxImageWidth, m_maxImageHeight;
ImageType m_detectorImageType; ImageType m_detectorImageType;
InternalStatus m_initilize_state; InternalStatus m_initilize_state;
InternalStatus m_trigger_state; InternalStatus m_trigger_state;
...@@ -183,13 +205,13 @@ namespace lima ...@@ -183,13 +205,13 @@ namespace lima
double m_temperature; double m_temperature;
double m_humidity; double m_humidity;
double m_exp_time; Cache<double> m_exp_time;
Cache<double> m_frame_time;
double m_readout_time; double m_readout_time;
double m_x_pixelsize, m_y_pixelsize; double m_x_pixelsize, m_y_pixelsize;
Cond m_cond; Cond m_cond;
std::string m_detector_ip; std::string m_detector_ip;
double m_min_frame_time; double m_min_frame_time;
}; };
} // namespace Eiger } // namespace Eiger
} // namespace lima } // namespace lima
......
...@@ -204,17 +204,16 @@ void Camera::prepareAcq() ...@@ -204,17 +204,16 @@ void Camera::prepareAcq()
if(m_trigger_state != IDLE) if(m_trigger_state != IDLE)
EIGER_SYNC_CMD(Requests::DISARM); EIGER_SYNC_CMD(Requests::DISARM);
int nb_frames; unsigned nb_images, nb_triggers;
unsigned nb_trigger;
switch(m_trig_mode) switch(m_trig_mode)
{ {
case IntTrig: case IntTrig:
case ExtTrigSingle: case ExtTrigSingle:
nb_frames = m_nb_frames,nb_trigger = 1;break; nb_images = m_nb_frames, nb_triggers = 1; break;
case IntTrigMult: case IntTrigMult:
case ExtTrigMult: case ExtTrigMult:
case ExtGate: case ExtGate:
nb_frames = 1,nb_trigger = m_nb_frames;break; nb_images = 1, nb_triggers = m_nb_frames; break;
default: default:
THROW_HW_ERROR(Error) << "Very weird can't be in this case"; THROW_HW_ERROR(Error) << "Very weird can't be in this case";
} }
...@@ -230,26 +229,31 @@ void Camera::prepareAcq() ...@@ -230,26 +229,31 @@ void Camera::prepareAcq()
bool parallel_sync_cmds = (m_api == Eiger1); bool parallel_sync_cmds = (m_api == Eiger1);
DEB_PARAM() << DEB_VAR1(frame_time);
std::shared_ptr<Requests::Param> frame_time_req=
m_requests->set_param(Requests::FRAME_TIME,frame_time);
if (!parallel_sync_cmds)
frame_time_req->wait();
std::shared_ptr<Requests::Param> nimages_req =
m_requests->set_param(Requests::NIMAGES,nb_frames);
if (!parallel_sync_cmds)
nimages_req->wait();
std::shared_ptr<Requests::Param> ntrigger_req =
m_requests->set_param(Requests::NTRIGGER,nb_trigger);
if (!parallel_sync_cmds)
ntrigger_req->wait();
try try
{ {
DEB_PARAM() << DEB_VAR1(frame_time);
std::shared_ptr<Requests::Param> frame_time_req;
if (m_frame_time.changed(frame_time)) {
frame_time_req = m_requests->set_param(Requests::FRAME_TIME,frame_time);
if (!parallel_sync_cmds)
frame_time_req->wait();
}
std::shared_ptr<Requests::Param> nimages_req;
if (m_nb_images.changed(nb_images)) {
nimages_req = m_requests->set_param(Requests::NIMAGES,nb_images);
if (!parallel_sync_cmds)
nimages_req->wait();
}
std::shared_ptr<Requests::Param> ntrigger_req;
if (m_nb_triggers.changed(nb_triggers)) {
ntrigger_req = m_requests->set_param(Requests::NTRIGGER,nb_triggers);
if (!parallel_sync_cmds)
ntrigger_req->wait();
}
if (parallel_sync_cmds) { if (parallel_sync_cmds) {
frame_time_req->wait(); if (frame_time_req) frame_time_req->wait();
nimages_req->wait(); if (nimages_req) nimages_req->wait();
ntrigger_req->wait(); if (ntrigger_req) ntrigger_req->wait();
} }
} }
catch(const eigerapi::EigerException &e) catch(const eigerapi::EigerException &e)
...@@ -427,9 +431,9 @@ void Camera::setTrigMode(TrigMode trig_mode) ///< [in] lima trigger mode to set ...@@ -427,9 +431,9 @@ void Camera::setTrigMode(TrigMode trig_mode) ///< [in] lima trigger mode to set
default: default:
THROW_HW_ERROR(NotSupported) << DEB_VAR1(trig_mode); THROW_HW_ERROR(NotSupported) << DEB_VAR1(trig_mode);
} }
EIGER_SYNC_SET_PARAM(Requests::TRIGGER_MODE,trig_name); if (m_trig_mode.changed(trig_mode))
m_trig_mode = trig_mode; EIGER_SYNC_SET_PARAM(Requests::TRIGGER_MODE,trig_name);
} }
...@@ -448,13 +452,14 @@ void Camera::getTrigMode(TrigMode& mode) ///< [out] current trigger mode ...@@ -448,13 +452,14 @@ void Camera::getTrigMode(TrigMode& mode) ///< [out] current trigger mode
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// Set the new exposure time /// Set the new exposure time
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Camera::setExpTime(double exp_time) ///< [in] exposure time to set void Camera::setExpTime(double exp_time, ///< [in] exposure time to set
bool force)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(exp_time); DEB_PARAM() << DEB_VAR1(exp_time);
EIGER_SYNC_SET_PARAM(Requests::EXPOSURE,exp_time); if (m_exp_time.changed(exp_time) || force)
m_exp_time = exp_time; EIGER_SYNC_SET_PARAM(Requests::EXPOSURE, exp_time);
} }
...@@ -479,8 +484,9 @@ void Camera::setLatTime(double lat_time) ///< [in] latency time ...@@ -479,8 +484,9 @@ void Camera::setLatTime(double lat_time) ///< [in] latency time
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(lat_time); DEB_PARAM() << DEB_VAR1(lat_time);
bool force_exp = (lat_time != m_latency_time);
m_latency_time = lat_time; m_latency_time = lat_time;
setExpTime(m_exp_time); setExpTime(m_exp_time, force_exp);
} }
...@@ -685,9 +691,9 @@ void Camera::initialiseController() ...@@ -685,9 +691,9 @@ void Camera::initialiseController()
synchro_list.push_back(m_requests->get_param(Requests::DETECTOR_NUMBER,m_detector_type)); synchro_list.push_back(m_requests->get_param(Requests::DETECTOR_NUMBER,m_detector_type));
synchro_list.push_back(m_requests->get_param(Requests::EXPOSURE,m_exp_time)); synchro_list.push_back(m_requests->get_param(Requests::EXPOSURE,m_exp_time));
synchro_list.push_back(m_requests->get_param(Requests::NIMAGES,m_nb_images));
unsigned nb_trigger; synchro_list.push_back(m_requests->get_param(Requests::NTRIGGER,m_nb_triggers));
synchro_list.push_back(m_requests->get_param(Requests::NTRIGGER,nb_trigger));
std::shared_ptr<Requests::Param> frame_time_req = m_requests->get_param(Requests::FRAME_TIME); std::shared_ptr<Requests::Param> frame_time_req = m_requests->get_param(Requests::FRAME_TIME);
synchro_list.push_back(frame_time_req); synchro_list.push_back(frame_time_req);
...@@ -716,9 +722,9 @@ void Camera::initialiseController() ...@@ -716,9 +722,9 @@ void Camera::initialiseController()
//Trigger mode //Trigger mode
if(trig_name == "ints") if(trig_name == "ints")
m_trig_mode = nb_trigger > 1 ? IntTrigMult : IntTrig; m_trig_mode = m_nb_triggers > 1 ? IntTrigMult : IntTrig;
else if(trig_name == "exts") else if(trig_name == "exts")
m_trig_mode = nb_trigger > 1 ? ExtTrigMult : ExtTrigSingle; m_trig_mode = m_nb_triggers > 1 ? ExtTrigMult : ExtTrigSingle;
else if(trig_name == "exte") else if(trig_name == "exte")
m_trig_mode = ExtGate; m_trig_mode = ExtGate;
else else
......
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