diff --git a/include/fdreadoutlibs/TDEEthTypeAdapter.hpp b/include/fdreadoutlibs/TDEEthTypeAdapter.hpp new file mode 100644 index 0000000..98f13e3 --- /dev/null +++ b/include/fdreadoutlibs/TDEEthTypeAdapter.hpp @@ -0,0 +1,108 @@ +#ifndef FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_TDEETHTYPEADAPTER_HPP_ +#define FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_TDEETHTYPEADAPTER_HPP_ + +#include "daqdataformats/FragmentHeader.hpp" +#include "daqdataformats/SourceID.hpp" +#include "fddetdataformats/TDEEthFrame.hpp" + +#include // uint_t types +#include // unique_ptr +#include +#include // memcpy +#include // tie + +namespace dunedaq { +namespace fdreadoutlibs { +namespace types { + +/** + * @brief For TDEEth the numbers are different. + * Header + (64 channels * 64 time slices) = 7200[Bytes] + * */ +const constexpr std::size_t kTDEEthSize = 7200; +struct TDEEthTypeAdapter +{ + using FrameType = dunedaq::fddetdataformats::TDEEthFrame; + // data + char data[kTDEEthSize]; + // comparable based on first timestamp + bool operator<(const TDEEthTypeAdapter& other) const + { + auto thisptr = reinterpret_cast(&data); // NOLINT + auto otherptr = reinterpret_cast(&other.data); // NOLINT + return thisptr->get_timestamp() < otherptr->get_timestamp() ? true : false; + } + + uint64_t get_first_timestamp() const // NOLINT(build/unsigned) + { + return reinterpret_cast(&data)->get_timestamp(); // NOLINT + } + + void set_first_timestamp(uint64_t ts) // NOLINT(build/unsigned) + { + auto frame = reinterpret_cast(&data); // NOLINT + frame->set_timestamp(ts); + } + + void fake_timestamps(uint64_t first_timestamp, uint64_t /*offset = 2048*/ ) // NOLINT(build/unsigned) + { + auto wef = reinterpret_cast(((uint8_t*)(&data))); // NOLINT + wef->set_timestamp(first_timestamp); + } + + void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id) { + for (unsigned int i = 0; i < get_num_frames(); ++i) { + auto df = reinterpret_cast((reinterpret_cast(&data)) + i * get_frame_size()); + df->daq_header.crate_id = crate_id; + df->daq_header.slot_id = slot_id; + df->daq_header.stream_id = stream_id; + } + } + + void fake_adc_pattern(int channel) { + auto frame = reinterpret_cast(&data); // NOLINT + // Set the ADC to the uint16 maximum value + // AAA: setting only the first time sample + frame->set_adc(channel, 0, 16383); + } + + void fake_frame_errors(std::vector* /*fake_errors*/) // NOLINT + { + // Set error bits in header + } + + FrameType* begin() + { + return reinterpret_cast(&data[0]); // NOLINT + } + + FrameType* end() + { + return reinterpret_cast(data + kTDEEthSize); // NOLINT + } + + size_t get_payload_size() { return kTDEEthSize; } + + size_t get_num_frames() { return 1; } + + size_t get_frame_size() { return kTDEEthSize; } + + static const constexpr size_t fixed_payload_size = 7200; + static const constexpr daqdataformats::SourceID::Subsystem subsystem = daqdataformats::SourceID::Subsystem::kDetectorReadout; + static const constexpr daqdataformats::FragmentType fragment_type = daqdataformats::FragmentType::kWIBEth; + // NOTE: the expected_tick_difference is different from WIBs because of the TDE sampling rate + static const constexpr uint64_t expected_tick_difference = 2000; // NOLINT(build/unsigned) + static const constexpr uint64_t samples_per_frame = 64; // NOLINT(build/unsigned) + // NOTE: this is actually 31.25 + static const constexpr uint64_t samples_tick_difference = 32; // NOLINT(build/unsigned) +}; + +static_assert(sizeof(struct dunedaq::fddetdataformats::TDEEthFrame) == kTDEEthSize, + "Check your assumptions on TDEEthTypeAdapter"); + + +} // namespace types +} // namespace fdreadoutlibs +} // namespace dunedaq + +#endif /* FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_TDEETHTYPEADAPTER_HPP_ */