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

Extend BadFrameList API (port_idx, slices), update Eiger::BadRecvFrameCorr

parent f4f0345c
......@@ -145,10 +145,11 @@ public:
void setTolerateLostPackets(bool tol_lost_packets);
void getTolerateLostPackets(bool& tol_lost_packets);
void getBadFrameList(IntList& bad_frame_list);
bool isBadFrame(int port_idx, FrameType frame)
{ return m_buffer_thread[port_idx].isBadFrame(frame); }
int getNbBadFrames(int port_idx);
void getBadFrameList(int port_idx, int first_idx, int last_idx,
IntList& bad_frame_list);
void getBadFrameList(int port_idx, IntList& bad_frame_list);
void prepareAcq();
void startAcq();
......@@ -267,6 +268,19 @@ private:
bool isBadFrame(FrameType frame);
int getNbBadFrames()
{
AutoMutex l = lock();
return m_bad_frame_list.size();
}
void getBadFrameList(int first_idx, int last_idx, IntList& bfl)
{
AutoMutex l = lock();
IntList::const_iterator b = m_bad_frame_list.begin();
bfl.assign(b + first_idx, b + last_idx);
}
protected:
virtual void start();
virtual void threadFunction();
......@@ -358,9 +372,10 @@ private:
bool checkLostPackets();
FrameType getLastReceivedFrame();
IntList getSortedBadFrameList(IntList first_idx, IntList last_idx);
IntList getSortedBadFrameList()
{ return getSortedBadFrameList(IntList(), IntList()); }
void getSortedBadFrameList(IntList first_idx, IntList last_idx,
IntList& bad_frame_list );
void getSortedBadFrameList(IntList& bad_frame_list)
{ getSortedBadFrameList(IntList(), IntList(), bad_frame_list); }
void addValidReadoutFlags(DebObj *deb_ptr, ReadoutFlags flags,
IntList& flag_list, NameList& flag_name_list);
......
......@@ -159,7 +159,19 @@ class Eiger : public Model
public:
BadRecvFrameCorr(Eiger *eiger);
virtual void prepareAcq();
virtual void correctFrame(FrameType frame, void *ptr);
protected:
struct BadFrameData {
int last_idx;
IntList bad_frame_list;
void reset();
};
Camera *m_cam;
int m_nb_ports;
std::vector<BadFrameData> m_bfd_list;
};
class PixelDepth4Corr : public CorrBase
......
......@@ -106,9 +106,12 @@ public:
void setTolerateLostPackets(bool tol_lost_packets);
void getTolerateLostPackets(bool& tol_lost_packets /Out/);
void getBadFrameList(std::vector<int>& bad_frame_list /Out/);
bool isBadFrame(int port_idx, unsigned long frame);
int getNbBadFrames(int port_idx);
void getBadFrameList(int port_idx, int first_idx, int last_idx,
std::vector<int>& bad_frame_list /Out/);
void getBadFrameList(int port_idx,
std::vector<int>& bad_frame_list /Out/);
void prepareAcq();
void startAcq();
......
......@@ -292,9 +292,12 @@ void Camera::BufferThread::processFinishInfo(FinishInfo& finfo)
<< "port_idx=" << m_port_idx
<< ", first=" << finfo.first_lost
<< ", nb=" << finfo.nb_lost;
FrameType f = finfo.first_lost;
for (int i = 0; i < finfo.nb_lost; ++i, ++f)
m_bad_frame_list.push_back(f);
{
AutoMutex l = lock();
FrameType f = finfo.first_lost;
for (int i = 0; i < finfo.nb_lost; ++i, ++f)
m_bad_frame_list.push_back(f);
}
SortedIntList::const_iterator it, end = finfo.finished.end();
for (it = finfo.finished.begin(); it != end; ++it)
m_cam->frameFinished(*it);
......@@ -311,6 +314,7 @@ void Camera::BufferThread::processFinishInfo(FinishInfo& finfo)
bool Camera::BufferThread::isBadFrame(FrameType frame)
{
AutoMutex l = lock();
IntList::iterator end = m_bad_frame_list.end();
return (find(m_bad_frame_list.begin(), end, frame) != end);
}
......@@ -407,9 +411,14 @@ void Camera::AcqThread::threadFunction()
det->stopReceiver();
}
IntList bfl = m_cam->getSortedBadFrameList();
DEB_ALWAYS() << "bad_frames=" << bfl.size() << ": "
<< PrettyIntList(bfl);
{
AutoMutexUnlock u(l);
IntList bfl;
m_cam->getSortedBadFrameList(bfl);
DEB_ALWAYS() << "bad_frames=" << bfl.size() << ": "
<< PrettyIntList(bfl);
}
Stats stats;
m_cam->getStats(stats);
DEB_ALWAYS() << DEB_VAR1(stats);
......@@ -1011,11 +1020,8 @@ bool Camera::checkLostPackets()
int nb_ports = getTotNbPorts();
IntList first_bad(nb_ports);
if (DEB_CHECK_ANY(DebTypeWarning)) {
AutoMutex l = lock();
for (int i = 0; i < nb_ports; ++i) {
IntList& buff_bfl = m_buffer_thread[i].m_bad_frame_list;
first_bad[i] = buff_bfl.size();
}
for (int i = 0; i < nb_ports; ++i)
first_bad[i] = m_buffer_thread[i].getNbBadFrames();
}
for (int i = 0; i < nb_ports; ++i) {
if (ifa[i] != last_frame)
......@@ -1023,12 +1029,10 @@ bool Camera::checkLostPackets()
}
if (DEB_CHECK_ANY(DebTypeWarning)) {
IntList last_bad(nb_ports);
AutoMutex l = lock();
for (int i = 0; i < nb_ports; ++i) {
IntList& buff_bfl = m_buffer_thread[i].m_bad_frame_list;
last_bad[i] = buff_bfl.size();
}
IntList bfl = getSortedBadFrameList(first_bad, last_bad);
for (int i = 0; i < nb_ports; ++i)
last_bad[i] = m_buffer_thread[i].getNbBadFrames();
IntList bfl;
getSortedBadFrameList(first_bad, last_bad, bfl);
DEB_WARNING() << "bad_frames=" << bfl.size() << ": "
<< PrettyIntList(bfl);
}
......@@ -1325,38 +1329,72 @@ void Camera::getTolerateLostPackets(bool& tol_lost_packets)
DEB_RETURN() << DEB_VAR1(tol_lost_packets);
}
IntList Camera::getSortedBadFrameList(IntList first_idx, IntList last_idx)
int Camera::getNbBadFrames(int port_idx)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(port_idx);
if ((port_idx < -1) || (port_idx >= getTotNbPorts()))
THROW_HW_ERROR(InvalidValue) << DEB_VAR1(port_idx);
int nb_bad_frames;
if (port_idx == -1) {
IntList bfl;
getBadFrameList(port_idx, bfl);
nb_bad_frames = bfl.size();
} else {
nb_bad_frames = m_buffer_thread[port_idx].getNbBadFrames();
}
DEB_RETURN() << DEB_VAR1(nb_bad_frames);
return nb_bad_frames;
}
void Camera::getSortedBadFrameList(IntList first_idx, IntList last_idx,
IntList& bad_frame_list)
{
int nb_ports = getTotNbPorts();
bool all = first_idx.empty();
IntList bfl;
for (int i = 0; i < nb_ports; ++i) {
IntList& buff_bfl = m_buffer_thread[i].m_bad_frame_list;
BufferThread *buffer_thread = m_buffer_thread;
for (int i = 0; i < nb_ports; ++i, ++buffer_thread) {
int first = all ? 0 : first_idx[i];
int last = all ? buff_bfl.size() : last_idx[i];
IntList::const_iterator b = buff_bfl.begin();
bfl.insert(bfl.end(), b + first, b + last);
int last = all ? buffer_thread->getNbBadFrames() : last_idx[i];
IntList l;
buffer_thread->getBadFrameList(first, last, l);
bfl.insert(bfl.end(), l.begin(), l.end());
}
IntList::iterator first = bfl.begin();
IntList::iterator last = bfl.end();
sort(first, last);
IntList aux(last - first);
IntList::iterator aux_end, aux_begin = aux.begin();
aux_end = unique_copy(first, last, aux_begin);
aux.resize(aux_end - aux_begin);
return aux;
bad_frame_list.resize(last - first);
IntList::iterator bfl_end, bfl_begin = bad_frame_list.begin();
bfl_end = unique_copy(first, last, bfl_begin);
bad_frame_list.resize(bfl_end - bfl_begin);
}
void Camera::getBadFrameList(IntList& bad_frame_list)
void Camera::getBadFrameList(int port_idx, int first_idx, int last_idx,
IntList& bad_frame_list)
{
DEB_MEMBER_FUNCT();
{
AutoMutex l = lock();
bad_frame_list = getSortedBadFrameList();
}
DEB_PARAM() << DEB_VAR3(port_idx, first_idx, last_idx);
if ((port_idx < 0) || (port_idx >= getTotNbPorts()))
THROW_HW_ERROR(InvalidValue) << DEB_VAR1(port_idx);
BufferThread *buffer_thread = &m_buffer_thread[port_idx];
buffer_thread->getBadFrameList(first_idx, last_idx, bad_frame_list);
DEB_RETURN() << DEB_VAR1(PrettyIntList(bad_frame_list));
}
void Camera::getBadFrameList(int port_idx, IntList& bad_frame_list)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(port_idx);
if (port_idx == -1)
getSortedBadFrameList(bad_frame_list);
else
getBadFrameList(port_idx, 0, getNbBadFrames(port_idx),
bad_frame_list);
}
void Camera::registerTimeRangesChangedCallback(TimeRangesChangedCallback& cb)
{
DEB_MEMBER_FUNCT();
......
......@@ -65,22 +65,54 @@ void Eiger::CorrBase::prepareAcq()
m_inter_lines[m_nb_eiger_modules - 1] = 0;
}
void Eiger::BadRecvFrameCorr::BadFrameData::reset()
{
last_idx = 0;
bad_frame_list.clear();
}
Eiger::BadRecvFrameCorr::BadRecvFrameCorr(Eiger *eiger)
: CorrBase(eiger)
{
DEB_CONSTRUCTOR();
m_cam = m_eiger->getCamera();
m_nb_ports = m_cam->getTotNbPorts();
m_bfd_list.resize(m_nb_ports);
}
void Eiger::BadRecvFrameCorr::prepareAcq()
{
DEB_MEMBER_FUNCT();
CorrBase::prepareAcq();
for (int i = 0; i < m_nb_ports; ++i)
m_bfd_list[i].reset();
}
void Eiger::BadRecvFrameCorr::correctFrame(FrameType frame, void *ptr)
{
DEB_MEMBER_FUNCT();
Camera *cam = m_eiger->getCamera();
int nb_ports = cam->getTotNbPorts();
for (int i = 0; i < nb_ports; ++i) {
if (cam->isBadFrame(i, frame))
m_eiger->processRecvPort(i, frame, NULL, 0,
(char *) ptr);
char *bptr = (char *) ptr;
for (int i = 0; i < m_nb_ports; ++i) {
BadFrameData& bfd = m_bfd_list[i];
IntList& bfl = bfd.bad_frame_list;
int& last_idx = bfd.last_idx;
if (bfl.empty()) {
int bad_frames = m_cam->getNbBadFrames(i);
if (bad_frames == last_idx)
continue;
m_cam->getBadFrameList(i, last_idx, bad_frames, bfl);
}
IntList::iterator end = bfl.end();
if (find(bfl.begin(), end, frame) != end)
m_eiger->processRecvPort(i, frame, NULL, 0, bptr);
if (*(end - 1) > int(frame))
continue;
last_idx += bfl.size();
bfl.clear();
}
}
......
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