Commit 00e08331 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Operator for ID00
Browse files

Add support for dynamic change of pixel depth (except 4 bit)

parent 60d26713
......@@ -64,6 +64,13 @@ public:
UnknownDet, GenericDet, EigerDet, JungfrauDet,
};
enum PixelDepth {
PixelDepth4 = 4,
PixelDepth8 = 8,
PixelDepth16 = 16,
PixelDepth32 = 32,
};
typedef uint64_t FrameType;
typedef std::vector<std::string> NameList;
typedef std::vector<int> IntList;
......@@ -99,6 +106,8 @@ public:
protected:
void updateCameraModel();
virtual void updateImageSize() = 0;
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
......@@ -205,6 +214,9 @@ public:
void setBufferCbMgr(StdBufferCbMgr *buffer_cb_mgr)
{ m_buffer_cb_mgr = buffer_cb_mgr; }
void setPixelDepth(PixelDepth pixel_depth);
void getPixelDepth(PixelDepth& pixel_depth);
void setRawMode(bool raw_mode);
void getRawMode(bool& raw_mode);
......@@ -388,6 +400,8 @@ private:
AutoMutex lock()
{ return AutoMutex(m_cond.mutex()); }
void updateImageSize();
int64_t NSec(double x)
{ return int64_t(x * 1e9); }
......@@ -434,6 +448,7 @@ private:
FrameMap m_recv_map;
AutoPtr<FrameFinishedCallback> m_frame_cb;
StdBufferCbMgr *m_buffer_cb_mgr;
PixelDepth m_pixel_depth;
ImageType m_image_type;
bool m_raw_mode;
AutoPtr<AcqThread> m_acq_thread;
......
......@@ -52,16 +52,12 @@ class Eiger : public Camera::Model
typedef unsigned short Word;
typedef unsigned int Long;
enum CorrType {
ChipBorder, Gap,
};
class CorrBase
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::CorrBase",
"SlsDetector");
public:
CorrBase(Eiger *eiger, CorrType type);
CorrBase(Eiger *eiger);
virtual ~CorrBase();
bool getRaw();
......@@ -74,14 +70,13 @@ class Eiger : public Camera::Model
protected:
friend class Eiger;
Eiger *m_eiger;
CorrType m_type;
int m_nb_modules;
FrameDim m_mod_frame_dim;
Size m_frame_size;
std::vector<int> m_inter_lines;
};
typedef std::map<CorrType, CorrBase *> CorrMap;
typedef std::vector<AutoPtr<CorrBase> > CorrList;
class InterModGapCorr : public CorrBase
{
......@@ -108,8 +103,7 @@ class Eiger : public Camera::Model
virtual Data process(Data& data);
private:
typedef std::vector<AutoPtr<CorrBase> > CorrList;
CorrList m_corr_list;
CorrList& m_corr_list;
};
Eiger(Camera *cam);
......@@ -130,6 +124,8 @@ class Eiger : public Camera::Model
Correction *createCorrectionTask();
protected:
virtual void updateImageSize();
virtual bool checkSettings(Settings settings);
virtual ReadoutFlags getReadoutFlagsMask();
......@@ -180,7 +176,7 @@ class Eiger : public Camera::Model
{
public:
ChipBorderCorr(Eiger *eiger)
: CorrBase(eiger, ChipBorder)
: CorrBase(eiger)
{}
virtual void prepareAcq()
......@@ -293,6 +289,7 @@ class Eiger : public Camera::Model
void addCorr(CorrBase *corr);
void removeCorr(CorrBase *corr);
void removeAllCorr();
double getBorderCorrFactor(int det, int line);
int getInterModuleGap(int det);
......@@ -304,7 +301,7 @@ class Eiger : public Camera::Model
int m_nb_det_modules;
FrameDim m_recv_frame_dim;
CorrMap m_corr_map;
CorrList m_corr_list;
PortGeometryList m_port_geom_list;
};
......
......@@ -43,6 +43,13 @@ public:
GenericDet, EigerDet, JungfrauDet,
};
enum PixelDepth {
PixelDepth4 = 4,
PixelDepth8 = 8,
PixelDepth16 = 16,
PixelDepth32 = 32,
};
class Model
{
public:
......@@ -72,6 +79,8 @@ public:
protected:
void updateCameraModel();
virtual void updateImageSize() = 0;
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
......@@ -145,6 +154,9 @@ public:
void setBufferCbMgr(StdBufferCbMgr *buffer_cb_mgr);
void setPixelDepth(SlsDetector::Camera::PixelDepth pixel_depth);
void getPixelDepth(SlsDetector::Camera::PixelDepth& pixel_depth /Out/);
void setRawMode(bool raw_mode);
void getRawMode(bool& raw_mode /Out/);
......
......@@ -61,6 +61,8 @@ class Eiger : public SlsDetector::Camera::Model
std::vector<double>& min_val_list /Out/);
protected:
virtual void updateImageSize();
virtual bool checkSettings(SlsDetector::Defs::Settings settings);
virtual SlsDetector::Defs::ReadoutFlags getReadoutFlagsMask();
......
......@@ -528,6 +528,7 @@ bool Camera::AcqThread::newFrameReady(FrameType frame)
Camera::Camera(string config_fname)
: m_model(NULL),
m_pixel_depth(PixelDepth16),
m_image_type(Bpp16),
m_raw_mode(false),
m_state(Idle)
......@@ -545,6 +546,10 @@ Camera::Camera(string config_fname)
const char *fname = m_input_data->config_file_name.c_str();
m_det->readConfigurationFile(fname);
m_pixel_depth = PixelDepth(m_det->setDynamicRange(-1));
if (m_pixel_depth == PixelDepth4)
m_pixel_depth = PixelDepth8;
setSettings(Defs::Standard);
setTrigMode(Defs::Auto);
setNbFrames(1);
......@@ -603,6 +608,7 @@ void Camera::setModel(Model *model)
if (!m_model)
return;
setPixelDepth(m_pixel_depth);
setSettings(m_settings);
}
......@@ -739,6 +745,50 @@ void Camera::getFramePeriod(double& frame_period)
DEB_RETURN() << DEB_VAR1(frame_period);
}
void Camera::updateImageSize()
{
DEB_MEMBER_FUNCT();
m_model->updateImageSize();
FrameDim frame_dim;
getFrameDim(frame_dim, m_raw_mode);
DEB_TRACE() << "MaxImageSizeChanged: " << DEB_VAR1(frame_dim);
maxImageSizeChanged(frame_dim.getSize(), frame_dim.getImageType());
}
void Camera::setPixelDepth(PixelDepth pixel_depth)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(pixel_depth);
if (getState() != Idle)
THROW_HW_FATAL(Error) << "Camera is not idle";
switch (pixel_depth) {
case PixelDepth4:
THROW_HW_ERROR(NotSupported) << "PixelDepth4 not supported yet";
case PixelDepth8:
m_image_type = Bpp8; break;
case PixelDepth16:
m_image_type = Bpp16; break;
case PixelDepth32:
m_image_type = Bpp32; break;
default:
THROW_HW_ERROR(InvalidValue) << DEB_VAR1(pixel_depth);
}
m_det->setDynamicRange(pixel_depth);
m_pixel_depth = pixel_depth;
if (m_model)
updateImageSize();
}
void Camera::getPixelDepth(PixelDepth& pixel_depth)
{
DEB_MEMBER_FUNCT();
pixel_depth = m_pixel_depth;
DEB_RETURN() << DEB_VAR1(pixel_depth);
}
void Camera::setRawMode(bool raw_mode)
{
DEB_MEMBER_FUNCT();
......@@ -748,10 +798,7 @@ void Camera::setRawMode(bool raw_mode)
return;
m_raw_mode = raw_mode;
FrameDim frame_dim;
getFrameDim(frame_dim, m_raw_mode);
DEB_TRACE() << "MaxImageSizeChanged: " << DEB_VAR1(frame_dim);
maxImageSizeChanged(frame_dim.getSize(), frame_dim.getImageType());
updateImageSize();
}
void Camera::getRawMode(bool& raw_mode)
......@@ -761,7 +808,6 @@ void Camera::getRawMode(bool& raw_mode)
DEB_RETURN() << DEB_VAR1(raw_mode);
}
Camera::State Camera::getState()
{
DEB_MEMBER_FUNCT();
......
......@@ -33,8 +33,8 @@ const int Eiger::ChipGap = 2;
const int Eiger::HalfModuleChips = 4;
const int Eiger::RecvPorts = 2;
Eiger::CorrBase::CorrBase(Eiger *eiger, CorrType type)
: m_eiger(eiger), m_type(type)
Eiger::CorrBase::CorrBase(Eiger *eiger)
: m_eiger(eiger)
{
DEB_CONSTRUCTOR();
m_nb_modules = m_eiger->m_nb_det_modules / 2;
......@@ -75,7 +75,7 @@ void Eiger::CorrBase::prepareAcq()
}
Eiger::InterModGapCorr::InterModGapCorr(Eiger *eiger)
: CorrBase(eiger, Gap)
: CorrBase(eiger)
{
DEB_CONSTRUCTOR();
}
......@@ -113,18 +113,9 @@ void Eiger::InterModGapCorr::correctFrame(FrameType frame, void *ptr)
}
Eiger::Correction::Correction(Eiger *eiger)
: m_corr_list(eiger->m_corr_list)
{
DEB_CONSTRUCTOR();
CorrBase *corr;
ImageType image_type = eiger->getCamera()->getImageType();
corr = eiger->createChipBorderCorr(image_type);
m_corr_list.push_back(corr);
if (corr->getNbModules() > 1) {
corr = eiger->createInterModGapCorr();
m_corr_list.push_back(corr);
}
}
Data Eiger::Correction::process(Data& data)
......@@ -246,9 +237,7 @@ Eiger::Eiger(Camera *cam)
Eiger::~Eiger()
{
DEB_DESTRUCTOR();
CorrMap::iterator it, end = m_corr_map.end();
for (it = m_corr_map.begin(); it != end; ++it)
removeCorr(it->second);
removeAllCorr();
}
void Eiger::getFrameDim(FrameDim& frame_dim, bool raw)
......@@ -397,6 +386,23 @@ void Eiger::getADCInfo(NameList& name_list, IntList& idx_list,
}
}
void Eiger::updateImageSize()
{
DEB_MEMBER_FUNCT();
removeAllCorr();
CorrBase *corr;
ImageType image_type = getCamera()->getImageType();
corr = createChipBorderCorr(image_type);
m_corr_list.push_back(corr);
if (corr->getNbModules() > 1) {
corr = createInterModGapCorr();
m_corr_list.push_back(corr);
}
}
bool Eiger::checkSettings(Settings settings)
{
DEB_MEMBER_FUNCT();
......@@ -494,11 +500,9 @@ void Eiger::prepareAcq()
for (int i = 0; i < m_nb_det_modules * RecvPorts; ++i)
m_port_geom_list[i]->prepareAcq();
CorrMap::iterator it, end = m_corr_map.end();
for (it = m_corr_map.begin(); it != end; ++it) {
CorrBase *corr = it->second;
corr->prepareAcq();
}
CorrList::iterator it, end = m_corr_list.end();
for (it = m_corr_list.begin(); it != end; ++it)
(*it)->prepareAcq();
}
void Eiger::processRecvFileStart(int recv_idx, uint32_t dsize)
......@@ -565,11 +569,7 @@ void Eiger::addCorr(CorrBase *corr)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(corr);
CorrMap::iterator it = m_corr_map.find(corr->m_type);
if (it != m_corr_map.end())
removeCorr(it->second);
m_corr_map[corr->m_type] = corr;
m_corr_list.push_back(corr);
}
void Eiger::removeCorr(CorrBase *corr)
......@@ -577,14 +577,22 @@ void Eiger::removeCorr(CorrBase *corr)
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(corr);
CorrMap::iterator it = m_corr_map.find(corr->m_type);
if (it == m_corr_map.end()) {
CorrList::iterator it, end = m_corr_list.end();
it = find(m_corr_list.begin(), end, corr);
if (it == end) {
DEB_WARNING() << DEB_VAR1(corr) << " already removed";
return;
}
corr->m_eiger = NULL;
m_corr_map.erase(it);
m_corr_list.erase(it);
}
void Eiger::removeAllCorr()
{
DEB_MEMBER_FUNCT();
while (!m_corr_list.empty())
m_corr_list.erase(m_corr_list.begin());
}
double Eiger::getBorderCorrFactor(int det, int line)
......
......@@ -105,10 +105,15 @@ void DetInfoCtrlObj::getCurrImageType(ImageType& curr_image_type)
void DetInfoCtrlObj::setCurrImageType(ImageType curr_image_type)
{
DEB_MEMBER_FUNCT();
ImageType unique_image_type = Bpp16;
if (curr_image_type != unique_image_type)
THROW_HW_ERROR(InvalidValue)
<< "Only " << DEB_VAR1(unique_image_type) << "allowed";
Camera::PixelDepth pixel_depth;
switch (curr_image_type) {
case Bpp8: pixel_depth = Camera::PixelDepth8; break;
case Bpp16: pixel_depth = Camera::PixelDepth16; break;
case Bpp32: pixel_depth = Camera::PixelDepth32; break;
default:
THROW_HW_ERROR(InvalidValue) << DEB_VAR1(curr_image_type);
}
m_cam.setPixelDepth(pixel_depth);
}
void DetInfoCtrlObj::getPixelSize(double& x_size, double& y_size)
......
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