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 ...@@ -104,6 +104,7 @@ add_library(slsdetector SHARED
src/SlsDetectorModel.cpp src/SlsDetectorModel.cpp
src/SlsDetectorReceiver.cpp src/SlsDetectorReceiver.cpp
src/SlsDetectorCamera.cpp src/SlsDetectorCamera.cpp
src/SlsDetectorReconstruction.cpp
src/SlsDetectorEiger.cpp src/SlsDetectorEiger.cpp
src/SlsDetectorJungfrau.cpp src/SlsDetectorJungfrau.cpp
src/SlsDetectorInterface.cpp src/SlsDetectorInterface.cpp
......
...@@ -41,6 +41,58 @@ namespace lima ...@@ -41,6 +41,58 @@ namespace lima
namespace SlsDetector 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 Eiger;
class Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGen class Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGen
...@@ -75,13 +127,14 @@ public: ...@@ -75,13 +127,14 @@ public:
Receiver* getRecv(int i) Receiver* getRecv(int i)
{ return m_recv_list[i]; } { return m_recv_list[i]; }
void setBufferCtrlObj(NumaSoftBufferCtrlObj *buffer_ctrl_obj) void setBufferCtrlObj(BufferCtrlObj *buffer_ctrl_obj,
{ m_buffer_ctrl_obj = buffer_ctrl_obj; } BufferType type = LimaBuffer);
void setModuleActive(int mod_idx, bool active); void setModuleActive(int mod_idx, bool active);
void getModuleActive(int mod_idx, bool& active); void getModuleActive(int mod_idx, bool& active);
void clearAllBuffers(); void clearAllBuffers();
void releaseBuffers();
void setPixelDepth(PixelDepth pixel_depth); void setPixelDepth(PixelDepth pixel_depth);
void getPixelDepth(PixelDepth& pixel_depth); void getPixelDepth(PixelDepth& pixel_depth);
...@@ -245,10 +298,21 @@ private: ...@@ -245,10 +298,21 @@ private:
AcqState getEffectiveState(); AcqState getEffectiveState();
StdBufferCbMgr *getBufferCbMgr() BufferCtrlObj **getBufferCtrlObjPtr(BufferType type)
{ return &m_buffer_ctrl_obj->getBuffer(); } {
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 removeSharedMem();
void createReceivers(); void createReceivers();
...@@ -303,7 +367,9 @@ private: ...@@ -303,7 +367,9 @@ private:
double m_lat_time; double m_lat_time;
double m_frame_period; double m_frame_period;
Settings m_settings; 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; PixelDepth m_pixel_depth;
ImageType m_image_type; ImageType m_image_type;
bool m_raw_mode; bool m_raw_mode;
......
...@@ -56,18 +56,6 @@ class Eiger : public Model ...@@ -56,18 +56,6 @@ class Eiger : public Model
NonParallel, Parallel, 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 class Geometry
{ {
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Geometry", DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Geometry",
...@@ -237,9 +225,6 @@ class Eiger : public Model ...@@ -237,9 +225,6 @@ class Eiger : public Model
ParallelMode parallel_mode, ParallelMode parallel_mode,
TimeRanges& time_ranges); TimeRanges& time_ranges);
// the returned object must be deleted by the caller
Correction *createCorrectionTask();
void setParallelMode(ParallelMode mode); void setParallelMode(ParallelMode mode);
void getParallelMode(ParallelMode& mode); void getParallelMode(ParallelMode& mode);
...@@ -273,6 +258,14 @@ class Eiger : public Model ...@@ -273,6 +258,14 @@ class Eiger : public Model
virtual bool isXferActive(); 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: protected:
virtual int getNbFrameMapItems(); virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map); virtual void updateFrameMapItems(FrameMap *map);
...@@ -290,7 +283,6 @@ class Eiger : public Model ...@@ -290,7 +283,6 @@ class Eiger : public Model
virtual void stopAcq(); virtual void stopAcq();
private: private:
friend class Correction;
friend class CorrBase; friend class CorrBase;
struct Beb { struct Beb {
...@@ -547,6 +539,20 @@ class Eiger : public Model ...@@ -547,6 +539,20 @@ class Eiger : public Model
std::vector<BorderFactor> m_f; 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() int getNbEigerModules()
{ return m_geom.getNbEigerModules(); } { return m_geom.getNbEigerModules(); }
...@@ -614,6 +620,7 @@ class Eiger : public Model ...@@ -614,6 +620,7 @@ class Eiger : public Model
Geometry m_geom; Geometry m_geom;
CorrList m_corr_list; CorrList m_corr_list;
RecvList m_recv_list; RecvList m_recv_list;
ModelReconstruction *m_reconstruction;
FrameType m_nb_frames; FrameType m_nb_frames;
FrameType m_next_frame; FrameType m_next_frame;
FrameType m_last_frame; FrameType m_last_frame;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "lima/HwInterface.h" #include "lima/HwInterface.h"
#include "SlsDetectorCamera.h" #include "SlsDetectorCamera.h"
#include "SlsDetectorReconstruction.h"
namespace lima namespace lima
{ {
...@@ -146,13 +147,47 @@ class SyncCtrlObj : public HwSyncCtrlObj ...@@ -146,13 +147,47 @@ class SyncCtrlObj : public HwSyncCtrlObj
class EventCtrlObj : public HwEventCtrlObj class EventCtrlObj : public HwEventCtrlObj
{ {
DEB_CLASS(DebModCamera, "EventCtrlObj"); DEB_CLASS_NAMESPC(DebModCamera, "EventCtrlObj", "SlsDetector");
public: public:
EventCtrlObj(); EventCtrlObj();
virtual ~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 * \class Interface
* \brief SlsDetector hardware interface * \brief SlsDetector hardware interface
...@@ -178,14 +213,17 @@ class Interface : public HwInterface ...@@ -178,14 +213,17 @@ class Interface : public HwInterface
void resetDefaults(); void resetDefaults();
void setReconstruction(Reconstruction *r);
private: private:
Camera& m_cam; Camera& m_cam;
CapList m_cap_list; CapList m_cap_list;
DetInfoCtrlObj m_det_info; DetInfoCtrlObj m_det_info;
NumaSoftBufferCtrlObj m_buffer; BufferCtrlObj m_buffer;
SyncCtrlObj m_sync; SyncCtrlObj m_sync;
EventCtrlObj m_event; EventCtrlObj m_event;
ReconstructionCtrlObj m_reconstruction;
SlsDetector::EventCallback m_event_cb; SlsDetector::EventCallback m_event_cb;
}; };
......
...@@ -136,18 +136,18 @@ class Jungfrau : public Model ...@@ -136,18 +136,18 @@ class Jungfrau : public Model
public: public:
ImgProcTask(Jungfrau *jungfrau); ImgProcTask(Jungfrau *jungfrau);
void setConfig(std::string config);
void getConfig(std::string &config);
virtual void process(Data& data); virtual void process(Data& data);
private: private:
Jungfrau *m_jungfrau; Jungfrau *m_jungfrau;
}; };
enum ImgSrc { Raw, GainPedCorr };
Jungfrau(Camera *cam); Jungfrau(Camera *cam);
~Jungfrau(); ~Jungfrau();
virtual void getFrameDim(FrameDim& frame_dim, bool raw = false); virtual void getFrameDim(FrameDim& frame_dim, bool raw = false);
virtual void getAcqFrameDim(FrameDim& frame_dim, bool raw = false);
virtual void getDetMap(Data& det_map); virtual void getDetMap(Data& det_map);
...@@ -176,11 +176,22 @@ class Jungfrau : public Model ...@@ -176,11 +176,22 @@ class Jungfrau : public Model
void readGainADCMaps(Data& gain_map, Data& adc_map, FrameType& frame); 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 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 bool isXferActive();
virtual Reconstruction *getReconstruction()
{ return m_reconstruction; }
protected: protected:
virtual int getNbFrameMapItems(); virtual int getNbFrameMapItems();
virtual void updateFrameMapItems(FrameMap *map); virtual void updateFrameMapItems(FrameMap *map);
...@@ -290,6 +301,7 @@ class Jungfrau : public Model ...@@ -290,6 +301,7 @@ class Jungfrau : public Model
virtual void updateImageSize(Size size, bool raw); virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq(); virtual void prepareAcq();
virtual void clear();
virtual void processFrame(Data& data) = 0; virtual void processFrame(Data& data) = 0;
protected: protected:
...@@ -361,7 +373,7 @@ class Jungfrau : public Model ...@@ -361,7 +373,7 @@ class Jungfrau : public Model
GainADCMapImgProc(Jungfrau *jungfrau); GainADCMapImgProc(Jungfrau *jungfrau);
virtual void updateImageSize(Size size, bool raw); virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq(); virtual void clear();
virtual void processFrame(Data& data); virtual void processFrame(Data& data);
void readGainADCMaps(Data& gain_map, Data& adc_map, void readGainADCMaps(Data& gain_map, Data& adc_map,
...@@ -401,7 +413,7 @@ class Jungfrau : public Model ...@@ -401,7 +413,7 @@ class Jungfrau : public Model
GainPedImgProc(Jungfrau *jungfrau); GainPedImgProc(Jungfrau *jungfrau);
virtual void updateImageSize(Size size, bool raw); virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq(); virtual void clear();
virtual void processFrame(Data& data); virtual void processFrame(Data& data);
void readProcMap(Data& proc_map, FrameType& frame); void readProcMap(Data& proc_map, FrameType& frame);
...@@ -427,6 +439,21 @@ class Jungfrau : public Model ...@@ -427,6 +439,21 @@ class Jungfrau : public Model
AutoPtr<Reader> m_reader; 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 getRawMode() {
bool raw; bool raw;
getCamera()->getRawMode(raw); getCamera()->getRawMode(raw);
...@@ -477,6 +504,7 @@ class Jungfrau : public Model ...@@ -477,6 +504,7 @@ class Jungfrau : public Model
void addImgProc(ImgProcBase *img_proc); void addImgProc(ImgProcBase *img_proc);
void removeImgProc(ImgProcBase *img_proc); void removeImgProc(ImgProcBase *img_proc);
void removeAllImgProc(); void removeAllImgProc();
void doSetImgProcConfig(std::string config, bool force);
int getNbJungfrauModules() int getNbJungfrauModules()
{ return getNbDetModules(); } { return getNbDetModules(); }
...@@ -509,6 +537,9 @@ class Jungfrau : public Model ...@@ -509,6 +537,9 @@ class Jungfrau : public Model
AutoPtr<GainADCMapImgProc> m_gain_adc_map_img_proc; AutoPtr<GainADCMapImgProc> m_gain_adc_map_img_proc;
std::string m_img_proc_config; std::string m_img_proc_config;
ImgProcList m_img_proc_list; ImgProcList m_img_proc_list;
ImgSrc m_img_src;
BufferCtrlObj m_acq_buffer_ctrl_obj;
ModelReconstruction *m_reconstruction;
RecvList m_recv_list; RecvList m_recv_list;
FrameType m_nb_frames; FrameType m_nb_frames;
FrameType m_next_frame; FrameType m_next_frame;
...@@ -519,6 +550,7 @@ class Jungfrau : public Model ...@@ -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::GainPed::MapType map_type);
std::ostream& operator <<(std::ostream& os, Jungfrau::ImgSrc src);
} // namespace SlsDetector } // namespace SlsDetector
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "SlsDetectorDefs.h" #include "SlsDetectorDefs.h"
#include "SlsDetectorCPUAffinity.h" #include "SlsDetectorCPUAffinity.h"
#include "SlsDetectorReconstruction.h"
#include "lima/SizeUtils.h" #include "lima/SizeUtils.h"
...@@ -51,7 +52,8 @@ class Model ...@@ -51,7 +52,8 @@ class Model
virtual ~Model(); virtual ~Model();
virtual void getFrameDim(FrameDim& frame_dim, bool raw = false) = 0; virtual void getFrameDim(FrameDim& frame_dim, bool raw = false) = 0;
virtual void getAcqFrameDim(FrameDim& frame_dim, bool raw = false);
Camera *getCamera() Camera *getCamera()
{ return m_cam; } { return m_cam; }
...@@ -87,16 +89,19 @@ class Model ...@@ -87,16 +89,19 @@ class Model
virtual void setThreadCPUAffinity(const CPUAffinityList& aff_list) = 0; virtual void setThreadCPUAffinity(const CPUAffinityList& aff_list) = 0;
virtual Reconstruction *getReconstruction();
protected: protected:
void updateCameraModel(); void updateCameraModel();
void updateTimeRanges(); void updateCameraImageSize();
void updateCameraTimeRanges();
virtual void updateImageSize() = 0; virtual void updateImageSize() = 0;
void putCmd(const std::string& s, int idx = -1); void putCmd(const std::string& s, int idx = -1);
std::string getCmd(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; 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
{