Skip to content

Commit 83486ae

Browse files
authored
Merge pull request #289 from DUNE-DAQ/johnfreeman/prep_release_merged
Johnfreeman/prep release merged
2 parents 0523f7f + 490a764 commit 83486ae

File tree

6 files changed

+279
-2
lines changed

6 files changed

+279
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.12)
2-
project(fdreadoutlibs VERSION 2.6.3)
2+
project(fdreadoutlibs VERSION 2.7.0)
33

44
find_package(daq-cmake REQUIRED)
55

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#ifndef FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
2+
#define FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
3+
4+
#include "daqdataformats/FragmentHeader.hpp"
5+
#include "daqdataformats/SourceID.hpp"
6+
#include "fddetdataformats/DAPHNEEthStreamFrame.hpp"
7+
8+
9+
10+
namespace dunedaq::fdreadoutlibs::types {
11+
12+
/**
13+
*/
14+
const constexpr std::size_t kDAPHNEEthStreamNumFrames = 1;
15+
const constexpr std::size_t kDAPHNEEthStreamSize = kDAPHNEEthStreamNumFrames * sizeof(dunedaq::fddetdataformats::DAPHNEEthStreamFrame);
16+
17+
struct DAPHNEEthStreamTypeAdapter {
18+
19+
using FrameType = dunedaq::fddetdataformats::DAPHNEEthStreamFrame;
20+
21+
char data[kDAPHNEEthStreamSize];
22+
23+
// comparable based on first timestamp
24+
bool operator<(const DAPHNEEthStreamTypeAdapter& other) const
25+
{
26+
auto thisptr = reinterpret_cast<const FrameType*>(&data); // NOLINT
27+
auto otherptr = reinterpret_cast<const FrameType*>(&other.data); // NOLINT
28+
return thisptr->get_timestamp() < otherptr->get_timestamp() ? true : false;
29+
}
30+
31+
uint64_t get_timestamp() const // NOLINT(build/unsigned)
32+
{
33+
return reinterpret_cast<const FrameType*>(&data)->daq_header.get_timestamp(); // NOLINT
34+
}
35+
36+
void set_timestamp(uint64_t ts) // NOLINT(build/unsigned)
37+
{
38+
auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
39+
frame->set_timestamp(ts);
40+
}
41+
42+
void fake_timestamps(uint64_t first_timestamp, uint64_t offset = 280) // NOLINT(build/unsigned)
43+
{
44+
uint64_t ts_next = first_timestamp; // NOLINT(build/unsigned)
45+
for (unsigned int i = 0; i < get_num_frames(); ++i) {
46+
auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
47+
df->daq_header.timestamp = ts_next;
48+
ts_next += offset;
49+
}
50+
}
51+
52+
void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id) {
53+
for (unsigned int i = 0; i < get_num_frames(); ++i) {
54+
auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
55+
df->daq_header.crate_id = crate_id;
56+
df->daq_header.slot_id = slot_id;
57+
df->daq_header.stream_id = stream_id;
58+
}
59+
}
60+
61+
void fake_adc_pattern(int channel) {
62+
// Set the ADC for the first sample to the 14-bit max value
63+
auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
64+
frame->set_adc(channel, 0, 0x3FFF);
65+
}
66+
67+
68+
void fake_frame_errors(std::vector<uint16_t>* /*fake_errors*/) // NOLINT
69+
{
70+
// Set frame error bits in header
71+
}
72+
73+
FrameType* begin()
74+
{
75+
return reinterpret_cast<FrameType*>(&data[0]); // NOLINT
76+
}
77+
78+
FrameType* end()
79+
{
80+
return reinterpret_cast<FrameType*>(data + kDAPHNEEthStreamSize); // NOLINT
81+
}
82+
83+
constexpr size_t get_payload_size() const { return kDAPHNEEthStreamSize; }
84+
85+
constexpr size_t get_num_frames() const { return kDAPHNEEthStreamNumFrames; }
86+
87+
constexpr size_t get_frame_size() const { return sizeof(dunedaq::fddetdataformats::DAPHNEEthStreamFrame); }
88+
89+
static const constexpr daqdataformats::SourceID::Subsystem subsystem = daqdataformats::SourceID::Subsystem::kDetectorReadout;
90+
static const constexpr daqdataformats::FragmentType fragment_type = daqdataformats::FragmentType::kDAPHNEEthStream;
91+
static const constexpr uint64_t expected_tick_difference = 280; // NOLINT(build/unsigned)
92+
};
93+
94+
static_assert(sizeof(struct DAPHNEEthStreamTypeAdapter) == kDAPHNEEthStreamSize,
95+
"Check your assumptions on DAPHNEEthStreamTypeAdapter");
96+
97+
98+
} // namespace dunedaq::fdreadoutlibs::types
99+
100+
101+
#endif // FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file DAPHNEEthStreamFrameProcessor.hpp DAPHNE specific Task based raw processor
3+
* for DAPHNE Eth Streaming mode
4+
*
5+
* This is part of the DUNE DAQ , copyright 2020.
6+
* Licensing/copyright details are in the COPYING file that you should have
7+
* received with this code.
8+
*/
9+
#ifndef FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETH_DAPHNEETHSTREAMFRAMEPROCESSOR_HPP_
10+
#define FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETH_DAPHNEETHSTREAMFRAMEPROCESSOR_HPP_
11+
12+
#include "logging/Logging.hpp"
13+
14+
#include "datahandlinglibs/FrameErrorRegistry.hpp"
15+
#include "datahandlinglibs/DataHandlingIssues.hpp"
16+
#include "datahandlinglibs/ReadoutLogging.hpp"
17+
#include "datahandlinglibs/models/TaskRawDataProcessorModel.hpp"
18+
19+
#include "fddetdataformats/DAPHNEEthStreamFrame.hpp"
20+
#include "fdreadoutlibs/DAPHNEEthStreamTypeAdapter.hpp"
21+
22+
#include <atomic>
23+
#include <functional>
24+
#include <memory>
25+
#include <string>
26+
27+
using dunedaq::datahandlinglibs::logging::TLVL_BOOKKEEPING;
28+
29+
namespace dunedaq {
30+
namespace fdreadoutlibs {
31+
32+
class DAPHNEEthStreamFrameProcessor : public datahandlinglibs::TaskRawDataProcessorModel<types::DAPHNEEthStreamTypeAdapter>
33+
{
34+
35+
public:
36+
using inherited = datahandlinglibs::TaskRawDataProcessorModel<types::DAPHNEEthStreamTypeAdapter>;
37+
using frameptr = types::DAPHNEEthStreamTypeAdapter*;
38+
using daphneframeptr = dunedaq::fddetdataformats::DAPHNEEthStreamFrame*;
39+
using timestamp_t = std::uint64_t; // NOLINT(build/unsigned)
40+
41+
explicit DAPHNEEthStreamFrameProcessor(std::unique_ptr<datahandlinglibs::FrameErrorRegistry>& error_registry, bool post_processing_enabled)
42+
: datahandlinglibs::TaskRawDataProcessorModel<types::DAPHNEEthStreamTypeAdapter>(error_registry, post_processing_enabled)
43+
{}
44+
45+
// Override config for pipeline setup
46+
void conf(const appmodel::DataHandlerModule* conf) override;
47+
48+
protected:
49+
/**
50+
* Pipeline Stage 1.: Check proper timestamp increments in DAPHNE frame
51+
* */
52+
void timestamp_check(frameptr /*fp*/);
53+
54+
/**
55+
* Pipeline Stage 2.: Check DAPHNE headers for error flags
56+
* */
57+
void frame_error_check(frameptr /*fp*/);
58+
59+
// Internals
60+
timestamp_t m_previous_ts = 0;
61+
timestamp_t m_current_ts = 0;
62+
bool m_first_ts_fake = true;
63+
bool m_first_ts_missmatch = true;
64+
bool m_problem_reported = false;
65+
std::atomic<int> m_ts_error_ctr{ 0 };
66+
67+
};
68+
69+
} // namespace fdreadoutlibs
70+
} // namespace dunedaq
71+
72+
#endif // FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETH_DAPHNEETHSTREAMFRAMEPROCESSOR_HPP_
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @file DAPHNEEthStreamFrameProcessor.hpp DAPHNE specific Task based raw processor
3+
* implementation for streaming mode
4+
*
5+
* This is part of the DUNE DAQ , copyright 2020.
6+
* Licensing/copyright details are in the COPYING file that you should have
7+
* received with this code.
8+
*/
9+
#include "fddetdataformats/DAPHNEEthStreamFrame.hpp"
10+
#include "fdreadoutlibs/daphneeth/DAPHNEEthStreamFrameProcessor.hpp"
11+
12+
#include <atomic>
13+
#include <functional>
14+
#include <memory>
15+
#include <string>
16+
17+
using dunedaq::datahandlinglibs::logging::TLVL_BOOKKEEPING;
18+
using dunedaq::datahandlinglibs::logging::TLVL_FRAME_RECEIVED;
19+
20+
namespace dunedaq {
21+
namespace fdreadoutlibs {
22+
23+
void
24+
DAPHNEEthStreamFrameProcessor::conf(const appmodel::DataHandlerModule* conf)
25+
{
26+
datahandlinglibs::TaskRawDataProcessorModel<types::DAPHNEEthStreamTypeAdapter>::add_preprocess_task(
27+
std::bind(&DAPHNEEthStreamFrameProcessor::timestamp_check, this, std::placeholders::_1));
28+
// m_tasklist.push_back( std::bind(&DAPHNEStreamFrameProcessor::frame_error_check, this, std::placeholders::_1) );
29+
TaskRawDataProcessorModel<types::DAPHNEEthStreamTypeAdapter>::conf(conf);
30+
}
31+
32+
/**
33+
* Pipeline Stage 1.: Check proper timestamp increments in DAPHNE frame
34+
* */
35+
void
36+
DAPHNEEthStreamFrameProcessor::timestamp_check(frameptr fp)
37+
{
38+
/* Let Source Emulator deal with this
39+
// If EMU data, emulate perfectly incrementing timestamp
40+
if (inherited::m_emulator_mode) { // emulate perfectly incrementing timestamp
41+
uint64_t ts_next = m_previous_ts + 64; // NOLINT(build/unsigned)
42+
auto df = reinterpret_cast<daphneframeptr>(((uint8_t*)fp)); // NOLINT
43+
for (unsigned int i = 0; i < fp->get_num_frames(); ++i) { // NOLINT(build/unsigned)
44+
//auto wfh = const_cast<dunedaq::fddetdataformats::WIB2Header*>(wf->get_wib_header());
45+
df->set_timestamp(ts_next);
46+
ts_next += 64;
47+
df++;
48+
}
49+
}
50+
*/
51+
// Acquire timestamp
52+
m_current_ts = fp->get_timestamp();
53+
uint64_t k_clock_frequency = 62500000; // NOLINT(build/unsigned)
54+
uint16_t tick_difference = types::DAPHNEEthStreamTypeAdapter::expected_tick_difference;
55+
uint16_t frame_tick_difference = tick_difference * fp->get_num_frames();
56+
TLOG_DEBUG(TLVL_FRAME_RECEIVED) << "Received DAPHNEEthStream frame timestamp value of " << m_current_ts << " ticks (..." << std::fixed << std::setprecision(8) << (static_cast<double>(m_current_ts % (k_clock_frequency*1000)) / static_cast<double>(k_clock_frequency)) << " sec)"; // NOLINT
57+
58+
// Check timestamp
59+
// RS warning : not fixed rate!
60+
if (m_current_ts - m_previous_ts != frame_tick_difference) {
61+
++m_ts_error_ctr;
62+
}
63+
64+
if (m_ts_error_ctr > 1000) {
65+
if (!m_problem_reported) {
66+
TLOG() << "*** Data Integrity ERROR *** Timestamp continuity is completely broken! "
67+
<< "Something is wrong with the FE source or with the configuration!";
68+
m_problem_reported = true;
69+
}
70+
}
71+
72+
m_previous_ts = m_current_ts;
73+
m_last_processed_daq_ts = m_current_ts;
74+
}
75+
76+
/**
77+
* Pipeline Stage 2.: Check DAPHNE headers for error flags
78+
* */
79+
void
80+
DAPHNEEthStreamFrameProcessor::frame_error_check(frameptr /*fp*/)
81+
{
82+
// check error fields
83+
}
84+
85+
} // namespace fdreadoutlibs
86+
} // namespace dunedaq

unittest/FDReadoutRequestHandlers_test.cxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define BOOST_TEST_MODULE FDReadoutRequestHandlers_test // NOLINT
1010

1111
#include "fdreadoutlibs/DAPHNEStreamSuperChunkTypeAdapter.hpp"
12+
#include "fdreadoutlibs/DAPHNEEthStreamTypeAdapter.hpp"
1213
#include "fdreadoutlibs/DAPHNESuperChunkTypeAdapter.hpp"
1314
#include "fdreadoutlibs/DAPHNEEthTypeAdapter.hpp"
1415
#include "fdreadoutlibs/DUNEWIBEthTypeAdapter.hpp"
@@ -56,7 +57,19 @@ BOOST_AUTO_TEST_CASE(BinarySearchQueueModel_DAPHNEStreamSuperChunk)
5657
dunedaq::datahandlinglibs::BinarySearchQueueModel,
5758
dunedaq::fdreadoutlibs::types::DAPHNEStreamSuperChunkTypeAdapter>();
5859
}
60+
BOOST_AUTO_TEST_CASE(FixedRateQueueModel_DAPHNEEthStream)
61+
{
62+
dunedaq::datahandlinglibs::test::test_request_model<
63+
dunedaq::datahandlinglibs::FixedRateQueueModel,
64+
dunedaq::fdreadoutlibs::types::DAPHNEEthStreamTypeAdapter>();
65+
}
5966

67+
BOOST_AUTO_TEST_CASE(BinarySearchQueueModel_DAPHNEEthStream)
68+
{
69+
dunedaq::datahandlinglibs::test::test_request_model<
70+
dunedaq::datahandlinglibs::BinarySearchQueueModel,
71+
dunedaq::fdreadoutlibs::types::DAPHNEEthStreamTypeAdapter>();
72+
}
6073
BOOST_AUTO_TEST_CASE(SkipListLatencyBufferModel_DAPHNESuperChunk)
6174
{
6275
dunedaq::datahandlinglibs::test::test_request_model<dunedaq::datahandlinglibs::SkipListLatencyBufferModel,

unittest/FDTypeAdaptersBuffers_test.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define BOOST_TEST_MODULE FDTypeAdaptersBuffers_test // NOLINT
1010

1111
#include "fdreadoutlibs/DAPHNEStreamSuperChunkTypeAdapter.hpp"
12+
#include "fdreadoutlibs/DAPHNEEthStreamTypeAdapter.hpp"
1213
#include "fdreadoutlibs/DAPHNEEthTypeAdapter.hpp"
1314
#include "fdreadoutlibs/DAPHNESuperChunkTypeAdapter.hpp"
1415
#include "fdreadoutlibs/DUNEWIBEthTypeAdapter.hpp"
@@ -56,7 +57,11 @@ BOOST_AUTO_TEST_CASE(SkipListLatencyBufferModel_DAPHNEEth)
5657
dunedaq::datahandlinglibs::test::test_queue_model<dunedaq::datahandlinglibs::SkipListLatencyBufferModel,
5758
dunedaq::fdreadoutlibs::types::DAPHNEEthTypeAdapter>();
5859
}
59-
BOOST_AUTO_TEST_CASE(FixedRateQueueModel_TDEEth)
60+
BOOST_AUTO_TEST_CASE(FixedRateQueueModel_DAPHNEEthStream)
61+
{
62+
dunedaq::datahandlinglibs::test::test_queue_model<dunedaq::datahandlinglibs::FixedRateQueueModel,
63+
dunedaq::fdreadoutlibs::types::DAPHNEEthStreamTypeAdapter>();
64+
}BOOST_AUTO_TEST_CASE(FixedRateQueueModel_TDEEth)
6065
{
6166
dunedaq::datahandlinglibs::test::test_queue_model<dunedaq::datahandlinglibs::FixedRateQueueModel,
6267
dunedaq::fdreadoutlibs::types::TDEEthTypeAdapter>();

0 commit comments

Comments
 (0)