DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::trgtools::EmulationUnit< T, U, V > Class Template Reference

#include <EmulationUnit.hpp>

Public Member Functions

uint64_t emulate (const input_t &input, std::vector< output_t > &outputs)
std::unique_ptr< daqdataformats::Fragment > emulate_vector (const std::vector< input_t > &inputs)
std::vector< output_t > get_last_output_buffer ()
void set_maker (std::unique_ptr< maker_t > &maker)
void set_timing_file (const std::string &file_name)
void write_csv_header (const std::string &header)

Private Types

using input_t = T
using output_t = U
using maker_t = V

Private Attributes

std::unique_ptr< maker_t > m_maker
std::vector< output_t > m_last_output_buffer
std::string m_timing_file_name

Detailed Description

template<typename T, typename U, typename V>
class dunedaq::trgtools::EmulationUnit< T, U, V >

Definition at line 27 of file EmulationUnit.hpp.

Member Typedef Documentation

◆ input_t

template<typename T, typename U, typename V>
using dunedaq::trgtools::EmulationUnit< T, U, V >::input_t = T
private

Definition at line 29 of file EmulationUnit.hpp.

◆ maker_t

template<typename T, typename U, typename V>
using dunedaq::trgtools::EmulationUnit< T, U, V >::maker_t = V
private

Definition at line 31 of file EmulationUnit.hpp.

◆ output_t

template<typename T, typename U, typename V>
using dunedaq::trgtools::EmulationUnit< T, U, V >::output_t = U
private

Definition at line 30 of file EmulationUnit.hpp.

Member Function Documentation

◆ emulate()

template<typename T, typename U, typename V>
uint64_t dunedaq::trgtools::EmulationUnit< T, U, V >::emulate ( const input_t & input,
std::vector< output_t > & outputs )

Definition at line 108 of file EmulationUnit.hxx.

109{
111 (*m_maker)(input, outputs); // Feed TX into the TXMaker
113
115 return time_diff;
116}

◆ emulate_vector()

template<typename T, typename U, typename V>
std::unique_ptr< daqdataformats::Fragment > dunedaq::trgtools::EmulationUnit< T, U, V >::emulate_vector ( const std::vector< input_t > & inputs)

Definition at line 18 of file EmulationUnit.hxx.

19{
20 // Create the output.
23
24 // Create the output tp variables
26 // TODO: Figure out a way of saving channelid if TPs. TCs don't have it
30 // Only pre-allocate memory if we're actually saving the latencies
31 if (!m_timing_file_name.empty()) {
32 time_diffs.reserve(inputs.size());
33 tp_adc_integral.reserve(inputs.size());
34 tp_time_start.reserve(inputs.size());
35 is_last_tp_in_ta.reserve(inputs.size());
36 }
37
38 for (const T& input : inputs) {
39 size_t output_buffer_size = output_buffer.size();
41 if (temp_buffer.size() != 0) {
42 output_buffer.insert(output_buffer.end(), temp_buffer.begin(), temp_buffer.end());
43 temp_buffer.clear();
44 }
45 // 1 if it's the TP that creates a TA, 0 otherwise
46 int last_tp_in_ta = (output_buffer_size == output_buffer.size()) ? 0 : 1;
47
48 // Don't save any times if we're not saving latencies
49 if (m_timing_file_name.empty())
50 continue;
51 time_diffs.push_back(time_diff);
52
53 // Don't save time_start, number of TPs etc. unless it's TA latencies per TP
55 continue;
56
57 tp_time_start.push_back(input.time_start);
58 tp_adc_integral.push_back(input.adc_integral);
60 }
61
62 // Write the timings for each new TP in this fragment.
63 if (!m_timing_file_name.empty()) {
66 for (size_t i = 0; i < time_diffs.size(); i++) {
68 timings << tp_time_start[i] << "," << tp_adc_integral[i] << "," << time_diffs[i] << "," << is_last_tp_in_ta[i]
69 << "\n";
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) {
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) {
94 }
95
96 // Hand it to a fragment,
99 // And release it.
100 free(static_cast<void*>(payload));
101
103 return frag;
104}
uint64_t emulate(const input_t &input, std::vector< output_t > &outputs)
std::vector< output_t > m_last_output_buffer
void write_overlay(const Object &object, void *buffer)
size_t get_overlay_nbytes(const Object &object)

◆ get_last_output_buffer()

template<typename T, typename U, typename V>
std::vector< U > dunedaq::trgtools::EmulationUnit< T, U, V >::get_last_output_buffer ( )

Definition at line 120 of file EmulationUnit.hxx.

121{
123}

◆ set_maker()

template<typename T, typename U, typename V>
void dunedaq::trgtools::EmulationUnit< T, U, V >::set_maker ( std::unique_ptr< maker_t > & maker)
inline

Definition at line 42 of file EmulationUnit.hpp.

std::unique_ptr< maker_t > m_maker

◆ set_timing_file()

template<typename T, typename U, typename V>
void dunedaq::trgtools::EmulationUnit< T, U, V >::set_timing_file ( const std::string & file_name)
inline

Definition at line 43 of file EmulationUnit.hpp.

◆ write_csv_header()

template<typename T, typename U, typename V>
void dunedaq::trgtools::EmulationUnit< T, U, V >::write_csv_header ( const std::string & header)
inline

Definition at line 44 of file EmulationUnit.hpp.

Member Data Documentation

◆ m_last_output_buffer

template<typename T, typename U, typename V>
std::vector<output_t> dunedaq::trgtools::EmulationUnit< T, U, V >::m_last_output_buffer
private

Definition at line 35 of file EmulationUnit.hpp.

◆ m_maker

template<typename T, typename U, typename V>
std::unique_ptr<maker_t> dunedaq::trgtools::EmulationUnit< T, U, V >::m_maker
private

Definition at line 34 of file EmulationUnit.hpp.

◆ m_timing_file_name

template<typename T, typename U, typename V>
std::string dunedaq::trgtools::EmulationUnit< T, U, V >::m_timing_file_name
private

Definition at line 36 of file EmulationUnit.hpp.


The documentation for this class was generated from the following files: