McStas Readout Master 0.3.3
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*/) {}
40};
41
42class RL_API NullParameterPublisher final : public ParameterPublisher {
43public:
44 void publish(size_t, const std::string &, const std::string &, const std::optional<std::string> &) override {}
45};
46
48class RL_API StreamParameterPublisher final : public ParameterPublisher {
49 std::ostream & out_;
50public:
51 explicit StreamParameterPublisher(std::ostream & out): out_{out} {}
52 void publish(size_t point, const std::string & name, const std::string & value, const std::optional<std::string> & unit) override;
53};
54
56struct RL_API ReplaySubset {
57 size_t first{0};
58 size_t number{0};
59 size_t every{1};
60};
61
62// New fields need a matching setter in readout_capi.h and a field in the
63// mcstas_readout.ReplayConfig Python dataclass (bump READOUT_CAPI_ABI_VERSION on change).
64struct RL_API ReplayConfig {
68 std::optional<double> counting_time{std::nullopt};
70 uint32_t seed{0};
72 bool random_order{false};
74 SenderConfigs senders{};
75 std::string default_address{"127.0.0.1"};
76 int default_port{9000};
78 size_t chunk_size{65536};
79 std::optional<ReplaySubset> subset{std::nullopt};
82 double pulse_rate{14.0};
85 bool fold_tof{false};
88 const std::atomic<bool> * stop{nullptr};
89};
90
106RL_API bool replay(const std::string & filename, const ReplayConfig & config, ParameterPublisher & publisher);
107RL_API bool replay(const std::string & filename, const ReplayConfig & config);
108
116RL_API void replay_all(const std::string & filename, const std::string & address, int port, int control);
117
128RL_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
Explicit EFU endpoint configuration for replay, parsed from JSON.
Prints "point N: name = value [unit]" lines to the provided stream.
Definition replay.h:48
Restrict replay to stored readouts with global index first + k * every, for k in [0,...
Definition replay.h:56