mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-04-30 19:42:22 +02:00
Statistics for sf-stream
This commit is contained in:
+11
-31
@@ -3,6 +3,7 @@
|
||||
#include <zmq.h>
|
||||
#include <RamBuffer.hpp>
|
||||
#include <BufferUtils.hpp>
|
||||
#include <StreamStats.hpp>
|
||||
|
||||
#include "buffer_config.hpp"
|
||||
#include "stream_config.hpp"
|
||||
@@ -15,57 +16,36 @@ using namespace stream_config;
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
if (argc != 3) {
|
||||
cout << endl;
|
||||
cout << "Usage: sf_stream [detector_json_filename]" << endl;
|
||||
cout << "Usage: sf_stream [detector_json_filename]"
|
||||
" [stream_name]" << endl;
|
||||
cout << "\tdetector_json_filename: detector config file path." << endl;
|
||||
cout << endl;
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
const auto stream_name = string(argv[2]);
|
||||
// TODO: Add stream_name to config reading - multiple stream definitions.
|
||||
auto config = BufferUtils::read_json_config(string(argv[1]));
|
||||
string RECV_IPC_URL = BUFFER_LIVE_IPC_URL + config.detector_name + "-";
|
||||
|
||||
string RECV_IPC_URL = BUFFER_LIVE_IPC_URL + config.detector_name + "-";
|
||||
auto ctx = zmq_ctx_new();
|
||||
zmq_ctx_set(ctx, ZMQ_IO_THREADS, STREAM_ZMQ_IO_THREADS);
|
||||
|
||||
ZmqPulseSyncReceiver receiver(ctx, config.detector_name, config.n_modules);
|
||||
RamBuffer ram_buffer(config.detector_name, config.n_modules);
|
||||
StreamStats stats(config.detector_name, stream_name, STREAM_STATS_MODULO);
|
||||
ZmqLiveSender sender(ctx, config);
|
||||
|
||||
// TODO: Remove stats trash.
|
||||
uint64_t last_pulse_id = 0;
|
||||
uint64_t last_pulse_id_range = 0;
|
||||
uint16_t n_good_images = 0;
|
||||
|
||||
ImageMetadata meta;
|
||||
while (true) {
|
||||
auto pulse_id = receiver.get_next_pulse_id();
|
||||
char* data = ram_buffer.read_image(pulse_id, meta);
|
||||
auto pulse_and_sync = receiver.get_next_pulse_id();
|
||||
char* data = ram_buffer.read_image(pulse_and_sync.pulse_id, meta);
|
||||
|
||||
sender.send(meta, data);
|
||||
|
||||
// TODO: This logic works only at 100Hz. Fix it systematically.
|
||||
uint64_t sync_lost_pulses = pulse_id - last_pulse_id;
|
||||
if (last_pulse_id > 0 && sync_lost_pulses > 1) {
|
||||
cout << "sf_stream:sync_lost_pulses " << sync_lost_pulses << endl;
|
||||
}
|
||||
last_pulse_id = pulse_id;
|
||||
|
||||
uint64_t curr_pulse_id_range = pulse_id / 10000;
|
||||
if (last_pulse_id_range != curr_pulse_id_range) {
|
||||
if (last_pulse_id_range > 0) {
|
||||
cout << "sf_stream:n_good_images " << n_good_images;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
last_pulse_id_range = curr_pulse_id_range;
|
||||
n_good_images = 0;
|
||||
}
|
||||
|
||||
if (meta.is_good_image) {
|
||||
n_good_images++;
|
||||
}
|
||||
stats.record_stats(meta, pulse_and_sync.n_lost_pulses);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user