11#include "data_types.hpp"
12#include "int_arith.hpp"
13#include "int_types.hpp"
14#include "introspect.hpp"
16#include "processor.hpp"
17#include "read_integers.hpp"
18#include "time_tagged_events.hpp"
58 std::array<std::byte, 16>
bytes;
97 [[nodiscard]]
constexpr auto time() const noexcept ->
i64np {
112 return make_from_fields(tag_type::time_tag, 0_u16np,
channel,
time);
124 return make_from_fields(tag_type::error, 0_u16np, 0_i32np,
time);
137 return make_from_fields(tag_type::overflow_begin, 0_u16np, 0_i32np,
150 return make_from_fields(tag_type::overflow_end, 0_u16np, 0_i32np,
179 return strm <<
"swabian_tag(type=" <<
static_cast<int>(e.type())
180 <<
", missed=" << e.missed_event_count()
181 <<
", channel=" << e.channel() <<
", time=" << e.time()
192 std::byte(
u8np(missed).value()),
193 std::byte(
u8np(missed >> 8).value()),
200 std::byte(
u8np(
time >> 16).value()),
201 std::byte(
u8np(
time >> 24).value()),
202 std::byte(
u8np(
time >> 32).value()),
203 std::byte(
u8np(
time >> 40).value()),
204 std::byte(
u8np(
time >> 48).value()),
205 std::byte(
u8np(
time >> 56).value()),
212template <
typename DataTypes,
typename Downstream>
class decode_swabian_tags {
213 static_assert(processor<Downstream, detection_event<DataTypes>,
214 begin_lost_interval_event<DataTypes>,
215 end_lost_interval_event<DataTypes>,
216 lost_counts_event<DataTypes>, warning_event>);
218 static_assert(representable_in<i64, typename DataTypes::abstime_type>);
219 static_assert(representable_in<i32, typename DataTypes::channel_type>);
220 static_assert(representable_in<u16, typename DataTypes::count_type>);
222 Downstream downstream;
225 void handle_coldpath_tag(swabian_tag_event
const &event) {
226 switch (event.type()) {
228 case tag_type::time_tag:
230 case tag_type::error:
231 return downstream.handle(warning_event{
"error tag encountered"});
232 case tag_type::overflow_begin:
233 return downstream.handle(
234 begin_lost_interval_event<DataTypes>{
event.time().value()});
235 case tag_type::overflow_end:
236 return downstream.handle(
237 end_lost_interval_event<DataTypes>{
event.time().value()});
238 case tag_type::missed_events:
239 return downstream.handle(lost_counts_event<DataTypes>{
240 event.time().value(),
event.channel().value(),
241 event.missed_event_count().value()});
244 std::ostringstream stream;
245 stream <<
"unknown event type ("
247 std::underlying_type_t<swabian_tag_event::tag_type>
>(
250 downstream.handle(warning_event{stream.str()});
254 explicit decode_swabian_tags(Downstream downstream)
255 : downstream(std::move(downstream)) {}
257 [[nodiscard]]
auto introspect_node() const -> processor_info {
258 return processor_info(
this,
"decode_swabian_tags");
261 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
262 return downstream.introspect_graph().push_entry_point(
this);
265 template <
typename Event>
266 requires std::convertible_to<std::remove_cvref_t<Event>,
268 void handle(Event &&event) {
269 if (event.type() == swabian_tag_event::tag_type::time_tag) {
270 downstream.handle(detection_event<DataTypes>{
271 event.time().value(),
event.channel().value()});
273 handle_coldpath_tag(event);
277 template <
typename Event>
278 requires(not std::convertible_to<std::remove_cvref_t<Event>,
279 swabian_tag_event> and
280 handler_for<Downstream, std::remove_cvref_t<Event>>)
281 void handle(Event &&event) {
282 downstream.handle(std::forward<Event>(event));
285 void flush() { downstream.flush(); }
314template <
typename DataTypes = default_data_types,
typename Downstream>
316 return internal::decode_swabian_tags<DataTypes, Downstream>(
317 std::move(downstream));
constexpr auto read_i32le_at(std::span< T, N > bytes) noexcept -> i32np
Read a little-endian 32-bit signed integer from bytes at offset.
Definition read_integers.hpp:146
npint< i64 > i64np
Non-promoted signed 64-bit integer.
Definition npint.hpp:341
constexpr auto read_u8_at(std::span< T, N > bytes) noexcept -> u8np
Read an 8-bit unsigned integer from bytes at offset.
Definition read_integers.hpp:77
constexpr auto read_i64le_at(std::span< T, N > bytes) noexcept -> i64np
Read a little-endian 64-bit signed integer from bytes at offset.
Definition read_integers.hpp:156
npint< i32 > i32np
Non-promoted signed 32-bit integer.
Definition npint.hpp:334
npint< u8 > u8np
Non-promoted unsigned 8-bit integer.
Definition npint.hpp:292
npint< u16 > u16np
Non-promoted unsigned 16-bit integer.
Definition npint.hpp:299
constexpr auto read_u16le_at(std::span< T, N > bytes) noexcept -> u16np
Read a little-endian 16-bit unsigned integer from bytes at offset.
Definition read_integers.hpp:90
auto count(access_tracker< count_access > &&tracker, Downstream downstream)
Create a processor that counts events of a given type.
Definition count.hpp:313
auto decode_swabian_tags(Downstream downstream)
Create a processor that decodes Swabian Tag events.
Definition swabian_tag.hpp:315
std::uint8_t u8
Short name for uint8_t.
Definition int_types.hpp:24
libtcspc namespace.
Definition acquire.hpp:29
Binary record interpretation for 16-byte Swabian time tag.
Definition swabian_tag.hpp:54
friend auto operator==(swabian_tag_event const &lhs, swabian_tag_event const &rhs) noexcept -> bool=default
Equality comparison operator.
constexpr auto time() const noexcept -> i64np
Read the time (picoseconds).
Definition swabian_tag.hpp:97
static constexpr auto make_overflow_end(i64np time) noexcept -> swabian_tag_event
Make an event representing the end of an overflow interval.
Definition swabian_tag.hpp:148
friend auto operator<<(std::ostream &strm, swabian_tag_event const &e) -> std::ostream &
Stream insertion operator.
Definition swabian_tag.hpp:177
constexpr auto missed_event_count() const noexcept -> u16np
Read the missed event count if this is a missed events event.
Definition swabian_tag.hpp:83
constexpr auto type() const noexcept -> tag_type
Read the event type.
Definition swabian_tag.hpp:74
static constexpr auto make_time_tag(i64np time, i32np channel) noexcept -> swabian_tag_event
Make an event representing a time tag.
Definition swabian_tag.hpp:110
static constexpr auto make_missed_events(i64np time, i32np channel, u16np count) noexcept -> swabian_tag_event
Make an event representing a missed event count.
Definition swabian_tag.hpp:165
std::array< std::byte, 16 > bytes
Bytes of the 16-byte format from Swabian API.
Definition swabian_tag.hpp:58
tag_type
8-bit type for the type field.
Definition swabian_tag.hpp:63
static constexpr auto make_error(i64np time) noexcept -> swabian_tag_event
Make an event representing an error.
Definition swabian_tag.hpp:122
static constexpr auto make_overflow_begin(i64np time) noexcept -> swabian_tag_event
Make an event representing the beginning of an overflow interval.
Definition swabian_tag.hpp:135
constexpr auto channel() const noexcept -> i32np
Read the channel if this is a time tag or missed events event.
Definition swabian_tag.hpp:90