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

Merge Receiver frame maps into Camera one

parent 687b4374
......@@ -164,13 +164,12 @@ public:
virtual int getRecvPorts() = 0;
virtual void prepareAcq() = 0;
virtual void processRecvFileStart(int recv_idx,
virtual void processRecvFileStart(int port_idx,
uint32_t dsize) = 0;
// TODO: add file finished callback
virtual void processRecvPort(int recv_idx, FrameType frame,
int port, char *dptr,
uint32_t dsize,
Mutex *lock, char *bptr) = 0;
virtual void processRecvPort(int port_idx, FrameType frame,
char *dptr, uint32_t dsize,
char *bptr) = 0;
private:
friend class Camera;
......@@ -265,6 +264,9 @@ public:
int getNbDetSubModules()
{ return m_det->getNMods(); }
int getPortIndex(int recv_idx, int port)
{ return recv_idx * m_recv_ports + port; }
void setBufferCbMgr(StdBufferCbMgr *buffer_cb_mgr)
{ m_buffer_cb_mgr = buffer_cb_mgr; }
......@@ -284,8 +286,8 @@ public:
void getFrameDim(FrameDim& frame_dim, bool raw = false)
{ m_model->getFrameDim(frame_dim, raw); }
const FrameMap& getRecvMap()
{ return m_recv_map; }
const FrameMap& getFrameMap()
{ return m_frame_map; }
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
......@@ -370,25 +372,8 @@ private:
~Receiver();
void start();
void prepareAcq();
private:
class FrameFinishedCallback : public FrameMap::Callback
{
DEB_CLASS_NAMESPC(DebModCamera,
"Camera::Receiver"
"::FrameFinishedCallback",
"SlsDetector");
public:
FrameFinishedCallback(Receiver *r);
protected:
virtual void frameFinished(FrameType frame);
private:
Receiver *m_recv;
};
friend class Camera;
friend class FrameFinishedCallback;
static int fileStartCallback(char *fpath, char *fname,
FrameType fidx, uint32_t dsize,
......@@ -413,16 +398,11 @@ private:
void portCallback(FrameType frame, int port, char *dptr,
uint32_t dsize);
void handleLostPackets();
Camera *m_cam;
int m_idx;
int m_rx_port;
int m_nb_ports;
FrameMap m_port_map;
Args m_args;
AutoPtr<slsReceiverUsers> m_recv;
AutoPtr<FrameFinishedCallback> m_cb;
};
typedef std::vector<AutoPtr<Receiver> > RecvList;
......@@ -476,10 +456,10 @@ private:
void removeSharedMem();
void createReceivers();
void receiverFrameFinished(FrameType frame, Receiver *recv);
void frameFinished(FrameType frame);
bool checkLostPackets();
void handleLostPackets();
FrameType getLastReceivedFrame();
void addValidReadoutFlags(DebObj *deb_ptr, ReadoutFlags flags,
......@@ -513,7 +493,8 @@ private:
double m_exp_time;
double m_frame_period;
Settings m_settings;
FrameMap m_recv_map;
FrameMap m_frame_map;
int m_recv_ports;
AutoPtr<FrameFinishedCallback> m_frame_cb;
StdBufferCbMgr *m_buffer_cb_mgr;
PixelDepth m_pixel_depth;
......
......@@ -94,10 +94,9 @@ class Eiger : public Camera::Model
virtual int getRecvPorts();
virtual void prepareAcq();
virtual void processRecvFileStart(int recv_idx, uint32_t dsize);
virtual void processRecvPort(int recv_idx, FrameType frame, int port,
char *dptr, uint32_t dsize, Mutex *lock,
char *bptr);
virtual void processRecvFileStart(int port_idx, uint32_t dsize);
virtual void processRecvPort(int port_idx, FrameType frame, char *dptr,
uint32_t dsize, char *bptr);
private:
friend class Correction;
......@@ -308,9 +307,6 @@ class Eiger : public Camera::Model
void getRecvFrameDim(FrameDim& frame_dim, bool raw, bool geom);
int getPortIndex(int recv_idx, int port)
{ return recv_idx * RecvPorts + port; }
CorrBase *createPixelDepth4Corr();
CorrBase *createChipBorderCorr(ImageType image_type);
CorrBase *createInterModGapCorr();
......
......@@ -98,12 +98,11 @@ public:
virtual int getRecvPorts() = 0;
virtual void prepareAcq() = 0;
virtual void processRecvFileStart(int recv_idx,
virtual void processRecvFileStart(int port_idx,
unsigned int dsize) = 0;
virtual void processRecvPort(int recv_idx, unsigned long frame,
int port, char *dptr,
unsigned int dsize,
Mutex *lock, char *bptr) = 0;
virtual void processRecvPort(int port_idx, unsigned long frame,
char *dptr, unsigned int dsize,
char *bptr) = 0;
};
class FrameMap
......@@ -151,6 +150,7 @@ public:
std::vector<std::string> getHostnameList();
int getNbDetModules();
int getNbDetSubModules();
int getPortIndex(int recv_idx, int port);
void setBufferCbMgr(StdBufferCbMgr *buffer_cb_mgr);
......@@ -167,7 +167,7 @@ public:
void getFrameDim(FrameDim& frame_dim /Out/, bool raw = false);
const SlsDetector::Camera::FrameMap& getRecvMap();
const SlsDetector::Camera::FrameMap& getFrameMap();
void putCmd(const std::string& s, int idx = -1);
std::string getCmd(const std::string& s, int idx = -1);
......
......@@ -73,10 +73,9 @@ class Eiger : public SlsDetector::Camera::Model
virtual int getRecvPorts();
virtual void prepareAcq();
virtual void processRecvFileStart(int recv_idx, unsigned int dsize);
virtual void processRecvPort(int recv_idx, unsigned long frame, int port,
char *dptr, unsigned int dsize, Mutex *lock,
char *bptr);
virtual void processRecvFileStart(int port_idx, unsigned int dsize);
virtual void processRecvPort(int port_idx, unsigned long frame,
char *dptr, unsigned int dsize, char *bptr);
};
}; // namespace SlsDetector
......@@ -329,28 +329,11 @@ ostream& lima::SlsDetector::operator <<(ostream& os,
return os << "}";
}
Camera::Receiver::FrameFinishedCallback::FrameFinishedCallback(Receiver *r)
: m_recv(r)
{
DEB_CONSTRUCTOR();
}
void Camera::Receiver::FrameFinishedCallback::frameFinished(FrameType frame)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(frame, m_recv->m_idx);
m_recv->m_cam->receiverFrameFinished(frame, m_recv);
}
Camera::Receiver::Receiver(Camera *cam, int idx, int rx_port)
: m_cam(cam), m_idx(idx), m_rx_port(rx_port), m_nb_ports(0)
: m_cam(cam), m_idx(idx), m_rx_port(rx_port)
{
DEB_CONSTRUCTOR();
m_cb = new FrameFinishedCallback(this);
m_port_map.setCallback(m_cb);
ostringstream os;
os << "slsReceiver"
<< " --rx_tcpport " << m_rx_port;
......@@ -379,14 +362,6 @@ void Camera::Receiver::start()
THROW_HW_ERROR(Error) << "Error starting slsReceiver";
}
void Camera::Receiver::prepareAcq()
{
DEB_MEMBER_FUNCT();
m_nb_ports = m_cam->m_model->getRecvPorts();
m_port_map.setNbItems(m_nb_ports);
m_port_map.clear();
}
int Camera::Receiver::fileStartCallback(char *fpath, char *fname,
uint64_t fidx, uint32_t dsize,
void *priv)
......@@ -424,8 +399,12 @@ int Camera::Receiver::fileStartCallback(char *fpath, char *fname,
{
DEB_MEMBER_FUNCT();
Model *model = m_cam->m_model;
if (model)
model->processRecvFileStart(m_idx, dsize);
if (model) {
for (int i = 0; i < model->getRecvPorts(); ++i) {
int port_idx = m_cam->getPortIndex(m_idx, i);
model->processRecvFileStart(port_idx, dsize);
}
}
return 0;
}
......@@ -439,21 +418,23 @@ void Camera::Receiver::portCallback(FrameType frame, int port, char *dptr,
return;
Mutex& lock = m_cam->m_cond.mutex();
FrameMap& frame_map = m_cam->m_frame_map;
try {
FrameType& nb_frames = m_cam->m_nb_frames;
if (frame >= nb_frames)
THROW_HW_ERROR(Error) << "Invalid "
<< DEB_VAR2(frame, nb_frames);
char *bptr = m_cam->getFrameBufferPtr(frame);
int port_idx = m_cam->getPortIndex(m_idx, port);
AutoMutex l(lock);
m_port_map.checkFinishedFrameItem(frame, port);
frame_map.checkFinishedFrameItem(frame, port_idx);
{
AutoMutexUnlock u(l);
model->processRecvPort(m_idx, frame, port, dptr, dsize,
&lock, bptr);
model->processRecvPort(port_idx, frame, dptr, dsize,
bptr);
}
m_port_map.frameItemFinished(frame, port, true);
frame_map.frameItemFinished(frame, port_idx, true);
} catch (Exception& e) {
ostringstream err_msg;
err_msg << "Receiver::frameCallback: " << e;
......@@ -465,23 +446,6 @@ void Camera::Receiver::portCallback(FrameType frame, int port, char *dptr,
}
}
void Camera::Receiver::handleLostPackets()
{
DEB_MEMBER_FUNCT();
Model *model = m_cam->m_model;
const FrameMap::List& nsff = m_port_map.getNonSeqFinishedFrames();
const FrameMap::Map& fm = m_port_map.getFramePendingItemsMap();
while (nsff.size() > 0) {
FrameType frame = m_port_map.getLastSeqFinishedFrame() + 1;
FrameMap::Map::const_iterator mit = fm.find(frame);
int port = (mit != fm.end()) ? *mit->second.begin() : 0;
char *bptr = m_cam->getFrameBufferPtr(frame);
model->processRecvPort(m_idx, frame, port, NULL, 0, NULL, bptr);
m_port_map.frameItemFinished(frame, port, true);
m_cam->m_bad_frame_list.push_back(frame);
}
}
Camera::FrameFinishedCallback::FrameFinishedCallback(Camera *cam)
: m_cam(cam)
{
......@@ -583,6 +547,7 @@ bool Camera::AcqThread::newFrameReady(FrameType frame)
Camera::Camera(string config_fname)
: m_model(NULL),
m_nb_frames(1),
m_recv_ports(0),
m_pixel_depth(PixelDepth16),
m_image_type(Bpp16),
m_raw_mode(false),
......@@ -710,8 +675,7 @@ void Camera::createReceivers()
}
m_frame_cb = new FrameFinishedCallback(this);
m_recv_map.setNbItems(recv_port_map.size());
m_recv_map.setCallback(m_frame_cb);
m_frame_map.setCallback(m_frame_cb);
}
void Camera::putCmd(const string& s, int idx)
......@@ -924,10 +888,10 @@ void Camera::prepareAcq()
{
AutoMutex l = lock();
RecvList::iterator it, end = m_recv_list.end();
for (it = m_recv_list.begin(); it != end; ++it)
(*it)->prepareAcq();
m_recv_map.clear();
m_recv_ports = m_model->getRecvPorts();
int nb_ports = m_recv_list.size() * m_recv_ports;
m_frame_map.setNbItems(nb_ports);
m_frame_map.clear();
DEB_TRACE() << DEB_VAR1(m_frame_queue.size());
while (!m_frame_queue.empty())
m_frame_queue.pop();
......@@ -967,13 +931,6 @@ void Camera::stopAcq()
THROW_HW_ERROR(Error) << "Camera not Idle";
}
void Camera::receiverFrameFinished(FrameType frame, Receiver *recv)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(frame, recv->m_idx);
m_recv_map.frameItemFinished(frame, recv->m_idx);
}
void Camera::frameFinished(FrameType frame)
{
DEB_MEMBER_FUNCT();
......@@ -987,27 +944,15 @@ bool Camera::checkLostPackets()
{
DEB_MEMBER_FUNCT();
bool bad_frames = false;
IntList::const_iterator bad_begin = m_bad_frame_list.end();
AutoMutex l = lock();
RecvList::iterator it, end = m_recv_list.end();
for (it = m_recv_list.begin(); it != end; ++it) {
Receiver *recv = *it;
const FrameMap& port_map = recv->m_port_map;
DEB_TRACE() << DEB_VAR2(recv->m_idx, port_map);
if (port_map.getNonSeqFinishedFrames().size() == 0)
continue;
if (m_tol_lost_packets) {
recv->handleLostPackets();
bad_frames = true;
continue;
}
if (m_frame_map.getNonSeqFinishedFrames().size() == 0) {
DEB_RETURN() << DEB_VAR1(false);
return false;
}
if (!m_tol_lost_packets) {
ostringstream err_msg;
err_msg << "checkLostPackets: recv[" << recv->m_idx << "]."
<< "port_map=" << port_map;
err_msg << "checkLostPackets: frame_map=" << m_frame_map;
Event::Code err_code = Event::CamOverrun;
Event *event = new Event(Hardware, Event::Error, Event::Camera,
err_code, err_msg.str());
......@@ -1020,7 +965,9 @@ bool Camera::checkLostPackets()
return true;
}
if (bad_frames && DEB_CHECK_ANY(DebTypeWarning)) {
IntList::const_iterator bad_begin = m_bad_frame_list.end();
handleLostPackets();
if (DEB_CHECK_ANY(DebTypeWarning)) {
AutoMutexUnlock u(l);
ostringstream msg;
IntList::const_iterator bad_end = m_bad_frame_list.end();
......@@ -1033,21 +980,26 @@ bool Camera::checkLostPackets()
return false;
}
Camera::FrameType Camera::getLastReceivedFrame()
void Camera::handleLostPackets()
{
DEB_MEMBER_FUNCT();
FrameType last_frame = -1;
RecvList::iterator it, end = m_recv_list.end();
for (it = m_recv_list.begin(); it != end; ++it) {
Receiver *recv = *it;
const FrameMap& port_map = recv->m_port_map;
DEB_TRACE() << DEB_VAR2(recv->m_idx, port_map);
FrameType frame = port_map.getLastItemFrame();
last_frame = port_map.latestFrame(last_frame, frame);
const FrameMap::List& nsff = m_frame_map.getNonSeqFinishedFrames();
const FrameMap::Map& fm = m_frame_map.getFramePendingItemsMap();
while (nsff.size() > 0) {
FrameType frame = m_frame_map.getLastSeqFinishedFrame() + 1;
FrameMap::Map::const_iterator mit = fm.find(frame);
int port_idx = (mit != fm.end()) ? *mit->second.begin() : 0;
char *bptr = getFrameBufferPtr(frame);
m_model->processRecvPort(port_idx, frame, NULL, 0, bptr);
m_frame_map.frameItemFinished(frame, port_idx, true);
m_bad_frame_list.push_back(frame);
}
}
Camera::FrameType Camera::getLastReceivedFrame()
{
DEB_MEMBER_FUNCT();
FrameType last_frame = m_frame_map.getLastItemFrame();
DEB_RETURN() << DEB_VAR1(last_frame);
return last_frame;
}
......
......@@ -545,21 +545,18 @@ void Eiger::prepareAcq()
(*cit)->prepareAcq();
}
void Eiger::processRecvFileStart(int recv_idx, uint32_t dsize)
void Eiger::processRecvFileStart(int port_idx, uint32_t dsize)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(recv_idx, dsize);
for (int i = 0; i < RecvPorts; ++i) {
int port_idx = getPortIndex(recv_idx, i);
m_port_geom_list[port_idx]->processRecvFileStart(dsize);
}
DEB_PARAM() << DEB_VAR2(port_idx, dsize);
m_port_geom_list[port_idx]->processRecvFileStart(dsize);
}
void Eiger::processRecvPort(int recv_idx, FrameType frame, int port, char *dptr,
uint32_t dsize, Mutex *lock, char *bptr)
void Eiger::processRecvPort(int port_idx, FrameType frame, char *dptr,
uint32_t dsize, char *bptr)
{
DEB_MEMBER_FUNCT();
int port_idx = getPortIndex(recv_idx, port);
DEB_PARAM() << DEB_VAR3(port_idx, frame, dsize);
m_port_geom_list[port_idx]->processRecvPort(frame, dptr, bptr);
}
......
......@@ -191,11 +191,11 @@ bool TestApp::newFrameReady(const HwFrameInfoType& frame_info)
Timestamp timestamp = Timestamp::now();
if (timestamp - m_last_msg_timestamp > WAIT_SLEEP_TIME) {
int frames_caught = m_cam->getFramesCaught();
const Camera::FrameMap& recv_map = m_cam->getRecvMap();
int finished_frames = recv_map.getLastSeqFinishedFrame() + 1;
const Camera::FrameMap& frame_map = m_cam->getFrameMap();
int finished_frames = frame_map.getLastSeqFinishedFrame() + 1;
DEB_ALWAYS() << DEB_VAR3(frame_info.acq_frame_nb,
frames_caught, finished_frames);
DEB_PARAM() << DEB_VAR1(recv_map);
DEB_PARAM() << DEB_VAR1(frame_map);
m_last_msg_timestamp = timestamp;
}
......
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