DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
trgtools
include
trgtools
detail
EmulationUnit.hxx
Go to the documentation of this file.
1
/* @file EmulationUnit.hxx
2
*
3
* This is part of the DUNE DAQ Application Framework, copyright 2023.
4
* Licensing/copyright details are in the COPYING file that you should have
5
* received with this code.
6
*/
7
8
#ifndef TRGTOOLS_EMULATIONUNIT_HXX_
9
#define TRGTOOLS_EMULATIONUNIT_HXX_
10
11
#include "
trgdataformats/TriggerPrimitive.hpp
"
12
13
namespace
dunedaq
{
14
namespace
trgtools
{
15
16
template
<
typename
T,
typename
U,
typename
V>
17
std::unique_ptr<daqdataformats::Fragment>
18
EmulationUnit<T, U, V>::emulate_vector
(
const
std::vector<T>& inputs) {
19
// Create the output.
20
std::vector<U> output_buffer;
21
std::vector<U> temp_buffer;
22
23
// Create the output tp variables
24
std::vector<uint64_t> time_diffs;
25
// TODO: Figure out a way of saving channelid if TPs. TCs don't have it
26
std::vector<uint64_t> tp_adc_integral;
27
std::vector<uint64_t> tp_time_start;
28
std::vector<int> is_last_tp_in_ta;
29
// Only pre-allocate memory if we're actually saving the latencies
30
if
(!
m_timing_file_name
.empty()) {
31
time_diffs.reserve(inputs.size());
32
tp_adc_integral.reserve(inputs.size());
33
tp_time_start.reserve(inputs.size());
34
is_last_tp_in_ta.reserve(inputs.size());
35
}
36
37
for
(
const
T& input : inputs) {
38
size_t
output_buffer_size = output_buffer.size();
39
uint64_t time_diff =
emulate
(input, temp_buffer);
40
if
(temp_buffer.size() != 0) {
41
output_buffer.insert(output_buffer.end(), temp_buffer.begin(), temp_buffer.end());
42
temp_buffer.clear();
43
}
44
// 1 if it's the TP that creates a TA, 0 otherwise
45
int
last_tp_in_ta = (output_buffer_size == output_buffer.size()) ? 0 : 1;
46
47
// Don't save any times if we're not saving latencies
48
if
(m_timing_file_name.empty())
49
continue
;
50
time_diffs.push_back(time_diff);
51
52
// Don't save time_start, number of TPs etc. unless it's TA latencies per TP
53
if
(!std::is_same<T, dunedaq::trgdataformats::TriggerPrimitive>::value)
54
continue
;
55
56
tp_time_start.push_back(input.time_start);
57
tp_adc_integral.push_back(input.adc_integral);
58
is_last_tp_in_ta.push_back(last_tp_in_ta);
59
}
60
61
// Write the timings for each new TP in this fragment.
62
if
(!m_timing_file_name.empty()) {
63
std::fstream timings;
64
timings.open(m_timing_file_name, std::ios::out | std::ios::app);
65
for
(
size_t
i = 0; i < time_diffs.size(); i++) {
66
if
(std::is_same<T, dunedaq::trgdataformats::TriggerPrimitive>::value) {
67
timings << tp_time_start[i] <<
","
<< tp_adc_integral[i] <<
","
68
<< time_diffs[i] <<
","
<< is_last_tp_in_ta[i] <<
"\n"
;
69
}
70
else
{
71
timings << time_diffs[i] <<
"\n"
;
72
}
73
}
74
timings.close();
75
}
76
77
// Get the size to save on.
78
size_t
payload_size(0);
79
for
(
const
U& output : output_buffer) {
80
payload_size +=
triggeralgs::get_overlay_nbytes
(output);
81
}
82
83
// Don't save empty fragments.
84
// The incomplete TX contents will get pushed onto the next fragment.
85
if
(payload_size == 0)
86
return
nullptr
;
87
88
// Awkward type conversion to avoid compiler complaints on void* arithmetic.
89
char
*
payload
=
static_cast<
char
*
>
(malloc(payload_size));
90
size_t
payload_offset(0);
91
for
(
const
U& output : output_buffer) {
92
triggeralgs::write_overlay
(output,
static_cast<
void
*
>
(payload + payload_offset));
93
payload_offset +=
triggeralgs::get_overlay_nbytes
(output);
94
}
95
96
// Hand it to a fragment,
97
std::unique_ptr<daqdataformats::Fragment> frag
98
= std::make_unique<daqdataformats::Fragment>(
static_cast<
void
*
>
(payload), payload_size);
99
// And release it.
100
free(
static_cast<
void
*
>
(payload));
101
102
m_last_output_buffer = output_buffer;
103
return
frag;
104
}
105
106
template
<
typename
T,
typename
U,
typename
V>
107
uint64_t
108
EmulationUnit<T, U, V>::emulate
(
const
T& input, std::vector<U>& outputs) {
109
auto
time_start
= std::chrono::steady_clock::now();
110
(*m_maker)(input, outputs);
// Feed TX into the TXMaker
111
auto
time_end
= std::chrono::steady_clock::now();
112
113
uint64_t time_diff = std::chrono::nanoseconds(
time_end
-
time_start
).count();
114
return
time_diff;
115
}
116
117
template
<
typename
T,
typename
U,
typename
V>
118
std::vector<U>
119
EmulationUnit<T, U, V>::get_last_output_buffer
() {
120
return
m_last_output_buffer
;
121
}
122
123
}
// namespace trgtools
124
}
// namespace dunedaq
125
126
#endif
// TRGTOOLS_EMULATIONUNIT_HXX_
time_end
time_end
Definition
TriggerActivity_serialization.hpp:39
time_start
time_start
Definition
TriggerActivity_serialization.hpp:38
dunedaq::trgtools::EmulationUnit::emulate_vector
std::unique_ptr< daqdataformats::Fragment > emulate_vector(const std::vector< input_t > &inputs)
Definition
EmulationUnit.hxx:18
dunedaq::trgtools::EmulationUnit::get_last_output_buffer
std::vector< output_t > get_last_output_buffer()
Definition
EmulationUnit.hxx:119
dunedaq::trgtools::EmulationUnit::emulate
uint64_t emulate(const input_t &input, std::vector< output_t > &outputs)
Definition
EmulationUnit.hxx:108
dunedaq::trgtools::EmulationUnit::m_timing_file_name
std::string m_timing_file_name
Definition
EmulationUnit.hpp:36
dunedaq::trgtools::EmulationUnit::m_last_output_buffer
std::vector< output_t > m_last_output_buffer
Definition
EmulationUnit.hpp:35
dpdklibs_udp_sender.payload
str payload
Definition
dpdklibs_udp_sender.py:15
dunedaq
Including Qt Headers.
Definition
module.cpp:16
trgtools
Definition
__init__.py:1
triggeralgs::write_overlay
void write_overlay(const Object &object, void *buffer)
Definition
TriggerObjectOverlay.hpp:54
triggeralgs::get_overlay_nbytes
size_t get_overlay_nbytes(const Object &object)
Definition
TriggerObjectOverlay.hpp:68
TriggerPrimitive.hpp
Generated on
for DUNE-DAQ by
1.17.0