Commit 681d3442 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Operator for ID00
Browse files

Move defs and Eiger code to seperate SlsDetectorDefs/Eiger files

parent e5e0cd18
......@@ -24,27 +24,19 @@
#define __SLS_DETECTOR_CAMERA_H
#include "SlsDetectorArgs.h"
#include "SlsDetectorDefs.h"
#include "multiSlsDetector.h"
#include "multiSlsDetectorCommand.h"
#include "slsReceiverUsers.h"
#include "receiver_defs.h"
#include "processlib/LinkTask.h"
#include "lima/SizeUtils.h"
#include "lima/RegExUtils.h"
#include "lima/ThreadUtils.h"
#include "lima/MemUtils.h"
#include "lima/HwBufferMgr.h"
#include "lima/HwMaxImageSizeCallback.h"
#include "lima/Event.h"
#include <iostream>
#include <string>
#include <stdexcept>
#include <cstdlib>
#include <set>
#include <queue>
namespace lima
......@@ -58,6 +50,9 @@ class Camera : public HwMaxImageSizeCallbackGen, public EventCallbackGen
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "SlsDetector");
public:
typedef Defs::TrigMode TrigMode;
typedef Defs::Settings Settings;
enum State {
Idle, Init, Starting, Running, StopReq, Stopping, Stopped,
};
......@@ -66,34 +61,6 @@ public:
UnknownDet, GenericDet, EigerDet, JungfrauDet,
};
enum TrigMode {
Auto = slsDetectorDefs::AUTO_TIMING,
TriggerExposure = slsDetectorDefs::TRIGGER_EXPOSURE,
TriggerReadout = slsDetectorDefs::TRIGGER_READOUT,
Gating = slsDetectorDefs::GATE_FIX_NUMBER,
TriggeredGating = slsDetectorDefs::GATE_WITH_START_TRIGGER,
BurstTrigger = slsDetectorDefs::BURST_TRIGGER,
};
enum Settings {
Standard = slsDetectorDefs::STANDARD,
Fast = slsDetectorDefs::FAST,
HighGain = slsDetectorDefs::HIGHGAIN,
DynamicGain = slsDetectorDefs::DYNAMICGAIN,
LowGain = slsDetectorDefs::LOWGAIN,
MediumGain = slsDetectorDefs::MEDIUMGAIN,
VeryHighGain = slsDetectorDefs::VERYHIGHGAIN,
LowNoise = slsDetectorDefs::LOWNOISE,
DynamicHG0 = slsDetectorDefs::DYNAMICHG0,
FixGain1 = slsDetectorDefs::FIXGAIN1,
FixGain2 = slsDetectorDefs::FIXGAIN2,
ForceSwitchG1 = slsDetectorDefs::FORCESWITCHG1,
ForceSwitchG2 = slsDetectorDefs::FORCESWITCHG2,
VeryLowGain = slsDetectorDefs::VERYLOWGAIN,
Undefined = slsDetectorDefs::UNDEFINED,
Unitialized = slsDetectorDefs::UNINITIALIZED,
};
typedef uint64_t FrameType;
typedef std::vector<std::string> HostnameList;
......@@ -185,7 +152,7 @@ public:
{ return m_map; }
bool isValidFrame(FrameType frame)
{ return (frame != -1); }
{ return (frame != FrameType(-1)); }
private:
friend class Callback;
......@@ -440,271 +407,12 @@ private:
std::ostream& operator <<(std::ostream& os, Camera::State state);
std::ostream& operator <<(std::ostream& os, Camera::Type type);
std::ostream& operator <<(std::ostream& os, Camera::TrigMode trig_mode);
std::ostream& operator <<(std::ostream& os, Camera::Settings settings);
std::ostream& operator <<(std::ostream& os, const Camera::FrameMap& m);
std::ostream& operator <<(std::ostream& os, const Camera::FrameMap::List& l);
std::ostream& operator <<(std::ostream& os, const Camera::FrameMap::Map& m);
#define EIGER_PACKET_DATA_LEN (4 * 1024)
class Eiger : public Camera::Model
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger", "SlsDetector");
public:
typedef unsigned char Byte;
typedef unsigned short Word;
typedef unsigned int Long;
typedef Camera::FrameType FrameType;
enum CorrType {
ChipBorder, Gap,
};
class CorrBase
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::CorrBase",
"SlsDetector");
public:
CorrBase(Eiger *eiger, CorrType type);
virtual ~CorrBase();
bool getRaw();
int getNbModules()
{ return m_nb_modules; }
virtual void prepareAcq();
virtual void correctFrame(FrameType frame, void *ptr) = 0;
protected:
friend class Eiger;
Eiger *m_eiger;
CorrType m_type;
int m_nb_modules;
FrameDim m_mod_frame_dim;
Size m_frame_size;
std::vector<int> m_inter_lines;
};
typedef std::map<CorrType, CorrBase *> CorrMap;
class InterModGapCorr : public CorrBase
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::InterModGapCorr",
"SlsDetector");
public:
InterModGapCorr(Eiger *eiger);
virtual void prepareAcq();
virtual void correctFrame(FrameType frame, void *ptr);
protected:
typedef std::pair<int, int> Block;
typedef std::vector<Block> BlockList;
BlockList m_gap_list;
};
class Correction : public LinkTask
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Correction",
"SlsDetector");
public:
Correction(Eiger *eiger);
virtual Data process(Data& data);
private:
typedef std::vector<AutoPtr<CorrBase> > CorrList;
CorrList m_corr_list;
};
Eiger(Camera *cam);
~Eiger();
virtual void getFrameDim(FrameDim& frame_dim, bool raw = false);
virtual std::string getName();
virtual void getPixelSize(double& x_size, double& y_size);
// the returned object must be deleted by the caller
Correction *createCorrectionTask();
protected:
virtual bool checkSettings(Camera::Settings settings);
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);
private:
friend class Correction;
friend class CorrBase;
class RecvPortGeometry
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::RecvPortGeometry",
"SlsDetector");
public:
RecvPortGeometry(Eiger *eiger, int recv_idx, int port);
void prepareAcq();
void processRecvFileStart(uint32_t dsize);
void processRecvPort(FrameType frame, char *dptr, char *bptr);
private:
Eiger *m_eiger;
int m_port;
bool m_top_half_recv;
bool m_port_idx;
bool m_raw;
int m_recv_idx;
int m_port_offset;
int m_dlw; // dest line width
int m_plw; // packet line width
int m_clw; // chip line width
int m_pchips;
};
typedef std::vector<AutoPtr<RecvPortGeometry> > PortGeometryList;
template <class T>
class ChipBorderCorr : public CorrBase
{
public:
ChipBorderCorr(Eiger *eiger)
: CorrBase(eiger, ChipBorder)
{}
virtual void prepareAcq()
{
CorrBase::prepareAcq();
m_f.resize(m_nb_modules);
std::vector<BorderFactor>::iterator it = m_f.begin();
for (int i = 0; i < m_nb_modules; ++i, ++it) {
it->resize(2);
(*it)[0] = m_eiger->getBorderCorrFactor(i, 0);
(*it)[1] = m_eiger->getBorderCorrFactor(i, 1);
}
}
virtual void correctFrame(FrameType frame, void *ptr)
{
correctBorderCols(ptr);
correctBorderRows(ptr);
correctInterChipCols(ptr);
correctInterChipRows(ptr);
}
private:
typedef std::vector<double> BorderFactor;
static void correctInterChipLine(T *d, int offset, int nb_iter,
int step)
{
for (int i = 0; i < nb_iter; ++i, d += step)
d[0] = d[offset] /= 2;
}
static void correctBorderLine(T *d, int nb_iter, int step,
double f)
{
for (int i = 0; i < nb_iter; ++i, d += step)
d[0] /= f;
}
void correctInterChipCols(void *ptr)
{
int width = m_frame_size.getWidth();
int height= m_frame_size.getHeight();
T *d = static_cast<T *>(ptr);
for (int i = 0; i < HalfModuleChips - 1; ++i) {
d += ChipSize;
correctInterChipLine(d++, -1, height, width);
correctInterChipLine(d++, 1, height, width);
}
}
void correctInterChipRows(void *ptr)
{
int width = m_frame_size.getWidth();
int mod_height = m_mod_frame_dim.getSize().getHeight();
T *p = static_cast<T *>(ptr);
for (int i = 0; i < m_nb_modules; ++i) {
T *d = p + ChipSize * width;
correctInterChipLine(d, -width, width, 1);
d += width;
correctInterChipLine(d, width, width, 1);
if (i == m_nb_modules - 1)
continue;
p += (mod_height + m_inter_lines[i]) * width;
}
}
void correctBorderCols(void *ptr)
{
int width = m_frame_size.getWidth();
int height= m_frame_size.getHeight();
T *d = static_cast<T *>(ptr);
correctBorderLine(d, height, width, 2);
d += width - 1;
correctBorderLine(d, height, width, 2);
}
void correctBorderRows(void *ptr)
{
int width = m_frame_size.getWidth();
int mod_height = m_mod_frame_dim.getSize().getHeight();
T *p = static_cast<T *>(ptr);
for (int i = 0; i < m_nb_modules; ++i) {
double f0 = m_f[i][0], f1 = m_f[i][1];
T *d = p;
correctBorderLine(d, width, 1, f0);
d += width;
correctBorderLine(d, width, 1, f1);
d += (mod_height - 1 - 2) * width;
correctBorderLine(d, width, 1, f1);
d += width;
correctBorderLine(d, width, 1, f0);
p += (mod_height + m_inter_lines[i]) * width;
}
}
std::vector<BorderFactor> m_f;
};
void getRecvFrameDim(FrameDim& frame_dim, bool raw, bool geom);
int getPortIndex(int recv_idx, int port)
{ return recv_idx * RecvPorts + port; }
CorrBase *createChipBorderCorr(ImageType image_type);
CorrBase *createInterModGapCorr();
void addCorr(CorrBase *corr);
void removeCorr(CorrBase *corr);
double getBorderCorrFactor(int det, int line);
int getInterModuleGap(int det);
static const int ChipSize;
static const int ChipGap;
static const int HalfModuleChips;
static const int RecvPorts;
int m_nb_det_modules;
FrameDim m_recv_frame_dim;
CorrMap m_corr_map;
PortGeometryList m_port_geom_list;
};
} // namespace SlsDetector
} // namespace lima
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __SLS_DETECTOR_DEFS_H
#define __SLS_DETECTOR_DEFS_H
#include "sls_detector_defs.h"
namespace lima
{
namespace SlsDetector
{
namespace Defs
{
enum TrigMode {
Auto = slsDetectorDefs::AUTO_TIMING,
TriggerExposure = slsDetectorDefs::TRIGGER_EXPOSURE,
TriggerReadout = slsDetectorDefs::TRIGGER_READOUT,
Gating = slsDetectorDefs::GATE_FIX_NUMBER,
TriggeredGating = slsDetectorDefs::GATE_WITH_START_TRIGGER,
BurstTrigger = slsDetectorDefs::BURST_TRIGGER,
};
enum Settings {
Standard = slsDetectorDefs::STANDARD,
Fast = slsDetectorDefs::FAST,
HighGain = slsDetectorDefs::HIGHGAIN,
DynamicGain = slsDetectorDefs::DYNAMICGAIN,
LowGain = slsDetectorDefs::LOWGAIN,
MediumGain = slsDetectorDefs::MEDIUMGAIN,
VeryHighGain = slsDetectorDefs::VERYHIGHGAIN,
LowNoise = slsDetectorDefs::LOWNOISE,
DynamicHG0 = slsDetectorDefs::DYNAMICHG0,
FixGain1 = slsDetectorDefs::FIXGAIN1,
FixGain2 = slsDetectorDefs::FIXGAIN2,
ForceSwitchG1 = slsDetectorDefs::FORCESWITCHG1,
ForceSwitchG2 = slsDetectorDefs::FORCESWITCHG2,
VeryLowGain = slsDetectorDefs::VERYLOWGAIN,
Undefined = slsDetectorDefs::UNDEFINED,
Unitialized = slsDetectorDefs::UNINITIALIZED,
};
std::ostream& operator <<(std::ostream& os, TrigMode trig_mode);
std::ostream& operator <<(std::ostream& os, Settings settings);
} // namespace Defs
} // namespace SlsDetector
} // namespace lima
#endif // __SLS_DETECTOR_DEFS_H
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef __SLS_DETECTOR_EIGER_H
#define __SLS_DETECTOR_EIGER_H
#include "SlsDetectorCamera.h"
#include "processlib/LinkTask.h"
namespace lima
{
namespace SlsDetector
{
#define EIGER_PACKET_DATA_LEN (4 * 1024)
class Eiger : public Camera::Model
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger", "SlsDetector");
public:
typedef Defs::Settings Settings;
typedef Camera::FrameType FrameType;
typedef unsigned char Byte;
typedef unsigned short Word;
typedef unsigned int Long;
enum CorrType {
ChipBorder, Gap,
};
class CorrBase
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::CorrBase",
"SlsDetector");
public:
CorrBase(Eiger *eiger, CorrType type);
virtual ~CorrBase();
bool getRaw();
int getNbModules()
{ return m_nb_modules; }
virtual void prepareAcq();
virtual void correctFrame(FrameType frame, void *ptr) = 0;
protected:
friend class Eiger;
Eiger *m_eiger;
CorrType m_type;
int m_nb_modules;
FrameDim m_mod_frame_dim;
Size m_frame_size;
std::vector<int> m_inter_lines;
};
typedef std::map<CorrType, CorrBase *> CorrMap;
class InterModGapCorr : public CorrBase
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::InterModGapCorr",
"SlsDetector");
public:
InterModGapCorr(Eiger *eiger);
virtual void prepareAcq();
virtual void correctFrame(FrameType frame, void *ptr);
protected:
typedef std::pair<int, int> Block;
typedef std::vector<Block> BlockList;
BlockList m_gap_list;
};
class Correction : public LinkTask
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::Correction",
"SlsDetector");
public:
Correction(Eiger *eiger);
virtual Data process(Data& data);
private:
typedef std::vector<AutoPtr<CorrBase> > CorrList;
CorrList m_corr_list;
};
Eiger(Camera *cam);
~Eiger();
virtual void getFrameDim(FrameDim& frame_dim, bool raw = false);
virtual std::string getName();
virtual void getPixelSize(double& x_size, double& y_size);
// the returned object must be deleted by the caller
Correction *createCorrectionTask();
protected:
virtual bool checkSettings(Settings settings);
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);
private:
friend class Correction;
friend class CorrBase;
class RecvPortGeometry
{
DEB_CLASS_NAMESPC(DebModCamera, "Eiger::RecvPortGeometry",
"SlsDetector");
public:
RecvPortGeometry(Eiger *eiger, int recv_idx, int port);
void prepareAcq();
void processRecvFileStart(uint32_t dsize);
void processRecvPort(FrameType frame, char *dptr, char *bptr);
private:
Eiger *m_eiger;
int m_port;
bool m_top_half_recv;
bool m_port_idx;
bool m_raw;
int m_recv_idx;
int m_port_offset;
int m_dlw; // dest line width
int m_plw; // packet line width
int m_clw; // chip line width
int m_pchips;
};
typedef std::vector<AutoPtr<RecvPortGeometry> > PortGeometryList;
template <class T>
class ChipBorderCorr : public CorrBase
{
public:
ChipBorderCorr(Eiger *eiger)
: CorrBase(eiger, ChipBorder)
{}
virtual void prepareAcq()
{
CorrBase::prepareAcq();
m_f.resize(m_nb_modules);
std::vector<BorderFactor>::iterator it = m_f.begin();
for (int i = 0; i < m_nb_modules; ++i, ++it) {
it->resize(2);
(*it)[0] = m_eiger->getBorderCorrFactor(i, 0);
(*it)[1] = m_eiger->getBorderCorrFactor(i, 1);
}
}
virtual void correctFrame(FrameType frame, void *ptr)