Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding type adapter for TDEEthFrame #181

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions include/fdreadoutlibs/TDEEthTypeAdapter.hpp
Original file line number Diff line number Diff line change
@@ -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 <cstdint> // uint_t types
#include <memory> // unique_ptr
#include <vector>
#include <cstring> // memcpy
#include <tuple> // 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<const FrameType*>(&data); // NOLINT
auto otherptr = reinterpret_cast<const FrameType*>(&other.data); // NOLINT
return thisptr->get_timestamp() < otherptr->get_timestamp() ? true : false;
}

uint64_t get_first_timestamp() const // NOLINT(build/unsigned)
{
return reinterpret_cast<const FrameType*>(&data)->get_timestamp(); // NOLINT
}

void set_first_timestamp(uint64_t ts) // NOLINT(build/unsigned)
{
auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
frame->set_timestamp(ts);
}

void fake_timestamps(uint64_t first_timestamp, uint64_t /*offset = 2048*/ ) // NOLINT(build/unsigned)
{
auto wef = reinterpret_cast<FrameType*>(((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<FrameType*>((reinterpret_cast<uint8_t*>(&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<FrameType*>(&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<uint16_t>* /*fake_errors*/) // NOLINT
{
// Set error bits in header
}

FrameType* begin()
{
return reinterpret_cast<FrameType*>(&data[0]); // NOLINT
}

FrameType* end()
{
return reinterpret_cast<FrameType*>(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_ */
Loading