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

Add TolerateLostPackets option, including retrieval of BadFrameList

parent 421488d9
......@@ -44,6 +44,49 @@ namespace lima
namespace SlsDetector
{
template <class T>
class PrettyList
{
public:
typedef typename T::const_iterator const_iterator;
PrettyList(const T& l) : begin(l.begin()), end(l.end()) {}
PrettyList(const_iterator b, const_iterator e) : begin(b), end(e) {}
ostream& print(ostream& os) const
{
os << "[";
int prev;
bool in_seq = false;
bool first = true;
for (const_iterator it = begin; it != end; ++it) {
int val = *it;
bool seq = (!first && (val == prev + 1));
if (!seq) {
if (in_seq)
os << "-" << prev;
os << (first ? "" : ",") << val;
}
prev = val;
in_seq = seq;
first = false;
}
if (in_seq)
os << "-" << prev;
return os << "]";
}
private:
const_iterator begin, end;
};
template <class T>
std::ostream& operator <<(std::ostream& os, const PrettyList<T>& pl)
{
return pl.print(os);
}
class Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGen
{
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "SlsDetector");
......@@ -127,7 +170,7 @@ public:
virtual void processRecvPort(int recv_idx, FrameType frame,
int port, char *dptr,
uint32_t dsize,
Mutex& lock, char *bptr) = 0;
Mutex *lock, char *bptr) = 0;
private:
friend class Camera;
......@@ -285,6 +328,10 @@ public:
void getReadoutFlags(ReadoutFlags& flags);
void getValidReadoutFlags(IntList& flag_list, NameList& flag_name_list);
void setTolerateLostPackets(bool tol_lost_packets);
void getTolerateLostPackets(bool& tol_lost_packets);
void getBadFrameList(IntList& bad_frame_list);
void prepareAcq();
void startAcq();
void stopAcq();
......@@ -366,9 +413,12 @@ 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;
......@@ -474,6 +524,8 @@ private:
FrameQueue m_frame_queue;
double m_new_frame_timeout;
double m_abort_sleep_time;
bool m_tol_lost_packets;
IntList m_bad_frame_list;
};
std::ostream& operator <<(std::ostream& os, Camera::State state);
......
......@@ -96,7 +96,7 @@ class Eiger : public Camera::Model
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 *dptr, uint32_t dsize, Mutex *lock,
char *bptr);
private:
......
......@@ -103,7 +103,7 @@ public:
virtual void processRecvPort(int recv_idx, unsigned long frame,
int port, char *dptr,
unsigned int dsize,
Mutex& lock, char *bptr) = 0;
Mutex *lock, char *bptr) = 0;
};
class FrameMap
......@@ -214,6 +214,10 @@ public:
void getValidReadoutFlags(std::vector<int>& flag_list /Out/,
std::vector<std::string>& flag_name_list /Out/);
void setTolerateLostPackets(bool tol_lost_packets);
void getTolerateLostPackets(bool& tol_lost_packets /Out/);
void getBadFrameList(std::vector<int>& bad_frame_list /Out/);
void prepareAcq();
void startAcq();
void stopAcq();
......
......@@ -75,7 +75,7 @@ class Eiger : public SlsDetector::Camera::Model
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 *dptr, unsigned int dsize, Mutex *lock,
char *bptr);
};
......
......@@ -26,6 +26,7 @@
#include "multiSlsDetectorCommand.h"
#include <limits.h>
#include <algorithm>
using namespace std;
using namespace lima;
......@@ -313,25 +314,7 @@ ostream& lima::SlsDetector::operator <<(ostream& os,
ostream& lima::SlsDetector::operator <<(ostream& os,
const Camera::FrameMap::List& l)
{
os << "[";
typedef Camera::FrameMap::List List;
List::const_iterator it, end = l.end();
bool first, in_seq = false;
int prev;
for (it = l.begin(), first = true; it != end; ++it, first = false) {
int val = *it;
bool seq = (!first && (val == prev + 1));
if (!seq) {
if (in_seq)
os << "-" << prev;
os << (first ? "" : ",") << val;
}
prev = val;
in_seq = seq;
}
if (in_seq)
os << "-" << prev;
return os << "]";
return os << PrettyList<Camera::FrameMap::List>(l);
}
ostream& lima::SlsDetector::operator <<(ostream& os,
......@@ -360,7 +343,7 @@ void Camera::Receiver::FrameFinishedCallback::frameFinished(FrameType frame)
}
Camera::Receiver::Receiver(Camera *cam, int idx, int rx_port)
: m_cam(cam), m_idx(idx), m_rx_port(rx_port)
: m_cam(cam), m_idx(idx), m_rx_port(rx_port), m_nb_ports(0)
{
DEB_CONSTRUCTOR();
......@@ -399,8 +382,8 @@ void Camera::Receiver::start()
void Camera::Receiver::prepareAcq()
{
DEB_MEMBER_FUNCT();
int recv_ports = m_cam->m_model->getRecvPorts();
m_port_map.setNbItems(recv_ports);
m_nb_ports = m_cam->m_model->getRecvPorts();
m_port_map.setNbItems(m_nb_ports);
m_port_map.clear();
}
......@@ -468,7 +451,7 @@ void Camera::Receiver::portCallback(FrameType frame, int port, char *dptr,
{
AutoMutexUnlock u(l);
model->processRecvPort(m_idx, frame, port, dptr, dsize,
lock, bptr);
&lock, bptr);
}
m_port_map.frameItemFinished(frame, port, true);
} catch (Exception& e) {
......@@ -482,6 +465,23 @@ 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)
{
......@@ -587,8 +587,9 @@ Camera::Camera(string config_fname)
m_image_type(Bpp16),
m_raw_mode(false),
m_state(Idle),
m_new_frame_timeout(1),
m_abort_sleep_time(1)
m_new_frame_timeout(0.1),
m_abort_sleep_time(1),
m_tol_lost_packets(true)
{
DEB_CONSTRUCTOR();
......@@ -930,6 +931,7 @@ void Camera::prepareAcq()
DEB_TRACE() << DEB_VAR1(m_frame_queue.size());
while (!m_frame_queue.empty())
m_frame_queue.pop();
m_bad_frame_list.clear();
}
m_model->prepareAcq();
......@@ -985,6 +987,9 @@ 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) {
......@@ -994,6 +999,12 @@ bool Camera::checkLostPackets()
if (port_map.getNonSeqFinishedFrames().size() == 0)
continue;
if (m_tol_lost_packets) {
recv->handleLostPackets();
bad_frames = true;
continue;
}
ostringstream err_msg;
err_msg << "checkLostPackets: recv[" << recv->m_idx << "]."
<< "port_map=" << port_map;
......@@ -1009,6 +1020,15 @@ bool Camera::checkLostPackets()
return true;
}
if (bad_frames && DEB_CHECK_ANY(DebTypeWarning)) {
AutoMutexUnlock u(l);
ostringstream msg;
IntList::const_iterator bad_end = m_bad_frame_list.end();
msg << PrettyList<IntList>(bad_begin, bad_end);
DEB_WARNING() << "bad_frames=" << (bad_end - bad_begin) << ": "
<< msg.str();
}
DEB_RETURN() << DEB_VAR1(false);
return false;
}
......@@ -1294,3 +1314,40 @@ void Camera::getValidReadoutFlags(IntList& flag_list, NameList& flag_name_list)
add_valid_flags(flags);
}
}
void Camera::setTolerateLostPackets(bool tol_lost_packets)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(tol_lost_packets);
m_tol_lost_packets = tol_lost_packets;
}
void Camera::getTolerateLostPackets(bool& tol_lost_packets)
{
DEB_MEMBER_FUNCT();
tol_lost_packets = m_tol_lost_packets;
DEB_RETURN() << DEB_VAR1(tol_lost_packets);
}
void Camera::getBadFrameList(IntList& bad_frame_list)
{
DEB_MEMBER_FUNCT();
IntList aux_list;
{
AutoMutex l = lock();
aux_list = m_bad_frame_list;
}
sort(aux_list.begin(), aux_list.end());
bad_frame_list.clear();
bool first = true;
int prev;
IntList::const_iterator it, end = aux_list.end();
for (it = aux_list.begin(); it != end; ++it) {
int val = *it;
if (first || (val != prev))
bad_frame_list.push_back(val);
first = false;
prev = val;
}
DEB_RETURN() << DEB_VAR1(PrettyList<IntList>(bad_frame_list));
}
......@@ -220,12 +220,16 @@ void Eiger::RecvPortGeometry::processRecvPort(FrameType frame, char *dptr,
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR3(frame, m_recv_idx, m_port);
bool valid_data = (dptr != NULL);
char *src = dptr;
char *dest = bptr + m_port_offset;
for (int i = 0; i < ChipSize; ++i, dest += m_ilw) {
char *d = dest;
for (int j = 0; j < m_pchips; ++j, src += m_scw, d += m_dcw)
memcpy(d, src, m_scw);
if (valid_data)
memcpy(d, src, m_scw);
else
memset(d, 0xff, m_scw);
}
}
......@@ -552,7 +556,7 @@ void Eiger::processRecvFileStart(int recv_idx, uint32_t dsize)
}
void Eiger::processRecvPort(int recv_idx, FrameType frame, int port, char *dptr,
uint32_t dsize, Mutex& lock, char *bptr)
uint32_t dsize, Mutex *lock, char *bptr)
{
DEB_MEMBER_FUNCT();
int port_idx = getPortIndex(recv_idx, port);
......
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