ProcessJFPacket: Enable conversion (no storage cells at the moment)
This commit is contained in:
@@ -6,13 +6,15 @@
|
||||
#include "ProcessJFPacket.h"
|
||||
#include "jf_packet.h"
|
||||
#include "../common/JFJochException.h"
|
||||
#include "JFConversionFixedPoint.h"
|
||||
|
||||
ProcessJFPacket::ProcessJFPacket(ThreadSafeFIFO<Completion> &in_c, ThreadSafeFIFO<WorkRequest> &in_wr,
|
||||
uint32_t nmodules)
|
||||
: m(2 * nmodules),
|
||||
c_fifo(in_c),
|
||||
wr_fifo(in_wr),
|
||||
module_info(2 * nmodules)
|
||||
module_info(2 * nmodules),
|
||||
conv(nmodules)
|
||||
{
|
||||
for (auto &i: module_info)
|
||||
i.c.frame_number = UINT64_MAX;
|
||||
@@ -65,7 +67,11 @@ void ProcessJFPacket::ProcessPacket(jf_udp_payload *datagram) {
|
||||
module_info[module_info_location].c.packet_count++;
|
||||
module_info[module_info_location].c.packet_mask[packetnum >= 64 ? 1 : 0] |= (1LU << (packetnum % 64));
|
||||
|
||||
memcpy(module_info[module_info_location].ptr + 4096 * packetnum, datagram->data, 4096 * sizeof(uint16_t));
|
||||
uint16_t* dst = module_info[module_info_location].ptr + 4096 * packetnum;
|
||||
if (conv[module_number])
|
||||
conv[module_number]->ConvertPacket((int16_t *) dst, datagram->data, packetnum);
|
||||
else
|
||||
memcpy(dst, datagram->data, 4096 * sizeof(uint16_t));
|
||||
}
|
||||
packet_counter++;
|
||||
}
|
||||
@@ -73,3 +79,23 @@ void ProcessJFPacket::ProcessPacket(jf_udp_payload *datagram) {
|
||||
uint64_t ProcessJFPacket::GetCounter() {
|
||||
return packet_counter;
|
||||
}
|
||||
|
||||
void ProcessJFPacket::RegisterConversion(const DiffractionExperiment &experiment,
|
||||
const JFCalibration &calib,
|
||||
uint16_t data_stream) {
|
||||
if (data_stream >= experiment.GetDataStreamsNum())
|
||||
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Data stream not found");
|
||||
|
||||
if (conv.size() != experiment.GetModulesNum(data_stream))
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Wrong module count");
|
||||
|
||||
auto module0 = experiment.GetFirstModuleOfDataStream(data_stream);
|
||||
for (int i = 0; i < experiment.GetModulesNum(data_stream); i++) {
|
||||
conv[i] = std::make_unique<JFConversionFixedPoint>();
|
||||
conv[i]->Setup(calib.GainCalibration(module0 + i),
|
||||
calib.Pedestal(module0 + i, 0, 0),
|
||||
calib.Pedestal(module0 + i, 1, 0),
|
||||
calib.Pedestal(module0 + i, 2, 0),
|
||||
experiment.GetPhotonEnergy_keV());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
#define JUNGFRAUJOCH_PROCESSJFPACKET_H
|
||||
|
||||
#include "../common/ThreadSafeFIFO.h"
|
||||
#include "../common/DiffractionExperiment.h"
|
||||
#include "../receiver/host/Completion.h"
|
||||
#include "JFConversion.h"
|
||||
#include "JFCalibration.h"
|
||||
#include "jf_packet.h"
|
||||
|
||||
#include <shared_mutex>
|
||||
@@ -22,9 +24,11 @@ class ProcessJFPacket {
|
||||
ThreadSafeFIFO<WorkRequest> &wr_fifo;
|
||||
std::vector<ModuleInfo> module_info;
|
||||
std::atomic<uint64_t> packet_counter = 0;
|
||||
std::vector<std::unique_ptr<JFConversion> > conv;
|
||||
public:
|
||||
ProcessJFPacket(ThreadSafeFIFO<Completion> &c, ThreadSafeFIFO<WorkRequest> &wr, uint32_t nmodules);
|
||||
~ProcessJFPacket();
|
||||
void RegisterConversion(const DiffractionExperiment& experiment, const JFCalibration& calib, uint16_t data_stream);
|
||||
void ProcessPacket(jf_udp_payload *datagram);
|
||||
uint64_t GetCounter();
|
||||
};
|
||||
|
||||
@@ -91,4 +91,42 @@ TEST_CASE("ProcessRawPacketTest") {
|
||||
CHECK(array_0[4096*36] == 6789);
|
||||
CHECK(array_1[4096*(36+64)] == 6345);
|
||||
CHECK(array_2[4096*(16+64)] == 6346);
|
||||
}
|
||||
|
||||
TEST_CASE("ProcessRawPacketTest_Conversion") {
|
||||
ThreadSafeFIFO<Completion> c_fifo;
|
||||
ThreadSafeFIFO<WorkRequest> wr_fifo;
|
||||
|
||||
std::vector<uint16_t> array_0(RAW_MODULE_SIZE);
|
||||
|
||||
wr_fifo.Put(WorkRequest{.ptr = array_0.data(), .handle = 0});
|
||||
|
||||
DiffractionExperiment experiment(DetectorGeometry(8));
|
||||
experiment.DataStreams(2).PhotonEnergy_keV(2);
|
||||
JFCalibration calibration(experiment);
|
||||
calibration.Pedestal(6, 0, 0).GetPedestal()[4096*36] = 300;
|
||||
calibration.Pedestal(6, 1, 0).GetPedestal()[4096*36+1] = 15000;
|
||||
calibration.Pedestal(6, 2, 0).GetPedestal()[4096*36+2] = 14000;
|
||||
|
||||
{
|
||||
ProcessJFPacket process(c_fifo, wr_fifo, 4);
|
||||
REQUIRE_NOTHROW(process.RegisterConversion(experiment, calibration, 1));
|
||||
jf_udp_payload datagram;
|
||||
|
||||
datagram.packetnum = 36;
|
||||
datagram.framenum = 2;
|
||||
datagram.bunchid = 84;
|
||||
datagram.data[0] = 600;
|
||||
datagram.data[1] = 16384 | 4000;
|
||||
datagram.data[2] = 32768 | 16384 | 9000;
|
||||
|
||||
datagram.xCoord = 4;
|
||||
process.ProcessPacket(&datagram);
|
||||
|
||||
REQUIRE(process.GetCounter() == 1);
|
||||
}
|
||||
|
||||
CHECK(array_0[4096*36] == std::round((600 - 300) / (DEFAULT_G0_FACTOR*2)));
|
||||
CHECK(array_0[4096*36+1] == std::round((4000 - 15000) / (DEFAULT_G1_FACTOR*2)));
|
||||
CHECK(array_0[4096*36+2] == std::round((9000 - 14000) / (DEFAULT_G2_FACTOR*2)));
|
||||
}
|
||||
Reference in New Issue
Block a user