DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
fdreadoutlibs
src
daphneeth
DAPHNEEthFrameProcessor.cpp
Go to the documentation of this file.
1
9
10
#include "
fddetdataformats/DAPHNEEthFrame.hpp
"
11
#include "
trgdataformats/TriggerPrimitive.hpp
"
12
#include "
fdreadoutlibs/daphneeth/DAPHNEEthFrameProcessor.hpp
"
13
14
#include "
confmodel/GeoId.hpp
"
15
16
#include <atomic>
17
#include <functional>
18
#include <memory>
19
#include <string>
20
21
using
dunedaq::datahandlinglibs::logging::TLVL_BOOKKEEPING
;
22
using
dunedaq::datahandlinglibs::logging::TLVL_FRAME_RECEIVED
;
23
24
DUNE_DAQ_TYPESTRING
(
dunedaq::trigger::TriggerPrimitiveTypeAdapter
,
"TriggerPrimitive"
)
25
DUNE_DAQ_TYPESTRING
(
std
::vector<
dunedaq
::trigger::TriggerPrimitiveTypeAdapter>,
"TriggerPrimitiveVector"
)
26
27
namespace
dunedaq
{
28
namespace
fdreadoutlibs {
29
30
void
31
DAPHNEEthFrameProcessor::conf
(
const
appmodel::DataHandlerModule
*
conf
)
32
{
33
TLOG
() <<
"Looking for TP sink..."
;
34
35
for
(
auto
output :
conf
->get_outputs()) {
36
TLOG
() <<
"On outputs... ("
<< output->UID() <<
","
<< output->get_data_type() <<
")"
;
37
try
{
38
if
(output->get_data_type() ==
"TriggerPrimitiveVector"
) {
39
TLOG
() <<
"Found TP sink."
;
40
m_tp_sink
=
get_iom_sender<std::vector<trigger::TriggerPrimitiveTypeAdapter>
>(output->UID());
41
TLOG
() <<
" SINK INITIALIZED for TriggerPrimitives with UID : "
<< output->UID();
42
}
43
}
catch
(
const
ers::Issue
& excpt) {
44
ers::error
(datahandlinglibs::ResourceQueueError(
ERS_HERE
,
"tp"
,
"DefaultRequestHandlerModel"
, excpt));
45
}
46
}
47
48
TLOG
() <<
"Registering processing tasks..."
;
49
inherited::add_preprocess_task
(std::bind(&
DAPHNEEthFrameProcessor::timestamp_check
,
this
, std::placeholders::_1));
50
51
auto
dp =
conf
->get_module_configuration()->get_data_processor();
52
if
(dp ==
nullptr
) {
53
TLOG
()<<
" PDS Data processor does not exist."
;
54
}
else
{
55
auto
proc_conf = dp->cast<
appmodel::PDSRawDataProcessor
>();
56
if
(proc_conf ==
nullptr
) {
57
TLOG
()<<
"PDS RawDataProcessor does not exist."
;
58
}
else
{
59
m_def_adc_intg_thresh
= proc_conf-> get_default_adc_intg_thresh();
60
61
auto
geo_id =
conf
->get_geo_id();
62
if
(geo_id !=
nullptr
) {
63
m_det_id
= geo_id->get_detector_id();
64
m_crate_id
= geo_id->get_crate_id();
65
m_slot_id
= geo_id->get_slot_id();
66
m_stream_id
= geo_id->get_stream_id();
67
}
68
69
m_channel_map
= dunedaq::detchannelmaps::make_pds_map(proc_conf->get_channel_map());
70
const
std::vector<unsigned int> channel_mask_vec = proc_conf->get_channel_mask();
71
72
for
(
int
chan = 0; chan < 48; chan++) {
// 40 physical PDS channel 8 not. 0->7 contain light info, 8,9, additional info. 10-17 light, 18,19 not etc...
73
trgdataformats::channel_t
off_channel =
m_channel_map
->get_offline_channel_from_det_crate_slot_stream_chan(
m_det_id
,
m_crate_id
,
m_slot_id
,
m_stream_id
, chan);
74
if
(std::find(channel_mask_vec.begin(), channel_mask_vec.end(), off_channel) != channel_mask_vec.end())
75
m_channel_mask_set
.insert(off_channel);
//m_channel_mask will be a vector fille with random chanel which need to be masked.
76
}
77
78
if
(
m_post_processing_enabled
) {
79
// Extract TPs back as a pre-processing task, due to LatencyBuffer post-proc issues using SkipList.
80
inherited::add_preprocess_task
(std::bind(&
DAPHNEEthFrameProcessor::extract_tps
,
this
, std::placeholders::_1));
81
}
82
}
83
}
84
85
TLOG
() <<
"Calling parent conf."
;
86
inherited::conf
(
conf
);
87
}
88
89
void
DAPHNEEthFrameProcessor::start
(
const
appfwk::DAQModule::CommandData_t& args)
90
{
91
// Reset timestamp check
92
m_previous_ts
= 0;
93
m_current_ts
= 0;
94
m_first_ts_missmatch
=
true
;
95
m_ts_error_ctr
= 0;
96
97
// Reset stats
98
m_t0
= std::chrono::high_resolution_clock::now();
99
m_num_new_tps
.exchange(0);
100
101
inherited::start
(args);
102
}
103
void
104
DAPHNEEthFrameProcessor::stop
(
const
appfwk::DAQModule::CommandData_t& args)
105
{
106
inherited::stop
(args);
107
}
108
111
void
112
DAPHNEEthFrameProcessor::timestamp_check
(
frameptr
fp)
113
{
114
115
/*
116
for (size_t i=0; i<types::kDAPHNENumFrames; i++){
117
auto df_ptr = reinterpret_cast<dunedaq::fddetdataformats::DAPHNEEthFrame*>(fp);
118
119
if(df_ptr[i].get_timestamp() > 0xFFFFFFFFFFFF0000 || df_ptr[i].get_timestamp() < 0xFFFF){
120
ers::warning(PDSUnphysicalFrameTimestamp(ERS_HERE, df_ptr[i].get_timestamp(), df_ptr[i].get_channel(), i));
121
// Force the TS to 0
122
df_ptr[i].daq_header.timestamp_1 = df_ptr[i].daq_header.timestamp_2 = 0;
123
}
124
}
125
*/
126
127
// Acquire timestamp
128
m_current_ts
= fp->
get_timestamp
();
129
uint64_t k_clock_frequency = 62500000;
// NOLINT(build/unsigned)
130
TLOG_DEBUG
(
TLVL_FRAME_RECEIVED
) <<
"Received DAPHNE 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
131
132
133
if
(
m_ts_error_ctr
> 1000) {
134
if
(!
m_problem_reported
) {
135
std::cout <<
"*** Data Integrity ERROR *** Timestamp continuity is completely broken! "
136
<<
"Something is wrong with the FE source or with the configuration!\n"
;
137
m_problem_reported
=
true
;
138
}
139
}
140
141
m_previous_ts
=
m_current_ts
;
142
m_last_processed_daq_ts
=
m_current_ts
;
143
}
144
148
void
149
DAPHNEEthFrameProcessor::frame_error_check
(
frameptr
/*fp*/
)
150
{
151
// check error fields
152
}
153
154
155
void
DAPHNEEthFrameProcessor::extract_tps
(
constframeptr
fp)
156
{
157
158
if
(!fp || fp==
nullptr
){
159
return
;
160
}
161
162
/*
163
auto nonconstframeptr = const_cast<frameptr>(fp);
164
auto df_ptr = reinterpret_cast<dunedaq::fddetdataformats::DAPHNEEthFrame*>((uint8_t*)nonconstframeptr); // NOLINT
165
std::vector<trigger::TriggerPrimitiveTypeAdapter> ttpp;
166
167
for (size_t i=0; i<types::kDAPHNENumFrames; i++)
168
{
169
for(size_t j=0; j<fddetdataformats::DAPHNEEthFrame::PeakDescriptorData::max_peaks;j++)
170
{
171
if(df_ptr[i].peaks_data.is_found(j))
172
{
173
int ch = m_channel_map->get_offline_channel_from_det_crate_slot_stream_chan(df_ptr[i].daq_header.det_id, df_ptr[i].daq_header.crate_id, df_ptr[i].daq_header.slot_id, df_ptr[i].daq_header.link_id, df_ptr[i].get_channel());
174
if (std::binary_search(m_channel_mask_set.begin(), m_channel_mask_set.end(), ch)) continue;
175
if (df_ptr[i].peaks_data.get_adc_integral(j) < m_def_adc_intg_thresh) continue;
176
177
178
trigger::TriggerPrimitiveTypeAdapter tpa;
179
tpa.tp = peak_to_tp(df_ptr[i],j);// this is the trigger primitive
180
//check for timestamps that are due to frame timestamps ~ ts=0, and ignore these peaks
181
if(tpa.tp.time_start > 0xFFFFFFFFFFFF0000 || tpa.tp.time_start < 0xFFFF){
182
ers::warning(PDSPeakIgnored(ERS_HERE, tpa.tp.time_start, tpa.tp.channel, i, j));
183
continue;
184
}
185
186
tpa.tp.detid = df_ptr->daq_header.det_id;
187
ttpp.push_back(tpa);
188
}
189
}
190
}
191
192
int num_new_tps = ttpp.size();
193
if (num_new_tps > 0) {
194
195
const auto s_ts_begin = ttpp.front().tp.time_start;
196
const auto channel_begin = ttpp.front().tp.channel;
197
const auto s_ts_end = ttpp.back().tp.time_start;
198
const auto channel_end = ttpp.back().tp.channel;
199
200
if (!m_tp_sink->try_send(std::move(ttpp), iomanager::Sender::s_no_block)) {
201
ers::warning(FailedToSendTPVector(ERS_HERE, s_ts_begin, channel_begin, s_ts_end, channel_end));
202
m_tps_send_failed += num_new_tps;
203
} else {
204
m_num_new_tps += num_new_tps;
205
}
206
}
207
*/
208
return
;
209
}
210
211
void
212
DAPHNEEthFrameProcessor::generate_opmon_data
() {
213
214
//right now, just fill some basic tp info...
215
if
(
m_post_processing_enabled
) {
216
auto
now
= std::chrono::high_resolution_clock::now();
217
int
num_new_tps =
m_num_new_tps
.exchange(0);
218
int
num_new_tps_suppressed_too_long = 0;
// not relevant for PDS TPs
219
int
num_new_tps_send_failed =
m_tps_send_failed
.exchange(0);
220
double
seconds = std::chrono::duration_cast<std::chrono::microseconds>(
now
-
m_t0
).count() / 1000000.;
221
TLOG_DEBUG
(
TLVL_BOOKKEEPING
) <<
"TP rate: "
<< std::to_string(num_new_tps / seconds / 1000.) <<
" [kHz]"
;
222
TLOG_DEBUG
(
TLVL_BOOKKEEPING
) <<
"Total new TPs: "
<< num_new_tps;
223
224
datahandlinglibs::opmon::HitFindingInfo
tp_info;
225
tp_info.
set_rate_tp_hits
(num_new_tps / seconds / 1000.);
226
227
tp_info.
set_num_tps_sent
(num_new_tps);
228
tp_info.
set_num_tps_suppressed_too_long
(num_new_tps_suppressed_too_long);
229
tp_info.
set_num_tps_send_failed
(num_new_tps_send_failed);
230
231
publish
(std::move(tp_info));
232
233
m_t0
=
now
;
234
235
}
236
237
inherited::generate_opmon_data
();
238
239
}
240
241
}
// namespace fdreadoutlibs
242
}
// namespace dunedaq
DAPHNEEthFrameProcessor.hpp
DAPHNEEthFrame.hpp
TLVL_FRAME_RECEIVED
@ TLVL_FRAME_RECEIVED
Definition
ReadoutLogging.hpp:28
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
DUNE_DAQ_TYPESTRING
#define DUNE_DAQ_TYPESTRING(Type, typestring)
Declare the datatype_to_string method for the given type.
Definition
Serialization.hpp:36
dunedaq::appmodel::DataHandlerModule
Definition
DataHandlerModule.hpp:36
dunedaq::appmodel::PDSRawDataProcessor
Definition
PDSRawDataProcessor.hpp:27
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::start
void start(const appfwk::DAQModule::CommandData_t &) override
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::add_preprocess_task
void add_preprocess_task(Task &&task)
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::conf
void conf(const appmodel::DataHandlerModule *conf) override
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::m_post_processing_enabled
bool m_post_processing_enabled
Definition
TaskRawDataProcessorModel.hpp:111
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::stop
void stop(const appfwk::DAQModule::CommandData_t &) override
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::generate_opmon_data
virtual void generate_opmon_data() override
dunedaq::datahandlinglibs::TaskRawDataProcessorModel< types::DAPHNEEthTypeAdapter >::m_last_processed_daq_ts
std::atomic< uint64_t > m_last_processed_daq_ts
Definition
TaskRawDataProcessorModel.hpp:126
dunedaq::datahandlinglibs::opmon::HitFindingInfo
Definition
datahandling_info.pb.h:1594
dunedaq::datahandlinglibs::opmon::HitFindingInfo::set_num_tps_send_failed
void set_num_tps_send_failed(::uint64_t value)
Definition
datahandling_info.pb.h:3306
dunedaq::datahandlinglibs::opmon::HitFindingInfo::set_num_tps_suppressed_too_long
void set_num_tps_suppressed_too_long(::uint64_t value)
Definition
datahandling_info.pb.h:3328
dunedaq::datahandlinglibs::opmon::HitFindingInfo::set_num_tps_sent
void set_num_tps_sent(::uint64_t value)
Definition
datahandling_info.pb.h:3284
dunedaq::datahandlinglibs::opmon::HitFindingInfo::set_rate_tp_hits
void set_rate_tp_hits(float value)
Definition
datahandling_info.pb.h:3262
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::generate_opmon_data
virtual void generate_opmon_data() override
Definition
DAPHNEEthFrameProcessor.cpp:212
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_current_ts
timestamp_t m_current_ts
Definition
DAPHNEEthFrameProcessor.hpp:84
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_ts_error_ctr
std::atomic< int > m_ts_error_ctr
Definition
DAPHNEEthFrameProcessor.hpp:88
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::timestamp_check
void timestamp_check(frameptr)
Definition
DAPHNEEthFrameProcessor.cpp:112
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_problem_reported
bool m_problem_reported
Definition
DAPHNEEthFrameProcessor.hpp:87
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::constframeptr
const types::DAPHNEEthTypeAdapter * constframeptr
Definition
DAPHNEEthFrameProcessor.hpp:56
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_tps_send_failed
std::atomic< uint64_t > m_tps_send_failed
Definition
DAPHNEEthFrameProcessor.hpp:112
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_num_new_tps
std::atomic< uint64_t > m_num_new_tps
Definition
DAPHNEEthFrameProcessor.hpp:110
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_t0
std::chrono::time_point< std::chrono::high_resolution_clock > m_t0
Definition
DAPHNEEthFrameProcessor.hpp:115
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::frame_error_check
void frame_error_check(frameptr)
Definition
DAPHNEEthFrameProcessor.cpp:149
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_channel_map
std::shared_ptr< detchannelmaps::PDSChannelMap > m_channel_map
Definition
DAPHNEEthFrameProcessor.hpp:95
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_tp_sink
std::shared_ptr< iomanager::SenderConcept< std::vector< trigger::TriggerPrimitiveTypeAdapter > > > m_tp_sink
Definition
DAPHNEEthFrameProcessor.hpp:108
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_def_adc_intg_thresh
uint32_t m_def_adc_intg_thresh
Definition
DAPHNEEthFrameProcessor.hpp:104
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::frameptr
types::DAPHNEEthTypeAdapter * frameptr
Definition
DAPHNEEthFrameProcessor.hpp:53
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_channel_mask_set
std::set< unsigned int > m_channel_mask_set
Definition
DAPHNEEthFrameProcessor.hpp:103
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_crate_id
uint32_t m_crate_id
Definition
DAPHNEEthFrameProcessor.hpp:99
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::extract_tps
void extract_tps(constframeptr fp)
Definition
DAPHNEEthFrameProcessor.cpp:155
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::stop
void stop(const appfwk::DAQModule::CommandData_t &args) override
Stop operation.
Definition
DAPHNEEthFrameProcessor.cpp:104
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_stream_id
uint32_t m_stream_id
Definition
DAPHNEEthFrameProcessor.hpp:101
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_slot_id
uint32_t m_slot_id
Definition
DAPHNEEthFrameProcessor.hpp:100
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_previous_ts
timestamp_t m_previous_ts
Definition
DAPHNEEthFrameProcessor.hpp:83
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_det_id
uint32_t m_det_id
Definition
DAPHNEEthFrameProcessor.hpp:98
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::m_first_ts_missmatch
bool m_first_ts_missmatch
Definition
DAPHNEEthFrameProcessor.hpp:86
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::start
void start(const appfwk::DAQModule::CommandData_t &args) override
Start operation.
Definition
DAPHNEEthFrameProcessor.cpp:89
dunedaq::fdreadoutlibs::DAPHNEEthFrameProcessor::conf
void conf(const appmodel::DataHandlerModule *conf) override
Set the emulator mode, if active, timestamps of processed packets are overwritten with new ones.
Definition
DAPHNEEthFrameProcessor.cpp:31
dunedaq::opmonlib::MonitorableObject::publish
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
Definition
MonitorableObject.cpp:58
ers::Issue
Base class for any user define issue.
Definition
Issue.hpp:80
GeoId.hpp
now
static int64_t now()
Definition
kafka_opmon_consumer.cxx:44
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
TLOG
#define TLOG(...)
Definition
macro.hpp:22
dunedaq::datahandlinglibs::logging::TLVL_BOOKKEEPING
@ TLVL_BOOKKEEPING
Definition
ReadoutLogging.hpp:26
dunedaq::datahandlinglibs::logging::TLVL_FRAME_RECEIVED
@ TLVL_FRAME_RECEIVED
Definition
ReadoutLogging.hpp:28
dunedaq::fdreadoutlibs::TLVL_BOOKKEEPING
@ TLVL_BOOKKEEPING
Definition
ReadoutLogging.hpp:26
dunedaq::trgdataformats::channel_t
uint32_t channel_t
Definition
Types.hpp:52
dunedaq
Including Qt Headers.
Definition
module.cpp:16
dunedaq::get_iom_sender
static std::shared_ptr< iomanager::SenderConcept< Datatype > > get_iom_sender(iomanager::ConnectionId const &id)
Definition
IOManager.hxx:171
ers::error
void error(const Issue &issue)
Definition
ers.hpp:92
std
Definition
SchemaUtils.hpp:118
dunedaq::fdreadoutlibs::types::DAPHNEEthTypeAdapter::get_timestamp
uint64_t get_timestamp() const
Definition
DAPHNEEthTypeAdapter.hpp:38
dunedaq::trigger::TriggerPrimitiveTypeAdapter
Definition
TriggerPrimitiveTypeAdapter.hpp:21
TriggerPrimitive.hpp
Generated on
for DUNE-DAQ by
1.17.0