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

SIP: add support of PixelDepth/CPUAffinity control; remove obsolete frame map

parent 838ecfe4
......@@ -198,6 +198,7 @@ public:
private:
Camera *m_cam;
};
typedef std::map<PixelDepth, SystemCPUAffinity>
PixelDepthCPUAffinityMap;
......
......@@ -24,91 +24,34 @@
{
%TypeHeaderCode
#include <set>
%End
%ConvertToTypeCode
if(sipIsErr == NULL)
{
bool aReturnFlag = PyList_Check(sipPy);
for(int i = 0;aReturnFlag && i < PyList_Size(sipPy);++i)
aReturnFlag = PyInt_Check(PyList_GET_ITEM(sipPy,i));
return aReturnFlag;
}
*sipCppPtr = new std::set<int>();
for(int i = 0;i < PyList_Size(sipPy);++i)
(*sipCppPtr)->insert(PyInt_AS_LONG(PyList_GET_ITEM(sipPy,i)));
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
PyObject* aReturnListPt = PyList_New(sipCpp->size());
std::set<int>::iterator lIter = sipCpp->begin();
for(int i = 0;lIter != sipCpp->end();++lIter,++i)
PyList_SET_ITEM(aReturnListPt,i,PyInt_FromLong(*lIter));
return aReturnListPt;
%End
};
using namespace std;
%MappedType std::map<unsigned long,std::set<int>>
{
%TypeHeaderCode
#include <map>
#include <set>
typedef set<int> CPP_SeqType;
%End
%ConvertToTypeCode
PyObject *key, *value;
SIP_SSIZE_T pos;
if(sipIsErr == NULL)
{
bool aReturnFlag = PyDict_Check(sipPy);
pos = 0;
while(aReturnFlag && PyDict_Next(sipPy, &pos, &key, &value))
{
aReturnFlag = PyInt_Check(key) && PyList_Check(value);
for(int i = 0;aReturnFlag && i < PyList_Size(value);++i)
aReturnFlag = PyInt_Check(PyList_GET_ITEM(value,i));
}
return aReturnFlag;
}
*sipCppPtr = new std::map<unsigned long,std::set<int> >();
pos = 0;
while(PyDict_Next(sipPy, &pos, &key, &value))
{
unsigned long anIndex = PyInt_AS_LONG(key);
std::pair<std::map<unsigned long,std::set<int> >::iterator, bool> aResult =
(*sipCppPtr)->insert(std::pair<unsigned long,std::set<int> >(anIndex,std::set<int>()));
for(int i = 0;i < PyList_Size(value);++i)
{
int n = PyInt_AS_LONG(PyList_GET_ITEM(value,i));
aResult.first->second.insert(n);
}
}
return sipGetState(sipTransferObj);
if (sipIsErr == NULL) {
bool ok = PyList_Check(sipPy);
for (int i = 0; ok && (i < PyList_Size(sipPy)); ++i)
ok = PyInt_Check(PyList_GET_ITEM(sipPy, i));
return ok;
}
*sipCppPtr = new CPP_SeqType();
for (int i = 0; i < PyList_Size(sipPy); ++i) {
int val = PyInt_AS_LONG(PyList_GET_ITEM(sipPy, i));
(*sipCppPtr)->insert(val);
}
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
PyObject* aReturnDictPt = PyDict_New();
for(std::map<unsigned long,std::set<int> >::iterator mIter = sipCpp->begin();
mIter != sipCpp->end();++mIter)
{
PyObject *aKeyPt = PyInt_FromLong(mIter->first);
PyObject *aValuePt = PyList_New(mIter->second.size());
PyDict_SetItem(aReturnDictPt,aKeyPt,aValuePt);
Py_DECREF(aKeyPt);Py_DECREF(aValuePt);
std::set<int>::iterator iPt = mIter->second.begin();
for(int i = 0;iPt != mIter->second.end();++i,++iPt)
PyList_SET_ITEM(aValuePt,i,PyInt_FromLong(*iPt));
}
return aReturnDictPt;
PyObject* sip_list = PyList_New(sipCpp->size());
CPP_SeqType::iterator it = sipCpp->begin();
for (int i = 0; it != sipCpp->end(); ++it, ++i)
PyList_SET_ITEM(sip_list, i, PyInt_FromLong(*it));
return sip_list;
%End
};
......@@ -20,6 +20,85 @@
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
// namespace SlsDetector
// {
// class Camera
// {
// public:
// typedef std::map<PixelDepth, SystemCPUAffinity> PixelDepthCPUAffinityMap;
// };
// };
%MappedType SlsDetector::Camera::PixelDepthCPUAffinityMap
{
%TypeHeaderCode
#include <map>
#include "SlsDetectorCamera.h"
#include "sipAPIlimaslsdetector.h"
using namespace std;
using namespace lima;
using namespace lima::SlsDetector;
typedef Camera::PixelDepth CPP_KeyType;
typedef Camera::SystemCPUAffinity CPP_ValueType;
typedef Camera::PixelDepthCPUAffinityMap CPP_MapType;
#define SIP_ValueType sipType_SlsDetector_Camera_SystemCPUAffinity
%End
%ConvertToTypeCode
PyObject *key, *value;
SIP_SSIZE_T pos;
if (sipIsErr == NULL) {
bool ok = PyDict_Check(sipPy);
pos = 0;
while (ok && PyDict_Next(sipPy, &pos, &key, &value))
ok = (PyInt_Check(key) &&
sipCanConvertToType(value, SIP_ValueType,
SIP_NOT_NONE));
return ok;
}
*sipCppPtr = new CPP_MapType();
pos = 0;
while (PyDict_Next(sipPy, &pos, &key, &value)) {
CPP_KeyType cpp_key = CPP_KeyType(PyInt_AS_LONG(key));
void *p = sipConvertToType(value, SIP_ValueType, NULL,
SIP_NOT_NONE, NULL, sipIsErr);
CPP_ValueType *cpp_value = static_cast<CPP_ValueType *>(p);
CPP_MapType::value_type map_value(cpp_key, *cpp_value);
(*sipCppPtr)->insert(map_value);
}
return sipGetState(sipTransferObj);
%End
%ConvertFromTypeCode
PyObject* sip_map = PyDict_New();
CPP_MapType::iterator it, end = sipCpp->end();
for (it = sipCpp->begin(); it != end; ++it) {
PyObject *key = PyInt_FromLong(it->first);
if (key == NULL)
goto error;
PyObject *value = sipConvertFromType(&it->second, SIP_ValueType,
sipTransferObj);
if (value == NULL) {
Py_DECREF(key);
goto error;
}
PyDict_SetItem(sip_map, key, value);
Py_DECREF(value);
Py_DECREF(key);
}
return sip_map;
error:
Py_DECREF(sip_map);
return NULL;
%End
};
namespace SlsDetector
{
......@@ -60,6 +139,35 @@ public:
double max_frame_period;
};
class CPUAffinity
{
public:
CPUAffinity(unsigned long m = 0);
static int getNbCPUs();
static unsigned long allCPUs();
void applyToTask(int task, bool incl_threads = true) const;
operator unsigned long() const;
//CPUAffinity& operator =(unsigned long m);
};
struct SystemCPUAffinity {
SlsDetector::Camera::CPUAffinity recv;
SlsDetector::Camera::CPUAffinity lima;
SlsDetector::Camera::CPUAffinity other;
SystemCPUAffinity(SlsDetector::Camera *cam = NULL);
void applyAndSet(const SlsDetector::Camera::SystemCPUAffinity& o);
};
//typedef std::map<SlsDetector::Camera::PixelDepth,
// SlsDetector::Camera::SystemCPUAffinity>
// PixelDepthCPUAffinityMap;
static bool isValidFrame(unsigned long frame);
static unsigned long latestFrame(unsigned long a, unsigned long b);
......@@ -254,6 +362,11 @@ public:
void stopAcq();
void getStats(SlsDetector::Camera::Stats& stats /Out/);
void setPixelDepthCPUAffinityMap(
SlsDetector::Camera::PixelDepthCPUAffinityMap aff_map);
void getPixelDepthCPUAffinityMap(
SlsDetector::Camera::PixelDepthCPUAffinityMap& aff_map /Out/);
};
......
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