STADLS
playback_program.h
Go to the documentation of this file.
1 #pragma once
2 #include <cstdint>
3 #include <memory>
4 #include <optional>
5 #include <string>
6 #include <vector>
7 
8 #include <boost/variant.hpp>
9 
10 #include "fisch/vx/container_cast.h"
11 #include "fisch/vx/container_ticket.h"
12 #include "fisch/vx/playback_program.h"
13 #include "haldls/cerealization.h"
14 #include "haldls/vx/common.h"
15 #include "haldls/vx/event.h"
16 #include "hate/type_list.h"
17 #include "hate/visibility.h"
18 #include "hxcomm/vx/target.h"
19 #include "stadls/vx/genpybind.h"
21 
22 #if defined(__GENPYBIND__) or defined(__GENPYBIND_GENERATED__)
23 #include <pybind11/numpy.h>
24 #include <pybind11/stl_bind.h>
25 #endif
26 
28 
29 namespace detail {
30 
31 template <typename, typename, template <typename> class>
33 template <typename, typename, template <typename> class>
35 
36 template <typename BackendContainerTypeList>
38 
39 template <typename... BackendContainer>
40 struct to_ticket_variant<hate::type_list<BackendContainer...>>
41 {
42  typedef boost::variant<fisch::vx::ContainerTicket<decltype(
43  fisch::vx::container_cast(std::declval<BackendContainer>()))>...>
45 };
46 
47 } // namespace detail
48 
49 class PlaybackProgram;
50 
51 class ReinitStackEntry;
52 
53 template <typename Connection>
55 
60 class GENPYBIND(visible) PlaybackProgram
61 {
62 public:
63  typedef fisch::vx::FPGATime fpga_time_type;
64 
69  template <typename T>
71  {
72  public:
73  typedef typename T::coordinate_type coordinate_type;
74 
80  T get() const SYMBOL_VISIBLE;
81 
86  bool valid() const SYMBOL_VISIBLE;
87 
92  coordinate_type get_coordinate() const SYMBOL_VISIBLE;
93 
100  GENPYBIND(getter_for(fpga_time))
101  fpga_time_type get_fpga_time() const SYMBOL_VISIBLE;
102 
103  private:
104  typedef typename detail::to_ticket_variant<
105  typename haldls::vx::detail::BackendContainerTrait<T>::container_list>::type
106  ticket_impl_type;
107 
108  template <typename, typename, template <typename> class>
109  friend class detail::PlaybackProgramBuilderAdapterImpl;
110 
111  ContainerTicket(coordinate_type const& coord, ticket_impl_type ticket_impl) :
112  m_coord(coord), m_ticket_impl(std::move(ticket_impl))
113  {}
114 
115  coordinate_type m_coord;
116  ticket_impl_type m_ticket_impl;
117  }; // ContainerTicket
118 
119 
121  PlaybackProgram() SYMBOL_VISIBLE;
122 
123  typedef std::vector<haldls::vx::SpikeFromChip> spikes_type;
124  typedef std::vector<haldls::vx::MADCSampleFromChip> madc_samples_type;
125  typedef std::vector<haldls::vx::HighspeedLinkNotification> highspeed_link_notifications_type;
126 
128  GENPYBIND(visible);
130  GENPYBIND(visible);
131 
136  GENPYBIND(getter_for(spikes))
137  spikes_type get_spikes() const SYMBOL_VISIBLE;
138 
143  GENPYBIND(getter_for(madc_samples))
144  madc_samples_type get_madc_samples() const SYMBOL_VISIBLE;
145 
150  GENPYBIND(getter_for(highspeed_link_notifications))
151  highspeed_link_notifications_type get_highspeed_link_notifications() const SYMBOL_VISIBLE;
152 
157  GENPYBIND(getter_for(spikes_pack_counts))
158  spike_pack_counts_type const& get_spikes_pack_counts() const SYMBOL_VISIBLE;
159 
164  GENPYBIND(getter_for(madc_samples_pack_counts))
165  madc_sample_pack_counts_type const& get_madc_samples_pack_counts() const SYMBOL_VISIBLE;
166 
171  GENPYBIND(getter_for(unsupported_targets))
172  std::unordered_set<hxcomm::vx::Target> const& get_unsupported_targets() const SYMBOL_VISIBLE;
173 
174  GENPYBIND(stringstream)
175  friend std::ostream& operator<<(std::ostream& os, PlaybackProgram const& program)
176  SYMBOL_VISIBLE;
177 
182  bool empty() const SYMBOL_VISIBLE;
183 
184  bool operator==(PlaybackProgram const& other) const SYMBOL_VISIBLE;
185  bool operator!=(PlaybackProgram const& other) const SYMBOL_VISIBLE;
186 
194  GENPYBIND_MANUAL({
195  PYBIND11_NUMPY_DTYPE(
196  haldls::vx::SpikeFromChip::SpikeFromChipDType, label, fpga_time, chip_time);
197 
198  // expose spikes_type with pybinds11 STL vector thingy
199  pybind11::bind_vector<stadls::vx::PlaybackProgram::spikes_type>(parent, "spikes_type");
200  {
201  auto attr = parent.attr("spikes_type");
202  auto ism = parent->py::is_method(attr);
203 
208  typedef ::stadls::vx::PlaybackProgram::spikes_type _values_type;
209  attr.attr("to_numpy") = parent->py::cpp_function(
210  [](_values_type const& self) {
211  pybind11::array_t<haldls::vx::SpikeFromChip::SpikeFromChipDType> ret(
212  {static_cast<pybind11::ssize_t>(self.size())},
213  reinterpret_cast<haldls::vx::SpikeFromChip::SpikeFromChipDType const*>(
214  self.data()));
215  return ret;
216  },
217  ism);
218  }
219  })
220 
228  GENPYBIND_MANUAL({
229  PYBIND11_NUMPY_DTYPE(
230  haldls::vx::MADCSampleFromChip::MADCSampleFromChipDType, value, channel, fpga_time,
231  chip_time);
232 
233  // expose madc_samples_type with pybinds11 STL vector thingy
234  pybind11::bind_vector<stadls::vx::PlaybackProgram::madc_samples_type>(
235  parent, "madc_samples_type");
236  {
237  typedef ::stadls::vx::PlaybackProgram::madc_samples_type _values_type;
238  auto attr = parent.attr("madc_samples_type");
239  auto ism = parent->py::is_method(attr);
240 
241  auto const to_numpy = [](_values_type const& self) {
242  pybind11::array_t<haldls::vx::MADCSampleFromChip::MADCSampleFromChipDType> ret(
243  {static_cast<pybind11::ssize_t>(self.size())},
244  reinterpret_cast<
245  haldls::vx::MADCSampleFromChip::MADCSampleFromChipDType const*>(
246  self.data()));
247  return ret;
248  };
249 
250  attr.attr("to_numpy") = parent->py::cpp_function(to_numpy, ism);
251  }
252  })
253 
254 private:
255  friend struct cereal::access;
256  template <typename Archive>
257  void serialize(Archive& ar, uint32_t);
258 
259  template <typename, typename, template <typename> class>
261 
262  template <typename, typename, template <typename> class>
264 
265  template <typename Connection>
266  friend RunTimeInfo run(Connection&, PlaybackProgram&);
267 
268  friend ReinitStackEntry;
269 
276  PlaybackProgram(
277  std::shared_ptr<fisch::vx::PlaybackProgram> const& program_impl,
278  std::unordered_set<hxcomm::vx::Target> unsupported_targets) SYMBOL_VISIBLE;
279 
280  std::shared_ptr<fisch::vx::PlaybackProgram> m_program_impl;
281 
282  std::unordered_set<hxcomm::vx::Target> m_unsupported_targets;
283 };
284 
285 } // namespace stadls::vx
286 
287 #if defined(__GENPYBIND__) or defined(__GENPYBIND_GENERATED__)
288 // disable pybind11's automatic conversion to python types via its `list_caster`
289 PYBIND11_MAKE_OPAQUE(stadls::vx::PlaybackProgram::spikes_type)
291 #endif
Ticket for to-be-available container data corresponding to a read instruction.
T get() const SYMBOL_VISIBLE
Get container data if available.
Sequential stream of executable instructions for the executor and result-container for event response...
std::vector< haldls::vx::HighspeedLinkNotification > highspeed_link_notifications_type
std::vector< haldls::vx::MADCSampleFromChip > madc_samples_type
fisch::vx::FPGATime fpga_time_type
fisch::vx::PlaybackProgram::madc_sample_pack_counts_type madc_sample_pack_counts_type
std::vector< haldls::vx::SpikeFromChip > spikes_type
::stadls::vx::PlaybackProgram::spikes_type _values_type
fisch::vx::PlaybackProgram::spike_pack_counts_type spike_pack_counts_type
PlaybackProgram() SYMBOL_VISIBLE
Default constructor.
#define GENPYBIND_TAG_STADLS_VX
Definition: genpybind.h:4
class SYMBOL_VISIBLE stadls::vx::detail::PlaybackProgramBuilderAdapter empty() const
Get whether builder is empty, i.e.
struct stadls::vx::v2::DumperDone access
hate::type_list<#define PLAYBACK_CONTAINER(Name, Type) # 13 "/jenkins/jenlib_workspaces_f9/bld_nightly-haldls.YmxkX25pZ2h0bHktaGFsZGxzIzEzNzk.x/haldls/include/stadls/vx/v2/coordinate_to_container.h" 2#define LAST_PLAYBACK_CONTAINER(Name, Type) #define PLAYBACK_CONTAINER(Name, Type) # 16 "/jenkins/jenlib_workspaces_f9/bld_nightly-haldls.YmxkX25pZ2h0bHktaGFsZGxzIzEzNzk.x/haldls/include/stadls/vx/v2/coordinate_to_container.h" 2 > container_list
List of container types used to resolve a container type from a coordinate type.
RunTimeInfo run(Connection &, PlaybackProgram &)
Transfer and execute the given playback program and fetch results.
fisch::vx::RunTimeInfo RunTimeInfo
Definition: run_time_info.h:8
auto const to_numpy
PlaybackProgramBuilderAdapter()
Construct builder.
boost::variant< fisch::vx::ContainerTicket< decltype(fisch::vx::container_cast(std::declval< BackendContainer >)))>... > type