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

Jungfrau: add DoubleBuffer to GainADCImgProc, read does not copy data

parent 70c62230
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define __SLS_DETECTOR_JUNGFRAU_H #define __SLS_DETECTOR_JUNGFRAU_H
#include "SlsDetectorCamera.h" #include "SlsDetectorCamera.h"
#include "SlsDetectorDoubleBuffer.h"
#include "processlib/SinkTask.h" #include "processlib/SinkTask.h"
...@@ -85,7 +86,7 @@ class Jungfrau : public Model ...@@ -85,7 +86,7 @@ class Jungfrau : public Model
void setImgProcConfig(std::string config); void setImgProcConfig(std::string config);
void getImgProcConfig(std::string &config); void getImgProcConfig(std::string &config);
void readGainADCMaps(Data& gain_map, Data& adc_map); void readGainADCMaps(Data& gain_map, Data& adc_map, FrameType& frame);
virtual bool isXferActive(); virtual bool isXferActive();
...@@ -210,6 +211,21 @@ class Jungfrau : public Model ...@@ -210,6 +211,21 @@ class Jungfrau : public Model
memset(d.data(), 0, d.size()); memset(d.data(), 0, d.size());
} }
static void makeDataRef(Data& src, Data& ref,
Buffer::Callback *cb) {
ref.type = src.type;
ref.dimensions = src.dimensions;
ref.frameNumber = src.frameNumber;
ref.timestamp = src.timestamp;
ref.header = src.header;
Buffer *b = new Buffer;
b->owner = Buffer::MAPPED;
b->callback = cb;
b->data = src.data();
ref.setBuffer(b);
b->unref();
}
protected: protected:
friend class Jungfrau; friend class Jungfrau;
Jungfrau *m_jungfrau; Jungfrau *m_jungfrau;
...@@ -228,38 +244,84 @@ class Jungfrau : public Model ...@@ -228,38 +244,84 @@ class Jungfrau : public Model
DEB_CLASS_NAMESPC(DebModCamera, "Jungfrau::GainADCMapImgProc", DEB_CLASS_NAMESPC(DebModCamera, "Jungfrau::GainADCMapImgProc",
"SlsDetector"); "SlsDetector");
public: public:
GainADCMapImgProc(Jungfrau *jungfrau);
virtual void updateImageSize(Size size, bool raw);
virtual void prepareAcq();
virtual void processFrame(Data& data);
void readGainADCMaps(Data& gain_map, Data& adc_map,
FrameType& frame);
private:
struct MapData { struct MapData {
Data gain_map; Data gain_map;
Data adc_map; Data adc_map;
Mutex mutex;
AutoMutex lock() { return mutex; }
MapData() { MapData() {
gain_map.type = Data::UINT8; gain_map.type = Data::UINT8;
adc_map.type = Data::UINT16; adc_map.type = Data::UINT16;
} }
void updateSize(Size size) { void updateSize(Size size) {
AutoMutex l = lock();
updateDataSize(gain_map, size); updateDataSize(gain_map, size);
updateDataSize(adc_map, size); updateDataSize(adc_map, size);
}; };
void clear() { void clear() {
AutoMutex l = lock();
clearData(gain_map); clearData(gain_map);
clearData(adc_map); clearData(adc_map);
} }
}; };
GainADCMapImgProc(Jungfrau *jungfrau); typedef DoubleBuffer<MapData> DBuffer;
virtual void updateImageSize(Size size, bool raw); class ReaderHelper : public Buffer::Callback {
virtual void prepareAcq(); DEB_CLASS_NAMESPC(DebModCamera, "Jungfrau::"
virtual void processFrame(Data& data); "GainADCMapImgProc::ReaderHelper",
"SlsDetector");
public:
void addRead(DBuffer& b, Data& gain_map, Data& adc_map,
FrameType frame) {
DEB_MEMBER_FUNCT();
if (m_reader)
THROW_HW_ERROR(Error)
<< "A reader is already active";
m_reader = new Reader(b, frame);
MapData& m = m_reader->getBuffer();
DEB_TRACE() << DEB_VAR1(&m);
makeDataRef(m.gain_map, gain_map, this);
++m_count;
makeDataRef(m.adc_map, adc_map, this);
++m_count;
DEB_TRACE() << DEB_VAR1(m_count);
frame = m_reader->getCounter();
}
protected:
virtual void destroy(void *buffer) {
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(m_count);
if ((m_count == 0) || !m_reader)
DEB_ERROR() << DEB_VAR1(m_count);
MapData& m = m_reader->getBuffer();
if ((buffer != m.gain_map.data()) &&
(buffer != m.adc_map.data()))
THROW_HW_ERROR(Error)
<< "Bad buffer";
if (--m_count == 0)
m_reader = NULL;
}
private: private:
friend class Jungfrau; typedef DoubleBufferReader<MapData> Reader;
MapData m_data;
AutoPtr<Reader> m_reader;
int m_count{0};
};
DBuffer m_buffer;
AutoPtr<ReaderHelper> m_reader;
}; };
void addImgProc(ImgProcBase *img_proc); void addImgProc(ImgProcBase *img_proc);
......
...@@ -75,7 +75,8 @@ class Jungfrau : public SlsDetector::Model ...@@ -75,7 +75,8 @@ class Jungfrau : public SlsDetector::Model
void setImgProcConfig(std::string config); void setImgProcConfig(std::string config);
void getImgProcConfig(std::string &config /Out/); void getImgProcConfig(std::string &config /Out/);
void readGainADCMaps(Data& gain_map /Out/, Data& adc_map /Out/); void readGainADCMaps(Data& gain_map /Out/, Data& adc_map /Out/,
unsigned long& frame /In,Out/);
virtual bool isXferActive(); virtual bool isXferActive();
......
...@@ -254,7 +254,7 @@ void Jungfrau::ImgProcBase::prepareAcq() ...@@ -254,7 +254,7 @@ void Jungfrau::ImgProcBase::prepareAcq()
*/ */
Jungfrau::GainADCMapImgProc::GainADCMapImgProc(Jungfrau *jungfrau) Jungfrau::GainADCMapImgProc::GainADCMapImgProc(Jungfrau *jungfrau)
: ImgProcBase(jungfrau, "gain_adc_map") : ImgProcBase(jungfrau, "gain_adc_map"), m_reader(new ReaderHelper)
{ {
DEB_CONSTRUCTOR(); DEB_CONSTRUCTOR();
} }
...@@ -262,27 +262,32 @@ Jungfrau::GainADCMapImgProc::GainADCMapImgProc(Jungfrau *jungfrau) ...@@ -262,27 +262,32 @@ Jungfrau::GainADCMapImgProc::GainADCMapImgProc(Jungfrau *jungfrau)
void Jungfrau::GainADCMapImgProc::updateImageSize(Size size, bool raw) void Jungfrau::GainADCMapImgProc::updateImageSize(Size size, bool raw)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
DEB_ALWAYS() << DEB_VAR3(m_name, size, raw); DEB_PARAM() << DEB_VAR3(m_name, size, raw);
ImgProcBase::updateImageSize(size, raw); ImgProcBase::updateImageSize(size, raw);
m_data.updateSize(size); for (auto& d : m_buffer)
d.updateSize(size);
} }
void Jungfrau::GainADCMapImgProc::prepareAcq() void Jungfrau::GainADCMapImgProc::prepareAcq()
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
ImgProcBase::prepareAcq(); ImgProcBase::prepareAcq();
m_data.clear();
for (auto& d : m_buffer)
d.clear();
m_buffer.reset();
} }
void Jungfrau::GainADCMapImgProc::processFrame(Data& data) void Jungfrau::GainADCMapImgProc::processFrame(Data& data)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
long frame = data.frameNumber; long frame = data.frameNumber;
DEB_ALWAYS() << DEB_VAR1(frame); DEB_PARAM() << DEB_VAR1(frame);
MapData& m = m_data; DoubleBufferWriter<MapData> w(m_buffer);
AutoMutex l = m.lock(); MapData& m = w.getBuffer();
DEB_TRACE() << DEB_VAR1(&m);
unsigned short *src; unsigned short *src;
{ {
src = (unsigned short *) data.data(); src = (unsigned short *) data.data();
...@@ -298,8 +303,17 @@ void Jungfrau::GainADCMapImgProc::processFrame(Data& data) ...@@ -298,8 +303,17 @@ void Jungfrau::GainADCMapImgProc::processFrame(Data& data)
*dst++ = *src++ & 0x3fff; *dst++ = *src++ & 0x3fff;
m.adc_map.frameNumber = frame; m.adc_map.frameNumber = frame;
} }
w.setCounter(frame);
} }
void Jungfrau::GainADCMapImgProc::readGainADCMaps(Data& gain_map, Data& adc_map,
FrameType& frame)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(frame);
m_reader->addRead(m_buffer, gain_map, adc_map, frame);
DEB_RETURN() << DEB_VAR3(gain_map, adc_map, frame);
}
/* /*
* Jungfrau detector class * Jungfrau detector class
...@@ -667,6 +681,10 @@ void Jungfrau::prepareAcq() ...@@ -667,6 +681,10 @@ void Jungfrau::prepareAcq()
ThreadList::iterator tit, tend = m_thread_list.end(); ThreadList::iterator tit, tend = m_thread_list.end();
for (tit = m_thread_list.begin(); tit != tend; ++tit) for (tit = m_thread_list.begin(); tit != tend; ++tit)
(*tit)->prepareAcq(); (*tit)->prepareAcq();
ImgProcList::iterator pit, pend = m_img_proc_list.end();
for (pit = m_img_proc_list.begin(); pit != pend; ++pit)
(*pit)->prepareAcq();
} }
void Jungfrau::startAcq() void Jungfrau::startAcq()
...@@ -827,7 +845,7 @@ void Jungfrau::getImgProcConfig(std::string &config) ...@@ -827,7 +845,7 @@ void Jungfrau::getImgProcConfig(std::string &config)
DEB_RETURN() << DEB_VAR1(config); DEB_RETURN() << DEB_VAR1(config);
} }
void Jungfrau::readGainADCMaps(Data& gain_map, Data& adc_map) void Jungfrau::readGainADCMaps(Data& gain_map, Data& adc_map, FrameType& frame)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
ImgProcList::iterator it, end = m_img_proc_list.end(); ImgProcList::iterator it, end = m_img_proc_list.end();
...@@ -838,9 +856,6 @@ void Jungfrau::readGainADCMaps(Data& gain_map, Data& adc_map) ...@@ -838,9 +856,6 @@ void Jungfrau::readGainADCMaps(Data& gain_map, Data& adc_map)
if (it == end) if (it == end)
THROW_HW_ERROR(Error) << "ImgProc gain_adc_map not found"; THROW_HW_ERROR(Error) << "ImgProc gain_adc_map not found";
GainADCMapImgProc *img_proc = static_cast<GainADCMapImgProc *>(*it); GainADCMapImgProc *img_proc = static_cast<GainADCMapImgProc *>(*it);
GainADCMapImgProc::MapData& m = img_proc->m_data; img_proc->readGainADCMaps(gain_map, adc_map, frame);
AutoMutex l = m.lock();
gain_map = m.gain_map.copy();
adc_map = m.adc_map.copy();
} }
...@@ -512,13 +512,15 @@ class SlsDetector(PyTango.Device_4Impl): ...@@ -512,13 +512,15 @@ class SlsDetector(PyTango.Device_4Impl):
@Core.DEB_MEMBER_FUNCT @Core.DEB_MEMBER_FUNCT
def read_jungfrau_gain_map(self, attr): def read_jungfrau_gain_map(self, attr):
jungfrau = _SlsDetectorJungfrau jungfrau = _SlsDetectorJungfrau
gain_data, adc_data = jungfrau.readGainADCMaps() gain_data, adc_data, frame = jungfrau.readGainADCMaps(-1)
deb.Always("frame=%s" % frame)
attr.set_value(gain_data.buffer) attr.set_value(gain_data.buffer)
@Core.DEB_MEMBER_FUNCT @Core.DEB_MEMBER_FUNCT
def read_jungfrau_adc_map(self, attr): def read_jungfrau_adc_map(self, attr):
jungfrau = _SlsDetectorJungfrau jungfrau = _SlsDetectorJungfrau
gain_data, adc_data = jungfrau.readGainADCMaps() gain_data, adc_data, frame = jungfrau.readGainADCMaps(-1)
deb.Always("frame=%s" % frame)
attr.set_value(adc_data.buffer) attr.set_value(adc_data.buffer)
@Core.DEB_MEMBER_FUNCT @Core.DEB_MEMBER_FUNCT
......
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