43class Data :
public IData<Data, ParentType> {
47 Data(
unsigned int nchannels,
double buffer_size,
double sample_rate,
size_t max_nspikes = 0);
50 : Data(parameters.nchannels, parameters.buffer_size, parameters.sample_rate) {}
52 static const std::string static_datatype() {
return "spike"; }
53 static const std::string static_dataname() {
return "spikes"; }
57 void ClearData()
override;
59 unsigned int n_channels()
const;
61 double sample_rate()
const;
62 double buffer_size()
const {
return buffer_size_; }
64 void add_spike(
const std::vector<double>& amplitudes,
65 uint64_t hw_timestamp);
68 void add_spike(
double* amplitudes, uint64_t hw_timestamp);
70 unsigned int n_detected_spikes()
const;
72 std::vector<double>& amplitudes();
76 const std::vector<uint64_t>& ts_detected_spikes()
const;
78 uint64_t ts_detected_spikes(
int index)
const;
80 std::vector<double>::const_iterator spike_amplitudes(std::size_t spike_index)
const;
82 void SerializeBinary(std::ostream& stream,
83 Serialization::Format format = Serialization::Format::FULL)
const final;
85 void SerializeYAML(YAML::Node& node,
86 Serialization::Format format = Serialization::Format::FULL)
const final;
88 void YAMLDescription(YAML::Node& node,
89 Serialization::Format format = Serialization::Format::FULL)
const final;
91 void SerializeFlatBuffer(flexbuffers::Builder& flex_builder)
final;
95 unsigned int n_detected_spikes_;
96 std::vector<double> amplitudes_;
98 std::vector<uint64_t> hw_ts_detected_spikes_;
105 static constexpr unsigned int DEFAULT_MAX_NSPIKES =
106 MAX_N_SPIKES_IN_BUFFER;
110 const std::string N_CHANNELS =
"n_channels";
111 const std::string N_DETECTED_SPIKES =
"n_detected_spikes";
112 const std::string TS_DETECTED_SPIKES =
"TS_detected_spikes";
113 const std::string SPIKE_AMPLITUDES =
"spike_amplitudes";
118 Capabilities(ChannelRange channel_range = ChannelRange(1, MAX_N_CHANNELS_SPIKE_DETECTION))
119 : channel_range_(channel_range) {}
121 ChannelRange channel_range()
const {
return channel_range_; }
123 void Validate(
const Data& prototype)
const {
124 if (!channel_range_.inrange(prototype.n_channels())) {
125 throw std::runtime_error(
"Number of channels cannot be zero and needs to be in range " +
126 channel_range_.to_string());
131 ChannelRange channel_range_;