Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions include/detdataformats/DAQEthHeader.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file DAQEthHeader.hpp Common header structure that is used by
* @file DAQEthHeader.hpp Common header structure that is used by
* every FrontEnd electronics board sending data over ethernet.
*
* This is part of the DUNE DAQ Application Framework, copyright 2020.
Expand All @@ -19,20 +19,22 @@ namespace dunedaq::detdataformats {
/**
* @brief DAQEthHeader is a versioned and unified structure for every FE electronics.
*/
struct DAQEthHeader
struct DAQEthHeader
{
using word_t = uint64_t; // NOLINT(build/unsigned)

word_t version : 6, det_id : 6, crate_id : 10, slot_id : 4, stream_id : 8, reserved : 6, seq_id : 12, block_length : 12;
word_t timestamp { std::numeric_limits<word_t>::max() };
word_t version : 6, det_id : 6, crate_id : 10, slot_id : 4, stream_id : 8, reserved : 6, seq_id : 12,
block_length : 12;
word_t timestamp{ std::numeric_limits<word_t>::max() };

uint64_t get_timestamp() const // NOLINT(build/unsigned) maintain a consistent interface with DAQHeader
{
return timestamp;
}
}
};

std::ostream& operator<<(std::ostream& o, DAQEthHeader const& h);
std::ostream&
operator<<(std::ostream& o, DAQEthHeader const& h);

} // namespace dunedaq::detdataformats

Expand Down
13 changes: 7 additions & 6 deletions include/detdataformats/DAQHeader.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file DAQHeader.hpp Common header structure that is used by
* @file DAQHeader.hpp Common header structure that is used by
* every FrontEnd electronics board.
*
* This is part of the DUNE DAQ Application Framework, copyright 2020.
Expand All @@ -19,21 +19,22 @@ namespace dunedaq::detdataformats {
/**
* @brief DAQHeader is a versioned and unified structure for every FE electronics.
*/
struct DAQHeader
struct DAQHeader
{
using word_t = uint32_t; // NOLINT(build/unsigned)

word_t version : 6, det_id : 6, crate_id : 10, slot_id : 4, link_id : 6;
word_t timestamp_1 { std::numeric_limits<word_t>::max() };
word_t timestamp_2 { std::numeric_limits<word_t>::max() };
word_t timestamp_1{ std::numeric_limits<word_t>::max() };
word_t timestamp_2{ std::numeric_limits<word_t>::max() };

uint64_t get_timestamp() const // NOLINT(build/unsigned)
{
return static_cast<uint64_t>(timestamp_1) | (static_cast<uint64_t>(timestamp_2) << 32); // NOLINT(build/unsigned)
}
}
};

std::ostream& operator<<(std::ostream& o, DAQHeader const& h);
std::ostream&
operator<<(std::ostream& o, DAQHeader const& h);

} // namespace dunedaq::detdataformats

Expand Down
11 changes: 7 additions & 4 deletions include/detdataformats/DetID.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ struct DetID
DetID() = default;

DetID(const Subdetector& subdetector_arg) // NOLINT(runtime/explicit) as DetID is just an enhanced enum
: subdetector(subdetector_arg)
{}
: subdetector(subdetector_arg)
{
}

static std::string subdetector_to_string(const Subdetector& type);
static Subdetector string_to_subdetector(const std::string& typestring);
};

std::ostream& operator<<(std::ostream& o, DetID const& det_id);
std::istream& operator>>(std::istream& is, DetID& det_id);
std::ostream&
operator<<(std::ostream& o, DetID const& det_id);
std::istream&
operator>>(std::istream& is, DetID& det_id);

} // namespace dunedaq::detdataformats

Expand Down
17 changes: 9 additions & 8 deletions include/detdataformats/HSIFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef DETDATAFORMATS_INCLUDE_DETDATAFORMATS_HSIFRAME_HPP_
#define DETDATAFORMATS_INCLUDE_DETDATAFORMATS_HSIFRAME_HPP_

#include <cstdint> // For uint32_t etc
#include <cstdint> // For uint32_t etc
#include <limits>

namespace dunedaq::detdataformats {
Expand All @@ -23,16 +23,17 @@ class HSIFrame
using word_t = uint32_t; // NOLINT

word_t version : 6, detector_id : 6, crate : 10, slot : 4, link : 6;
word_t timestamp_low { std::numeric_limits<word_t>::max() } ;
word_t timestamp_high { std::numeric_limits<word_t>::max() } ;
word_t input_low { std::numeric_limits<word_t>::max() } ;
word_t input_high { std::numeric_limits<word_t>::max() } ;
word_t trigger { std::numeric_limits<word_t>::max() } ;
word_t sequence { std::numeric_limits<word_t>::max() } ;
word_t timestamp_low{ std::numeric_limits<word_t>::max() };
word_t timestamp_high{ std::numeric_limits<word_t>::max() };
word_t input_low{ std::numeric_limits<word_t>::max() };
word_t input_high{ std::numeric_limits<word_t>::max() };
word_t trigger{ std::numeric_limits<word_t>::max() };
word_t sequence{ std::numeric_limits<word_t>::max() };

uint64_t get_timestamp() const // NOLINT(build/unsigned)
{
return static_cast<uint64_t>(timestamp_low) | (static_cast<uint64_t>(timestamp_high) << 32); // NOLINT(build/unsigned)
return static_cast<uint64_t>(timestamp_low) | // NOLINT(build/unsigned)
(static_cast<uint64_t>(timestamp_high) << 32); // NOLINT(build/unsigned)
}

void set_timestamp(uint64_t ts) // NOLINT(build/unsigned)
Expand Down
34 changes: 16 additions & 18 deletions include/detdataformats/detail/DAQEthHeader.hxx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@

namespace dunedaq::detdataformats {

static_assert(std::endian::native == std::endian::little, "The DAQEthHeader bitfield layout assumes little-endian architecture");
static_assert(std::endian::native == std::endian::little,
"The DAQEthHeader bitfield layout assumes little-endian architecture");

static_assert(std::is_trivially_copyable_v<DAQEthHeader>, "DAQEthHeader isn't trivially copyable and can't be safely std::memcpy'd");
static_assert(std::is_standard_layout_v<DAQEthHeader>, "DAQEthHeader isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");
static_assert(std::is_trivially_copyable_v<DAQEthHeader>,
"DAQEthHeader isn't trivially copyable and can't be safely std::memcpy'd");
static_assert(std::is_standard_layout_v<DAQEthHeader>,
"DAQEthHeader isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");

static_assert(sizeof(DAQEthHeader) == 16, "DAQEthHeader not the expected size");
static_assert(offsetof(DAQEthHeader, timestamp) == 8, "timestamp field not at expected offset");
static_assert(sizeof(DAQEthHeader) == 16, "DAQEthHeader not the expected size");
static_assert(offsetof(DAQEthHeader, timestamp) == 8, "timestamp field not at expected offset");

inline std::ostream&
operator<<(std::ostream& o, DAQEthHeader const& h)
{
return o << "Version:" << static_cast<unsigned>(h.version) <<
" DetID:" << static_cast<unsigned>(h.det_id) <<
" CrateID:" << static_cast<unsigned>(h.crate_id) <<
" SlotID:" << static_cast<unsigned>(h.slot_id) <<
" StreamID:" << static_cast<unsigned>(h.stream_id) <<
" SequenceID: " << static_cast<unsigned>(h.seq_id) <<
" Block length: " << static_cast<unsigned>(h.block_length) <<
" Timestamp: " << h.get_timestamp() <<
'\n';
}
inline std::ostream&
operator<<(std::ostream& o, DAQEthHeader const& h)
{
return o << "Version:" << static_cast<unsigned>(h.version) << " DetID:" << static_cast<unsigned>(h.det_id)
<< " CrateID:" << static_cast<unsigned>(h.crate_id) << " SlotID:" << static_cast<unsigned>(h.slot_id)
<< " StreamID:" << static_cast<unsigned>(h.stream_id) << " SequenceID: " << static_cast<unsigned>(h.seq_id)
<< " Block length: " << static_cast<unsigned>(h.block_length) << " Timestamp: " << h.get_timestamp() << '\n';
}

} // namespace dunedaq::detdataformats
19 changes: 8 additions & 11 deletions include/detdataformats/detail/DAQHeader.hxx
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@

#include <type_traits>
#include <bit>
#include <cstddef>
#include <type_traits>

namespace dunedaq::detdataformats {

static_assert(std::is_trivially_copyable_v<DAQHeader>, "DAQHeader isn't trivially copyable and can't be safely std::memcpy'd");
static_assert(std::is_standard_layout_v<DAQHeader>, "DAQHeader isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");
static_assert(std::is_trivially_copyable_v<DAQHeader>,
"DAQHeader isn't trivially copyable and can't be safely std::memcpy'd");
static_assert(std::is_standard_layout_v<DAQHeader>,
"DAQHeader isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");
static_assert(std::endian::native == std::endian::little,
"The DAQHeader bitfield layout assumes little-endian architecture");

static_assert(sizeof(DAQHeader) == 12, "DAQHeader struct size different than expected!");
static_assert(offsetof(DAQHeader, timestamp_1) == 4, "DAQHeader timestamp_1 field not at expected offset");
static_assert(offsetof(DAQHeader, timestamp_2) == 8, "DAQHeader timestamp_2 field not at expected offset");


inline std::ostream&
operator<<(std::ostream& o, DAQHeader const& h)
{
return o << "Version:" << static_cast<unsigned>(h.version) <<
" DetID:" << static_cast<unsigned>(h.det_id) <<
" CrateID:" << static_cast<unsigned>(h.crate_id) <<
" SlotID:" << static_cast<unsigned>(h.slot_id) <<
" LinkID:" << static_cast<unsigned>(h.link_id) <<
" Timestamp: " << h.get_timestamp() <<
'\n';
return o << "Version:" << static_cast<unsigned>(h.version) << " DetID:" << static_cast<unsigned>(h.det_id)
<< " CrateID:" << static_cast<unsigned>(h.crate_id) << " SlotID:" << static_cast<unsigned>(h.slot_id)
<< " LinkID:" << static_cast<unsigned>(h.link_id) << " Timestamp: " << h.get_timestamp() << '\n';
}

} // namespace dunedaq::detdataformats
4 changes: 2 additions & 2 deletions include/detdataformats/detail/DetID.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ operator<<(std::ostream& o, DetID::Subdetector const& type)
inline std::ostream&
operator<<(std::ostream& o, DetID const& det_id)
{
return o << "subdetector: " << det_id.subdetector ;
return o << "subdetector: " << det_id.subdetector;
}

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ inline std::istream&
operator>>(std::istream& is, DetID& det_id)
{
std::string tmp;
is >> tmp >> det_id.subdetector;
is >> tmp >> det_id.subdetector;

return is;
}
Expand Down
8 changes: 5 additions & 3 deletions include/detdataformats/detail/HSIFrame.hxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

#include <type_traits>
#include <bit>
#include <cstddef>
#include <type_traits>

namespace dunedaq::detdataformats {

static_assert(std::is_trivially_copyable_v<HSIFrame>, "HSIFrame isn't trivially copyable and can't be safely std::memcpy'd");
static_assert(std::is_standard_layout_v<HSIFrame>, "HSIFrame isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");
static_assert(std::is_trivially_copyable_v<HSIFrame>,
"HSIFrame isn't trivially copyable and can't be safely std::memcpy'd");
static_assert(std::is_standard_layout_v<HSIFrame>,
"HSIFrame isn't standard layout; reinterpret_cast and offsetof can't safely be used with it");
static_assert(std::endian::native == std::endian::little,
"The HSIFrame bitfield layout assumes little-endian architecture");

Expand Down
4 changes: 2 additions & 2 deletions pybindsrc/daqethheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace py = pybind11;

namespace dunedaq::detdataformats::python {

// Quiet the linter about use of unsigned ints in the file
// NOLINTBEGIN(build/unsigned)
// Quiet the linter about use of unsigned ints in the file
// NOLINTBEGIN(build/unsigned)

void
register_daqethheader(py::module& m)
Expand Down
63 changes: 32 additions & 31 deletions pybindsrc/daqheader.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,50 @@ namespace py = pybind11;

namespace dunedaq::detdataformats::python {

// Quiet the linter about use of unsigned ints in the file
// NOLINTBEGIN(build/unsigned)
// Quiet the linter about use of unsigned ints in the file
// NOLINTBEGIN(build/unsigned)

void register_daqheader(py::module& m) {
void
register_daqheader(py::module& m)
{

py::class_<DAQHeader>(m, "DAQHeader", py::buffer_protocol())
.def(py::init<>())
.def_property("version",
.def_property(
"version",
[](DAQHeader& self) -> uint32_t { return self.version; },
[](DAQHeader& self, uint32_t version) { self.version = version; }
)
.def_property("det_id",
[](DAQHeader& self, uint32_t version) { self.version = version; })
.def_property(
"det_id",
[](DAQHeader& self) -> uint32_t { return self.det_id; },
[](DAQHeader& self, uint32_t det_id) { self.det_id = det_id; }
)
.def_property("crate_id",
[](DAQHeader& self, uint32_t det_id) { self.det_id = det_id; })
.def_property(
"crate_id",
[](DAQHeader& self) -> uint32_t { return self.crate_id; },
[](DAQHeader& self, uint32_t crate_id) { self.crate_id = crate_id; }
)
.def_property("slot_id",
[](DAQHeader& self, uint32_t crate_id) { self.crate_id = crate_id; })
.def_property(
"slot_id",
[](DAQHeader& self) -> uint32_t { return self.slot_id; },
[](DAQHeader& self, uint32_t slot_id) { self.slot_id = slot_id; }
)
.def_property("link_id",
[](DAQHeader& self, uint32_t slot_id) { self.slot_id = slot_id; })
.def_property(
"link_id",
[](DAQHeader& self) -> uint32_t { return self.link_id; },
[](DAQHeader& self, uint32_t link_id) { self.link_id = link_id; }
)
.def_property("timestamp_1",
[](DAQHeader& ) -> uint32_t {
throw std::runtime_error("Cannot directly read timestamp_1; use get_timestamp() instead");
[](DAQHeader& self, uint32_t link_id) { self.link_id = link_id; })
.def_property(
"timestamp_1",
[](DAQHeader&) -> uint32_t {
throw std::runtime_error("Cannot directly read timestamp_1; use get_timestamp() instead");
},
[](DAQHeader& self, uint32_t timestamp_1) { self.timestamp_1 = timestamp_1; }
)
.def_property("timestamp_2",
[](DAQHeader& ) -> uint32_t {
throw std::runtime_error("Cannot directly read timestamp_2; use get_timestamp() instead");
[](DAQHeader& self, uint32_t timestamp_1) { self.timestamp_1 = timestamp_1; })
.def_property(
"timestamp_2",
[](DAQHeader&) -> uint32_t {
throw std::runtime_error("Cannot directly read timestamp_2; use get_timestamp() instead");
},
[](DAQHeader& self, uint32_t timestamp_2) { self.timestamp_2 = timestamp_2; }
)
.def("get_timestamp", &DAQHeader::get_timestamp)
;
[](DAQHeader& self, uint32_t timestamp_2) { self.timestamp_2 = timestamp_2; })
.def("get_timestamp", &DAQHeader::get_timestamp);
}

} // namespace dunedaq::detdataformats::python
} // namespace dunedaq::detdataformats::python

// NOLINTEND(build/unsigned)
Loading