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
void setTrigMode(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 setLatTime(double lat_time);
......@@ -161,12 +161,34 @@ namespace lima
friend class InitCallback;
void initialiseController(); /// Used during plug-in initialization
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
int m_nb_frames;
Cache<unsigned int> m_nb_images;
Cache<unsigned int> m_nb_triggers;
int m_image_number;
double m_latency_time;
TrigMode m_trig_mode;
Cache<TrigMode> m_trig_mode;
//- camera stuff
ApiGeneration m_api;
......@@ -183,13 +205,13 @@ namespace lima
double m_temperature;
double m_humidity;
double m_exp_time;
Cache<double> m_exp_time;
Cache<double> m_frame_time;
double m_readout_time;
double m_x_pixelsize, m_y_pixelsize;
Cond m_cond;
std::string m_detector_ip;
double m_min_frame_time;
};
} // namespace Eiger
} // namespace lima
......
......@@ -204,17 +204,16 @@ void Camera::prepareAcq()
if(m_trigger_state != IDLE)
EIGER_SYNC_CMD(Requests::DISARM);
int nb_frames;
unsigned nb_trigger;
unsigned nb_images, nb_triggers;
switch(m_trig_mode)
{
case IntTrig:
case ExtTrigSingle:
nb_frames = m_nb_frames,nb_trigger = 1;break;
nb_images = m_nb_frames, nb_triggers = 1; break;
case IntTrigMult:
case ExtTrigMult:
case ExtGate:
nb_frames = 1,nb_trigger = m_nb_frames;break;
nb_images = 1, nb_triggers = m_nb_frames; break;
default:
THROW_HW_ERROR(Error) << "Very weird can't be in this case";
}
......@@ -230,26 +229,31 @@ void Camera::prepareAcq()
bool parallel_sync_cmds = (m_api == Eiger1);
try
{
DEB_PARAM() << DEB_VAR1(frame_time);
std::shared_ptr<Requests::Param> frame_time_req=
m_requests->set_param(Requests::FRAME_TIME,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 =
m_requests->set_param(Requests::NIMAGES,nb_frames);
}
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 =
m_requests->set_param(Requests::NTRIGGER,nb_trigger);
}
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();
try
{
}
if (parallel_sync_cmds) {
frame_time_req->wait();
nimages_req->wait();
ntrigger_req->wait();
if (frame_time_req) frame_time_req->wait();
if (nimages_req) nimages_req->wait();
if (ntrigger_req) ntrigger_req->wait();
}
}
catch(const eigerapi::EigerException &e)
......@@ -428,8 +432,8 @@ void Camera::setTrigMode(TrigMode trig_mode) ///< [in] lima trigger mode to set
THROW_HW_ERROR(NotSupported) << DEB_VAR1(trig_mode);
}
if (m_trig_mode.changed(trig_mode))
EIGER_SYNC_SET_PARAM(Requests::TRIGGER_MODE,trig_name);
m_trig_mode = trig_mode;
}
......@@ -448,13 +452,14 @@ void Camera::getTrigMode(TrigMode& mode) ///< [out] current trigger mode
//-----------------------------------------------------------------------------
/// 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_PARAM() << DEB_VAR1(exp_time);
EIGER_SYNC_SET_PARAM(Requests::EXPOSURE,exp_time);
m_exp_time = exp_time;
if (m_exp_time.changed(exp_time) || force)
EIGER_SYNC_SET_PARAM(Requests::EXPOSURE, exp_time);
}
......@@ -479,8 +484,9 @@ void Camera::setLatTime(double lat_time) ///< [in] latency time
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(lat_time);
bool force_exp = (lat_time != m_latency_time);
m_latency_time = lat_time;
setExpTime(m_exp_time);
setExpTime(m_exp_time, force_exp);
}
......@@ -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::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,nb_trigger));
synchro_list.push_back(m_requests->get_param(Requests::NTRIGGER,m_nb_triggers));
std::shared_ptr<Requests::Param> frame_time_req = m_requests->get_param(Requests::FRAME_TIME);
synchro_list.push_back(frame_time_req);
......@@ -716,9 +722,9 @@ void Camera::initialiseController()
//Trigger mode
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")
m_trig_mode = nb_trigger > 1 ? ExtTrigMult : ExtTrigSingle;
m_trig_mode = m_nb_triggers > 1 ? ExtTrigMult : ExtTrigSingle;
else if(trig_name == "exte")
m_trig_mode = ExtGate;
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