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

#include <HSISourceModel.hpp>

Inheritance diagram for dunedaq::trigger::HSISourceModel:
[legend]
Collaboration diagram for dunedaq::trigger::HSISourceModel:
[legend]

Public Types

using inherited = datahandlinglibs::SourceConcept
 
- Public Types inherited from dunedaq::opmonlib::MonitorableObject
using NodePtr = std::weak_ptr<MonitorableObject>
 
using NewNodePtr = std::shared_ptr<MonitorableObject>
 
using ElementId = std::string
 

Public Member Functions

 HSISourceModel ()
 SourceModel Constructor.
 
 ~HSISourceModel () override
 
void init (const confmodel::DaqModule *cfg) override
 
void start ()
 
void stop ()
 
bool handle_payload (dfmessages::HSIEvent &data)
 
void generate_opmon_data () override
 
void print_opmon_stats ()
 
- Public Member Functions inherited from dunedaq::datahandlinglibs::SourceConcept
 SourceConcept ()
 
virtual ~SourceConcept ()
 
 SourceConcept (const SourceConcept &)=delete
 SourceConcept is not copy-constructible.
 
SourceConceptoperator= (const SourceConcept &)=delete
 SourceConcept is not copy-assginable.
 
 SourceConcept (SourceConcept &&)=delete
 SourceConcept is not move-constructible.
 
SourceConceptoperator= (SourceConcept &&)=delete
 SourceConcept is not move-assignable.
 
- Public Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject (const MonitorableObject &)=delete
 
MonitorableObjectoperator= (const MonitorableObject &)=delete
 
 MonitorableObject (MonitorableObject &&)=delete
 
MonitorableObjectoperator= (MonitorableObject &&)=delete
 
virtual ~MonitorableObject ()=default
 
auto get_opmon_id () const noexcept
 
auto get_opmon_level () const noexcept
 

Private Types

using source_t = dunedaq::iomanager::ReceiverConcept<dfmessages::HSIEvent>
 
using sink_t = dunedaq::iomanager::SenderConcept<triggeralgs::TriggerCandidate>
 
using metric_counter_type = uint64_t
 

Private Attributes

std::shared_ptr< source_tm_data_receiver
 
std::shared_ptr< sink_tm_data_sender
 
std::map< uint32_t, HSISignalm_signals
 map of HSI signal ID bits to TC output configurations
 
std::atomic< metric_counter_typem_received_events_count {0}
 
std::atomic< metric_counter_typem_tcs_made_count {0}
 
std::atomic< metric_counter_typem_tcs_sent_count {0}
 
std::atomic< metric_counter_typem_tcs_dropped_count {0}
 
uint64_t m_prescale
 {rescale for the input HSIEvents, default 1
 
std::atomic< bool > m_running_flag { false }
 
std::atomic< bool > m_latency_monitoring { false }
 
dunedaq::trigger::Latency m_latency_instance
 
std::atomic< metric_counter_typem_latency_in { 0 }
 
std::atomic< metric_counter_typem_latency_out { 0 }
 

Additional Inherited Members

- Static Public Member Functions inherited from dunedaq::opmonlib::MonitorableObject
static bool publishable_metric (OpMonLevel entry, OpMonLevel system) noexcept
 
- Protected Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject ()=default
 
void register_node (ElementId name, NewNodePtr)
 
void publish (google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
 

Detailed Description

Definition at line 44 of file HSISourceModel.hpp.

Member Typedef Documentation

◆ inherited

◆ metric_counter_type

Definition at line 224 of file HSISourceModel.hpp.

◆ sink_t

◆ source_t

Constructor & Destructor Documentation

◆ HSISourceModel()

dunedaq::trigger::HSISourceModel::HSISourceModel ( )
inline

SourceModel Constructor.

Parameters
nameInstance name for this SourceModel instance

Definition at line 53 of file HSISourceModel.hpp.

53: datahandlinglibs::SourceConcept() {}

◆ ~HSISourceModel()

dunedaq::trigger::HSISourceModel::~HSISourceModel ( )
inlineoverride

Definition at line 54 of file HSISourceModel.hpp.

55 {
56 m_data_receiver.reset();
57 m_data_sender.reset();
58 m_signals.clear();
59 }
std::shared_ptr< sink_t > m_data_sender
std::map< uint32_t, HSISignal > m_signals
map of HSI signal ID bits to TC output configurations
std::shared_ptr< source_t > m_data_receiver

Member Function Documentation

◆ generate_opmon_data()

void dunedaq::trigger::HSISourceModel::generate_opmon_data ( )
inlineoverridevirtual

Hook for customisable pubblication. The function can throw, exception will be caught by the monitoring thread

Reimplemented from dunedaq::opmonlib::MonitorableObject.

Definition at line 181 of file HSISourceModel.hpp.

182 {
183 opmon::HSISourceModelInfo info;
184
185 info.set_received_events_count( m_received_events_count );
186 info.set_tcs_made_count( m_tcs_made_count );
187 info.set_tcs_sent_count( m_tcs_sent_count );
188 info.set_tcs_dropped_count( m_tcs_dropped_count );
189
190 this->publish(std::move(info));
191
192 if ( m_latency_monitoring.load() && m_running_flag.load() ) {
193 opmon::TriggerLatency lat_info;
194
195 lat_info.set_latency_in( m_latency_instance.get_latency_in() );
196 lat_info.set_latency_out( m_latency_instance.get_latency_out() );
197
198 this->publish(std::move(lat_info));
199 }
200 }
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
std::atomic< metric_counter_type > m_tcs_made_count
std::atomic< bool > m_latency_monitoring
std::atomic< metric_counter_type > m_received_events_count
dunedaq::trigger::Latency m_latency_instance
std::atomic< metric_counter_type > m_tcs_sent_count
std::atomic< metric_counter_type > m_tcs_dropped_count
latency get_latency_in() const
Definition Latency.hpp:48
latency get_latency_out() const
Definition Latency.hpp:53

◆ handle_payload()

bool dunedaq::trigger::HSISourceModel::handle_payload ( dfmessages::HSIEvent & data)
inline

Definition at line 129 of file HSISourceModel.hpp.

130 {
133
134 // Prescale after n-hsi received
136 return true;
137 }
138
139 TLOG_DEBUG(1) << "Received HSIEvent with signal map " << data.signal_map << " and timestamp " << data.timestamp;
140
141 // Iterate over all the signals
142 uint32_t signal_map = data.signal_map;
143 while (signal_map) {
144 // Get the index of the least significant bit
145 int bit_index = __builtin_ctzll(signal_map);
146 uint32_t signal = 1 << bit_index;
147
148 // Throw an error if we don't have this signal bit configured
149 if (!m_signals.count(signal)) {
150 throw dunedaq::trigger::SignalTypeError(ERS_HERE, "HSI subscriber" , data.signal_map);
151 }
152
153 // Create the trigger candidate
155 candidate.time_start = data.timestamp - m_signals[signal].time_before;
156 candidate.time_end = data.timestamp + m_signals[signal].time_after;
157 candidate.time_candidate = data.timestamp;
158 // throw away bits 31-16 of header, that's OK for now
159 candidate.detid = (uint)detdataformats::DetID::Subdetector::kDAQ ; // NOLINT(build/unsigned)
160 candidate.type = m_signals[signal].type;
162 candidate.inputs = {};
164
166 // Send the TC
167 if (!m_data_sender->try_send(std::move(candidate), iomanager::Sender::s_no_block)) {
169 }
170 else {
172 }
173
174 // Clear the least significant bit
175 signal_map &= signal_map - 1;
176 }
177
178 return true;
179 }
#define ERS_HERE
static constexpr timeout_t s_no_block
Definition Sender.hpp:26
uint64_t m_prescale
{rescale for the input HSIEvents, default 1
void update_latency_out(uint64_t latency)
Definition Latency.hpp:43
void update_latency_in(uint64_t latency)
Definition Latency.hpp:38
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
std::vector< dunedaq::trgdataformats::TriggerActivityData > inputs

◆ init()

void dunedaq::trigger::HSISourceModel::init ( const confmodel::DaqModule * cfg)
inlineoverridevirtual

Implements dunedaq::datahandlinglibs::SourceConcept.

Definition at line 61 of file HSISourceModel.hpp.

62 {
63 if (cfg->get_outputs().size() != 1) {
64 throw datahandlinglibs::InitializationError(ERS_HERE, "Only 1 output supported for subscribers");
65 }
67
68 if (cfg->get_inputs().size() != 1) {
69 throw datahandlinglibs::InitializationError(ERS_HERE, "Only 1 input supported for subscribers");
70 }
71 m_data_receiver = get_iom_receiver<dfmessages::HSIEvent>(cfg->get_inputs()[0]->UID());
72 auto data_reader = cfg->cast<appmodel::DataSubscriberModule>();
73 if (data_reader == nullptr) {
74 throw datahandlinglibs::InitializationError(ERS_HERE, "DAQ module is not a DataReader");
75 }
76 auto hsi_conf = data_reader->get_configuration()->cast<appmodel::HSI2TCTranslatorConf>();
77 if (hsi_conf == nullptr) {
78 throw datahandlinglibs::InitializationError(ERS_HERE, "Missing HSI2TCTranslatorConf");
79 }
80
81 // Get the HSI-signal to TC-output map
82 for (auto win : hsi_conf->get_signals()) {
84 tc_type = static_cast<triggeralgs::TriggerCandidate::Type>(
86
87 // Throw error if unknown TC type
89 throw datahandlinglibs::InitializationError(ERS_HERE, "Provided an unknown TC type output to HSISourceModel");
90 }
91
92 // Throw error if already exists
93 uint32_t signal = win->get_signal_type();
94 if (m_signals.count(signal)) {
95 throw datahandlinglibs::InitializationError(ERS_HERE, "Provided more than one of the same HSI signal ID input to HSISourceModel");
96 }
97
98 // Fill the signal-tctype map
99 m_signals[signal] = { tc_type,
100 win->get_time_before(),
101 win->get_time_after() };
102
103 TLOG() << "Will cover HSI signal id: " << signal << " to TC type: " << win->get_tc_type_name()
104 << " window before: " << win->get_time_before() << " window after: " << win->get_time_after();
105 }
106
107 m_prescale = hsi_conf->get_prescale();
108 m_latency_monitoring.store( hsi_conf->get_latency_monitoring() );
109
110 }
#define TLOG(...)
Definition macro.hpp:22
int string_to_trigger_candidate_type(const std::string &name)
static std::shared_ptr< iomanager::SenderConcept< Datatype > > get_iom_sender(iomanager::ConnectionId const &id)
static std::shared_ptr< iomanager::ReceiverConcept< Datatype > > get_iom_receiver(iomanager::ConnectionId const &id)

◆ print_opmon_stats()

void dunedaq::trigger::HSISourceModel::print_opmon_stats ( )
inline

Definition at line 202 of file HSISourceModel.hpp.

203 {
204 TLOG() << "HSI Source Model opmon counters summary:";
205 TLOG() << "------------------------------";
206 TLOG() << "Signals received: \t" << m_received_events_count;
207 TLOG() << "TCs made: \t\t" << m_tcs_made_count;
208 TLOG() << "TCs sent: \t\t" << m_tcs_sent_count;
209 TLOG() << "TCs dropped: \t\t" << m_tcs_dropped_count;
210 TLOG();
211 }

◆ start()

void dunedaq::trigger::HSISourceModel::start ( )
inlinevirtual

Implements dunedaq::datahandlinglibs::SourceConcept.

Definition at line 112 of file HSISourceModel.hpp.

112 {
113 m_data_receiver->add_callback(std::bind(&HSISourceModel::handle_payload, this, std::placeholders::_1));
114
115 m_running_flag.store(true);
116
118 m_tcs_made_count.store(0);
119 m_tcs_sent_count.store(0);
120 m_tcs_dropped_count.store(0);
121 }
bool handle_payload(dfmessages::HSIEvent &data)

◆ stop()

void dunedaq::trigger::HSISourceModel::stop ( )
inlinevirtual

Implements dunedaq::datahandlinglibs::SourceConcept.

Definition at line 123 of file HSISourceModel.hpp.

123 {
124 m_data_receiver->remove_callback();
125 m_running_flag.store(false);
127 }

Member Data Documentation

◆ m_data_receiver

std::shared_ptr<source_t> dunedaq::trigger::HSISourceModel::m_data_receiver
private

Definition at line 215 of file HSISourceModel.hpp.

◆ m_data_sender

std::shared_ptr<sink_t> dunedaq::trigger::HSISourceModel::m_data_sender
private

Definition at line 218 of file HSISourceModel.hpp.

◆ m_latency_in

std::atomic<metric_counter_type> dunedaq::trigger::HSISourceModel::m_latency_in { 0 }
private

Definition at line 237 of file HSISourceModel.hpp.

237{ 0 };

◆ m_latency_instance

dunedaq::trigger::Latency dunedaq::trigger::HSISourceModel::m_latency_instance
private

Definition at line 236 of file HSISourceModel.hpp.

◆ m_latency_monitoring

std::atomic<bool> dunedaq::trigger::HSISourceModel::m_latency_monitoring { false }
private

Definition at line 235 of file HSISourceModel.hpp.

235{ false };

◆ m_latency_out

std::atomic<metric_counter_type> dunedaq::trigger::HSISourceModel::m_latency_out { 0 }
private

Definition at line 238 of file HSISourceModel.hpp.

238{ 0 };

◆ m_prescale

uint64_t dunedaq::trigger::HSISourceModel::m_prescale
private

{rescale for the input HSIEvents, default 1

Definition at line 231 of file HSISourceModel.hpp.

◆ m_received_events_count

std::atomic<metric_counter_type> dunedaq::trigger::HSISourceModel::m_received_events_count {0}
private

Definition at line 225 of file HSISourceModel.hpp.

225{0};

◆ m_running_flag

std::atomic<bool> dunedaq::trigger::HSISourceModel::m_running_flag { false }
private

Definition at line 234 of file HSISourceModel.hpp.

234{ false };

◆ m_signals

std::map<uint32_t, HSISignal> dunedaq::trigger::HSISourceModel::m_signals
private

map of HSI signal ID bits to TC output configurations

Definition at line 221 of file HSISourceModel.hpp.

◆ m_tcs_dropped_count

std::atomic<metric_counter_type> dunedaq::trigger::HSISourceModel::m_tcs_dropped_count {0}
private

Definition at line 228 of file HSISourceModel.hpp.

228{0};

◆ m_tcs_made_count

std::atomic<metric_counter_type> dunedaq::trigger::HSISourceModel::m_tcs_made_count {0}
private

Definition at line 226 of file HSISourceModel.hpp.

226{0};

◆ m_tcs_sent_count

std::atomic<metric_counter_type> dunedaq::trigger::HSISourceModel::m_tcs_sent_count {0}
private

Definition at line 227 of file HSISourceModel.hpp.

227{0};

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