DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::dfmodules::TriggerInhibitAgent Class Reference

#include <TriggerInhibitAgent.hpp>

Inheritance diagram for dunedaq::dfmodules::TriggerInhibitAgent:
[legend]
Collaboration diagram for dunedaq::dfmodules::TriggerInhibitAgent:
[legend]

Public Types

using trigdecreceiver_t = iomanager::ReceiverConcept<dfmessages::TriggerDecision>
using triginhsender_t = iomanager::SenderConcept<dfmessages::TriggerInhibit>

Public Member Functions

 TriggerInhibitAgent (const std::string &, std::shared_ptr< trigdecreceiver_t >, std::shared_ptr< triginhsender_t >)
 TriggerInhibitAgent Constructor.
 TriggerInhibitAgent (const TriggerInhibitAgent &)=delete
 TriggerInhibitAgent is not copy-constructible.
TriggerInhibitAgent & operator= (const TriggerInhibitAgent &)=delete
 TriggerInhibitAgent is not copy-assignable.
 TriggerInhibitAgent (TriggerInhibitAgent &&)=delete
 TriggerInhibitAgent is not move-constructible.
TriggerInhibitAgent & operator= (TriggerInhibitAgent &&)=delete
 TriggerInhibitAgent is not move-assignable.
void start_checking ()
void stop_checking ()
void set_threshold_for_inhibit (uint32_t value)
void set_latest_trigger_number (daqdataformats::trigger_number_t trig_num)
Public Member Functions inherited from dunedaq::utilities::NamedObject
 NamedObject (const std::string &name)
 NamedObject Constructor.
 NamedObject (NamedObject const &)=delete
 NamedObject is not copy-constructible.
 NamedObject (NamedObject &&)=default
 NamedObject is move-constructible.
NamedObject & operator= (NamedObject const &)=delete
 NamedObject is not copy-assignable.
NamedObject & operator= (NamedObject &&)=default
 NamedObject is move-assignable.
virtual ~NamedObject ()=default
 Default virtual destructor.
const std::string & get_name () const final
 Get the name of this NamedObejct.
Public Member Functions inherited from dunedaq::utilities::Named
 Named ()=default
 Named Constructor.
 Named (Named const &)=delete
 Named is not copy-constructible.
 Named (Named &&)=default
 Named is move-constructible.
Named & operator= (Named const &)=delete
 Named is not copy-assignable.
Named & operator= (Named &&)=default
 Named is move-assignable.
virtual ~Named ()=default
 Default virtual destructor.

Private Member Functions

void do_work (std::atomic< bool > &)

Private Attributes

dunedaq::utilities::WorkerThread m_thread
std::chrono::milliseconds m_queue_timeout
std::atomic< uint32_t > m_threshold_for_inhibit
std::shared_ptr< trigdecreceiver_t > m_trigger_decision_receiver
std::shared_ptr< triginhsender_t > m_trigger_inhibit_sender
std::atomic< daqdataformats::trigger_number_t > m_trigger_number_at_start_of_processing_chain
std::atomic< daqdataformats::trigger_number_t > m_trigger_number_at_end_of_processing_chain

Detailed Description

Definition at line 36 of file TriggerInhibitAgent.hpp.

Member Typedef Documentation

◆ trigdecreceiver_t

◆ triginhsender_t

Constructor & Destructor Documentation

◆ TriggerInhibitAgent() [1/3]

dunedaq::dfmodules::TriggerInhibitAgent::TriggerInhibitAgent ( const std::string & parent_name,
std::shared_ptr< trigdecreceiver_t > our_input,
std::shared_ptr< triginhsender_t > our_output )
explicit

TriggerInhibitAgent Constructor.

Definition at line 31 of file TriggerInhibitAgent.cpp.

34 : NamedObject(parent_name + "::TriggerInhibitAgent")
35 , m_thread(std::bind(&TriggerInhibitAgent::do_work, this, std::placeholders::_1))
36 , m_queue_timeout(100)
39 , m_trigger_inhibit_sender(our_output)
42{
43}
std::shared_ptr< triginhsender_t > m_trigger_inhibit_sender
std::shared_ptr< trigdecreceiver_t > m_trigger_decision_receiver
std::atomic< daqdataformats::trigger_number_t > m_trigger_number_at_start_of_processing_chain
dunedaq::utilities::WorkerThread m_thread
std::atomic< daqdataformats::trigger_number_t > m_trigger_number_at_end_of_processing_chain
NamedObject(const std::string &name)
NamedObject Constructor.

◆ TriggerInhibitAgent() [2/3]

dunedaq::dfmodules::TriggerInhibitAgent::TriggerInhibitAgent ( const TriggerInhibitAgent & )
delete

TriggerInhibitAgent is not copy-constructible.

◆ TriggerInhibitAgent() [3/3]

dunedaq::dfmodules::TriggerInhibitAgent::TriggerInhibitAgent ( TriggerInhibitAgent && )
delete

TriggerInhibitAgent is not move-constructible.

Member Function Documentation

◆ do_work()

void dunedaq::dfmodules::TriggerInhibitAgent::do_work ( std::atomic< bool > & running_flag)
private

Definition at line 64 of file TriggerInhibitAgent.cpp.

65{
66 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Entering do_work() method";
67
68 // configuration (hard-coded, for now; will be input from calling code later)
69 int fake_busy_interval_sec = 0;
70 std::chrono::seconds chrono_fake_busy_interval(fake_busy_interval_sec);
71 int fake_busy_duration_sec = 0;
72 std::chrono::seconds chrono_fake_busy_duration(fake_busy_duration_sec);
73 int min_interval_between_inhibit_messages_msec = 0;
74 std::chrono::milliseconds chrono_min_interval_between_inhibit_messages(min_interval_between_inhibit_messages_msec);
75
76 // initialization
77 enum LocalState
78 {
79 no_update,
80 free_state,
81 busy_state
82 };
83 std::chrono::steady_clock::time_point current_time = std::chrono::steady_clock::now();
84 // std::chrono::steady_clock::time_point start_time_of_latest_fake_busy = current_time - chrono_fake_busy_duration;
85 std::chrono::steady_clock::time_point last_sent_time = current_time;
86 LocalState requested_state = no_update;
87 LocalState current_state = free_state;
88 int32_t received_message_count = 0;
89 int32_t sent_message_count = 0;
90
91 // work loop
92 while (running_flag.load()) {
93
94 // check if a TriggerDecision message has arrived, and save the trigger
95 // number contained within it, if one has arrived
96 try {
97 dfmessages::TriggerDecision trig_dec = m_trigger_decision_receiver->receive(m_queue_timeout);
98 ++received_message_count;
99 TLOG_DEBUG(TLVL_WORK_STEPS) << get_name() << ": Popped the TriggerDecision for trigger number "
100 << trig_dec.trigger_number << " off the input queue";
101 m_trigger_number_at_start_of_processing_chain.store(trig_dec.trigger_number);
102 } catch (const iomanager::TimeoutExpired& excpt) {
103 // it is perfectly reasonable that there will be no data in the queue some
104 // fraction of the times that we check, so we just continue on and try again later
105 }
106
107 // to-do: add some logic to fake inhibits
108
109 // check if A) we are supposed to be checking the trigger_number difference, and
110 // B) if so, whether an Inhibit should be asserted or cleared
111 uint32_t threshold = m_threshold_for_inhibit.load(); // NOLINT
112 if (threshold > 0) {
115 if (temp_trig_num_at_start >= temp_trig_num_at_end &&
116 (temp_trig_num_at_start - temp_trig_num_at_end) >= threshold) {
117 if (current_state == free_state) {
118 requested_state = busy_state;
119 }
120 } else {
121 if (current_state == busy_state) {
122 requested_state = free_state;
123 }
124 }
125 }
126
127 // to-do: add some logic to periodically send a message even if nothing has changed
128
129 // send an Inhibit messages, if needed (either Busy or Free state)
130 if (requested_state != no_update && requested_state != current_state) {
131 if ((std::chrono::steady_clock::now() - last_sent_time) >= chrono_min_interval_between_inhibit_messages) {
132 dfmessages::TriggerInhibit inhibit_message;
133 if (requested_state == busy_state) {
134 inhibit_message.busy = true;
135 } else {
136 inhibit_message.busy = false;
137 }
138
139 TLOG_DEBUG(TLVL_WORK_STEPS) << get_name() << ": Pushing a TriggerInhibit message with busy state set to "
140 << inhibit_message.busy << " onto the output queue";
141 try {
142 m_trigger_inhibit_sender->send(std::move(inhibit_message), m_queue_timeout);
143 ++sent_message_count;
144#if 0
145 // temporary logging
146 std::ostringstream oss_sent;
147 oss_sent << ": Successfully pushed a TriggerInhibit message with busy state set to " << inhibit_message.busy
148 << " onto the output queue";
149 TLOG() << ProgressUpdate(ERS_HERE, get_name(), oss_sent.str());
150#endif
151 // if we successfully pushed the message to the Sink, then we assume that the
152 // receiver will get it, and we update our internal state accordingly
153 current_state = requested_state;
154 requested_state = no_update;
155 last_sent_time = std::chrono::steady_clock::now();
156 } catch (const iomanager::TimeoutExpired& excpt) {
157 // It is not ideal if we fail to send the inhibit message out, but rather than
158 // retrying some unknown number of times, we simply output a TRACE message and
159 // go on. This has the benefit of being responsive with pulling TriggerDecision
160 // messages off the input queue, and maybe our Busy/Free state will have changed
161 // by the time that the receiver is ready to receive more messages.
163 << ": TIMEOUT pushing a TriggerInhibit message onto the output queue";
164 }
165 }
166 }
167 }
168
169 std::ostringstream oss_summ;
170 oss_summ << ": Exiting the do_work() method, received " << received_message_count
171 << " TriggerDecision messages and sent " << sent_message_count
172 << " TriggerInhibit messages of all types (both Busy and Free).";
173 TLOG() << ProgressUpdate(ERS_HERE, get_name(), oss_summ.str());
174 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Exiting do_work() method";
175}
#define ERS_HERE
virtual const std::string & get_name() const =0
Get the name of this Named.
#define TLVL_ENTER_EXIT_METHODS
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
#define TLOG(...)
Definition macro.hpp:21
uint64_t trigger_number_t
Definition Types.hpp:18

◆ operator=() [1/2]

TriggerInhibitAgent & dunedaq::dfmodules::TriggerInhibitAgent::operator= ( const TriggerInhibitAgent & )
delete

TriggerInhibitAgent is not copy-assignable.

◆ operator=() [2/2]

TriggerInhibitAgent & dunedaq::dfmodules::TriggerInhibitAgent::operator= ( TriggerInhibitAgent && )
delete

TriggerInhibitAgent is not move-assignable.

◆ set_latest_trigger_number()

void dunedaq::dfmodules::TriggerInhibitAgent::set_latest_trigger_number ( daqdataformats::trigger_number_t trig_num)
inline

Definition at line 63 of file TriggerInhibitAgent.hpp.

64 {
66 }

◆ set_threshold_for_inhibit()

void dunedaq::dfmodules::TriggerInhibitAgent::set_threshold_for_inhibit ( uint32_t value)
inline

Definition at line 58 of file TriggerInhibitAgent.hpp.

59 {
60 m_threshold_for_inhibit.store(value);
61 }

◆ start_checking()

void dunedaq::dfmodules::TriggerInhibitAgent::start_checking ( )

Definition at line 46 of file TriggerInhibitAgent.cpp.

47{
48 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Entering start_checking() method";
50 TLOG() << get_name() << " successfully started";
51 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Exiting start_checking() method";
52}
void start_working_thread(const std::string &name="noname")
Start the working thread (which executes the do_work() function).

◆ stop_checking()

void dunedaq::dfmodules::TriggerInhibitAgent::stop_checking ( )

Definition at line 55 of file TriggerInhibitAgent.cpp.

56{
57 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Entering stop_checking() method";
59 TLOG() << get_name() << " successfully stopped";
60 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Exiting stop_checking() method";
61}
void stop_working_thread()
Stop the working thread.

Member Data Documentation

◆ m_queue_timeout

std::chrono::milliseconds dunedaq::dfmodules::TriggerInhibitAgent::m_queue_timeout
private

Definition at line 74 of file TriggerInhibitAgent.hpp.

◆ m_thread

dunedaq::utilities::WorkerThread dunedaq::dfmodules::TriggerInhibitAgent::m_thread
private

Definition at line 70 of file TriggerInhibitAgent.hpp.

◆ m_threshold_for_inhibit

std::atomic<uint32_t> dunedaq::dfmodules::TriggerInhibitAgent::m_threshold_for_inhibit
private

Definition at line 75 of file TriggerInhibitAgent.hpp.

◆ m_trigger_decision_receiver

std::shared_ptr<trigdecreceiver_t> dunedaq::dfmodules::TriggerInhibitAgent::m_trigger_decision_receiver
private

Definition at line 78 of file TriggerInhibitAgent.hpp.

◆ m_trigger_inhibit_sender

std::shared_ptr<triginhsender_t> dunedaq::dfmodules::TriggerInhibitAgent::m_trigger_inhibit_sender
private

Definition at line 79 of file TriggerInhibitAgent.hpp.

◆ m_trigger_number_at_end_of_processing_chain

std::atomic<daqdataformats::trigger_number_t> dunedaq::dfmodules::TriggerInhibitAgent::m_trigger_number_at_end_of_processing_chain
private

Definition at line 83 of file TriggerInhibitAgent.hpp.

◆ m_trigger_number_at_start_of_processing_chain

std::atomic<daqdataformats::trigger_number_t> dunedaq::dfmodules::TriggerInhibitAgent::m_trigger_number_at_start_of_processing_chain
private

Definition at line 82 of file TriggerInhibitAgent.hpp.


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