DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CRTBernTypeAdapter.hpp
Go to the documentation of this file.
1#ifndef FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_CRTBERNTYPEADAPTER_
2#define FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_CRTBERNTYPEADAPTER_
3
7
8#include <cstdint> // uint_t types
9#include <cstring> // memcpy
10#include <memory> // unique_ptr
11#include <tuple> // tie
12#include <vector>
13
14namespace dunedaq {
15namespace fdreadoutlibs {
16namespace types {
17
18const constexpr std::size_t kCRTBernFrameSize = sizeof(dunedaq::fddetdataformats::CRTBernFrame);
19
21{
23 // data
25 // comparable based on first timestamp
26 bool operator<(const CRTBernTypeAdapter& other) const
27 {
28 auto thisptr = reinterpret_cast<const FrameType*>(&data); // NOLINT
29 auto otherptr = reinterpret_cast<const FrameType*>(&other.data); // NOLINT
30 return thisptr->get_timestamp() < otherptr->get_timestamp();
31 }
32
33 uint64_t get_timestamp() const // NOLINT(build/unsigned)
34 {
35 return reinterpret_cast<const FrameType*>(&data)->get_timestamp(); // NOLINT
36 }
37
38 void set_timestamp(uint64_t ts) // NOLINT(build/unsigned)
39 {
40 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
41 frame->set_timestamp(ts);
42 }
43
44 void fake_timestamps(uint64_t first_timestamp,
45 uint64_t /*offset*/ = expected_tick_difference) // NOLINT(build/unsigned)
46 {
47 set_timestamp(first_timestamp);
48 }
49
50 void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id)
51 {
52 auto df = reinterpret_cast<FrameType*>(reinterpret_cast<uint8_t*>(&data));
53 df->daq_header.slot_id = slot_id;
54 df->daq_header.stream_id = stream_id;
55 df->daq_header.crate_id = crate_id;
56 }
57
58 void fake_adc_pattern(int channel)
59 {
60 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
61 frame->set_adc(channel, 0xbeef);
62 }
63
64 void fake_frame_errors(std::vector<uint16_t>* /*fake_errors*/) // NOLINT
65 {
66 // Set frame error bits in header
67 }
68
70 {
71 return reinterpret_cast<FrameType*>(&data[0]); // NOLINT
72 }
73
75 {
76 return reinterpret_cast<FrameType*>(data + kCRTBernFrameSize); // NOLINT
77 }
78
80
81 size_t get_num_frames() { return 1; }
82
83 size_t get_frame_size() { return kCRTBernFrameSize; }
84
85 static const constexpr size_t fixed_payload_size = kCRTBernFrameSize;
89 static const constexpr uint64_t expected_tick_difference = 1; // NOLINT(build/unsigned)
90};
91
92static_assert(sizeof(struct CRTBernTypeAdapter) == kCRTBernFrameSize, "Check your assumptions on CRTBernTypeAdapter");
93
94} // namespace types
95} // namespace fdreadoutlibs
96} // namespace dunedaq
97
98#endif /* FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_CRTBERNTYPEADAPTER_ */
FragmentType
All defined Fragment types.
const constexpr std::size_t kCRTBernFrameSize
The DUNE-DAQ namespace.
Subsystem
The Subsystem enum describes the kind of source we're dealing with.
Definition SourceID.hpp:40
Struct for accessing/holding raw CRT data from the 'Bern' panels ProtoDUNE-II VD.
void set_adc(int i_ch, uint16_t val)
Set the adc value for channel i_ch to val.
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
detdataformats::DAQEthHeader daq_header
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame also set the underlying ts0 to be consistent.
void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id)
static const constexpr uint64_t expected_tick_difference
void fake_timestamps(uint64_t first_timestamp, uint64_t=expected_tick_difference)
bool operator<(const CRTBernTypeAdapter &other) const
static const constexpr daqdataformats::SourceID::Subsystem subsystem
static const constexpr daqdataformats::FragmentType fragment_type
dunedaq::fddetdataformats::CRTBernFrame FrameType