Add std-udp-sync project

This commit is contained in:
2021-07-05 16:12:53 +02:00
parent 9ff380e78a
commit eb9c87cf2f
12 changed files with 570 additions and 4 deletions
+27
View File
@@ -0,0 +1,27 @@
#ifndef SF_DAQ_BUFFER_SYNCSTATS_HPP
#define SF_DAQ_BUFFER_SYNCSTATS_HPP
#include <chrono>
#include <string>
#include <formats.hpp>
class SyncStats {
const std::string detector_name_;
const size_t stats_modulo_;
int image_counter_;
int n_sync_lost_images_;
std::chrono::time_point<std::chrono::steady_clock> stats_interval_start_;
void reset_counters();
void print_stats();
public:
SyncStats(const std::string &detector_name,
const size_t stats_modulo);
void record_stats(const uint32_t n_lost_pulses);
};
#endif //SF_DAQ_BUFFER_SYNCSTATS_HPP
+29
View File
@@ -0,0 +1,29 @@
#ifndef SF_DAQ_BUFFER_UDPRECVCONFIG_HPP
#define SF_DAQ_BUFFER_UDPRECVCONFIG_HPP
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <string>
#include <fstream>
struct UdpSyncConfig {
static UdpSyncConfig from_json_file(const std::string& filename) {
std::ifstream ifs(filename);
rapidjson::IStreamWrapper isw(ifs);
rapidjson::Document config_parameters;
config_parameters.ParseStream(isw);
return {
config_parameters["detector_name"].GetString(),
config_parameters["n_modules"].GetInt()
};
}
const std::string detector_name;
const int n_modules;
};
#endif //SF_DAQ_BUFFER_UDPRECVCONFIG_HPP
@@ -0,0 +1,34 @@
#ifndef SF_DAQ_BUFFER_ZMQPULSESYNCRECEIVER_HPP
#define SF_DAQ_BUFFER_ZMQPULSESYNCRECEIVER_HPP
#include <cstddef>
#include <string>
#include <vector>
#include "formats.hpp"
struct PulseAndSync {
const uint64_t image_id;
const uint32_t n_lost_pulses;
};
class ZmqPulseSyncReceiver {
void* ctx_;
const int n_modules_;
std::vector<void*> sockets_;
public:
ZmqPulseSyncReceiver(
void* ctx,
const std::string& detector_name,
const int n_modules);
~ZmqPulseSyncReceiver();
PulseAndSync get_next_pulse_id() const;
};
#endif //SF_DAQ_BUFFER_ZMQPULSESYNCRECEIVER_HPP
+11
View File
@@ -0,0 +1,11 @@
namespace sync_config
{
// If the modules are offset more than 1000 pulses, crush.
const uint64_t PULSE_OFFSET_LIMIT = 100;
// Number of times we try to re-sync in case of failure.
const int SYNC_RETRY_LIMIT = 3;
// Number of pulses between each statistics print out.
const size_t SYNC_STATS_MODULO = 1000;
}