This commit is contained in:
Erik Frojdh 2019-04-09 17:32:54 +02:00
parent 31a4a46fb6
commit 026d4019c5
5 changed files with 84 additions and 1 deletions

View File

@ -69,6 +69,7 @@ outputs:
host:
- python
- pybind11 2.2
- pyzmq
- sls_detector_lib
- libstdcxx-ng
- libgcc-ng

View File

@ -1,3 +1,6 @@
import os
import sys
sys.path.append(os.path.join(os.getcwd(), 'bin'))
from sls_detector import Eiger
from sls_detector import ExperimentalDetector

View File

@ -2,6 +2,7 @@
#include <pybind11/stl.h>
#include "Detector.h"
#include "mythenFileIO.h"
namespace py = pybind11;
@ -284,6 +285,7 @@ py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
.def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP)
;
m.def("hej", &hej, "some");
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;

77
python/src/mythenFileIO.h Normal file
View File

@ -0,0 +1,77 @@
#pragma once
#include <cassert>
#include <cmath>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <vector>
template <size_t bit_index0, size_t bit_index1>
std::vector<int> ExtractBits(const std::vector<uint64_t> &data, int dr = 24) {
constexpr int mask0 = (1 << bit_index0);
constexpr int mask1 = (1 << bit_index1);
constexpr int NumStrips = 2;
const int NumCompleteSamples = data.size() / dr;
const int NumCounters = NumCompleteSamples * NumStrips;
std::vector<int> result(NumCounters);
auto ptr = data.data();
auto strip0 = result.data();
auto strip1 = strip0 + NumCompleteSamples;
for (int j = 0; j != NumCompleteSamples; ++j) {
for (int i = 0; i != dr; ++i) {
int bit0 = (*ptr & mask0) >> bit_index0;
int bit1 = (*ptr++ & mask1) >> bit_index1;
*strip0 |= bit0 << i;
*strip1 |= bit1 << i;
}
strip0++;
strip1++;
}
return result;
}
template <size_t bit_index>
std::vector<int> ExtractBits(const std::vector<uint64_t> &data, int dr = 24) {
constexpr int mask = (1 << bit_index);
const int NumCompleteSamples = data.size() / dr;
std::vector<int> result(NumCompleteSamples);
auto ptr = data.data();
for (auto &r : result) {
for (int i = 0; i != dr; ++i) {
int bit = (*ptr++ & mask) >> bit_index;
r |= bit << i;
}
}
return result;
}
std::vector<uint64_t> ReadFile(const std::string &fname, int offset = 8, int dr = 24) {
const int element_size = static_cast<int>(sizeof(uint64_t));
const int byte_offset = element_size * offset;
const int expected_size = dr * element_size * 32 * 3;
std::ifstream fs(fname, std::ios::binary | std::ios::ate);
if (!fs.is_open()) {
throw std::runtime_error("File not found: " + std::string(fname));
}
auto data_size = static_cast<long>(fs.tellg()) - byte_offset;
if (data_size != expected_size) {
auto diff = data_size - expected_size;
std::cout << "WARNING: data size is: " << data_size
<< " expected size is: " << expected_size << ", " << std::abs(diff) << " bytes "
<< ((diff < 0) ? "missing" : "too many") << '\n';
}
std::vector<uint64_t> data(expected_size / element_size);
fs.seekg(byte_offset, std::ios::beg);
fs.read(reinterpret_cast<char *>(data.data()), data_size);
return data;
}
int hej(){
return 5;
}

View File

@ -2112,7 +2112,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int (*measurement_finished)(int, int, void *){nullptr};
void *measFinished_p{nullptr};
int (*progress_call)(double, void *);
int (*progress_call)(double, void *){nullptr};
void *pProgressCallArg{nullptr};
int (*dataReady)(detectorData *, int, int, void *){nullptr};