Commit 5b2f190b authored by seb's avatar seb
Browse files

insert debug and trace into CtAcquisition


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@184 45c4679d-1946-429d-baad-37912b19538b
parent 1cc03ebc
......@@ -508,6 +508,8 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
DEB_VAR4(v1, v2, v3, v4) << ", " << #v5 << "=" << v5
#define DEB_VAR6(v1, v2, v3, v4, v5, v6) \
DEB_VAR5(v1, v2, v3, v4, v5) << ", " << #v6 << "=" << v6
#define DEB_VAR7(v1, v2, v3, v4, v5, v6, v7) \
DEB_VAR6(v1, v2, v3, v4, v5, v6) << ", " << #v7 << "=" << v7
#define DEB_OBJ_NAME(o) \
((o)->getDebObjName())
......
......@@ -5,96 +5,120 @@
#include "HwInterface.h"
#include "HwCap.h"
#include "CtControl.h"
#include "Debug.h"
namespace lima {
namespace lima
{
class CtAcquisition {
class CtAcquisition
{
DEB_CLASS_NAMESPC(DebModControl,"Acquisition","Control");
friend class CtControl;
public:
struct Parameters {
Parameters();
void reset();
AcqMode acqMode;
int acqNbFrames;
double acqExpoTime;
double accMaxExpoTime;
int concatNbFrames;
double latencyTime;
TrigMode triggerMode;
};
CtAcquisition(HwInterface *hw);
~CtAcquisition();
public:
// --- global
void setPars(const Parameters &pars);
void getPars(Parameters& pars) const;
struct Parameters {
DEB_CLASS_NAMESPC(DebModControl,"Acquisition::Parameters","Control");
public:
Parameters();
void reset();
void reset();
void apply(CtControl::ApplyPolicy policy);
void sync();
AcqMode acqMode;
int acqNbFrames;
double acqExpoTime;
double accMaxExpoTime;
int concatNbFrames;
double latencyTime;
TrigMode triggerMode;
};
// --- acq modes
CtAcquisition(HwInterface *hw);
~CtAcquisition();
void setAcqMode(AcqMode mode);
void getAcqMode(AcqMode& mode) const;
// --- global
void setAcqNbFrames(int nframes);
void getAcqNbFrames(int& nframes) const;
void setPars(const Parameters &pars);
void getPars(Parameters& pars) const;
void setAcqExpoTime(double acq_time);
void getAcqExpoTime(double& acq_time) const;
void reset();
void apply(CtControl::ApplyPolicy policy);
void sync();
void setAccMaxExpoTime(double max_time);
// --- acq modes
void getAccNbFrames(int& nframes) const;
void getAccExpoTime(double& acc_time) const;
void setAcqMode(AcqMode mode);
void getAcqMode(AcqMode& mode) const;
void setConcatNbFrames(int nframes);
void getConcatNbFrames(int& nframes) const;
void setAcqNbFrames(int nframes);
void getAcqNbFrames(int& nframes) const;
// --- common
void setAcqExpoTime(double acq_time);
void getAcqExpoTime(double& acq_time) const;
void setLatencyTime(double latency_time);
void getLatencyTime(double& latency_time) const;
void setAccMaxExpoTime(double max_time);
void setTriggerMode(TrigMode mode);
void getTriggerMode(TrigMode& mode) const;
void getAccNbFrames(int& nframes) const;
void getAccExpoTime(double& acc_time) const;
private:
void setConcatNbFrames(int nframes);
void getConcatNbFrames(int& nframes) const;
struct ChangedPars {
ChangedPars();
void set(bool);
void check(Parameters p1, Parameters p2);
// --- common
bool acqExpoTime;
bool acqNbFrames;
bool latencyTime;
bool triggerMode;
bool accMaxExpoTime;
};
void setLatencyTime(double latency_time);
void getLatencyTime(double& latency_time) const;
void _updateAccPars() const;
void _setDefaultPars(Parameters* pars);
void _apply();
void _hwRead();
void setTriggerMode(TrigMode mode);
void getTriggerMode(TrigMode& mode) const;
HwSyncCtrlObj *m_hw_sync;
HwSyncCtrlObj::ValidRangesType m_valid_ranges;
Parameters m_inpars, m_hwpars;
ChangedPars m_changes;
double m_readout_time;
double m_frame_rate;
mutable int m_acc_nframes;
mutable double m_acc_exptime;
bool m_applied_once;
};
private:
struct ChangedPars {
DEB_CLASS_NAMESPC(DebModControl,"Acquisition::ChangedPars","Control");
public:
ChangedPars();
void set(bool);
void check(Parameters p1, Parameters p2);
bool acqExpoTime;
bool acqNbFrames;
bool latencyTime;
bool triggerMode;
bool accMaxExpoTime;
};
void _updateAccPars() const;
void _setDefaultPars(Parameters* pars);
void _apply();
void _hwRead();
HwSyncCtrlObj *m_hw_sync;
HwSyncCtrlObj::ValidRangesType m_valid_ranges;
Parameters m_inpars, m_hwpars;
ChangedPars m_changes;
double m_readout_time;
double m_frame_rate;
mutable int m_acc_nframes;
mutable double m_acc_exptime;
bool m_applied_once;
};
inline std::ostream& operator<<(std::ostream &os,const CtAcquisition::Parameters &params)
{
os << "<"
<< "acqMode=" << params.acqMode << ", "
<< "acqNbFrames=" << params.acqNbFrames << ", "
<< "acqExpoTime=" << params.acqExpoTime << ", "
<< "accMaxExpoTime=" << params.accMaxExpoTime << ", "
<< "concatNbFrames=" << params.concatNbFrames << ", "
<< "latencyTime=" << params.latencyTime << ", "
<< "triggerMode=" << params.triggerMode << ", "
<< ">";
return os;
}
} // namespace lima
#endif // CTACQUISITION_H
......@@ -7,242 +7,327 @@ using namespace lima;
CtAcquisition::CtAcquisition(HwInterface *hw)
{
if (!hw->getHwCtrlObj(m_hw_sync))
throw LIMA_CTL_EXC(Error, "Cannot get hardware sync object");
DEB_CONSTRUCTOR();
m_hw_sync->getValidRanges(m_valid_ranges);
m_applied_once= false;
if (!hw->getHwCtrlObj(m_hw_sync))
throw LIMA_CTL_EXC(Error, "Cannot get hardware sync object");
m_hw_sync->getValidRanges(m_valid_ranges);
m_applied_once= false;
}
CtAcquisition::~CtAcquisition()
{
DEB_DESTRUCTOR();
}
void CtAcquisition::setPars(const Parameters &pars)
{
setAcqMode(pars.acqMode);
setAcqNbFrames(pars.acqNbFrames);
setAcqExpoTime(pars.acqExpoTime);
setAccMaxExpoTime(pars.accMaxExpoTime);
setConcatNbFrames(pars.concatNbFrames);
setLatencyTime(pars.latencyTime);
setTriggerMode(pars.triggerMode);
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(pars);
setAcqMode(pars.acqMode);
setAcqNbFrames(pars.acqNbFrames);
setAcqExpoTime(pars.acqExpoTime);
setAccMaxExpoTime(pars.accMaxExpoTime);
setConcatNbFrames(pars.concatNbFrames);
setLatencyTime(pars.latencyTime);
setTriggerMode(pars.triggerMode);
}
void CtAcquisition::getPars(Parameters& pars) const
{
pars= m_inpars;
DEB_MEMBER_FUNCT();
pars = m_inpars;
DEB_RETURN() << DEB_VAR1(pars);
}
void CtAcquisition::reset()
{
DEB_MEMBER_FUNCT();
// TODO
}
void CtAcquisition::apply(CtControl::ApplyPolicy policy)
{
CtControl::ApplyPolicy use_policy;
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(policy);
use_policy= m_applied_once ? policy : CtControl::All;
CtControl::ApplyPolicy use_policy;
use_policy= m_applied_once ? policy : CtControl::All;
switch (policy) {
case CtControl::All:
// --- apply all parameters
m_changes.set(1);
_apply();
break;
case CtControl::Changes:
// --- apply changed parameters (use internal soft cache)
m_changes.check(m_inpars, m_hwpars);
_apply();
break;
case CtControl::HwSyncChanges:
// --- read hw and apply changed parameters
_hwRead();
m_changes.check(m_inpars, m_hwpars);
_apply();
break;
default:
m_changes.set(1);
_apply();
}
switch (policy) {
case CtControl::All:
// --- apply all parameters
m_changes.set(1);
_apply();
break;
case CtControl::Changes:
// --- apply changed parameters (use internal soft cache)
m_changes.check(m_inpars, m_hwpars);
_apply();
break;
case CtControl::HwSyncChanges:
// --- read hw and apply changed parameters
_hwRead();
m_changes.check(m_inpars, m_hwpars);
_apply();
break;
default:
m_changes.set(1);
_apply();
}
}
void CtAcquisition::sync()
{
_hwRead();
m_inpars= m_hwpars;
DEB_MEMBER_FUNCT();
_hwRead();
m_inpars= m_hwpars;
DEB_TRACE() << DEB_VAR1(m_inpars);
}
void CtAcquisition::_hwRead()
{
int read_nframes;
m_hw_sync->getTrigMode(m_hwpars.triggerMode);
m_hw_sync->getExpTime(m_hwpars.acqExpoTime);
m_hw_sync->getLatTime(m_hwpars.latencyTime);
m_hw_sync->getNbFrames(m_hwpars.acqNbFrames);
switch (m_hwpars.acqMode) {
case Single:
m_hwpars.acqNbFrames= read_nframes;
m_hwpars.concatNbFrames= 0;
m_acc_exptime= m_hwpars.accMaxExpoTime;
m_acc_nframes= 0;
break;
case Concatenation:
// concatNbFrames unchanged (or read in buffer ??)
m_hwpars.acqNbFrames= read_nframes;
m_acc_exptime= m_hwpars.accMaxExpoTime;
m_acc_nframes= 0;
break;
case Accumulation:
m_hwpars.concatNbFrames= 0;
_updateAccPars();
m_hwpars.acqNbFrames= int(read_nframes / m_acc_nframes);
break;
}
DEB_MEMBER_FUNCT();
int read_nframes;
m_hw_sync->getTrigMode(m_hwpars.triggerMode);
m_hw_sync->getExpTime(m_hwpars.acqExpoTime);
m_hw_sync->getLatTime(m_hwpars.latencyTime);
m_hw_sync->getNbFrames(m_hwpars.acqNbFrames);
switch (m_hwpars.acqMode) {
case Single:
m_hwpars.acqNbFrames= read_nframes;
m_hwpars.concatNbFrames= 0;
m_acc_exptime= m_hwpars.accMaxExpoTime;
m_acc_nframes= 0;
break;
case Concatenation:
// concatNbFrames unchanged (or read in buffer ??)
m_hwpars.acqNbFrames= read_nframes;
m_acc_exptime= m_hwpars.accMaxExpoTime;
m_acc_nframes= 0;
break;
case Accumulation:
m_hwpars.concatNbFrames= 0;
_updateAccPars();
m_hwpars.acqNbFrames= int(read_nframes / m_acc_nframes);
break;
}
DEB_TRACE() << DEB_VAR1(m_hwpars);
}
void CtAcquisition::_apply()
{
if (m_changes.triggerMode) m_hw_sync->setTrigMode(m_inpars.triggerMode);
if (m_changes.latencyTime) m_hw_sync->setLatTime(m_inpars.latencyTime);
switch (m_inpars.acqMode) {
case Single:
if (m_changes.acqExpoTime) m_hw_sync->setExpTime(m_inpars.acqExpoTime);
if (m_changes.acqNbFrames) m_hw_sync->setNbFrames(m_inpars.acqNbFrames);
break;
case Concatenation:
if (m_changes.acqExpoTime) m_hw_sync->setExpTime(m_inpars.acqExpoTime);
if (m_changes.acqNbFrames) m_hw_sync->setNbFrames(m_inpars.acqNbFrames);
break;
case Accumulation:
if (m_changes.acqExpoTime || m_changes.accMaxExpoTime) {
_updateAccPars();
m_hw_sync->setExpTime(m_acc_exptime);
m_hw_sync->setNbFrames(m_inpars.acqNbFrames * m_acc_nframes);
} else if (m_changes.acqNbFrames) {
m_hw_sync->setNbFrames(m_inpars.acqNbFrames * m_acc_nframes);
}
break;
}
m_hwpars= m_inpars;
m_changes.set(0);
DEB_MEMBER_FUNCT();
if (m_changes.triggerMode) m_hw_sync->setTrigMode(m_inpars.triggerMode);
if (m_changes.latencyTime) m_hw_sync->setLatTime(m_inpars.latencyTime);
switch (m_inpars.acqMode) {
case Single:
if (m_changes.acqExpoTime) m_hw_sync->setExpTime(m_inpars.acqExpoTime);
if (m_changes.acqNbFrames) m_hw_sync->setNbFrames(m_inpars.acqNbFrames);
break;
case Concatenation:
if (m_changes.acqExpoTime) m_hw_sync->setExpTime(m_inpars.acqExpoTime);
if (m_changes.acqNbFrames) m_hw_sync->setNbFrames(m_inpars.acqNbFrames);
break;
case Accumulation:
if (m_changes.acqExpoTime || m_changes.accMaxExpoTime) {
_updateAccPars();
m_hw_sync->setExpTime(m_acc_exptime);
m_hw_sync->setNbFrames(m_inpars.acqNbFrames * m_acc_nframes);
} else if (m_changes.acqNbFrames) {
m_hw_sync->setNbFrames(m_inpars.acqNbFrames * m_acc_nframes);
}
break;
}
m_hwpars = m_inpars;
DEB_TRACE() << DEB_VAR1(m_hwpars);
m_changes.set(0);
}
void CtAcquisition::setTriggerMode(TrigMode mode)
{
m_inpars.triggerMode= mode;
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(mode);
m_inpars.triggerMode= mode;
}
void CtAcquisition::getTriggerMode(TrigMode& mode) const
{
mode= m_inpars.triggerMode;
DEB_MEMBER_FUNCT();
mode = m_inpars.triggerMode;
DEB_RETURN() << DEB_VAR1(mode);
}
void CtAcquisition::setAcqMode(AcqMode mode)
{
m_inpars.acqMode= mode;
switch (m_inpars.acqMode) {
case Single:
if (m_inpars.acqNbFrames<1) m_inpars.acqNbFrames= 1;
break;
case Accumulation:
if (m_inpars.accMaxExpoTime<=0) {
m_inpars.accMaxExpoTime= m_inpars.acqExpoTime;
}
case Concatenation:
if (m_inpars.concatNbFrames<1)
m_inpars.concatNbFrames= 1;
break;
}
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(mode);
m_inpars.acqMode= mode;
switch (m_inpars.acqMode) {
case Single:
if (m_inpars.acqNbFrames<1) m_inpars.acqNbFrames= 1;
break;
case Accumulation:
if (m_inpars.accMaxExpoTime<=0) {
m_inpars.accMaxExpoTime= m_inpars.acqExpoTime;
}
case Concatenation:
if (m_inpars.concatNbFrames<1)
m_inpars.concatNbFrames= 1;
break;
}
DEB_TRACE() << DEB_VAR1(m_inpars);
}
void CtAcquisition::getAcqMode(AcqMode& mode) const
{
mode= m_inpars.acqMode;
DEB_MEMBER_FUNCT();
mode = m_inpars.acqMode;
DEB_RETURN() << DEB_VAR1(mode);
}
void CtAcquisition::setAcqNbFrames(int nframes)
{
m_inpars.acqNbFrames= nframes;
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(nframes);
m_inpars.acqNbFrames= nframes;
}
void CtAcquisition::getAcqNbFrames(int& nframes) const
{
nframes= m_inpars.acqNbFrames;
DEB_MEMBER_FUNCT();
nframes= m_inpars.acqNbFrames;
DEB_RETURN() << DEB_VAR1(nframes);
}
void CtAcquisition::setAcqExpoTime(double acq_time)
{
if (acq_time < m_valid_ranges.min_exp_time)
throw LIMA_CTL_EXC(InvalidValue, "Exposure time too short");
if (acq_time > m_valid_ranges.max_exp_time)
throw LIMA_CTL_EXC(InvalidValue, "Exposure time too long");
m_inpars.acqExpoTime= acq_time;
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(acq_time);
if (acq_time < m_valid_ranges.min_exp_time)
throw LIMA_CTL_EXC(InvalidValue, "Exposure time too short");
if (acq_time > m_valid_ranges.max_exp_time)
throw LIMA_CTL_EXC(InvalidValue, "Exposure time too long");
m_inpars.acqExpoTime= acq_time;
}
void CtAcquisition::getAcqExpoTime(double& acq_time) const
{
acq_time= m_inpars.acqExpoTime;
DEB_MEMBER_FUNCT();
acq_time= m_inpars.acqExpoTime;
DEB_RETURN() << DEB_VAR1(acq_time);
}
void CtAcquisition::getAccNbFrames(int& nframes) const
{
_updateAccPars();
nframes= m_acc_nframes;
DEB_MEMBER_FUNCT();
_updateAccPars();
nframes= m_acc_nframes;
DEB_RETURN() << DEB_VAR1(nframes);
}
void CtAcquisition::setAccMaxExpoTime(double acc_time)
{
m_inpars.accMaxExpoTime= acc_time;
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(acc_time);
m_inpars.accMaxExpoTime= acc_time;
}
void CtAcquisition::getAccExpoTime(double& acc_time) const
{
_updateAccPars();
acc_time= m_acc_exptime;
DEB_MEMBER_FUNCT();
_updateAccPars();
acc_time= m_acc_exptime;
DEB_RETURN() << DEB_VAR1(acc_time);
}
void CtAcquisition::_updateAccPars() const
{
int acc_div;
acc_div= int(m_inpars.acqExpoTime / m_inpars.accMaxExpoTime);
if (fmod(m_inpars.acqExpoTime,m_inpars.accMaxExpoTime)) {
m_acc_nframes= acc_div + 1;
m_acc_exptime= m_inpars.acqExpoTime / m_acc_nframes;
} else {
m_acc_nframes= acc_div;
m_acc_exptime= m_inpars.accMaxExpoTime;
}
DEB_MEMBER_FUNCT();
int acc_div;
acc_div= int(m_inpars.acqExpoTime / m_inpars.accMaxExpoTime);
if (fmod(m_inpars.acqExpoTime,m_inpars.accMaxExpoTime)) {
m_acc_nframes= acc_div + 1;
m_acc_exptime= m_inpars.acqExpoTime / m_acc_nframes;
} else {
m_acc_nframes= acc_div;
m_acc_exptime= m_inpars.accMaxExpoTime;
}
DEB_TRACE() << DEB_VAR2(m_acc_nframes,m_acc_exptime);
}
void CtAcquisition::setConcatNbFrames(int nframes)