DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
datahandlinglibs
include
datahandlinglibs
models
detail
TaskRawDataProcessorModel.hxx
Go to the documentation of this file.
1
// Declarations for TaskRawDataProcessorModel
2
3
namespace
dunedaq
{
4
namespace
datahandlinglibs
{
5
6
template
<
class
ReadoutType>
7
void
8
TaskRawDataProcessorModel<ReadoutType>::conf
(
const
appmodel::DataHandlerModule
*
conf
)
9
{
10
auto
cfg =
conf
->get_module_configuration()->get_data_processor();
11
m_postprocess_queue_sizes
= cfg->get_queue_sizes();
12
m_sourceid
.id =
conf
->get_source_id();
13
m_sourceid
.subsystem = ReadoutType::subsystem;
14
15
for
(
size_t
i = 0; i <
m_post_process_functions
.size(); ++i) {
16
m_items_to_postprocess_queues
.push_back(
17
std::make_unique<folly::ProducerConsumerQueue<const ReadoutType*>>(
m_postprocess_queue_sizes
));
18
m_post_process_threads
[i]->set_name(cfg->get_thread_names_prefix() + std::to_string(i),
m_sourceid
.id);
19
}
20
}
21
22
template
<
class
ReadoutType>
23
void
24
TaskRawDataProcessorModel<ReadoutType>::scrap
(
const
appfwk::DAQModule::CommandData_t&
/*cfg*/
)
25
{
26
m_items_to_postprocess_queues
.clear();
27
m_post_process_threads
.clear();
28
m_post_process_functions
.clear();
29
m_preprocess_functions
.clear();
30
}
31
32
template
<
class
ReadoutType>
33
void
34
TaskRawDataProcessorModel<ReadoutType>::start
(
const
appfwk::DAQModule::CommandData_t&
/*args*/
)
35
{
36
// m_last_processed_daq_ts =
37
// std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
38
m_run_marker
.store(
true
);
39
for
(
size_t
i = 0; i <
m_post_process_threads
.size(); ++i) {
40
m_post_process_threads
[i]->set_work(&
TaskRawDataProcessorModel<ReadoutType>::run_post_processing_thread
,
41
this
,
42
std::ref(
m_post_process_functions
[i]),
43
std::ref(*
m_items_to_postprocess_queues
[i]));
44
}
45
}
46
47
template
<
class
ReadoutType>
48
void
49
TaskRawDataProcessorModel<ReadoutType>::stop
(
const
appfwk::DAQModule::CommandData_t&
/*args*/
)
50
{
51
m_run_marker
.store(
false
);
52
for
(
auto
&
thread
:
m_post_process_threads
) {
53
while
(!
thread
->get_readiness()) {
54
std::this_thread::sleep_for(std::chrono::milliseconds(50));
55
}
56
}
57
}
58
59
template
<
class
ReadoutType>
60
void
61
TaskRawDataProcessorModel<ReadoutType>::postprocess_item
(
const
ReadoutType* item)
62
{
63
for
(
size_t
i = 0; i <
m_items_to_postprocess_queues
.size(); ++i) {
64
if
(!
m_items_to_postprocess_queues
[i]->write(item)) {
65
ers::warning
(PostprocessingNotKeepingUp(
ERS_HERE
,
m_sourceid
, i));
66
}
67
}
68
}
69
70
template
<
class
ReadoutType>
71
template
<
typename
Task>
72
void
73
TaskRawDataProcessorModel<ReadoutType>::add_preprocess_task
(Task&& task)
74
{
75
m_preprocess_functions
.push_back(std::forward<Task>(task));
76
}
77
78
template
<
class
ReadoutType>
79
template
<
typename
Task>
80
void
81
TaskRawDataProcessorModel<ReadoutType>::add_postprocess_task
(Task&& task)
82
{
83
m_post_process_threads
.emplace_back(std::make_unique<utilities::ReusableThread>(0));
84
m_post_process_functions
.push_back(std::forward<Task>(task));
85
}
86
87
template
<
class
ReadoutType>
88
void
89
TaskRawDataProcessorModel<ReadoutType>::invoke_all_preprocess_functions
(ReadoutType* item)
90
{
91
for
(
auto
&& task :
m_preprocess_functions
) {
92
task(item);
93
}
94
}
95
96
template
<
class
ReadoutType>
97
void
98
TaskRawDataProcessorModel<ReadoutType>::launch_all_preprocess_functions
(ReadoutType* item)
99
{
100
for
(
auto
&& task :
m_preprocess_functions
) {
101
auto
fut = std::async(std::launch::async, task, item);
102
}
103
}
104
105
template
<
class
ReadoutType>
106
void
107
TaskRawDataProcessorModel<ReadoutType>::run_post_processing_thread
(
108
std::function<
void
(
const
ReadoutType*)>& function,
109
folly::ProducerConsumerQueue<const ReadoutType*>& queue)
110
{
111
while
(
m_run_marker
.load() || queue.sizeGuess() > 0) {
112
const
ReadoutType* element;
113
if
(queue.read(element)) {
114
function(element);
115
}
else
{
116
std::this_thread::sleep_for(std::chrono::microseconds(50));
117
}
118
}
119
}
120
121
template
<
class
ReadoutType>
122
void
123
TaskRawDataProcessorModel<ReadoutType>::generate_opmon_data
()
124
{
125
for
(
size_t
i = 0; i <
m_items_to_postprocess_queues
.size(); ++i) {
126
opmon::DataProcessorInfo
info;
127
info.set_elements_queued(
m_items_to_postprocess_queues
[i]->sizeGuess());
128
this->
publish
(std::move(info), {{
"post_processor_id"
, std::to_string(i)}});
129
}
130
}
131
132
}
// namespace datahandlinglibs
133
}
// namespace dunedaq
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
dunedaq::appmodel::DataHandlerModule
Definition
DataHandlerModule.hpp:36
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::start
void start(const appfwk::DAQModule::CommandData_t &) override
Start operation.
Definition
TaskRawDataProcessorModel.hxx:34
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::postprocess_item
void postprocess_item(const ReadoutType *item) override
Postprocess one element.
Definition
TaskRawDataProcessorModel.hxx:61
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::add_preprocess_task
void add_preprocess_task(Task &&task)
Definition
TaskRawDataProcessorModel.hxx:73
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_postprocess_queue_sizes
size_t m_postprocess_queue_sizes
Definition
TaskRawDataProcessorModel.hpp:122
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::add_postprocess_task
void add_postprocess_task(Task &&task)
Definition
TaskRawDataProcessorModel.hxx:81
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_sourceid
daqdataformats::SourceID m_sourceid
Definition
TaskRawDataProcessorModel.hpp:124
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::conf
void conf(const appmodel::DataHandlerModule *conf) override
Set the emulator mode, if active, timestamps of processed packets are overwritten with new ones.
Definition
TaskRawDataProcessorModel.hxx:8
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_preprocess_functions
std::vector< std::function< void(ReadoutType *)> > m_preprocess_functions
Definition
TaskRawDataProcessorModel.hpp:105
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::stop
void stop(const appfwk::DAQModule::CommandData_t &) override
Stop operation.
Definition
TaskRawDataProcessorModel.hxx:49
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::launch_all_preprocess_functions
void launch_all_preprocess_functions(ReadoutType *item)
Definition
TaskRawDataProcessorModel.hxx:98
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_run_marker
std::atomic< bool > m_run_marker
Definition
TaskRawDataProcessorModel.hpp:114
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::run_post_processing_thread
void run_post_processing_thread(std::function< void(const ReadoutType *)> &function, folly::ProducerConsumerQueue< const ReadoutType * > &queue)
Definition
TaskRawDataProcessorModel.hxx:107
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_post_process_threads
std::vector< std::unique_ptr< utilities::ReusableThread > > m_post_process_threads
Definition
TaskRawDataProcessorModel.hpp:119
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::generate_opmon_data
virtual void generate_opmon_data() override
Definition
TaskRawDataProcessorModel.hxx:123
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_post_process_functions
std::vector< std::function< void(const ReadoutType *)> > m_post_process_functions
Definition
TaskRawDataProcessorModel.hpp:117
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::m_items_to_postprocess_queues
std::vector< std::unique_ptr< folly::ProducerConsumerQueue< const ReadoutType * > > > m_items_to_postprocess_queues
Definition
TaskRawDataProcessorModel.hpp:118
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::scrap
void scrap(const appfwk::DAQModule::CommandData_t &) override
Unconfigure.
Definition
TaskRawDataProcessorModel.hxx:24
dunedaq::datahandlinglibs::TaskRawDataProcessorModel::invoke_all_preprocess_functions
void invoke_all_preprocess_functions(ReadoutType *item)
Definition
TaskRawDataProcessorModel.hxx:89
dunedaq::datahandlinglibs::opmon::DataProcessorInfo
Definition
datahandling_info.pb.h:1242
dunedaq::opmonlib::MonitorableObject::publish
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
Definition
MonitorableObject.cpp:58
dunedaq::datahandlinglibs
Definition
DataHandlingConcept.hpp:16
dunedaq
Including Qt Headers.
Definition
module.cpp:16
ers::warning
void warning(const Issue &issue)
Definition
ers.hpp:126
thread
Generated on
for DUNE-DAQ by
1.17.0