-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from DUNE-DAQ/thea/tde_v5
Adding support for TDEEthFrame readout
- Loading branch information
Showing
3 changed files
with
465 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#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::kTDEEth; | ||
// 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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* @file TDEEthFrameProcessor.hpp WIBEth specific Task based raw processor | ||
* | ||
* This is part of the DUNE DAQ , copyright 2022. | ||
* Licensing/copyright details are in the COPYING file that you should have | ||
* received with this code. | ||
*/ | ||
#ifndef FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_TDEETH_TDEETHFRAMEPROCESSOR_HPP_ | ||
#define FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_TDEETH_TDEETHFRAMEPROCESSOR_HPP_ | ||
|
||
// #include "appfwk/DAQModuleHelper.hpp" | ||
#include "iomanager/IOManager.hpp" | ||
#include "iomanager/Sender.hpp" | ||
#include "logging/Logging.hpp" | ||
|
||
#include "datahandlinglibs/models/TaskRawDataProcessorModel.hpp" | ||
|
||
#include "fdreadoutlibs/FDReadoutIssues.hpp" | ||
#include "fdreadoutlibs/TDEEthTypeAdapter.hpp" | ||
#include "trigger/TriggerPrimitiveTypeAdapter.hpp" | ||
|
||
#include "daqdataformats/Types.hpp" | ||
|
||
#include <atomic> | ||
#include <bitset> | ||
#include <functional> | ||
#include <future> | ||
#include <memory> | ||
#include <pthread.h> | ||
#include <queue> | ||
#include <string> | ||
#include <thread> | ||
#include <utility> | ||
#include <vector> | ||
#include <random> | ||
|
||
|
||
namespace dunedaq { | ||
namespace fdreadoutlibs { | ||
|
||
class TDEEthFrameProcessor : public datahandlinglibs::TaskRawDataProcessorModel<types::TDEEthTypeAdapter> | ||
{ | ||
|
||
public: | ||
using inherited = datahandlinglibs::TaskRawDataProcessorModel<types::TDEEthTypeAdapter>; | ||
using frameptr = types::TDEEthTypeAdapter*; | ||
using constframeptr = const types::TDEEthTypeAdapter*; | ||
using tdeframeptr = dunedaq::fddetdataformats::TDEEthFrame*; | ||
|
||
explicit TDEEthFrameProcessor(std::unique_ptr<datahandlinglibs::FrameErrorRegistry>& error_registry); | ||
|
||
~TDEEthFrameProcessor(); | ||
|
||
void start(const nlohmann::json& args) override; | ||
|
||
void stop(const nlohmann::json& args) override; | ||
|
||
// void init(const nlohmann::json& args) override; | ||
|
||
void conf(const appmodel::DataHandlerModule* conf) override; | ||
|
||
void get_info(opmonlib::InfoCollector& ci, int level) override; | ||
|
||
protected: | ||
// Internals | ||
dunedaq::daqdataformats::timestamp_t m_previous_ts = 0; | ||
dunedaq::daqdataformats::timestamp_t m_current_ts = 0; | ||
|
||
uint16_t m_previous_seq_id = 0; | ||
uint16_t m_current_seq_id = 0; | ||
|
||
dunedaq::daqdataformats::timestamp_t m_pattern_generator_previous_ts = 0; | ||
dunedaq::daqdataformats::timestamp_t m_pattern_generator_current_ts = 0; | ||
|
||
bool m_first_ts_missmatch = true; | ||
bool m_ts_problem_reported = false; | ||
std::atomic<uint64_t> m_ts_error_ctr{ 0 }; | ||
|
||
bool m_first_seq_id_mismatch = true; | ||
bool m_seq_id_problem_reported = false; | ||
std::atomic<uint64_t> m_seq_id_error_ctr{ 0 }; | ||
std::atomic<int16_t> m_seq_id_min_jump{ 0 }; | ||
std::atomic<int16_t> m_seq_id_max_jump{ 0 }; | ||
|
||
/** | ||
* Pipeline Stage 0: Pattern generator for hit finding in emulated mode | ||
* */ | ||
void use_pattern_generator(frameptr fp); | ||
|
||
/** | ||
* Pipeline Stage 1.: Check proper sequence id increments in DAQ Eth header | ||
* */ | ||
|
||
void sequence_check(frameptr fp); | ||
|
||
/** | ||
* Pipeline Stage 1.: Check proper timestamp increments in DAQ Eth header | ||
* */ | ||
|
||
void timestamp_check(frameptr fp); | ||
|
||
private: | ||
uint32_t m_det_id; // NOLINT(build/unsigned) | ||
uint32_t m_crate_id; // NOLINT(build/unsigned) | ||
uint32_t m_slot_id; // NOLINT(build/unsigned) | ||
uint32_t m_stream_id; // NOLINT(build/unsigned) | ||
bool m_emulator_mode = false; | ||
|
||
std::shared_ptr<iomanager::SenderConcept<trigger::TriggerPrimitiveTypeAdapter>> m_tp_sink; | ||
|
||
}; | ||
|
||
} // namespace fdreadoutlibs | ||
} // namespace dunedaq | ||
|
||
#endif // FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_TDEETH_TDEETHFRAMEPROCESSOR_HPP_ |
Oops, something went wrong.