10#include "cluon-complete.hpp"
21#include "SenderConfigs.h"
23#include "hdf_interface.h"
47 std::string IpAddress,
const int UDPPort,
const int TCPPort,
const DetectorType detector_type,
const ReadoutType readout_type,
const pulse_grid grid
48 ): detector_type(detector_type),
49 readout_type(readout_type),
50 ipaddr(std::move(IpAddress)),
54 period(grid.period()),
55 sender{ipaddr,
static_cast<uint16_t
>(UDPPort)}
63 std::string IpAddress,
const int UDPPort,
const int TCPPort,
const DetectorType detector_type,
const ReadoutType readout_type,
const efu_time p =
efu_time(1)
67 :
Sender(config.ip_address, config.
udp_port, config.
tcp_port, config.detector_type, config.readout_type, grid) {}
74 if (DataSize >
static_cast<int>(
sizeof(
struct PacketHeaderV0))) {
83 void addReadout(uint8_t Ring, uint8_t FEN,
double tof,
double weight,
const void * data);
100 void setPulseTime(uint32_t PHI, uint32_t PLO, uint32_t PPHI, uint32_t PPLO);
128 void fold_tof(
const bool fold) { fold_tof_ = fold; }
133 [[nodiscard]] std::pair<uint32_t, uint32_t> lastPulseTime()
const;
136 [[nodiscard]] std::pair<uint32_t, uint32_t> prevPulseTime()
const;
137 [[nodiscard]] std::pair<uint32_t, uint32_t> lastEventTime()
const;
148 case Verbosity::details: verbosity=3;
break;
149 case Verbosity::info: verbosity=2;
break;
150 case Verbosity::warnings: verbosity=1;
break;
151 case Verbosity::errors: verbosity=0;
break;
152 case Verbosity::silent: verbosity=-1;
break;
153 default: verbosity=0;
157 int verbose(
const int v){verbosity = v;
return verbosity;}
160 void check_size_and_send();
164 void maybe_advance_pulse();
167 void set_pulse(uint64_t ns);
180 DetectorType detector_type;
181 ReadoutType readout_type;
186 const int MaxDataSize{8950};
193 bool fold_tof_{
false};
194 bool hold_pulse_{
false};
195 std::atomic<uint64_t> long_tof_{0};
196 void report_long_tof()
const;
200 uint64_t pulse_ns{0};
201 cluon::UDPSender sender;
203 std::mutex time_mutex, send_mutex;
Umbrella header for the C API used by the McStas components.
ESS and Bifrost readout data structures.
Buffers ESS readout records and transmits them as UDP packets to one EFU.
void announce_pulse()
Send the current pulse's header with no readouts, so the EFU sees the pulse even when nothing is dete...
uint64_t lastPulseNanoseconds() const
The current pulse exactly, in nanoseconds since the UNIX epoch: a pulse_grid tick.
void hold_pulse(const bool hold)
Keep the pulse begun by begin_pulse()/begin_pulse_at() however long sending takes,...
void newPacket()
Initialize a new packet with no readouts.
uint64_t long_tof_count() const
How many readouts so far had a time-of-flight of at least one pulse period.
void addReadout(uint8_t Ring, uint8_t FEN, efu_time t, const void *data)
Add a single readout with an explicit event time.
void begin_pulse_at(uint64_t at)
begin_pulse(), at the grid tick at (rounded up onto the grid), so that several Senders can begin one ...
void flush()
Send whatever is buffered for the current pulse now.
int command_shutdown() const
Tell the remote EFU to shut down via its TCP command port.
int send()
Transmit the current data buffer; the caller is responsible for starting a new packet (newPacket()) b...
uint64_t next_pulse() const
The tick begin_pulse() would begin: the first after now and after the current pulse.
void setPulseTime(uint32_t PHI, uint32_t PLO, uint32_t PPHI, uint32_t PPLO)
Update the pulse and previous pulse times (high/low pairs).
void begin_pulse()
Start a new pulse: flush any buffered readouts, wait until the next pulse-grid tick has passed on the...
int verbose(const Verbosity v)
Set verbosity via enum.
void fold_tof(const bool fold)
Choose whether add-by-time-of-flight readouts are stamped at pulse + (tof % period) — attributing eac...
void addReadout(uint8_t Ring, uint8_t FEN, double tof, double weight, const void *data)
Add one readout with its event time set to the current pulse time plus tof; the weight is ignored (st...
ESS EFU two-integer timestamp: whole seconds since the UNIX epoch plus ticks of the 88....
static uint64_t now_nanoseconds()
The system clock, in nanoseconds since the UNIX epoch.
The source's pulses: pulse k is at k periods after the UNIX epoch.
static pulse_grid from_period(const efu_time &period)
For a period given as a time: to the nearest nanosecond. efu_time(double) truncates to a whole tick,...
uint64_t at_or_before(const uint64_t ns) const
The latest pulse at or before ns.
One Event Formation Unit endpoint for a (detector, readout) pair.
uint16_t tcp_port
command port
uint16_t udp_port
event-packet port