Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to verify that the HSIEvent Sender is really ready to send messages before completing the 'start' transition #33

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/hsilibs/HSIEventSender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class HSIEventSender : public dunedaq::appfwk::DAQModule
std::shared_ptr<hsievent_sender_ct> m_hsievent_sender;

// push events to HSIEvent output queue
virtual bool ready_to_send(std::chrono::milliseconds timeout);
virtual void send_hsi_event(dfmessages::HSIEvent& event);
virtual void send_raw_hsi_data(const std::array<uint32_t, 7>& raw_data, raw_sender_ct* sender);

Expand Down
7 changes: 7 additions & 0 deletions include/hsilibs/Issues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ ERS_DECLARE_ISSUE_BASE(hsilibs,
((std::string)name),
((std::string)queueType))

ERS_DECLARE_ISSUE_BASE(hsilibs,
SenderReadyTimeout,
appfwk::GeneralDAQModuleIssue,
"Timeout waiting for the Sender for connection " << conn << " to be ready.",
((std::string)name),
((std::string)conn))

ERS_DECLARE_ISSUE(hsilibs, ///< Namespace
UHALIssue, ///< Issue class name
" UHAL related issue: " << message, ///< Message
Expand Down
26 changes: 26 additions & 0 deletions plugins/FakeHSIEventGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ FakeHSIEventGenerator::do_start(const nlohmann::json& obj)
}
m_run_number.store(start_params.run);

// 28-Sep-2023, KAB: added code to wait for the Sender connection to be ready.
// This code needs to come *before* the Sender connection is first used, and
// before any threads that use the Sender connection are start, and it needs
// to come *after* any Receiver connections are created/started so that it
// doesn't block other modules that are trying to connect to this one.
// We retry for 10 seconds. That seems like it should be plenty long enough
// for the connection to be established but short enough so that it doesn't
// annoy users if/when the connection readiness times out.
if (! ready_to_send(std::chrono::milliseconds(1))) {
bool ready = false;
for (int loop_counter = 0; loop_counter < 10; ++loop_counter) {
TLOG() << get_name() << " Waiting for the Sender for the " << m_hsievent_send_connection
<< " connection to be ready to send messages, loop_count=" << (loop_counter+1);
if (ready_to_send(std::chrono::milliseconds(1000))) {
ready = true;
break;
}
}
if (ready) {
TLOG() << get_name() << " The Sender for the " << m_hsievent_send_connection
<< " connection is now ready.";
} else {
throw(SenderReadyTimeout(ERS_HERE, get_name(), m_hsievent_send_connection));
}
}

m_thread.start_working_thread("fake-tsd-gen");
TLOG() << get_name() << " successfully started";
TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Exiting do_start() method";
Expand Down
9 changes: 8 additions & 1 deletion src/HSIEventSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ HSIEventSender::init(const nlohmann::json& init_data)
m_hsievent_sender = get_iom_sender<dfmessages::HSIEvent>(m_hsievent_send_connection);
}

bool
HSIEventSender::ready_to_send(std::chrono::milliseconds timeout)
{
if (m_hsievent_sender == nullptr) {return false;}
return m_hsievent_sender->is_ready_for_sending(timeout);
}

void
HSIEventSender::send_hsi_event(dfmessages::HSIEvent& event)
{
Expand All @@ -50,7 +57,7 @@ HSIEventSender::send_hsi_event(dfmessages::HSIEvent& event)
bool was_successfully_sent = false;
while (!was_successfully_sent) {
try {
dfmessages::HSIEvent event_copy(event);
dfmessages::HSIEvent event_copy(event);
m_hsievent_sender->send(std::move(event_copy), m_queue_timeout);
++m_sent_counter;
m_last_sent_timestamp.store(event.timestamp);
Expand Down
Loading