bit depth parameter infrastructure. partial eiger assemble image routine.

This commit is contained in:
lhdamiani
2021-07-02 10:44:51 +02:00
parent 3f7fef4f61
commit c344daaffe
37 changed files with 4369 additions and 103 deletions
+2
View File
@@ -18,6 +18,7 @@ namespace BufferUtils
const std::string detector_name;
const int n_modules;
const int n_submodules;
const int start_udp_port;
const std::string buffer_folder;
@@ -31,6 +32,7 @@ namespace BufferUtils
<< det_config.GAIN_FILENAME << ' '
<< det_config.detector_name << ' '
<< det_config.n_modules << ' '
<< det_config.n_submodules << ' '
<< det_config.start_udp_port << ' '
<< det_config.buffer_folder << ' ';
}
+14 -1
View File
@@ -7,7 +7,12 @@
class RamBuffer {
const std::string detector_name_;
const int n_modules_;
const int n_submodules_;
const int n_slots_;
const int bit_depth_;
const size_t n_packets_per_frame_;
const size_t data_bytes_per_frame_;
const size_t meta_bytes_;
const size_t image_bytes_;
@@ -19,10 +24,15 @@ class RamBuffer {
ModuleFrame* meta_buffer_;
char* image_buffer_;
private:
void assemble_eiger_image(ImageMetadata &image_meta,
const int bit_depth, const size_t slot_n) const;
public:
RamBuffer(const std::string& detector_name,
const int n_modules,
const int n_slots=buffer_config::RAM_BUFFER_N_SLOTS);
const int n_submodules,
const int bit_depth);
~RamBuffer();
void write_frame(const ModuleFrame &src_meta, const char *src_data) const;
@@ -33,6 +43,9 @@ public:
char* read_image(const uint64_t pulse_id) const;
void assemble_image(
const uint64_t pulse_id, ImageMetadata &image_meta) const;
};
-6
View File
@@ -6,12 +6,6 @@
namespace buffer_config {
const size_t MODULE_X_SIZE = 1024;
const size_t MODULE_Y_SIZE = 512;
const size_t MODULE_N_PIXELS = MODULE_X_SIZE * MODULE_Y_SIZE;
const size_t PIXEL_N_BYTES = 2;
const size_t MODULE_N_BYTES = MODULE_N_PIXELS * PIXEL_N_BYTES;
// How many frames we store in each file.
// Must be power of 10 and <= than FOLDER_MOD
const size_t FILE_MOD = 1000;
+29 -6
View File
@@ -4,11 +4,34 @@
#include <cstdint>
#define N_MODULES 1
#define BYTES_PER_PACKET 1072
#define DATA_BYTES_PER_PACKET 1024
#define BYTES_PER_PACKET 4144
#define DATA_BYTES_PER_PACKET 4096
// EIGER 1M
// Each packet line is made of 2 chip lines -> [CHIP1]<gap>[CHIP2]
// gaps between chips
// For a 1M:
// 0 gap 1
// gap gap
// 2 gap 3
#define MODULE_X_SIZE 256
#define MODULE_Y_SIZE 512
#define MODULE_N_PIXELS 131072
#define PIXEL_N_BYTES 2
#define MODULE_N_BYTES 262144
#define GAP_X_MODULE_PIXELS 2
#define GAP_Y_MODULE_PIXELS 2
#define GAP_X_EIGERMOD_PIXELS 8
#define GAP_Y_EIGERMOD_PIXELS 36
#define N_BYTES_PER_MODULE_LINE(bit_depth) ((MODULE_X_SIZE * bit_depth) / 8)
// #define N_BYTES_PER_IMAGE_LINE(bit_depth, n_submodules) ((n_submodules / 2 * MODULE_X_SIZE * bit_depth) / 8)
// DR 16
#define N_PACKETS_PER_FRAME 256
#define DATA_BYTES_PER_FRAME 262144
// #define N_PACKETS_PER_FRAME 256
// #define DATA_BYTES_PER_FRAME 262144
// DR 32
// #define N_PACKETS_PER_FRAME 512
// #define DATA_BYTES_PER_FRAME 524288
@@ -24,8 +47,8 @@ struct det_packet {
uint64_t timestamp;
uint16_t moduleID;
uint16_t xCoord;
uint16_t yCoord;
uint16_t row;
uint16_t column;
uint16_t reserved;
uint32_t debug;
+3 -5
View File
@@ -9,10 +9,7 @@
#include "eiger.hpp"
#endif
#ifdef DEBUG_OUTPUT
#define EIGER_DATA_BYTES_PER_PACKET_VALIDATION 262144
#define JUNGFRAU_DATA_BYTES_PER_PACKET_VALIDATION 1048576
#endif
#define IS_BOTTOM(n) ((n%2 != 0) ? -1 : 1)
#pragma pack(push)
#pragma pack(1)
@@ -22,6 +19,7 @@ struct ModuleFrame {
uint64_t daq_rec;
uint64_t n_recv_packets;
uint64_t module_id;
uint16_t bit_depth;
uint16_t row;
uint16_t column;
};
@@ -47,7 +45,7 @@ struct ModuleFrameBuffer {
struct BufferBinaryFormat {
const char FORMAT_MARKER = 0xBE;
ModuleFrame meta;
char data[buffer_config::MODULE_N_BYTES];
char data[MODULE_N_BYTES];
};
#pragma pack(pop)
+11 -4
View File
@@ -6,8 +6,15 @@
#define N_MODULES 32
#define BYTES_PER_PACKET 8240
#define DATA_BYTES_PER_PACKET 8192
#define N_PACKETS_PER_FRAME 128
#define DATA_BYTES_PER_FRAME 1048576
#define MODULE_X_SIZE 1024
#define MODULE_Y_SIZE 512
#define MODULE_N_PIXELS 524288
#define PIXEL_N_BYTES 2
#define MODULE_N_BYTES 1048576
// #define N_PACKETS_PER_FRAME 128
// #define DATA_BYTES_PER_FRAME 1048576
// 48 bytes + 8192 bytes = 8240 bytes
#pragma pack(push)
@@ -21,8 +28,8 @@ struct det_packet {
uint64_t timestamp;
uint16_t moduleID;
uint16_t xCoord;
uint16_t yCoord;
uint16_t row;
uint16_t column;
uint16_t zCoord;
uint32_t debug;
+2 -5
View File
@@ -94,13 +94,9 @@ void BufferUtils::create_destination_folder(const string& output_file)
void* BufferUtils::connect_socket(
void* ctx, const string& detector_name, const string& stream_name)
{
string ipc_address = BUFFER_LIVE_IPC_URL +
string ipc_address = buffer_config::BUFFER_LIVE_IPC_URL +
detector_name + "-" +
stream_name;
#ifdef DEBUG_OUTPUT
cout << "[BufferUtils::connect_socket]";
cout << " IPC address: " << ipc_address << endl;
#endif
void* socket = zmq_socket(ctx, ZMQ_SUB);
if (socket == nullptr) {
@@ -171,6 +167,7 @@ BufferUtils::DetectorConfig BufferUtils::read_json_config(
config_parameters["gain_file"].GetString(),
config_parameters["detector_name"].GetString(),
config_parameters["n_modules"].GetInt(),
config_parameters["n_submodules"].GetInt(),
config_parameters["start_udp_port"].GetInt(),
config_parameters["buffer_folder"].GetString(),
};
+117 -10
View File
@@ -17,14 +17,30 @@ using namespace buffer_config;
RamBuffer::RamBuffer(
const string &detector_name,
const int n_modules,
const int n_slots) :
const int n_submodules,
const int bit_depth) :
detector_name_(detector_name),
n_modules_(n_modules),
n_slots_(n_slots),
n_submodules_(n_submodules_),
bit_depth_(bit_depth),
n_slots_(buffer_config::RAM_BUFFER_N_SLOTS),
meta_bytes_(sizeof(ModuleFrame) * n_modules_),
n_packets_per_frame_(bit_depth_ * MODULE_N_PIXELS / 8 / DATA_BYTES_PER_PACKET / n_modules * n_submodules),
data_bytes_per_frame_(n_packets_per_frame_ * DATA_BYTES_PER_PACKET),
image_bytes_(MODULE_N_BYTES * n_modules_),
buffer_bytes_((meta_bytes_ + image_bytes_) * n_slots_)
{
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [RamBuffer::Constructor] :";
cout << " || bit_depth_ " << bit_depth_;
cout << " || n_packets_per_frame_ " << n_packets_per_frame_;
cout << " || image_bytes_ " << image_bytes_;
cout << " || data_bytes_per_frame_ " << data_bytes_per_frame_;
cout << endl;
#endif
shm_fd_ = shm_open(detector_name_.c_str(), O_RDWR | O_CREAT, 0777);
if (shm_fd_ < 0) {
throw runtime_error(strerror(errno));
@@ -66,7 +82,7 @@ void RamBuffer::write_frame(
char *dst_data = image_buffer_ +
(image_bytes_ * slot_n) +
(MODULE_N_BYTES * src_meta.module_id);
(data_bytes_per_frame_ * src_meta.module_id);
#ifdef DEBUG_OUTPUT
using namespace date;
@@ -81,7 +97,7 @@ void RamBuffer::write_frame(
#endif
memcpy(dst_meta, &src_meta, sizeof(ModuleFrame));
memcpy(dst_data, src_data, MODULE_N_BYTES);
memcpy(dst_data, src_data, data_bytes_per_frame_);
}
void RamBuffer::read_frame(
@@ -106,21 +122,30 @@ void RamBuffer::assemble_image(
const uint64_t pulse_id, ImageMetadata &image_meta) const
{
const size_t slot_n = pulse_id % n_slots_;
ModuleFrame *src_meta = meta_buffer_ + (n_modules_ * slot_n);
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [RamBuffer::assemble_image] :";
cout << " pulse_id : " << pulse_id;
cout << endl;
#endif
auto is_pulse_init = false;
auto is_good_image = true;
// for each module it collects the metadata from each frame
for (int i_module=0; i_module < n_modules_; i_module++) {
// and verifies if is a good frame
for (int i_module=0; i_module < n_modules_; i_module++) {
ModuleFrame *frame_meta = src_meta + i_module;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [RamBuffer::assemble_image] :";
cout << "module_id: " << i_module;
cout << "] module_id: " << i_module;
cout << " || frame index: " << frame_meta->frame_index;
cout << " || pulse index: " << frame_meta->pulse_id;
cout << " || row: " << frame_meta->row;
cout << " || column: " << frame_meta->column;
cout << " || n_recv_packets: " << frame_meta->n_recv_packets;
@@ -128,7 +153,7 @@ void RamBuffer::assemble_image(
#endif
auto is_good_frame =
frame_meta->n_recv_packets == N_PACKETS_PER_FRAME;
frame_meta->n_recv_packets == n_packets_per_frame_;
if (!is_good_frame) {
is_good_image = false;
@@ -137,7 +162,7 @@ void RamBuffer::assemble_image(
cout << " [" << std::chrono::system_clock::now();
cout << "] [RamBuffer::assemble_image] ";
cout << " not a good frame " << is_good_frame;
cout << "n_recv_packets != N_PACKETS_PER_FRAME";
cout << "n_recv_packets != n_packets_per_frame_";
cout << endl;
#endif
continue;
@@ -217,6 +242,13 @@ void RamBuffer::assemble_image(
image_meta.is_good_image = is_good_image;
// bad practice, what'd be the nicest way to do this?
#ifdef USE_EIGER
if (is_good_image){
assemble_eiger_image(image_meta, bit_depth_, slot_n);
}
#endif
if (!is_pulse_init) {
image_meta.pulse_id = 0;
image_meta.frame_index = 0;
@@ -231,3 +263,78 @@ char* RamBuffer::read_image(const uint64_t pulse_id) const
return src_data;
}
void RamBuffer::assemble_eiger_image(ImageMetadata &image_meta, const int bit_depth, const size_t slot_n) const
{
const uint32_t n_bytes_per_module_line = N_BYTES_PER_MODULE_LINE(bit_depth);
const uint32_t n_bytes_per_gap = GAP_X_MODULE_PIXELS * bit_depth / 8;
const uint32_t n_bytes_per_image_line = n_bytes_per_module_line * 2 + n_bytes_per_gap;
const int n_lines_per_frame = DATA_BYTES_PER_PACKET / n_bytes_per_module_line * n_packets_per_frame_;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [RamBuffer::is_good_image] ";
cout << " image_meta.frame_index" << image_meta.frame_index;
cout << " Verification: " << endl;
cout << " || n_bytes_per_module_line " << n_bytes_per_module_line << endl;
cout << " || n_bytes_per_gap " << n_bytes_per_gap << endl;
cout << " || n_bytes_per_image_line " << n_bytes_per_image_line;
cout << " || n_lines_per_frame " << n_lines_per_frame << endl;;
#endif
for (int i_module=0; i_module < n_modules_; i_module++) {
// defines from which eiger module this submodule is part
const int eiger_module_index = i_module / n_submodules_;
// module frame metadata
ModuleFrame *frame_meta = meta_buffer_ + (n_modules_ * slot_n) + i_module;
// module frame data
char *frame_data = image_buffer_ + (image_bytes_ * slot_n) + (data_bytes_per_frame_ * i_module);
// top
uint32_t source_offset = 0;
uint32_t reverse_factor = 0;
uint32_t bottom_offset = 0;
uint32_t line_number = 0;
uint32_t dest_line_offset=0;
// If bottom -> reversed
const auto reverse = IS_BOTTOM(frame_meta->row);
if (reverse == -1){
line_number = MODULE_Y_SIZE + GAP_Y_MODULE_PIXELS;
reverse_factor = MODULE_Y_SIZE - 1;
dest_line_offset += n_bytes_per_image_line * (MODULE_Y_SIZE + GAP_Y_MODULE_PIXELS);
}
const auto i_module_row = frame_meta->row;
const auto i_module_column = frame_meta->column;
uint32_t dest_module_line = line_number;
if (i_module_column == 1){
source_offset += MODULE_X_SIZE + GAP_X_MODULE_PIXELS;
dest_line_offset += n_bytes_per_module_line + n_bytes_per_gap;
}
for (uint32_t frame_line=0; frame_line < n_lines_per_frame; frame_line++)
{
// Copy each chip line individually, to allow a gap of n_bytes_per_chip_gap in the destination memory.
memcpy (
(char*)(image_buffer_ + (image_bytes_ * slot_n)) + dest_line_offset,
(char*) frame_data + source_offset,
n_bytes_per_module_line
);
memcpy (
(char*)(image_buffer_ + (image_bytes_ * slot_n)) + dest_line_offset + n_bytes_per_module_line,
(char*) frame_data + source_offset + n_bytes_per_module_line,
n_bytes_per_module_line
);
source_offset += n_bytes_per_module_line;
dest_line_offset += reverse * n_bytes_per_image_line;
}
line_number += n_lines_per_frame;
dest_module_line = line_number + n_lines_per_frame - 1;
}
}
+1
View File
@@ -7,6 +7,7 @@
"gain_file": "",
"detector_name": "eiger",
"n_modules": 2,
"n_submodules": 2,
"start_udp_port": 50200,
"buffer_folder": ""
}
+17
View File
@@ -0,0 +1,17 @@
detsize 1024 512
hostname beb031+beb032
udp_dstmac 9c:dc:71:4d:2a:b5
udp_dstip 10.30.20.6
#top
0:udp_dstport 50200
0:udp_dstport2 50201
0:udp_srcip 10.30.20.201
#bottom
1:udp_dstport 50202
1:udp_dstport2 50203
1:udp_srcip 10.30.20.201
tengiga 1
+13
View File
@@ -0,0 +1,13 @@
{
"streamvis_stream": "tcp://0.0.0.0:9006",
"streamvis_rate": 10,
"live_stream": "tcp://0.0.0.0:9106",
"live_rate": 10,
"pedestal_file": "",
"gain_file": "",
"detector_name": "Eiger-16",
"n_modules": 1,
"n_submodules":4,
"start_udp_port": 50200,
"buffer_folder": ""
}
+13
View File
@@ -0,0 +1,13 @@
detsize 1024 512
hostname localhost:2070+localhost:2072+
udp_dstmac 9c:dc:71:5f:28:10
udp_srcmac 9c:dc:71:5f:28:10
udp_srcip 129.129.241.43
udp_dstip 129.129.241.43
0:udp_dstport 50250
0:udp_dstport2 50251
1:udp_dstport 50252
1:udp_dstport2 50253
+13
View File
@@ -0,0 +1,13 @@
{
"streamvis_stream": "tcp://0.0.0.0:9006",
"streamvis_rate": 10,
"live_stream": "tcp://0.0.0.0:9106",
"live_rate": 10,
"pedestal_file": "",
"gain_file": "",
"detector_name": "eiger",
"n_modules": 2,
"n_submodules":2,
"start_udp_port": 50250,
"buffer_folder": ""
}
+46
View File
@@ -0,0 +1,46 @@
#!/bin/bash
UDP=0
STREAM=0
ASSEMBLER=0
HELP_FLAG=0
while getopts h:u:s:a: flag
do
case "${flag}" in
h ) HELP_FLAG=${OPTARG};;
u ) UDP=${OPTARG};;
s ) STREAM=${OPTARG};;
a ) ASSEMBLER=${OPTARG};;
esac
done
if (( ${UDP} == 0 )) && (( ${STREAM} == 0 )) && (( ${ASSEMBLER} == 0 )); then
echo "Nothing to do..."
exit
fi
# prints help and exits
if (( ${HELP_FLAG} == 1 )); then
echo "Usage : $0 -u <udp_recvs> -s <stream> -a <assembler> -h <help_flag>"
echo " udp : kill udp receivers."
echo " stream : kill stream."
echo " assembler : kill assembler."
echo " help_flag : show this help and exits."
exit
fi
if (( ${UDP} == 1 )); then
echo "Killing upd recvs..."
ps aux | grep eiger_udp_recv | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {}
fi
if (( ${STREAM} == 1 )); then
echo "Killing stream..."
ps aux | grep eiger_stream | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {}
fi
if (( ${ASSEMBLER} == 1 )); then
echo "Killing assembler..."
ps aux | grep eiger_assembler | awk 'NR > 1 { print prev } { prev = $2 }' | xargs -I{} kill {}
fi
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
# usage ./start_eiger_detector.sh Eiger 1
if [ $# -lt 1 ]
then
echo "Usage : $0 DETECTOR_NAME <number_of_cycles>"
echo " DETECTOR_NAME: Eiger..."
echo " number_of_cycles : optional, default 100"
exit
fi
#SLS_DET_PACKAGE_PATH='/home/dbe/git/sf_daq_buffer_eiger/slsDetectorPackage/build/bin/'
# SLS_DET_PACKAGE_PATH='/home/hax_l/sf_daq_buffer/slsDetectorPackage/build/bin/'
# DETECTOR=$1
n_cycles=100
if [ $# == 2 ]
then
n_cycles=$2
fi
${SLS_DET_PACKAGE_PATH}sls_detector_put timing auto
${SLS_DET_PACKAGE_PATH}sls_detector_put triggers ${n_cycles}
${SLS_DET_PACKAGE_PATH}sls_detector_put exptime 0.000005
${SLS_DET_PACKAGE_PATH}sls_detector_put frames 1000
${SLS_DET_PACKAGE_PATH}sls_detector_put dr 16
#sls_detector_put ${D}-clearbit to 0x5d 0 # normal mode, not highG0
${SLS_DET_PACKAGE_PATH}sls_detector_put acquire
echo "Now start trigger"
+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
MAKE_FLAG=0
ASSEMBLER='/home/hax_l/sf_daq_buffer/build/eiger_assembler'
CONFIG_FILE='/home/hax_l/sf_daq_buffer/eiger/sf-daq-4/config/eiger.json'
BUILD_PATH='/home/hax_l/sf_daq_buffer/build'
NAME='eiger_assembler'
BIT_DEPTH=16
HELP_FLAG=0
while getopts m:h:c:b: flag
do
case "${flag}" in
m ) MAKE_FLAG=${OPTARG};;
h ) HELP_FLAG=${OPTARG};;
c ) CONFIG_FILE=${OPTARG};;
b ) BIT_DEPTH=${OPTARG};;
esac
done
# prints help and exits
if (( ${HELP_FLAG} == 1 )); then
echo "Usage : $0 -c <config_file> -m <make_flag> -h <help_flag>"
echo " config_file : detector configuration file."
echo " make_flag : compile code before running."
echo " help_flag : show this help and exits."
exit
fi
# compiles the sf_buffer_daq
if (( ${MAKE_FLAG} == 1 )); then
echo "Compile flag detected..."
set -e
cd ${BUILD_PATH} && make
fi
# proceeds to start the receivers
echo "Starting the ${NAME} (config file: ${CONFIG_FILE})"
if [ -f "${ASSEMBLER}" ]; then
if [ -f "${CONFIG_FILE}" ]; then
${ASSEMBLER} ${CONFIG_FILE} ${BIT_DEPTH} &
else
echo "Something went wrong with the config file..."
exit
fi
else
echo ${ASSEMBLER}
echo "Something went wrong with the assembler executable..."
exit
fi
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
MAKE_FLAG=0
STREAM='/home/hax_l/software/sf_daq_buffer/build/eiger_stream'
CONFIG_FILE='/home/hax_l/software/sf_daq_buffer/eiger/config/eiger.json'
BUILD_PATH='/home/hax_l/software/sf_daq_buffer/build'
STREAM_NAME='eiger'
HELP_FLAG=0
while getopts m:h:n:c: flag
do
case "${flag}" in
m ) MAKE_FLAG=${OPTARG};;
h ) HELP_FLAG=${OPTARG};;
n ) STREAM_NAME=${OPTARG};;
c ) CONFIG_FILE=${OPTARG};;
esac
done
# prints help and exits
if (( ${HELP_FLAG} == 1 )); then
echo "Usage : $0 -c <config_file> -n <stream_name> -m <make_flag> -h <help_flag>"
echo " config_file : detector configuration file."
echo " stream_name : stream name."
echo " make_flag : compile code before running."
echo " help_flag : show this help and exits."
exit
fi
# compiles the sf_buffer_daq
if (( ${MAKE_FLAG} == 1 )); then
echo "Compile flag detected..."
set -e
cd ${BUILD_PATH} && make
fi
# proceeds to start the receivers
echo "Starting stream name ${STREAM_NAME} (config file: ${CONFIG_FILE})"
if [ -f "${STREAM}" ]; then
if [ -f "${CONFIG_FILE}" ]; then
${STREAM} ${CONFIG_FILE} ${STREAM_NAME} &
else
echo "Something went wrong with the config file..."
exit
fi
else
echo "Something went wrong with the stream executable..."
exit
fi
+57
View File
@@ -0,0 +1,57 @@
#!/bin/bash
N_UDP_RECVS=2
MAKE_FLAG=0
UDP_RECV='/home/hax_l/sf_daq_buffer/build/eiger_udp_recv'
CONFIG_FILE='/home/hax_l/sf_daq_buffer/eiger/sf-daq-4/config/eiger.json'
BUILD_PATH='/home/hax_l/sf_daq_buffer/build'
HELP_FLAG=0
BIT_DEPTH=16
while getopts n:m:h:u:c:b: flag
do
case "${flag}" in
n ) N_UDP_RECVS=${OPTARG};;
m ) MAKE_FLAG=${OPTARG};;
h ) HELP_FLAG=${OPTARG};;
u ) UDP_RECV=${OPTARG};;
c ) CONFIG_FILE=${OPTARG};;
b ) BIT_DEPTH=${OPTARG};;
esac
done
# prints help and exits
if (( ${HELP_FLAG} == 1 )); then
echo "Usage : $0 -n <n_udp_recvs> -c <compile_flag> -h <help_flag> -u <udp_executable> -c <config_file> -b <bit_depth>"
echo " n_udp_recvs : number of receivers."
echo " compile_flag : compile code before running."
echo " help_flag : show this help and exits."
echo " udp_executable : executable for the udp receivers."
echo " config_file : detector configuration file."
echo " bit_depth : detector bit depth."
exit
fi
# compiles the sf_buffer_daq
if (( ${MAKE_FLAG} == 1 )); then
echo "Compile flag detected..."
set -e
cd ${BUILD_PATH} && make
fi
# proceeds to start the receivers
echo "Starting ${N_UDP_RECVS} udp receivers..."
COUNTER=0
if [ -f "${UDP_RECV}" ]; then
if [ -f "${CONFIG_FILE}" ]; then
while [ $COUNTER -lt ${N_UDP_RECVS} ]; do
${UDP_RECV} ${CONFIG_FILE} ${COUNTER} ${BIT_DEPTH} &
let COUNTER=COUNTER+1
sleep 0.5
done
else
echo "Something went wrong with the udp recv executable..."
exit
fi
else
echo "Something went wrong with the udp recv executable..."
exit
fi
+55
View File
@@ -0,0 +1,55 @@
#!/bin/bash
MAKE_FLAG=0
MASTER='/home/hax_l/sf_daq_buffer/slsDetectorPackage/build/bin/eigerDetectorServerMaster_virtual'
SLAVE='/home/hax_l/sf_daq_buffer/slsDetectorPackage/build/bin/eigerDetectorServerSlaveBottom_virtual'
DET_PUT='/home/hax_l/sf_daq_buffer/slsDetectorPackage/build/bin/sls_detector_put'
CONFIG_FILE='/home/hax_l/sf_daq_buffer/eiger/sf-daq-4/config/veiger-sf-daq-4.txt'
HELP_FLAG=0
PORT_MASTER=2070
while getopts h:p:c: flag
do
case "${flag}" in
h ) HELP_FLAG=${OPTARG};;
p ) PORT_MASTER=${OPTARG};;
c ) CONFIG_FILE=${OPTARG};;
esac
done
PORT_SLAVE=$(( $PORT_MASTER + 2 ))
# prints help and exits
if (( ${HELP_FLAG} == 1 )); then
echo "Usage : $0 -c <config_file> -h <help_flag>"
echo " port : port connection for master virtual eiger."
echo " config_file : detector configuration file."
echo " help_flag : show this help and exits."
exit
fi
# proceeds to start the receivers
echo "Starting the virtual eiger (master and slave) (config file: ${CONFIG_FILE})"
if [ -f "${MASTER}" ]; then
if [ -f "${MASTER}" ]; then
if [ -f "${CONFIG_FILE}" ]; then
${MASTER} -p ${PORT_MASTER} &
sleep 1
${SLAVE} -p ${PORT_SLAVE} &
sleep 1
# ${DET_PUT} config ${CONFIG_FILE}
else
echo "Something went wrong with the config file..."
exit
fi
fi
else
echo "Something went wrong with the virtual eiger executable..."
exit
fi
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
IP:Port: 10.30.20.6 50200
+37
View File
@@ -0,0 +1,37 @@
import socket
import numpy as np
frame_header_dt = np.dtype(
[
("Frame Number", "u8"),
("SubFrame Number/ExpLength", "u4"),
("Packet Number", "u4"),
("Bunch ID", "u8"),
("Timestamp", "u8"),
("Module Id", "u2"),
("Row", "u2"),
("Column", "u2"),
("Reserved", "u2"),
("Debug", "u4"),
("Round Robin Number", "u2"),
("Detector Type", "u1"),
("Header Version", "u1"),
]
)
ip = "10.30.20.6"
ports = list(range(50200, 50204, 1))
sockets = [socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in range(len(ports))]
for s, p in zip(sockets, ports):
print("IP:Port: ", ip, p)
s.bind((ip, p))
while True:
for s in sockets:
data, address = s.recvfrom(4096)
h = np.frombuffer(data, count=1, dtype=frame_header_dt)[0]
print(
f'[{h["Timestamp"]}] frame: {h["Frame Number"]}, pkt:{h["Packet Number"]}, explength:{h["SubFrame Number/ExpLength"]}, module id: {h["Module Id"]} ,row: {h["Row"]}, column: {h["Column"]}'
)
+2 -2
View File
@@ -1,6 +1,6 @@
#!/bin/bash
export PATH=/home/dbe/miniconda3/bin:$PATH
export PATH=/home/dbe/miniconda3/bin:$PATH:/home/hax_l/sf_daq_buffer/slsDetectorPackage/build/bin/
source /home/dbe/miniconda3/etc/profile.d/conda.sh
conda deactivate
conda activate sf-daq
conda activate sf-daq
+37
View File
@@ -0,0 +1,37 @@
import socket
import numpy as np
frame_header_dt = np.dtype(
[
("Frame Number", "u8"),
("SubFrame Number/ExpLength", "u4"),
("Packet Number", "u4"),
("Bunch ID", "u8"),
("Timestamp", "u8"),
("Module Id", "u2"),
("Row", "u2"),
("Column", "u2"),
("Reserved", "u2"),
("Debug", "u4"),
("Round Robin Number", "u2"),
("Detector Type", "u1"),
("Header Version", "u1"),
]
)
ip = "10.30.20.6"
ports = list(range(50200, 50204, 1))
sockets = [socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in range(len(ports))]
for s, p in zip(sockets, ports):
print("IP:Port: ", ip, p)
s.bind((ip, p))
while True:
for s in sockets:
data, address = s.recvfrom(4096)
h = np.frombuffer(data, count=1, dtype=frame_header_dt)[0]
print(
f'pkt:{h["Packet Number"]}, frame: {h["Frame Number"]}, row: {h["Row"]}, column: {h["Column"]}'
)
+57
View File
@@ -0,0 +1,57 @@
#!/bin/bash
INTERFACES=("$@")
echo $# interfaces will be analysed:
# array of proc ids
declare -a PROC_IDS=()
# start tcpdump for the specified interfaces
for i in "${INTERFACES[@]}"
do
if [ -f "$i".dump ]; then
echo "Removing file $i.dump"
rm "$i".dump
fi
if [ -f "$i".txt ]; then
echo "Removing file $i.txt"
rm $i.txt
fi
# starts the tcpdump for each interface
echo "Starting tcpdump on $i..."
#echo $i
nohup tcpdump -i $i -enn -B 400000000 -w $i.dump &
PROC_IDS+=($!)
done
# loop waiting to stop
echo "Press ESC key to quit"
# read a single character
while read -r -n1 key
do
# if input == ESC key
if [[ $key == $'\e' ]];
then
break;
fi
done
# kills tcp dump processes
for i in "${PROC_IDS[@]}"
do
echo Killing proccess with pid $i
kill $i
done
# delete if previous report file exists
report_filename='tcp_dump_report.txt'
if [ -f $report_filename ]; then
rm $report_filename
# creates an empty file
touch $report_filename
fi
touch $report_filename
# converts raw to text and parses the file
for i in "${INTERFACES[@]}"
do
echo "Treating raw data into txt file and parsing relevant info..."
tcpdump -r $i.dump > $i.txt && cat $i.txt | awk '{print $5" "$8}' | awk -F. '{print $4}' | awk -F: '{print $1" "$2}' | sort | uniq -c >> $report_filename && sed '/length/d' -i $report_filename
done
echo "Finishing tcpdump analysis..."
+42
View File
@@ -0,0 +1,42 @@
detsize 2048 2560
hostname BEB111+BEB070+BEB060+BEB042+BEB004+BEB120+BEB105+BEB121+BEB092+BEB091+BEB058+BEB059+BEB030+BEB038+BEB110+BEB115+BEB095+BEB094+BEB119+BEB055+
#
udp_dstmac 9c:dc:71:47:e5:dc
udp_dstip 10.30.20.6
0:rx_tcpport 1980
0:udp_dstport 50000
0:udp_dstport2 50001
1:rx_tcpport 1981
1:udp_dstport 50002
1:udp_dstport2 50003
2:rx_tcpport 1982
2:udp_dstport 50004
2:udp_dstport2 50005
3:rx_tcpport 1983
3:udp_dstport 50006
3:udp_dstport2 50007
4:rx_tcpport 1984
4:udp_dstport 50008
4:udp_dstport2 50009
5:rx_tcpport 1985
5:udp_dstport 50010
5:udp_dstport2 50011
6:rx_tcpport 1986
6:udp_dstport 50012
6:udp_dstport2 50013
7:rx_tcpport 1987
7:udp_dstport 50014
7:udp_dstport2 50015
8:rx_tcpport 1988
8:udp_dstport 50016
8:udp_dstport2 50017
9:rx_tcpport 1989
9:udp_dstport 50018
9:udp_dstport2 50019
+42
View File
@@ -0,0 +1,42 @@
import socket
import numpy as np
frame_header_dt = np.dtype(
[
("Frame Number", "u8"),
("SubFrame Number/ExpLength", "u4"),
("Packet Number", "u4"),
("Bunch ID", "u8"),
("Timestamp", "u8"),
("Module Id", "u2"),
("Row", "u2"),
("Column", "u2"),
("Reserved", "u2"),
("Debug", "u4"),
("Round Robin Number", "u2"),
("Detector Type", "u1"),
("Header Version", "u1"),
]
)
hostnames = ['BEB111','BEB070','BEB060','BEB042','BEB004','BEB120','BEB105','BEB121','BEB092','BEB091','BEB058','BEB059','BEB030', 'BEB038','BEB110', 'BEB115', 'BEB095', 'BEB094', 'BEB119', 'BEB055']
# ip = "10.30.20.6"
ips = []
for hostname in hostnames:
ips.append(socket.gethostbyname('BEB111'))
ports = list(range(50000, 50204, 1))
sockets = [socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in range(len(ports))]
for s, p in zip(sockets, ports):
print("IP:Port: ", ip, p)
s.bind((ip, p))
while True:
for s in sockets:
data, address = s.recvfrom(4096)
h = np.frombuffer(data, count=1, dtype=frame_header_dt)[0]
print(
f'[{h["Timestamp"]}] frame: {h["Frame Number"]}, pkt:{h["Packet Number"]}, explength:{h["SubFrame Number/ExpLength"]}, module id: {h["Module Id"]} ,row: {h["Row"]}, column: {h["Column"]}'
)
+20
View File
@@ -0,0 +1,20 @@
output=`ping -c 1 BEB111 2>&1` || echo $output
output=`ping -c 1 BEB070 2>&1` || echo $output
output=`ping -c 1 BEB060 2>&1` || echo $output
output=`ping -c 1 BEB042 2>&1` || echo $output
output=`ping -c 1 BEB004 2>&1` || echo $output
output=`ping -c 1 BEB120 2>&1` || echo $output
output=`ping -c 1 BEB105 2>&1` || echo $output
output=`ping -c 1 BEB121 2>&1` || echo $output
output=`ping -c 1 BEB092 2>&1` || echo $output
output=`ping -c 1 BEB091 2>&1` || echo $output
output=`ping -c 1 BEB058 2>&1` || echo $output
output=`ping -c 1 BEB059 2>&1` || echo $output
output=`ping -c 1 BEB030 2>&1` || echo $output
output=`ping -c 1 BEB038 2>&1` || echo $output
output=`ping -c 1 BEB110 2>&1` || echo $output
output=`ping -c 1 BEB115 2>&1` || echo $output
output=`ping -c 1 BEB095 2>&1` || echo $output
output=`ping -c 1 BEB094 2>&1` || echo $output
output=`ping -c 1 BEB119 2>&1` || echo $output
output=`ping -c 1 BEB055 2>&1` || echo $output
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
NUM_MOD=20
# Unit are in 10ns
DELAY_DIFF=50000
for i in `seq 0 $((NUM_MOD-1))`; do
sls_detector_put $i:txndelay_left $((i*2*DELAY_DIFF))
sls_detector_put $i:txndelay_right $(((i*2+1)*DELAY_DIFF))
done
sls_detector_put txndelay_frame $((NUM_MOD*2*DELAY_DIFF))
+2 -3
View File
@@ -46,7 +46,6 @@ PulseAndSync ZmqPulseSyncReceiver::get_next_pulse_id() const
bool modules_in_sync = true;
for (int i = 0; i < n_modules_; i++) {
zmq_recv(sockets_[i], &pulses[i], sizeof(uint64_t), 0);
if (pulses[0] != pulses[i]) {
modules_in_sync = false;
}
@@ -56,8 +55,8 @@ PulseAndSync ZmqPulseSyncReceiver::get_next_pulse_id() const
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [ZmqPulseSyncReceiver::get_next_pulse_id] modules_in_sync true";
cout << "] returning pulses[0] (frame index):" << pulses[0];
cout << "] [ZmqPulseSyncReceiver::get_next_pulse_id] ";
cout << "] (modules_in_sync) Frame index:" << pulses[0];
cout << endl;
#endif
return {pulses[0], 0};
+19 -11
View File
@@ -9,6 +9,7 @@
#include <chrono>
#include "assembler_config.hpp"
#include "ZmqPulseSyncReceiver.hpp"
using namespace std;
using namespace buffer_config;
@@ -16,42 +17,49 @@ using namespace assembler_config;
int main (int argc, char *argv[])
{
if (argc != 2) {
if (argc != 3) {
cout << endl;
#ifndef USE_EIGER
cout << "Usage: jf_assembler [detector_json_filename]" << endl;
cout << "Usage: jf_assembler [detector_json_filename] [bit_depth]" << endl;
#else
cout << "Usage: eiger_assembler [detector_json_filename]" << endl;
cout << "Usage: eiger_assembler [detector_json_filename] [bit_depth]" << endl;
#endif
cout << "\tdetector_json_filename: detector config file path." << endl;
cout << "\tbit_depth: bit depth of the incoming udp packets." << endl;
cout << endl;
exit(-1);
}
auto config = BufferUtils::read_json_config(string(argv[1]));
const int bit_depth = atoi(argv[2]);
auto const stream_name = "assembler";
auto ctx = zmq_ctx_new();
zmq_ctx_set(ctx, ZMQ_IO_THREADS, ASSEMBLER_ZMQ_IO_THREADS);
auto sender = BufferUtils::bind_socket(
ctx, config.detector_name, stream_name);
ZmqPulseSyncReceiver receiver(ctx, config.detector_name, config.n_modules);
RamBuffer ram_buffer(config.detector_name, config.n_modules);
AssemblerStats stats(config.detector_name, ASSEMBLER_STATS_MODULO);
ImageMetadata meta;
const int n_receivers = config.n_modules * config.n_submodules;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [Assembler] :";
cout << " Details of Assembler:";
cout << "detector_name: " << config.detector_name;
cout << "n_modules: " << config.n_modules;
cout << " detector_name: " << config.detector_name;
cout << " || n_modules: " << config.n_modules;
cout << " || n_receivers: " << n_receivers;
cout << endl;
#endif
ZmqPulseSyncReceiver receiver(ctx, config.detector_name, n_receivers);
RamBuffer ram_buffer(config.detector_name, n_receivers, config.n_submodules, bit_depth);
AssemblerStats stats(config.detector_name, ASSEMBLER_STATS_MODULO);
ImageMetadata meta;
while (true) {
auto pulse_and_sync = receiver.get_next_pulse_id();
ram_buffer.assemble_image(pulse_and_sync.pulse_id, meta);
+6 -1
View File
@@ -8,7 +8,10 @@
class FrameStats {
const std::string detector_name_;
const int n_modules_;
const int module_id_;
const int bit_depth_;
const int n_packets_per_frame_;
size_t stats_time_;
int frames_counter_;
@@ -20,9 +23,11 @@ class FrameStats {
void reset_counters();
void print_stats();
public:
public:////config.detector_name, n_receivers, module_id, bit_depth, STATS_TIME
FrameStats(const std::string &detector_name,
const int n_modules,
const int module_id,
const int bit_depth,
const size_t stats_time);
void record_stats(const ModuleFrame &meta, const bool bad_pulse_id);
};
+4 -1
View File
@@ -8,6 +8,9 @@
class FrameUdpReceiver {
const int module_id_;
const int bit_depth_;
const size_t n_packets_per_frame_;
const size_t data_bytes_per_frame_;
PacketUdpReceiver udp_receiver_;
@@ -27,7 +30,7 @@ class FrameUdpReceiver {
const int n_packets, ModuleFrame& metadata, char* frame_buffer);
public:
FrameUdpReceiver(const uint16_t port, const int module_id);
FrameUdpReceiver(const int module_id, const uint16_t port, const int n_modules, const int n_submodules, const int bit_depth);
virtual ~FrameUdpReceiver();
uint64_t get_frame_from_udp(ModuleFrame& metadata, char* frame_buffer);
};
+19 -3
View File
@@ -1,15 +1,20 @@
#include <iostream>
#include "FrameStats.hpp"
#include "date.h"
using namespace std;
using namespace chrono;
FrameStats::FrameStats(
const std::string &detector_name,
const int n_modules,
const int module_id,
const int bit_depth,
const size_t stats_time) :
detector_name_(detector_name),
n_modules_(n_modules),
module_id_(module_id),
bit_depth_(bit_depth),
n_packets_per_frame_(bit_depth_ * MODULE_N_PIXELS / 8 / DATA_BYTES_PER_PACKET / n_modules),
stats_time_(stats_time)
{
reset_counters();
@@ -31,9 +36,20 @@ void FrameStats::record_stats(const ModuleFrame &meta, const bool bad_pulse_id)
n_corrupted_pulse_id_++;
}
if (meta.n_recv_packets < N_PACKETS_PER_FRAME) {
n_missed_packets_ += N_PACKETS_PER_FRAME - meta.n_recv_packets;
if (meta.n_recv_packets < n_packets_per_frame_) {
n_missed_packets_ += n_packets_per_frame_ - meta.n_recv_packets;
n_corrupted_frames_++;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [FrameStats::record_stats] :";
cout << " meta.frame "<< meta.frame_index;
cout << " || meta.n_recv_packets " << meta.n_recv_packets;
cout << " || n_missed_packets_ " << n_missed_packets_;
cout << endl;
#endif
}
frames_counter_++;
+28 -29
View File
@@ -3,15 +3,22 @@
#include <ostream>
#include <iostream>
#include <chrono>
#include <unistd.h>
#include "date.h"
using namespace std;
using namespace buffer_config;
FrameUdpReceiver::FrameUdpReceiver(
const int module_id,
const uint16_t port,
const int module_id) :
module_id_(module_id)
const int n_modules,
const int n_submodules,
const int bit_depth):
module_id_(module_id),
bit_depth_(bit_depth),
n_packets_per_frame_(bit_depth_ * MODULE_N_PIXELS / 8 / DATA_BYTES_PER_PACKET / n_modules * n_submodules),
data_bytes_per_frame_(n_packets_per_frame_ * DATA_BYTES_PER_PACKET)
{
#ifdef DEBUG_OUTPUT
using namespace date;
@@ -20,11 +27,12 @@ FrameUdpReceiver::FrameUdpReceiver(
cout << " Details of FrameUdpReceiver:";
cout << "module_id: " << module_id_;
cout << " || port: " << port;
cout << " BUFFER_UDP_N_RECV_MSG: " << BUFFER_UDP_N_RECV_MSG << endl;
cout << " || bit_depth : " << bit_depth_;
cout << " || n_packets_per_frame_ : " << n_packets_per_frame_;
cout << " || data_bytes_per_frame_: " << data_bytes_per_frame_ << " !!";
cout << endl;
#endif
udp_receiver_.bind(port);
for (int i = 0; i < BUFFER_UDP_N_RECV_MSG; i++) {
recv_buff_ptr_[i].iov_base = (void*) &(packet_buffer_[i]);
recv_buff_ptr_[i].iov_len = sizeof(det_packet);
@@ -43,12 +51,16 @@ FrameUdpReceiver::~FrameUdpReceiver() {
inline void FrameUdpReceiver::init_frame(
ModuleFrame& frame_metadata, const int i_packet)
{
frame_metadata.pulse_id = packet_buffer_[i_packet].bunchid;
// Eiger has no pulse_id, frame number instead
frame_metadata.pulse_id = packet_buffer_[i_packet].framenum;
frame_metadata.frame_index = packet_buffer_[i_packet].framenum;
frame_metadata.daq_rec = (uint64_t) packet_buffer_[i_packet].debug;
frame_metadata.module_id = (int64_t) module_id_;
frame_metadata.row = (int16_t) packet_buffer_[i_packet].xCoord;
frame_metadata.column = (int16_t) packet_buffer_[i_packet].yCoord;
frame_metadata.bit_depth = (int16_t) bit_depth_;
frame_metadata.row = (int16_t) packet_buffer_[i_packet].row;
frame_metadata.column = (int16_t) packet_buffer_[i_packet].column;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
@@ -56,6 +68,8 @@ inline void FrameUdpReceiver::init_frame(
cout << "module_id: " << module_id_;
cout << " || row: " << frame_metadata.row;
cout << " || column: " << frame_metadata.column;
cout << " || pulse_id: " << frame_metadata.pulse_id;
cout << " || frame_index: " << frame_metadata.frame_index;
cout << endl;
#endif
@@ -70,8 +84,9 @@ inline void FrameUdpReceiver::copy_packet_to_buffers(
(void*) (frame_buffer + frame_buffer_offset),
packet_buffer_[i_packet].data,
DATA_BYTES_PER_PACKET);
metadata.n_recv_packets++;
// cout << "[ frame" << metadata.frame_index << "] NUMBER OF RECV PACKETS : " << metadata.n_recv_packets ;
}
inline uint64_t FrameUdpReceiver::process_packets(
@@ -84,7 +99,7 @@ inline uint64_t FrameUdpReceiver::process_packets(
i_packet++) {
// First packet for this frame.
if (i_packet == 0) {
if (metadata.pulse_id == 0) {
init_frame(metadata, i_packet);
// Happens if the last packet from the previous frame gets lost.
@@ -101,7 +116,7 @@ inline uint64_t FrameUdpReceiver::process_packets(
// Last frame packet received. Frame finished.
if (packet_buffer_[i_packet].packetnum ==
N_PACKETS_PER_FRAME - 1)
n_packets_per_frame_ - 1)
{
#ifdef DEBUG_OUTPUT
using namespace date;
@@ -109,8 +124,6 @@ inline uint64_t FrameUdpReceiver::process_packets(
cout << "] [FrameUdpReceiver::process_packets] :";
cout << " Frame " << metadata.frame_index << " || ";
cout << packet_buffer_[i_packet].packetnum << " packets received.";
cout << " packet_buffer_n_packets_ " << packet_buffer_n_packets_;
cout << " I_PACKET "<< i_packet;
cout << " PULSE ID "<< metadata.pulse_id;
cout << endl;
#endif
@@ -126,7 +139,7 @@ inline uint64_t FrameUdpReceiver::process_packets(
packet_buffer_offset_ = 0;
}
return metadata.frame_index;
return metadata.pulse_id;
}
}
// We emptied the buffer.
@@ -142,27 +155,13 @@ uint64_t FrameUdpReceiver::get_frame_from_udp(
// Reset the metadata and frame buffer for the next frame.
metadata.pulse_id = 0;
metadata.n_recv_packets = 0;
memset(frame_buffer, 0, DATA_BYTES_PER_FRAME);
#ifdef DEBUG_OUTPUT
using namespace date;
cout << " [" << std::chrono::system_clock::now();
cout << "] [FrameUdpReceiver::get_frame_from_udp] Detector frame:";
if (JUNGFRAU_DATA_BYTES_PER_PACKET_VALIDATION == DATA_BYTES_PER_FRAME) {
cout << " Jungfrau (current DATA_BYTES_PER_FRAME: ";
}else if(EIGER_DATA_BYTES_PER_PACKET_VALIDATION == DATA_BYTES_PER_FRAME){
cout << " Eiger (current DATA_BYTES_PER_FRAME: ";
};
cout << DATA_BYTES_PER_FRAME;
cout << ").";
cout << endl;
#endif
memset(frame_buffer, 0, data_bytes_per_frame_);
// Happens when last packet from previous frame was missed.
if (packet_buffer_loaded_) {
auto pulse_id = process_packets(
packet_buffer_offset_, metadata, frame_buffer);
if (pulse_id != 0) {
return pulse_id;
}
+16 -16
View File
@@ -8,7 +8,7 @@
#include "FrameUdpReceiver.hpp"
#include "BufferUtils.hpp"
#include "FrameStats.hpp"
using namespace std;
using namespace chrono;
using namespace buffer_config;
@@ -18,28 +18,30 @@ using namespace BufferUtils;
int main (int argc, char *argv[]) {
if (argc != 3) {
if (argc != 4) {
cout << endl;
#ifndef USE_EIGER
cout << "Usage: jf_udp_recv [detector_json_filename] [module_id]";
cout << "Usage: jf_udp_recv [detector_json_filename] [module_id] [bit_depth]";
#else
cout << "Usage: eiger_udp_recv [detector_json_filename] [module_id]";
cout << "Usage: eiger_udp_recv [detector_json_filename] [module_id] [bit_depth]";
#endif
cout << endl;
cout << "\tdetector_json_filename: detector config file path." << endl;
cout << "\tmodule_id: id of the module for this process." << endl;
cout << "\tbit_depth: bit depth of the incoming udp packets." << endl;
cout << endl;
exit(-1);
}
const auto config = read_json_config(string(argv[1]));
const int module_id = atoi(argv[2]);
const int bit_depth = atoi(argv[3]);
const int n_receivers = config.n_modules * config.n_submodules;
const auto udp_port = config.start_udp_port + module_id;
FrameUdpReceiver receiver(udp_port, module_id);
RamBuffer buffer(config.detector_name, config.n_modules);
FrameStats stats(config.detector_name, module_id, STATS_TIME);
FrameUdpReceiver receiver(module_id, udp_port, n_receivers, config.n_submodules, bit_depth);
RamBuffer buffer(config.detector_name, n_receivers, config.n_submodules, bit_depth);
FrameStats stats(config.detector_name, n_receivers, module_id, bit_depth, STATS_TIME);
auto ctx = zmq_ctx_new();
auto socket = bind_socket(ctx, config.detector_name, to_string(module_id));
@@ -49,19 +51,17 @@ int main (int argc, char *argv[]) {
uint64_t pulse_id_previous = 0;
uint64_t frame_index_previous = 0;
while (true) {
auto pulse_id = receiver.get_frame_from_udp(meta, data);
bool bad_pulse_id = false;
if ( meta.frame_index != (frame_index_previous+1) && frame_index_previous != 0) {
bool bad_pulse_id = false;
if ( ( meta.frame_index != (frame_index_previous+1) ) ||
( (meta.frame_index-frame_index_previous) <= 0 ) ||
( (meta.frame_index-frame_index_previous) > 1000 ) ){
bad_pulse_id = true;
} else {
buffer.write_frame(meta, data);
zmq_send(socket, &pulse_id, sizeof(pulse_id), 0);