Commit 83021557 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

Move frame packet assembly to Reconstruction

parent 1f168a62
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "SlsDetectorArgs.h" #include "SlsDetectorArgs.h"
#include "SlsDetectorReceiver.h" #include "SlsDetectorReceiver.h"
#include "SlsDetectorCPUAffinity.h" #include "SlsDetectorCPUAffinity.h"
#include "SlsDetectorModel.h"
#include "sls/Detector.h" #include "sls/Detector.h"
...@@ -222,6 +223,7 @@ private: ...@@ -222,6 +223,7 @@ private:
friend class Model; friend class Model;
friend class Receiver; friend class Receiver;
friend class GlobalCPUAffinityMgr; friend class GlobalCPUAffinityMgr;
friend class Reconstruction;
friend class Eiger; friend class Eiger;
...@@ -247,7 +249,8 @@ private: ...@@ -247,7 +249,8 @@ private:
void createReceivers(); void createReceivers();
DetFrameImagePackets readRecvPackets(); DetFrameImagePackets readRecvPackets();
void assemblePackets(DetFrameImagePackets&& det_packets); void publishFrame(FrameType frame);
void assemblePackets(DetFrameImagePackets&& det_frame_packets);
bool checkLostPackets(); bool checkLostPackets();
FrameType getLastReceivedFrame(); FrameType getLastReceivedFrame();
......
...@@ -514,10 +514,12 @@ class Eiger : public Model ...@@ -514,10 +514,12 @@ class Eiger : public Model
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::ModelReconstruction", DEB_CLASS_NAMESPC(DebModCamera, "Eiger::ModelReconstruction",
"SlsDetector"); "SlsDetector");
public: public:
ModelReconstruction(Eiger *eiger) : m_eiger(eiger) ModelReconstruction(Eiger *eiger)
: SlsDetector::Reconstruction(eiger->getCamera()),
m_eiger(eiger)
{ setActive(true); } { setActive(true); }
virtual Data process(Data& data); virtual Data processModel(Data& data);
private: private:
friend class Eiger; friend class Eiger;
......
...@@ -509,10 +509,12 @@ class Jungfrau : public Model ...@@ -509,10 +509,12 @@ class Jungfrau : public Model
DEB_CLASS_NAMESPC(DebModCamera, "Jungfrau::ModelReconstruction", DEB_CLASS_NAMESPC(DebModCamera, "Jungfrau::ModelReconstruction",
"SlsDetector"); "SlsDetector");
public: public:
ModelReconstruction(Jungfrau *jungfrau) : m_jungfrau(jungfrau) ModelReconstruction(Jungfrau *jungfrau)
: SlsDetector::Reconstruction(jungfrau->getCamera()),
m_jungfrau(jungfrau)
{} {}
virtual Data process(Data& data); virtual Data processModel(Data& data);
private: private:
friend class Jungfrau; friend class Jungfrau;
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
#define __SLS_DETECTOR_RECEIVER_H #define __SLS_DETECTOR_RECEIVER_H
#include "SlsDetectorFrameMap.h" #include "SlsDetectorFrameMap.h"
#include "SlsDetectorModel.h" #include "SlsDetectorCPUAffinity.h"
#include "SlsDetectorArgs.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "lima/Debug.h" #include "lima/Debug.h"
#include "lima/Exceptions.h" #include "lima/Exceptions.h"
#include "SlsDetectorReceiver.h"
namespace lima namespace lima
{ {
...@@ -58,16 +60,28 @@ public: ...@@ -58,16 +60,28 @@ public:
Reconstruction *m_r; Reconstruction *m_r;
}; };
Reconstruction(); Reconstruction(Camera *cam);
virtual ~Reconstruction(); virtual ~Reconstruction();
void setActive(bool active); void setActive(bool active);
void getActive(bool& active); void getActive(bool& active);
virtual void prepare();
void addFramePackets(DetFrameImagePackets&& det_frame_packets);
virtual Data process(Data& data);
virtual Data processModel(Data& data) = 0;
virtual void cleanUp();
private: private:
friend class CtrlObjProxy; friend class CtrlObjProxy;
Camera *m_cam;
CtrlObjProxy *m_proxy; CtrlObjProxy *m_proxy;
bool m_active; bool m_active;
Mutex m_mutex;
FramePacketMap m_frame_packet_map;
}; };
} // namespace SlsDetector } // namespace SlsDetector
......
...@@ -41,11 +41,14 @@ public: ...@@ -41,11 +41,14 @@ public:
virtual void reconstructionChange(LinkTask *task) = 0; virtual void reconstructionChange(LinkTask *task) = 0;
}; };
Reconstruction(); Reconstruction(SlsDetector::Camera *cam);
virtual ~Reconstruction(); virtual ~Reconstruction();
void setActive(bool active); void setActive(bool active);
void getActive(bool& active /Out/); void getActive(bool& active /Out/);
virtual Data process(Data& data);
virtual Data processModel(Data& data) = 0;
}; };
......
...@@ -876,6 +876,7 @@ void Camera::prepareAcq() ...@@ -876,6 +876,7 @@ void Camera::prepareAcq()
m_model->prepareAcq(); m_model->prepareAcq();
m_global_cpu_affinity_mgr.prepareAcq(); m_global_cpu_affinity_mgr.prepareAcq();
m_model->getReconstruction()->prepare();
resetFramesCaught(); resetFramesCaught();
EXC_CHECK(m_det->setFileWrite(0)); EXC_CHECK(m_det->setFileWrite(0));
...@@ -901,6 +902,9 @@ void Camera::stopAcq() ...@@ -901,6 +902,9 @@ void Camera::stopAcq()
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
Reconstruction *r = m_model ? m_model->getReconstruction() : NULL;
if (r)
r->cleanUp();
m_global_cpu_affinity_mgr.stopAcq(); m_global_cpu_affinity_mgr.stopAcq();
AutoMutex l = lock(); AutoMutex l = lock();
...@@ -984,6 +988,14 @@ DetFrameImagePackets Camera::readRecvPackets() ...@@ -984,6 +988,14 @@ DetFrameImagePackets Camera::readRecvPackets()
return det_frame_packets; return det_frame_packets;
} }
void Camera::publishFrame(FrameType frame)
{
DEB_MEMBER_FUNCT();
FrameMap::Item *mi = m_frame_map.getItem(0);
Model::FinishInfo finfo = mi->frameFinished(frame, true, true);
m_model->processFinishInfo(finfo);
}
void Camera::assemblePackets(DetFrameImagePackets&& det_frame_packets) void Camera::assemblePackets(DetFrameImagePackets&& det_frame_packets)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
...@@ -1003,10 +1015,6 @@ void Camera::assemblePackets(DetFrameImagePackets&& det_frame_packets) ...@@ -1003,10 +1015,6 @@ void Camera::assemblePackets(DetFrameImagePackets&& det_frame_packets)
if (!ok) if (!ok)
m_recv_list[i]->fillBadFrame(bptr); m_recv_list[i]->fillBadFrame(bptr);
} }
FrameMap::Item *mi = m_frame_map.getItem(0);
Model::FinishInfo finfo = mi->frameFinished(frame, true, true);
m_model->processFinishInfo(finfo);
} }
bool Camera::checkLostPackets() bool Camera::checkLostPackets()
......
...@@ -166,7 +166,7 @@ void Eiger::InterModGapCorr::correctFrame(FrameType /*frame*/, void *ptr) ...@@ -166,7 +166,7 @@ void Eiger::InterModGapCorr::correctFrame(FrameType /*frame*/, void *ptr)
} }
} }
Data Eiger::ModelReconstruction::process(Data& data) Data Eiger::ModelReconstruction::processModel(Data& data)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
......
...@@ -616,7 +616,7 @@ void Jungfrau::AveImgProc::readAveMap(Data& ave_map, FrameType& nb_frames, ...@@ -616,7 +616,7 @@ void Jungfrau::AveImgProc::readAveMap(Data& ave_map, FrameType& nb_frames,
* Jungfrau::ModelReconstruction class * Jungfrau::ModelReconstruction class
*/ */
Data Jungfrau::ModelReconstruction::process(Data& data) Data Jungfrau::ModelReconstruction::processModel(Data& data)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR4(m_jungfrau, data.frameNumber, DEB_PARAM() << DEB_VAR4(m_jungfrau, data.frameNumber,
......
...@@ -119,7 +119,9 @@ void Model::getAcqFrameDim(FrameDim& frame_dim, bool raw) ...@@ -119,7 +119,9 @@ void Model::getAcqFrameDim(FrameDim& frame_dim, bool raw)
void Model::processPackets() { void Model::processPackets() {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
DetFrameImagePackets packets = m_cam->readRecvPackets(); DetFrameImagePackets packets = m_cam->readRecvPackets();
m_cam->assemblePackets(std::move(packets)); FrameType frame = packets.first;
getReconstruction()->addFramePackets(std::move(packets));
m_cam->publishFrame(frame);
} }
void Model::processFinishInfo(const FinishInfo& finfo) void Model::processFinishInfo(const FinishInfo& finfo)
......
...@@ -25,6 +25,8 @@ using namespace lima; ...@@ -25,6 +25,8 @@ using namespace lima;
using namespace lima::SlsDetector; using namespace lima::SlsDetector;
using namespace std; using namespace std;
#include "SlsDetectorCamera.h"
/******************************************************************* /*******************************************************************
* \brief ReconstructionCtrlObj constructor * \brief ReconstructionCtrlObj constructor
*******************************************************************/ *******************************************************************/
...@@ -51,13 +53,13 @@ Reconstruction::CtrlObjProxy::~CtrlObjProxy() ...@@ -51,13 +53,13 @@ Reconstruction::CtrlObjProxy::~CtrlObjProxy()
LinkTask *Reconstruction::CtrlObjProxy::getReconstructionTask() LinkTask *Reconstruction::CtrlObjProxy::getReconstructionTask()
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
LinkTask *task = (m_r && m_r->m_active) ? m_r : NULL; LinkTask *task = m_r ? m_r : NULL;
DEB_RETURN() << DEB_VAR1(task); DEB_RETURN() << DEB_VAR1(task);
return task; return task;
} }
Reconstruction::Reconstruction() Reconstruction::Reconstruction(Camera *cam)
: m_proxy(NULL), m_active(false) : m_cam(cam), m_proxy(NULL), m_active(false)
{ {
DEB_CONSTRUCTOR(); DEB_CONSTRUCTOR();
} }
...@@ -73,11 +75,9 @@ void Reconstruction::setActive(bool active) ...@@ -73,11 +75,9 @@ void Reconstruction::setActive(bool active)
{ {
DEB_MEMBER_FUNCT(); DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(active, m_active); DEB_PARAM() << DEB_VAR2(active, m_active);
if (active == m_active)
return;
m_active = active; m_active = active;
if (m_proxy) if (m_proxy)
m_proxy->reconstructionChange(m_active ? this : NULL); m_proxy->reconstructionChange(this);
} }
void Reconstruction::getActive(bool& active) void Reconstruction::getActive(bool& active)
...@@ -86,3 +86,45 @@ void Reconstruction::getActive(bool& active) ...@@ -86,3 +86,45 @@ void Reconstruction::getActive(bool& active)
active = m_active; active = m_active;
DEB_RETURN() << DEB_VAR1(active); DEB_RETURN() << DEB_VAR1(active);
} }
void Reconstruction::prepare()
{
DEB_MEMBER_FUNCT();
AutoMutex l(m_mutex);
m_frame_packet_map.clear();
}
void Reconstruction::cleanUp()
{
DEB_MEMBER_FUNCT();
AutoMutex l(m_mutex);
m_frame_packet_map.clear();
}
void Reconstruction::addFramePackets(DetFrameImagePackets&& det_frame_packets)
{
DEB_MEMBER_FUNCT();
AutoMutex l(m_mutex);
m_frame_packet_map.emplace(std::move(det_frame_packets));
}
Data Reconstruction::process(Data& data)
{
DEB_MEMBER_FUNCT();
FrameType frame = data.frameNumber;
AutoMutex l(m_mutex);
FramePacketMap::iterator it = m_frame_packet_map.find(frame);
if (it == m_frame_packet_map.end())
return data;
DetFrameImagePackets det_frame_packets = std::move(*it);
m_frame_packet_map.erase(it);
l.unlock();
m_cam->assemblePackets(std::move(det_frame_packets));
return m_active ? processModel(data) : data;
}
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