DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
hsilibs
src
HSIEventSender.cpp
Go to the documentation of this file.
1
9
10
#include "
hsilibs/HSIEventSender.hpp
"
11
12
#include "
iomanager/IOManager.hpp
"
13
#include "
logging/Logging.hpp
"
14
#include "
confmodel/DaqModule.hpp
"
15
#include "
confmodel/Connection.hpp
"
16
17
#include <chrono>
18
#include <cstdlib>
19
#include <string>
20
#include <thread>
21
#include <vector>
22
23
namespace
dunedaq
{
24
namespace
hsilibs
{
25
26
HSIEventSender::HSIEventSender
(
const
std::string& name)
27
:
dunedaq
::
appfwk
::DAQModule(name)
28
,
m_hsievent_send_connection
(
""
)
29
,
m_queue_timeout
(1)
30
,
m_hsievent_sender
(nullptr)
31
,
m_sent_counter
(0)
32
,
m_failed_to_send_counter
(0)
33
,
m_last_sent_timestamp
(0)
34
{
35
}
36
37
void
38
HSIEventSender::init
(std::shared_ptr<appfwk::ConfigurationManager> mcfg)
39
{
40
auto
mdal = mcfg->get_dal<
confmodel::DaqModule
>(get_name());
// Only need generic DaqModule for output
41
42
if
(!mdal) {
43
throw
appfwk::CommandFailed(
ERS_HERE
,
"init"
, get_name(),
"Unable to retrieve configuration object"
);
44
}
45
46
for
(
auto
con : mdal->get_outputs()) {
47
if
(con->get_data_type() == datatype_to_string<dfmessages::HSIEvent>()) {
48
m_hsievent_send_connection
= con->UID();
49
}
50
}
51
52
m_hsievent_sender
=
get_iom_sender<dfmessages::HSIEvent>
(
m_hsievent_send_connection
);
53
}
54
55
bool
56
HSIEventSender::ready_to_send
(std::chrono::milliseconds timeout)
57
{
58
if
(
m_hsievent_sender
==
nullptr
) {
59
return
false
;
60
}
61
return
m_hsievent_sender
->is_ready_for_sending(timeout);
62
}
63
64
void
65
HSIEventSender::send_hsi_event
(
dfmessages::HSIEvent
& event)
66
{
67
TLOG_DEBUG
(3) << get_name() <<
": Sending HSIEvent to "
<<
m_hsievent_send_connection
<<
". \n"
68
<<
event
.header <<
", "
<< std::bitset<32>(event.
signal_map
) <<
", "
<<
event
.timestamp <<
", "
69
<<
event
.sequence_counter <<
"\n"
;
70
71
bool
was_successfully_sent =
false
;
72
while
(!was_successfully_sent) {
73
try
{
74
dfmessages::HSIEvent
event_copy(event);
75
m_hsievent_sender
->send(std::move(event_copy),
m_queue_timeout
);
76
++
m_sent_counter
;
77
m_last_sent_timestamp
.store(event.
timestamp
);
78
was_successfully_sent =
true
;
79
}
catch
(
const
dunedaq::iomanager::TimeoutExpired& excpt) {
80
std::ostringstream oss_warn;
81
oss_warn <<
"push to output connection \""
<<
m_hsievent_send_connection
<<
"\""
;
82
ers::error
(dunedaq::iomanager::TimeoutExpired(
ERS_HERE
, get_name(), oss_warn.str(),
m_queue_timeout
.count()));
83
++
m_failed_to_send_counter
;
84
}
85
}
86
if
(
m_sent_counter
> 0 &&
m_sent_counter
% 200000 == 0)
87
TLOG_DEBUG
(3) <<
"Have sent out "
<<
m_sent_counter
<<
" HSI events"
;
88
}
89
90
void
91
HSIEventSender::send_raw_hsi_data
(
const
std::array<uint32_t, 7>& raw_data,
raw_sender_ct
* sender)
92
{
93
HSI_FRAME_STRUCT
payload;
94
::memcpy(&payload, &raw_data[0],
sizeof
(
HSI_FRAME_STRUCT
));
95
96
TLOG_DEBUG
(3) << get_name() <<
": Sending HSI_FRAME_STRUCT "
<< std::hex <<
"0x"
<< payload.frame.version <<
", 0x"
97
<< payload.frame.detector_id
98
99
<<
"; 0x"
<< payload.frame.timestamp_low <<
"; 0x"
<< payload.frame.timestamp_high <<
"; 0x"
100
<< payload.frame.input_low <<
"; 0x"
<< payload.frame.input_high <<
"; 0x"
<< payload.frame.trigger
101
<<
"; 0x"
<< payload.frame.sequence << std::endl;
102
103
try
{
104
// TODO deal with this
105
if
(!sender) {
106
throw
(QueueIsNullFatalError(
ERS_HERE
, get_name(),
"HSIEventSender output"
));
107
}
108
sender->
send
(std::move(payload),
m_queue_timeout
);
109
}
catch
(
const
dunedaq::iomanager::TimeoutExpired& excpt) {
110
std::ostringstream oss_warn;
111
oss_warn <<
"push to output raw hsi data queue failed"
;
112
ers::error
(dunedaq::iomanager::TimeoutExpired(
ERS_HERE
, get_name(), oss_warn.str(),
m_queue_timeout
.count()));
113
++
m_failed_to_send_counter
;
114
}
115
}
116
117
}
// namespace hsilibs
118
}
// namespace dunedaq
119
120
// Local Variables:
121
// c-basic-offset: 2
122
// End:
IOManager.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
dunedaq::confmodel::DaqModule
Definition
DaqModule.hpp:34
dunedaq::hsilibs::HSIEventSender::HSIEventSender
HSIEventSender(const std::string &name)
HSIEventSender Constructor.
Definition
HSIEventSender.cpp:26
dunedaq::hsilibs::HSIEventSender::send_hsi_event
virtual void send_hsi_event(dfmessages::HSIEvent &event)
Definition
HSIEventSender.cpp:65
dunedaq::hsilibs::HSIEventSender::send_raw_hsi_data
virtual void send_raw_hsi_data(const std::array< uint32_t, 7 > &raw_data, raw_sender_ct *sender)
Definition
HSIEventSender.cpp:91
dunedaq::hsilibs::HSIEventSender::m_last_sent_timestamp
std::atomic< uint64_t > m_last_sent_timestamp
Definition
HSIEventSender.hpp:72
dunedaq::hsilibs::HSIEventSender::init
void init(std::shared_ptr< appfwk::ConfigurationManager > mcfg) override
Definition
HSIEventSender.cpp:38
dunedaq::hsilibs::HSIEventSender::m_hsievent_send_connection
std::string m_hsievent_send_connection
Definition
HSIEventSender.hpp:57
dunedaq::hsilibs::HSIEventSender::m_failed_to_send_counter
std::atomic< uint64_t > m_failed_to_send_counter
Definition
HSIEventSender.hpp:71
dunedaq::hsilibs::HSIEventSender::m_sent_counter
std::atomic< uint64_t > m_sent_counter
Definition
HSIEventSender.hpp:70
dunedaq::hsilibs::HSIEventSender::m_hsievent_sender
std::shared_ptr< hsievent_sender_ct > m_hsievent_sender
Definition
HSIEventSender.hpp:63
dunedaq::hsilibs::HSIEventSender::m_queue_timeout
std::chrono::milliseconds m_queue_timeout
Definition
HSIEventSender.hpp:58
dunedaq::hsilibs::HSIEventSender::raw_sender_ct
iomanager::SenderConcept< HSI_FRAME_STRUCT > raw_sender_ct
Definition
HSIEventSender.hpp:60
dunedaq::hsilibs::HSIEventSender::ready_to_send
virtual bool ready_to_send(std::chrono::milliseconds timeout)
Definition
HSIEventSender.cpp:56
dunedaq::hsilibs::HSI_FRAME_STRUCT
Definition
Types.hpp:36
dunedaq::iomanager::SenderConcept::send
virtual void send(Datatype &&data, Sender::timeout_t timeout)=0
Connection.hpp
DaqModule.hpp
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
appfwk
Definition
__init__.py:1
dunedaq::hsilibs
Definition
HSIEventSender.hpp:27
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
HSIEventSender.hpp
dunedaq::dfmessages::HSIEvent
A message used to convey an HSI event.
Definition
HSIEvent.hpp:26
dunedaq::dfmessages::HSIEvent::timestamp
daqdataformats::timestamp_t timestamp
Timestamp of HSI event.
Definition
HSIEvent.hpp:29
dunedaq::dfmessages::HSIEvent::signal_map
uint32_t signal_map
Bit map of signals. 1 bit, 1 signal // NOLINT(build/unsigned).
Definition
HSIEvent.hpp:28
Generated on
for DUNE-DAQ by
1.17.0