10#include "cluon-complete.hpp"
20#include "hdf_interface.h"
39 std::string IpAddress,
44 ): Type(detectorType_from_int(Type)),
45 ipaddr(std::move(IpAddress)),
49 period(grid.period()),
50 sender{ipaddr,
static_cast<uint16_t
>(UDPPort)}
53 hp = (PacketHeaderV0*)&buffer[0];
59 std::string IpAddress,
75 void addReadout(uint8_t Ring, uint8_t FEN,
double tof,
double weight,
const void * data);
90 void setPulseTime(uint32_t PHI, uint32_t PLO, uint32_t PPHI, uint32_t PPLO);
104 [[nodiscard]] std::pair<uint32_t, uint32_t> lastPulseTime()
const;
105 [[nodiscard]] std::pair<uint32_t, uint32_t> prevPulseTime()
const;
106 [[nodiscard]] std::pair<uint32_t, uint32_t> lastEventTime()
const;
117 case Verbosity::details: verbosity=3;
break;
118 case Verbosity::info: verbosity=2;
break;
119 case Verbosity::warnings: verbosity=1;
break;
120 case Verbosity::errors: verbosity=0;
break;
121 case Verbosity::silent: verbosity=-1;
break;
122 default: verbosity=0;
126 int verbose(
const int v){verbosity = v;
return verbosity;}
129 void dump_to(
const std::string & filename,
const std::string & dataset_name =
"events");
135 void fold_tof(
const bool fold) { fold_tof_ = fold; }
143 hp->OutputQueue =
static_cast<uint8_t
>(queue);
145 [[nodiscard]]
int output_queue()
const {
return OutputQueue; }
149 void enable_network() {network =
true;}
150 void disable_network() {network =
false;}
152 void set_random_seed(
const uint32_t seed) {
153 random_engine.seed(seed);
156 int random_poisson(
const double mean) {
157 std::poisson_distribution<int> distribution(mean);
158 return distribution(random_engine);
162 HighFive::CompoundType datatype()
const {
163 return ::hdf_compound_type(readoutType_from_detectorType(Type));
166 void check_size_and_send();
182 PacketHeaderV0 *hp{};
184 const int MaxDataSize{8950};
192 std::optional<Writer> writer{std::nullopt};
194 bool fold_tof_{
false};
195 uint64_t long_tof_{0};
196 void report_long_tof()
const;
199 cluon::UDPSender sender;
202 void set_pulse(
const uint64_t ns) {
205 setPulseTime(time.high(), time.low(), prev.high(), prev.low());
208 std::mt19937 random_engine{std::default_random_engine{}()};
Umbrella header for the C API used by the McStas components.
ESS and Bifrost readout data structures.
Runtime-streaming readout generator used by the legacy Readout components.
void addReadout(uint8_t Ring, uint8_t FEN, efu_time t, const void *data)
Add a single readout with an explicit event time.
void output_queue(const int queue)
Send on this output queue (0 until set). An EFU keeps one packet sequence per queue,...
int command_shutdown() const
Tell the remote EFU to shut down via its TCP command port.
void newPacket()
Initialize a new packet with no readouts.
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 a weighted readout: draws n ~ Poisson(weight) and buffers the event n times (weight <= 0 is a noi...
void update_time()
Advance the reference (pulse) time to now, flushing the buffer and starting a new packet; keeps (now ...
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 dump_to(const std::string &filename, const std::string &dataset_name="events")
Also store every added readout to a legacy flat HDF5 file (see Writer).
uint64_t long_tof_count() const
How many readouts so far had a time-of-flight of at least one pulse period.
int send()
Transmit the current data buffer.
int sequence_number() const
The number the next packet will be sent with.
int verbose(const Verbosity v)
Set verbosity via enum.
ESS EFU two-integer timestamp: whole seconds since the UNIX epoch plus ticks of the 88....
static efu_time from_nanoseconds(const uint64_t ns)
Nanoseconds since the UNIX epoch, to the nearest tick.
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.