McStas Readout Master 0.8.0
Loading...
Searching...
No Matches
replay.h
1#pragma once
2#include <atomic>
3#include <cstdint>
4#include <optional>
5#include <string>
6
7#include "SenderConfigs.h"
8
9#ifdef WIN32
10// Export symbols if compile flags "READOUT_SHARED" and "READOUT_EXPORT" are set on Windows.
11 #ifdef READOUT_SHARED
12 #ifdef READOUT_EXPORT
13 #define RL_API __declspec(dllexport)
14 #else
15 #define RL_API __declspec(dllimport)
16 #endif
17 #else
18 // Disable definition if linking statically.
19 #define RL_API
20 #endif
21#else
22// Disable definition for non-Win32 systems.
23#define RL_API
24#endif
25
26enum Replay {NONE = 0, ALL = 1, SEQUENTIAL = 2, RANDOM = 4};
27
35class RL_API ParameterPublisher {
36public:
37 virtual ~ParameterPublisher() = default;
38 virtual void publish(size_t point, const std::string & name, const std::string & value, const std::optional<std::string> & unit) = 0;
39 virtual void point_ready(size_t /*point*/) {}
52 virtual void pulse_ready(size_t /*point*/, uint64_t /*pulse_ns*/) {}
53};
54
55class RL_API NullParameterPublisher final : public ParameterPublisher {
56public:
57 void publish(size_t, const std::string &, const std::string &, const std::optional<std::string> &) override {}
58};
59
61class RL_API StreamParameterPublisher final : public ParameterPublisher {
62 std::ostream & out_;
63public:
64 explicit StreamParameterPublisher(std::ostream & out): out_{out} {}
65 void publish(size_t point, const std::string & name, const std::string & value, const std::optional<std::string> & unit) override;
66};
67
69struct RL_API ReplaySubset {
70 size_t first{0};
71 size_t number{0};
72 size_t every{1};
73};
74
75// New fields need a matching setter in readout_capi.h and a field in the
76// mcstas_readout.ReplayConfig Python dataclass (bump READOUT_CAPI_ABI_VERSION on change).
77struct RL_API ReplayConfig {
81 std::optional<double> counting_time{std::nullopt};
83 uint32_t seed{0};
85 bool random_order{false};
87 SenderConfigs senders{};
88 std::string default_address{"127.0.0.1"};
89 int default_port{9000};
91 size_t chunk_size{65536};
92 std::optional<ReplaySubset> subset{std::nullopt};
95 double pulse_rate{14.0};
98 bool fold_tof{false};
107 size_t pulses_per_point{0};
110 const std::atomic<bool> * stop{nullptr};
111};
112
128RL_API bool replay(const std::string & filename, const ReplayConfig & config, ParameterPublisher & publisher);
129RL_API bool replay(const std::string & filename, const ReplayConfig & config);
130
138RL_API void replay_all(const std::string & filename, const std::string & address, int port, int control);
139
150RL_API void replay_subset(const std::string & filename, const std::string & address, int port, size_t first, size_t number, size_t every, int control);
Receives the per-point instrument parameter values as replay steps through a file.
Definition replay.h:35
virtual void pulse_ready(size_t, uint64_t)
The point's pulse has begun, at pulse_ns nanoseconds since the epoch.
Definition replay.h:52
Explicit EFU endpoint configuration for replay, parsed from JSON.
Prints "point N: name = value [unit]" lines to the provided stream.
Definition replay.h:61
Restrict replay to stored readouts with global index first + k * every, for k in [0,...
Definition replay.h:69