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

Jungfrau: add ImgSrc GainPedCorr, injecting corrected images to Lima

* Add Reconstruction helper for both Eiger & Jungfrau image corrections
* Allow an Acq BufferCtrlObj, in addition to Lima one, for raw images
* Support both 16 & 32 bit GainPed maps
* Disable GainPedImgProc if necessary
parent 3ee6bbab
Pipeline #41852 failed with stages
in 7 minutes and 1 second
......@@ -104,6 +104,7 @@ add_library(slsdetector SHARED
src/SlsDetectorModel.cpp
src/SlsDetectorReceiver.cpp
src/SlsDetectorCamera.cpp
src/SlsDetectorReconstruction.cpp
src/SlsDetectorEiger.cpp
src/SlsDetectorJungfrau.cpp
src/SlsDetectorInterface.cpp
......
......@@ -41,6 +41,58 @@ namespace lima
namespace SlsDetector
{
enum BufferType {
AcqBuffer, LimaBuffer
};
class BufferCtrlObj : public NumaSoftBufferCtrlObj {
public:
BufferCtrlObj() : m_type(AcqBuffer) {}
void releaseBuffers() { getBuffer().releaseBuffers(); }
void setType(BufferType type)
{
if (type == m_type)
return;
releaseBuffers();
m_type = type;
}
virtual void getMaxNbBuffers(int& max_nb_buffers)
{
if (m_type == LimaBuffer)
max_nb_buffers = 1024;
else
NumaSoftBufferCtrlObj::getMaxNbBuffers(max_nb_buffers);
}
Data getFrameData(FrameType frame)
{
Data d;
StdBufferCbMgr& buffer = getBuffer();
const FrameDim& frame_dim = buffer.getFrameDim();
switch (frame_dim.getImageType()) {
case Bpp8: d.type = Data::UINT8; break;
case Bpp16: d.type = Data::UINT16; break;
case Bpp32: d.type = Data::UINT32; break;
default: throw LIMA_HW_EXC(Error, "Invalid image type");
}
const Size& size = frame_dim.getSize();
d.dimensions = {size.getWidth(), size.getHeight()};
Buffer *b = new Buffer;
b->owner = Buffer::MAPPED;
b->data = buffer.getFrameBufferPtr(frame);;
d.setBuffer(b);
b->unref();
return d;
}
private:
BufferType m_type;
};
class Eiger;
class Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGen
......@@ -75,13 +127,14 @@ public:
Receiver* getRecv(int i)
{ return m_recv_list[i]; }
void setBufferCtrlObj(NumaSoftBufferCtrlObj *buffer_ctrl_obj)
{ m_buffer_ctrl_obj = buffer_ctrl_obj; }
void setBufferCtrlObj(BufferCtrlObj *buffer_ctrl_obj,
BufferType type = LimaBuffer);
void setModuleActive(int mod_idx, bool active);
void getModuleActive(int mod_idx, bool& active);
void clearAllBuffers();
void releaseBuffers();
void setPixelDepth(PixelDepth pixel_depth);
void getPixelDepth(PixelDepth& pixel_depth);
......@@ -245,10 +298,21 @@ private:
AcqState getEffectiveState();
StdBufferCbMgr *getBufferCbMgr()
{ return &m_buffer_ctrl_obj->getBuffer(); }
BufferCtrlObj **getBufferCtrlObjPtr(BufferType type)
{
return (type == AcqBuffer) ? &m_acq_buffer_ctrl_obj :
&m_lima_buffer_ctrl_obj;
}
StdBufferCbMgr *getBufferCbMgr(BufferType type)
{
BufferCtrlObj *buffer = *getBufferCtrlObjPtr(type);
return buffer ? &buffer->getBuffer() : NULL;
}
void setAcqBufferCPUAffinity(CPUAffinity buffer_affinity);
char *getFrameBufferPtr(FrameType frame_nb);
char *getAcqFrameBufferPtr(FrameType frame_nb);
void removeSharedMem();
void createReceivers();
......@@ -303,7 +367,9 @@ private:
double m_lat_time;
double m_frame_period;
Settings m_settings;
NumaSoftBufferCtrlObj *m_buffer_ctrl_obj;
CPUAffinity m_buffer_affinity;
BufferCtrlObj *m_acq_buffer_ctrl_obj;
BufferCtrlObj *m_lima_buffer_ctrl_obj;
PixelDepth m_pixel_depth;
ImageType m_image_type;
bool m_raw_mode;
......
......@@ -56,18 +56,6 @@ class Eiger : public Model
NonParallel, Parallel,
};
class Correction : public LinkTask
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Correction",
"SlsDetector");
public:
Correction(Eiger *eiger);
virtual Data process(Data& data);
private:
Eiger *m_eiger;
};
class Geometry
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Geometry",
......@@ -237,9 +225,6 @@ class Eiger : public Model
ParallelMode parallel_mode,
TimeRanges& time_ranges);
// the returned object must be deleted by the caller
Correction *createCorrectionTask();
void setParallelMode(ParallelMode mode);
void getParallelMode(ParallelMode& mode);
......@@ -273,6 +258,14 @@ class Eiger : public Model
virtual bool isXferActive();
void setApplyCorrections(bool active)
{ m_reconstruction->setActive(active); }
void getApplyCorrections(bool& active)
{ m_reconstruction->getActive(active); }
virtual Reconstruction *getReconstruction()
{ return m_reconstruction; }
protected:
virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map);
......@@ -290,7 +283,6 @@ class Eiger : public Model
virtual void stopAcq();
private:
friend class Correction;
friend class CorrBase;
struct Beb {
......@@ -547,6 +539,20 @@ class Eiger : public Model
std::vector<BorderFactor> m_f;
};
class ModelReconstruction : public SlsDetector::Reconstruction {
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::ModelReconstruction",
"SlsDetector");
public:
ModelReconstruction(Eiger *eiger) : m_eiger(eiger)
{ setActive(true); }
virtual Data process(Data& data);
private:
friend class Eiger;
Eiger *m_eiger;
};
int getNbEigerModules()
{ return m_geom.getNbEigerModules(); }
......@@ -614,6 +620,7 @@ class Eiger : public Model
Geometry m_geom;
CorrList m_corr_list;
RecvList m_recv_list;
ModelReconstruction *m_reconstruction;
FrameType m_nb_frames;
FrameType m_next_frame;
FrameType m_last_frame;
......
......@@ -24,6 +24,7 @@
#include "lima/HwInterface.h"
#include "SlsDetectorCamera.h"
#include "SlsDetectorReconstruction.h"
namespace lima
{
......@@ -146,13 +147,47 @@ class SyncCtrlObj : public HwSyncCtrlObj
class EventCtrlObj : public HwEventCtrlObj
{
DEB_CLASS(DebModCamera, "EventCtrlObj");
DEB_CLASS_NAMESPC(DebModCamera, "EventCtrlObj", "SlsDetector");
public:
EventCtrlObj();
virtual ~EventCtrlObj();
};
/*******************************************************************
* \class ReconstructionCtrlObj
* \brief Control object providing SlsDetector reconstruction
*******************************************************************/
class ReconstructionCtrlObj : public HwReconstructionCtrlObj
{
DEB_CLASS_NAMESPC(DebModCamera, "ReconstructionCtrlObj", "SlsDetector");
public:
void setReconstruction(Reconstruction *r);
virtual LinkTask *getReconstructionTask();
private:
class Proxy : public Reconstruction::CtrlObjProxy {
DEB_CLASS_NAMESPC(DebModCamera, "ReconstructionCtrlObj::Proxy",
"SlsDetector");
public:
typedef ReconstructionCtrlObj Owner;
Proxy(Owner *owner, Reconstruction *r);
virtual void reconstructionChange(LinkTask *task);
private:
Owner *m_owner;
};
AutoPtr<Proxy> m_proxy;
};
/*******************************************************************
* \class Interface
* \brief SlsDetector hardware interface
......@@ -178,14 +213,17 @@ class Interface : public HwInterface
void resetDefaults();
void setReconstruction(Reconstruction *r);
private:
Camera& m_cam;
CapList m_cap_list;
DetInfoCtrlObj m_det_info;
NumaSoftBufferCtrlObj m_buffer;
BufferCtrlObj m_buffer;
SyncCtrlObj m_sync;
EventCtrlObj m_event;
ReconstructionCtrlObj m_reconstruction;
SlsDetector::EventCallback m_event_cb;
};
......
......@@ -136,18 +136,18 @@ class Jungfrau : public Model
public:
ImgProcTask(Jungfrau *jungfrau);
void setConfig(std::string config);
void getConfig(std::string &config);
virtual void process(Data& data);
private:
Jungfrau *m_jungfrau;
};
enum ImgSrc { Raw, GainPedCorr };
Jungfrau(Camera *cam);
~Jungfrau();
virtual void getFrameDim(FrameDim& frame_dim, bool raw = false);
virtual void getAcqFrameDim(FrameDim& frame_dim, bool raw = false);
virtual void getDetMap(Data& det_map);
......@@ -176,11 +176,22 @@ class Jungfrau : public Model
void readGainADCMaps(Data& gain_map, Data& adc_map, FrameType& frame);
GainPed& getGainPed() { return m_gain_ped_img_proc->m_gain_ped; }
void readGainPedProcMap(Data& proc_map, FrameType& frame);
void setGainPedMapType(GainPed::MapType map_type);
void getGainPedMapType(GainPed::MapType& map_type);
void getGainPedCalib(GainPed::Calib& calib)
{ m_gain_ped_img_proc->m_gain_ped.getCalib(calib); }
void setImgSrc(ImgSrc img_src);
void getImgSrc(ImgSrc& img_src);
virtual bool isXferActive();
virtual Reconstruction *getReconstruction()
{ return m_reconstruction; }
protected:
virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map);
......@@ -290,6 +301,7 @@ class Jungfrau : public Model
virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq();
virtual void clear();
virtual void processFrame(Data& data) = 0;
protected:
......@@ -361,7 +373,7 @@ class Jungfrau : public Model
GainADCMapImgProc(Jungfrau *jungfrau);
virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq();
virtual void clear();
virtual void processFrame(Data& data);
void readGainADCMaps(Data& gain_map, Data& adc_map,
......@@ -401,7 +413,7 @@ class Jungfrau : public Model
GainPedImgProc(Jungfrau *jungfrau);
virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq();
virtual void clear();
virtual void processFrame(Data& data);
void readProcMap(Data& proc_map, FrameType& frame);
......@@ -427,6 +439,21 @@ class Jungfrau : public Model
AutoPtr<Reader> m_reader;
};
class ModelReconstruction : public SlsDetector::Reconstruction
{
DEB_CLASS_NAMESPC(DebModCamera, "Jungfrau::ModelReconstruction",
"SlsDetector");
public:
ModelReconstruction(Jungfrau *jungfrau) : m_jungfrau(jungfrau)
{}
virtual Data process(Data& data);
private:
friend class Jungfrau;
Jungfrau *m_jungfrau;
};
bool getRawMode() {
bool raw;
getCamera()->getRawMode(raw);
......@@ -477,6 +504,7 @@ class Jungfrau : public Model
void addImgProc(ImgProcBase *img_proc);
void removeImgProc(ImgProcBase *img_proc);
void removeAllImgProc();
void doSetImgProcConfig(std::string config, bool force);
int getNbJungfrauModules()
{ return getNbDetModules(); }
......@@ -509,6 +537,9 @@ class Jungfrau : public Model
AutoPtr<GainADCMapImgProc> m_gain_adc_map_img_proc;
std::string m_img_proc_config;
ImgProcList m_img_proc_list;
ImgSrc m_img_src;
BufferCtrlObj m_acq_buffer_ctrl_obj;
ModelReconstruction *m_reconstruction;
RecvList m_recv_list;
FrameType m_nb_frames;
FrameType m_next_frame;
......@@ -519,6 +550,7 @@ class Jungfrau : public Model
};
std::ostream& operator <<(std::ostream& os, Jungfrau::GainPed::MapType map_type);
std::ostream& operator <<(std::ostream& os, Jungfrau::ImgSrc src);
} // namespace SlsDetector
......
......@@ -25,6 +25,7 @@
#include "SlsDetectorDefs.h"
#include "SlsDetectorCPUAffinity.h"
#include "SlsDetectorReconstruction.h"
#include "lima/SizeUtils.h"
......@@ -51,7 +52,8 @@ class Model
virtual ~Model();
virtual void getFrameDim(FrameDim& frame_dim, bool raw = false) = 0;
virtual void getAcqFrameDim(FrameDim& frame_dim, bool raw = false);
Camera *getCamera()
{ return m_cam; }
......@@ -87,16 +89,19 @@ class Model
virtual void setThreadCPUAffinity(const CPUAffinityList& aff_list) = 0;
virtual Reconstruction *getReconstruction();
protected:
void updateCameraModel();
void updateTimeRanges();
void updateCameraImageSize();
void updateCameraTimeRanges();
virtual void updateImageSize() = 0;
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
char *getFrameBufferPtr(FrameType frame_nb);
char *getAcqFrameBufferPtr(FrameType frame_nb);
virtual bool checkSettings(Settings settings) = 0;
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __SLS_DETECTOR_RECONSTRUCTION_H
#define __SLS_DETECTOR_RECONSTRUCTION_H
#include "processlib/LinkTask.h"
#include "lima/Debug.h"
#include "lima/Exceptions.h"
namespace lima
{
namespace SlsDetector
{
/*******************************************************************
* Reconstruction
*******************************************************************/
class Reconstruction : public LinkTask
{
DEB_CLASS_NAMESPC(DebModCamera, "Reconstruction", "SlsDetector");
public:
class CtrlObjProxy {
DEB_CLASS_NAMESPC(DebModCamera, "Reconstruction::CtrlObjProxy",
"SlsDetector");
public:
CtrlObjProxy(Reconstruction *r);
virtual ~CtrlObjProxy();
LinkTask *getReconstructionTask();
protected:
virtual void reconstructionChange(LinkTask *task) = 0;
private:
friend class Reconstruction;
Reconstruction *m_r;
};
Reconstruction();
virtual ~Reconstruction();
void setActive(bool active);
void getActive(bool& active);
private:
friend class CtrlObjProxy;
CtrlObjProxy *m_proxy;
bool m_active;
};
} // namespace SlsDetector
} // namespace lima
#endif // __SLS_DETECTOR_RECONSTRUCTION_H
......@@ -38,12 +38,11 @@ public:
std::vector<std::string> getHostnameList();
int getNbDetModules();
// void setBufferCtrlObj(NumaSoftBufferCtrlObj *buffer_ctrl_obj);
void setModuleActive(int mod_idx, bool active);
void getModuleActive(int mod_idx, bool& active /Out/);
void clearAllBuffers();
void releaseBuffers();
void setPixelDepth(SlsDetector::PixelDepth pixel_depth);
void getPixelDepth(SlsDetector::PixelDepth& pixel_depth /Out/);
......
......@@ -40,22 +40,12 @@ class Eiger : public SlsDetector::Model
NonParallel, Parallel,
};
class Correction : public LinkTask
{
public:
Correction(SlsDetector::Eiger *eiger);
virtual Data process(Data& data);
};
Eiger(SlsDetector::Camera *cam);
virtual void getFrameDim(FrameDim& frame_dim /Out/, bool raw = false);
virtual void getDetMap(Data& det_map /Out/);
SlsDetector::Eiger::Correction *createCorrectionTask() /Factory/;
virtual std::string getName();
virtual void getPixelSize(double& x_size /Out/, double& y_size /Out/);
......@@ -100,6 +90,11 @@ class Eiger : public SlsDetector::Model
virtual bool isXferActive();
void setApplyCorrections(bool active);
void getApplyCorrections(bool& active /Out/);
virtual Reconstruction *getReconstruction();
protected:
virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map);
......
......@@ -133,6 +133,8 @@ class Interface : HwInterface
void resetDefaults();
void setReconstruction(SlsDetector::Reconstruction *r);
SIP_PYOBJECT getHwCtrlObj(HwCap::Type cap_type);
%MethodCode
HwInterface::CapList cap_list;
......
......@@ -138,24 +138,17 @@ class Jungfrau : public SlsDetector::Model
void processFrame(Data& data, Data& proc /In,Out/);
};
class ImgProcTask : public SinkTaskBase
{
public:
ImgProcTask(SlsDetector::Jungfrau *jungfrau);
void setConfig(std::string config);
void getConfig(std::string &config /Out/);
virtual void process(Data& data);
};
enum ImgSrc { Raw, GainPedCorr };
Jungfrau(SlsDetector::Camera *cam);
virtual void getFrameDim(FrameDim& frame_dim /Out/, bool raw = false);
virtual void getAcqFrameDim(FrameDim& frame_dim /Out/,
bool raw = false);
virtual void getDetMap(Data& det_map /Out/);
SlsDetector::Jungfrau::ImgProcTask *createImgProcTask() /Factory/;
SinkTaskBase *createImgProcTask() /Factory/;
virtual std::string getName();
virtual void getPixelSize(double& x_size /Out/, double& y_size /Out/);
......@@ -182,12 +175,21 @@ class Jungfrau : public SlsDetector::Model
void readGainADCMaps(Data& gain_map /Out/, Data& adc_map /Out/,
unsigned long& frame /In,Out/);
SlsDetector::Jungfrau::GainPed& getGainPed();
void readGainPedProcMap(Data& proc_map /Out/,
unsigned long& frame /In,Out/);
void setGainPedMapType(Jungfrau::GainPed::MapType map_type);
void getGainPedMapType(Jungfrau::GainPed::MapType& map_type /Out/);
void getGainPedCalib(SlsDetector::Jungfrau::GainPed::Calib& calib /Out/);
void setImgSrc(Jungfrau::ImgSrc img_src);
void getImgSrc(Jungfrau::ImgSrc& img_src /Out/);
virtual bool isXferActive();
virtual SlsDetector::Reconstruction *getReconstruction();
protected:
virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map);
......
......@@ -34,12 +34,13 @@ public:
Model(SlsDetector::Camera *cam, SlsDetector::Type type);
virtual ~Model();