DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::timinglibs::TimingHardwareManagerBase Class Referenceabstract

TimingHardwareManagerBase creates vectors of ints and writes them to the configured output queues. More...

#include <TimingHardwareManagerBase.hpp>

Inheritance diagram for dunedaq::timinglibs::TimingHardwareManagerBase:
[legend]
Collaboration diagram for dunedaq::timinglibs::TimingHardwareManagerBase:
[legend]

Public Member Functions

 TimingHardwareManagerBase (const std::string &name)
 TimingHardwareManagerBase Constructor.
 
 TimingHardwareManagerBase (const TimingHardwareManagerBase &)=delete
 TimingHardwareManagerBase is not copy-constructible.
 
TimingHardwareManagerBaseoperator= (const TimingHardwareManagerBase &)=delete
 TimingHardwareManagerBase is not copy-assignable.
 
 TimingHardwareManagerBase (TimingHardwareManagerBase &&)=delete
 TimingHardwareManagerBase is not move-constructible.
 
TimingHardwareManagerBaseoperator= (TimingHardwareManagerBase &&)=delete
 TimingHardwareManagerBase is not move-assignable.
 
virtual ~TimingHardwareManagerBase ()
 
void init (std::shared_ptr< appfwk::ConfigurationManager > mcfg) override
 
virtual void conf (const nlohmann::json &data)
 
- Public Member Functions inherited from dunedaq::timinglibs::TimingHardwareInterface
 TimingHardwareInterface ()
 TimingHardwareInterface Constructor.
 
 TimingHardwareInterface (const TimingHardwareInterface &)=delete
 TimingHardwareInterface is not copy-constructible.
 
TimingHardwareInterfaceoperator= (const TimingHardwareInterface &)=delete
 TimingHardwareInterface is not copy-assignable.
 
 TimingHardwareInterface (TimingHardwareInterface &&)=delete
 TimingHardwareInterface is not move-constructible.
 
TimingHardwareInterfaceoperator= (TimingHardwareInterface &&)=delete
 TimingHardwareInterface is not move-assignable.
 

Protected Types

using source_t = dunedaq::iomanager::ReceiverConcept<timingcmd::TimingHwCmd>
 

Protected Member Functions

virtual void do_scrap (const nlohmann::json &)
 
virtual void process_hardware_command (timingcmd::TimingHwCmd &timing_hw_cmd)
 
virtual void register_common_hw_commands_for_design ()=0
 
virtual void register_master_hw_commands_for_design ()=0
 
virtual void register_endpoint_hw_commands_for_design ()=0
 
virtual void register_hsi_hw_commands_for_design ()=0
 
template<class TIMING_DEV >
TIMING_DEV get_timing_device (const std::string &device_name)
 
const timing::TimingNodeget_timing_device_plain (const std::string &device_name)
 
template<typename Child >
void register_timing_hw_command (const std::string &hw_cmd_id, void(Child::*f)(const timingcmd::TimingHwCmd &))
 
void io_reset (const timingcmd::TimingHwCmd &hw_cmd)
 
void print_status (const timingcmd::TimingHwCmd &hw_cmd)
 
void set_timestamp (const timingcmd::TimingHwCmd &hw_cmd)
 
void set_endpoint_delay (const timingcmd::TimingHwCmd &hw_cmd)
 
void send_fl_cmd (const timingcmd::TimingHwCmd &hw_cmd)
 
void master_endpoint_scan (const timingcmd::TimingHwCmd &hw_cmd)
 
virtual void partition_configure (const timingcmd::TimingHwCmd &hw_cmd)=0
 
void endpoint_enable (const timingcmd::TimingHwCmd &hw_cmd)
 
void endpoint_disable (const timingcmd::TimingHwCmd &hw_cmd)
 
void endpoint_reset (const timingcmd::TimingHwCmd &hw_cmd)
 
void hsi_reset (const timingcmd::TimingHwCmd &hw_cmd)
 
void hsi_configure (const timingcmd::TimingHwCmd &hw_cmd)
 
void hsi_start (const timingcmd::TimingHwCmd &hw_cmd)
 
void hsi_stop (const timingcmd::TimingHwCmd &hw_cmd)
 
void hsi_print_status (const timingcmd::TimingHwCmd &hw_cmd)
 
void register_info_gatherer (uint gather_interval, const std::string &device_name, int op_mon_level)
 
void gather_monitor_data (InfoGatherer &gatherer)
 
virtual void start_hw_mon_gathering (const std::string &device_name="")
 
virtual void stop_hw_mon_gathering (const std::string &device_name="")
 
virtual std::vector< std::string > check_hw_mon_gatherer_is_running (const std::string &device_name)
 
virtual void perform_endpoint_scan (const timingcmd::TimingHwCmd &hw_cmd)
 
virtual void clean_endpoint_scan_threads ()
 
- Protected Member Functions inherited from dunedaq::timinglibs::TimingHardwareInterface
template<class TIMING_DEV >
TIMING_DEV cast_timing_device (const uhal::Node *device_node, std::string timing_device_name)
 
void configure_uhal (const dunedaq::timinglibs::dal::TimingHardwareInterfaceConf *mdal)
 
void configure_uhal (const std::string &uhal_log_level, const std::string &connections_file)
 
void scrap_uhal ()
 

Protected Attributes

std::string m_hw_cmd_connection
 
std::shared_ptr< source_tm_hw_command_receiver
 
uint m_gather_interval
 
uint m_gather_interval_debug
 
std::map< std::string, std::unique_ptr< uhal::HwInterface > > m_hw_device_map
 
std::mutex m_hw_device_map_mutex
 
std::string m_monitored_device_name_master
 
std::map< uint, std::string > m_monitored_device_names_fanout
 
std::string m_monitored_device_name_endpoint
 
std::string m_monitored_device_name_hsi
 
std::map< timingcmd::TimingHwCmdId, std::function< void(const timingcmd::TimingHwCmd &)> > m_timing_hw_cmd_map_
 
std::atomic< uint64_t > m_received_hw_commands_counter
 
std::atomic< uint64_t > m_accepted_hw_commands_counter
 
std::atomic< uint64_t > m_rejected_hw_commands_counter
 
std::atomic< uint64_t > m_failed_hw_commands_counter
 
std::map< std::string, std::unique_ptr< InfoGatherer > > m_info_gatherers
 
std::mutex m_command_threads_map_mutex
 
std::map< std::string, std::unique_ptr< std::thread > > m_command_threads
 
std::mutex master_sfp_mutex
 
std::unique_ptr< dunedaq::utilities::ReusableThreadm_endpoint_scan_threads_clean_up_thread
 
std::atomic< bool > m_run_endpoint_scan_cleanup_thread
 
const timinglibs::dal::TimingHardwareManagerConfm_params
 
std::map< uint, int > m_monitored_endpoints_round_trip_times
 
- Protected Attributes inherited from dunedaq::timinglibs::TimingHardwareInterface
std::string m_connections_file
 
std::string m_uhal_log_level
 
std::unique_ptr< uhal::ConnectionManager > m_connection_manager
 

Detailed Description

TimingHardwareManagerBase creates vectors of ints and writes them to the configured output queues.

Definition at line 52 of file TimingHardwareManagerBase.hpp.

Member Typedef Documentation

◆ source_t

Constructor & Destructor Documentation

◆ TimingHardwareManagerBase() [1/3]

dunedaq::timinglibs::TimingHardwareManagerBase::TimingHardwareManagerBase ( const std::string & name)
explicit

TimingHardwareManagerBase Constructor.

Parameters
nameInstance name for this TimingHardwareManagerBase instance

Definition at line 39 of file TimingHardwareManagerBase.cpp.

40 : dunedaq::appfwk::DAQModule(name)
41 , m_hw_cmd_connection("timing_cmds")
42 , m_hw_command_receiver(nullptr)
53{
54 // register_command("start", &TimingHardwareManagerBase::do_start);
55 // register_command("stop", &TimingHardwareManagerBase::do_stop);
56 register_command("scrap", &TimingHardwareManagerBase::do_scrap);
57}
std::unique_ptr< dunedaq::utilities::ReusableThread > m_endpoint_scan_threads_clean_up_thread

◆ TimingHardwareManagerBase() [2/3]

dunedaq::timinglibs::TimingHardwareManagerBase::TimingHardwareManagerBase ( const TimingHardwareManagerBase & )
delete

TimingHardwareManagerBase is not copy-constructible.

◆ TimingHardwareManagerBase() [3/3]

dunedaq::timinglibs::TimingHardwareManagerBase::TimingHardwareManagerBase ( TimingHardwareManagerBase && )
delete

TimingHardwareManagerBase is not move-constructible.

◆ ~TimingHardwareManagerBase()

virtual dunedaq::timinglibs::TimingHardwareManagerBase::~TimingHardwareManagerBase ( )
inlinevirtual

Definition at line 66 of file TimingHardwareManagerBase.hpp.

66{}

Member Function Documentation

◆ check_hw_mon_gatherer_is_running()

std::vector< std::string > dunedaq::timinglibs::TimingHardwareManagerBase::check_hw_mon_gatherer_is_running ( const std::string & device_name)
protectedvirtual

Definition at line 268 of file TimingHardwareManagerBase.cpp.

269{
270 std::vector<std::string> running_gatherers;
271 for (auto it = m_info_gatherers.lower_bound(device_name); it != m_info_gatherers.end(); ++it)
272 {
273 TLOG_DEBUG(0) << get_name() << " Checking run state of info gatherer: " << it->first << ", and the state is " << it->second.get()->run_gathering();
274 if (it->second.get()->run_gathering())
275 {
276 running_gatherers.push_back(it->first);
277 }
278 }
279 return running_gatherers;
280}
std::map< std::string, std::unique_ptr< InfoGatherer > > m_info_gatherers
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112

◆ clean_endpoint_scan_threads()

void dunedaq::timinglibs::TimingHardwareManagerBase::clean_endpoint_scan_threads ( )
protectedvirtual

Definition at line 499 of file TimingHardwareManagerBase.cpp.

500{
501 TLOG_DEBUG(0) << "Entering clean_endpoint_scan_threads()";
502 bool break_flag = false;
503 while (!break_flag)
504 {
505 for (auto& thread : m_command_threads)
506 {
507 if (thread.second->joinable())
508 {
509 std::unique_lock map_lock(m_command_threads_map_mutex);
510 TLOG_DEBUG(2) << thread.first << " thread ready. Cleaning up.";
511 thread.second->join();
512 m_command_threads.erase(thread.first);
513 }
514 }
515
516 auto prev_clean_time = std::chrono::steady_clock::now();
517 auto next_clean_time = prev_clean_time + std::chrono::milliseconds(30);
518
519 // check running_flag periodically
520 auto flag_check_period = std::chrono::milliseconds(1);
521 auto next_flag_check_time = prev_clean_time + flag_check_period;
522
523 while (next_clean_time > next_flag_check_time + flag_check_period) {
525 TLOG_DEBUG(2) << "while waiting to clean up endpoint scan threads, negative run gatherer flag detected.";
526 break_flag = true;
527 break;
528 }
529 std::this_thread::sleep_until(next_flag_check_time);
530 next_flag_check_time = next_flag_check_time + flag_check_period;
531 }
532 if (break_flag == false) {
533 std::this_thread::sleep_until(next_clean_time);
534 }
535 }
536 TLOG_DEBUG(0) << "Exiting clean_endpoint_scan_threads()";
537}
std::map< std::string, std::unique_ptr< std::thread > > m_command_threads

◆ conf()

void dunedaq::timinglibs::TimingHardwareManagerBase::conf ( const nlohmann::json & data)
virtual

Definition at line 85 of file TimingHardwareManagerBase.cpp.

86{
91
94
96 for (auto fanout : m_params->get_monitored_device_names_fanout())
97 {
98 TLOG_DEBUG(3) << fanout->get_device() << ": device, slot: " << fanout->get_fanout_slot() << std::endl;
99 m_monitored_device_names_fanout.emplace(fanout->get_fanout_slot(), fanout->get_device());
100 }
101
104
105 configure_uhal(m_params); // configure hw ipbus connection
106
107 m_hw_command_receiver->add_callback(std::bind(&TimingHardwareManagerBase::process_hardware_command, this, std::placeholders::_1));
108
111}
void configure_uhal(const dunedaq::timinglibs::dal::TimingHardwareInterfaceConf *mdal)
virtual void process_hardware_command(timingcmd::TimingHwCmd &timing_hw_cmd)
const timinglibs::dal::TimingHardwareManagerConf * m_params
uint32_t get_gather_interval() const
Get "gather_interval" attribute value. Hardware device data gather interval [us].
const std::string & get_monitored_device_name_hsi() const
Get "monitored_device_name_hsi" attribute value. Name of hsi device to be monitored.
const std::string & get_monitored_device_name_endpoint() const
Get "monitored_device_name_endpoint" attribute value. Name of timing endpoint device to be monitored.
uint32_t get_gather_interval_debug() const
Get "gather_interval_debug" attribute value. Hardware device data gather debug interval [us].
const std::string & get_monitored_device_name_master() const
Get "monitored_device_name_master" attribute value. Name of timing master device to be monitored.
const std::vector< const dunedaq::timinglibs::dal::TimingFanoutDevice * > & get_monitored_device_names_fanout() const
Get "monitored_device_names_fanout" relationship value. Timing fanout devices to be monitored.

◆ do_scrap()

void dunedaq::timinglibs::TimingHardwareManagerBase::do_scrap ( const nlohmann::json & )
protectedvirtual

Definition at line 113 of file TimingHardwareManagerBase.cpp.

114{
115 m_hw_command_receiver->remove_callback();
116
117 auto time_of_scrap = std::chrono::high_resolution_clock::now();
118 while(m_command_threads.size())
119 {
120 auto now = std::chrono::high_resolution_clock::now();
121 auto ms_since_scrap = std::chrono::duration_cast<std::chrono::milliseconds>(now - time_of_scrap);
122 TLOG_DEBUG(0) << "Have been waiting for " << ms_since_scrap.count() << " ms for " << m_command_threads.size() << " command threads to finish...";
123 std::this_thread::sleep_for(std::chrono::microseconds(250000));
124 }
126
128
129 scrap_uhal();
130
131 m_command_threads.clear();
132 m_info_gatherers.clear();
133 m_timing_hw_cmd_map_.clear();
134 m_hw_device_map.clear();
135 m_connection_manager.reset();
136}
std::unique_ptr< uhal::ConnectionManager > m_connection_manager
std::map< std::string, std::unique_ptr< uhal::HwInterface > > m_hw_device_map
virtual void stop_hw_mon_gathering(const std::string &device_name="")
std::map< timingcmd::TimingHwCmdId, std::function< void(const timingcmd::TimingHwCmd &)> > m_timing_hw_cmd_map_
static int64_t now()

◆ endpoint_disable()

void dunedaq::timinglibs::TimingHardwareManagerBase::endpoint_disable ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 582 of file TimingHardwareManagerBase.cpp.

583{
584 timingcmd::TimingEndpointCmdPayload cmd_payload;
585 timingcmd::from_json(hw_cmd.payload, cmd_payload);
586
587 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " ept disable";
588
590 design->get_endpoint_node_plain(cmd_payload.endpoint_id)->disable();
591}
TIMING_DEV get_timing_device(const std::string &device_name)
void from_json(const data_t &j, EndpointLocation &obj)
Definition Nljs.hpp:26
design(obj, device)
Definition design.py:41

◆ endpoint_enable()

void dunedaq::timinglibs::TimingHardwareManagerBase::endpoint_enable ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 569 of file TimingHardwareManagerBase.cpp.

570{
571 timingcmd::TimingEndpointConfigureCmdPayload cmd_payload;
572 timingcmd::from_json(hw_cmd.payload, cmd_payload);
573
574 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " ept enable, adr: " << cmd_payload.address
575 << ", part: " << cmd_payload.partition;
576
578 design->get_endpoint_node_plain(cmd_payload.endpoint_id)->enable(cmd_payload.address, cmd_payload.partition);
579}

◆ endpoint_reset()

void dunedaq::timinglibs::TimingHardwareManagerBase::endpoint_reset ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 594 of file TimingHardwareManagerBase.cpp.

595{
596 timingcmd::TimingEndpointConfigureCmdPayload cmd_payload;
597 timingcmd::from_json(hw_cmd.payload, cmd_payload);
598
599 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " ept reset, adr: " << cmd_payload.address
600 << ", part: " << cmd_payload.partition;
601
603 design->get_endpoint_node_plain(cmd_payload.endpoint_id)->reset(cmd_payload.address, cmd_payload.partition);
604}

◆ gather_monitor_data()

void dunedaq::timinglibs::TimingHardwareManagerBase::gather_monitor_data ( InfoGatherer & gatherer)
protected

Definition at line 171 of file TimingHardwareManagerBase.cpp.

172{
173 auto device_name = gatherer.get_device_name();
174
175 while (gatherer.run_gathering()) {
176
177 // collect the data from the hardware
178 try {
180
181 gatherer.collect_info_from_device(*design);
182 } catch (const std::exception& excpt) {
183 ers::warning(FailedToCollectOpMonInfo(ERS_HERE, device_name, excpt));
184 }
185
186 auto prev_gather_time = std::chrono::steady_clock::now();
187 auto next_gather_time = prev_gather_time + std::chrono::microseconds(gatherer.get_gather_interval());
188
189 // check running_flag periodically
190 auto slice_period = std::chrono::microseconds(10000);
191 auto next_slice_gather_time = prev_gather_time + slice_period;
192
193 bool break_flag = false;
194 while (next_gather_time > next_slice_gather_time + slice_period) {
195 if (!gatherer.run_gathering()) {
196 TLOG_DEBUG(0) << "while waiting to gather data, negative run gatherer flag detected.";
197 break_flag = true;
198 break;
199 }
200 std::this_thread::sleep_until(next_slice_gather_time);
201 next_slice_gather_time = next_slice_gather_time + slice_period;
202 }
203 if (break_flag == false) {
204 std::this_thread::sleep_until(next_gather_time);
205 }
206 }
207}
#define ERS_HERE
void warning(const Issue &issue)
Definition ers.hpp:115

◆ get_timing_device()

template<class TIMING_DEV >
TIMING_DEV dunedaq::timinglibs::TimingHardwareManagerBase::get_timing_device ( const std::string & device_name)
protected

Definition at line 22 of file TimingHardwareManagerBase.hxx.

23{
24 auto device = get_timing_device_plain(device_name);
25 auto timing_device = cast_timing_device<TIMING_DEV>(device, device_name);
26 return timing_device;
27}
TIMING_DEV cast_timing_device(const uhal::Node *device_node, std::string timing_device_name)
const timing::TimingNode * get_timing_device_plain(const std::string &device_name)

◆ get_timing_device_plain()

const timing::TimingNode * dunedaq::timinglibs::TimingHardwareManagerBase::get_timing_device_plain ( const std::string & device_name)
protected

Definition at line 139 of file TimingHardwareManagerBase.cpp.

140{
141
142 if (!device_name.compare("")) {
143 std::stringstream message;
144 message << "UHAL device name is an empty string";
145 throw UHALDeviceNameIssue(ERS_HERE, message.str());
146 }
147
148 if (auto hw_device_entry = m_hw_device_map.find(device_name); hw_device_entry != m_hw_device_map.end()) {
149 return dynamic_cast<const timing::TimingNode*>(&hw_device_entry->second->getNode(""));
150 } else {
151 TLOG_DEBUG(0) << get_name() << ": hw device interface for: " << device_name
152 << " does not exist. I will try to create it.";
153
154 try {
155 std::lock_guard<std::mutex> hw_device_map_guard(m_hw_device_map_mutex);
156 m_hw_device_map.emplace(device_name,
157 std::make_unique<uhal::HwInterface>(m_connection_manager->getDevice(device_name)));
158 } catch (const uhal::exception::ConnectionUIDDoesNotExist& exception) {
159 std::stringstream message;
160 message << "UHAL device name not " << device_name << " in connections file";
161 throw UHALDeviceNameIssue(ERS_HERE, message.str(), exception);
162 }
163
164 TLOG_DEBUG(0) << get_name() << ": hw device interface for: " << device_name << " successfully created.";
165
166 return dynamic_cast<const timing::TimingNode*>(&m_hw_device_map.find(device_name)->second->getNode(""));
167 }
168}
caught dunedaq::conffwk::Exception exception
Unknown serialization Cannot deserialize message

◆ hsi_configure()

void dunedaq::timinglibs::TimingHardwareManagerBase::hsi_configure ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 617 of file TimingHardwareManagerBase.cpp.

618{
619 timingcmd::HSIConfigureCmdPayload cmd_payload;
620 timingcmd::from_json(hw_cmd.payload, cmd_payload);
621
622 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " hsi configure";
623
625 design->configure_hsi(
626 cmd_payload.data_source, cmd_payload.rising_edge_mask, cmd_payload.falling_edge_mask, cmd_payload.invert_edge_mask, cmd_payload.random_rate);
627}

◆ hsi_print_status()

void dunedaq::timinglibs::TimingHardwareManagerBase::hsi_print_status ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 648 of file TimingHardwareManagerBase.cpp.

649{
650 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " hsi print status";
651
653 TLOG() << std::endl << design->get_hsi_node().get_status();
654}
#define TLOG(...)
Definition macro.hpp:22

◆ hsi_reset()

void dunedaq::timinglibs::TimingHardwareManagerBase::hsi_reset ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 608 of file TimingHardwareManagerBase.cpp.

609{
610 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " hsi reset";
611
613 design->get_hsi_node().reset_hsi();
614}

◆ hsi_start()

void dunedaq::timinglibs::TimingHardwareManagerBase::hsi_start ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 630 of file TimingHardwareManagerBase.cpp.

631{
632 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " hsi start";
633
635 design->get_hsi_node().start_hsi();
636}

◆ hsi_stop()

void dunedaq::timinglibs::TimingHardwareManagerBase::hsi_stop ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 639 of file TimingHardwareManagerBase.cpp.

640{
641 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " hsi stop";
642
644 design->get_hsi_node().stop_hsi();
645}

◆ init()

void dunedaq::timinglibs::TimingHardwareManagerBase::init ( std::shared_ptr< appfwk::ConfigurationManager > mcfg)
override

Definition at line 60 of file TimingHardwareManagerBase.cpp.

61{
62 auto mod_config = mcfg->get_dal<timinglibs::dal::TimingHardwareManagerBase>(get_name());
63 m_params = mod_config->get_configuration();
64
65 // set up queues
66 for (auto con : mod_config->get_inputs())
67 {
68 if (con->get_data_type() == datatype_to_string<timingcmd::TimingHwCmd>()) {
69 m_hw_cmd_connection = con->UID();
70 TLOG() << "m_hw_cmd_connection: " << m_hw_cmd_connection;
71 }
72 }
73
74 try
75 {
76 m_hw_command_receiver = iomanager::IOManager::get()->get_receiver<timingcmd::TimingHwCmd>(m_hw_cmd_connection);
77 } catch (const ers::Issue& excpt) {
78 throw InvalidQueueFatalError(ERS_HERE, get_name(), "input", excpt);
79 }
80
81 m_endpoint_scan_threads_clean_up_thread = std::make_unique<dunedaq::utilities::ReusableThread>(0);
82}
static std::shared_ptr< IOManager > get()
Definition IOManager.hpp:40
Base class for any user define issue.
Definition Issue.hpp:69
Unknown serialization Cannot deserialize std::string datatype_to_string()

◆ io_reset()

void dunedaq::timinglibs::TimingHardwareManagerBase::io_reset ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 321 of file TimingHardwareManagerBase.cpp.

322{
323 timingcmd::IOResetCmdPayload cmd_payload;
324 timingcmd::from_json(hw_cmd.payload, cmd_payload);
325
326 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " io reset";
327
328 // io reset disrupts hw mon gathering, so stop if running
329 auto running_hw_gatherers = check_hw_mon_gatherer_is_running(hw_cmd.device);
330 for (auto& gatherer: running_hw_gatherers)
331 {
332 stop_hw_mon_gathering(gatherer);
333 }
334
336
337 if (cmd_payload.soft) {
338 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " soft io reset";
339 design->soft_reset_io();
340 } else if (!cmd_payload.clock_config.empty()) {
341 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device
342 << " io reset, with supplied clk file: " << cmd_payload.clock_config;
343 design->reset_io(cmd_payload.clock_config);
344 }
345 else
346 {
347 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device
348 << " io reset, with supplied clk source: " << cmd_payload.clock_source;
349 design->reset_io(static_cast<timing::ClockSource>(cmd_payload.clock_source));
350 }
351
352 // if hw mon gathering was running previously, start it again
353 for (auto& gatherer: running_hw_gatherers)
354 {
355 start_hw_mon_gathering(gatherer);
356 }
357}
virtual void start_hw_mon_gathering(const std::string &device_name="")
virtual std::vector< std::string > check_hw_mon_gatherer_is_running(const std::string &device_name)

◆ master_endpoint_scan()

void dunedaq::timinglibs::TimingHardwareManagerBase::master_endpoint_scan ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 383 of file TimingHardwareManagerBase.cpp.

384{
385 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " master_endpoint_scan";
386
387 std::stringstream command_thread_uid;
388 auto t = std::time(nullptr);
389 auto tm = *std::localtime(&t);
390 command_thread_uid << "enpoint_scan_cmd_at_" << std::put_time(&tm, "%d-%m-%Y %H-%M-%S") << "_cmd_num_" << m_accepted_hw_commands_counter.load();
391
392 if (m_command_threads.size() > 5)
393 {
394 ers::warning(TooManyEndpointScanThreadsQueued(ERS_HERE, m_command_threads.size()));
395 }
396 else
397 {
398 TLOG_DEBUG(1) << "Queuing: " << command_thread_uid.str();
399
400 auto thread_key = command_thread_uid.str();
401 std::unique_lock map_lock(m_command_threads_map_mutex);
402
403 m_command_threads.emplace(thread_key, std::make_unique<std::thread>(std::bind(&TimingHardwareManagerBase::perform_endpoint_scan, this, hw_cmd)));
404 }
405}
virtual void perform_endpoint_scan(const timingcmd::TimingHwCmd &hw_cmd)

◆ operator=() [1/2]

TimingHardwareManagerBase & dunedaq::timinglibs::TimingHardwareManagerBase::operator= ( const TimingHardwareManagerBase & )
delete

TimingHardwareManagerBase is not copy-assignable.

◆ operator=() [2/2]

TimingHardwareManagerBase & dunedaq::timinglibs::TimingHardwareManagerBase::operator= ( TimingHardwareManagerBase && )
delete

TimingHardwareManagerBase is not move-assignable.

◆ partition_configure()

virtual void dunedaq::timinglibs::TimingHardwareManagerBase::partition_configure ( const timingcmd::TimingHwCmd & hw_cmd)
protectedpure virtual

◆ perform_endpoint_scan()

void dunedaq::timinglibs::TimingHardwareManagerBase::perform_endpoint_scan ( const timingcmd::TimingHwCmd & hw_cmd)
protectedvirtual

Definition at line 407 of file TimingHardwareManagerBase.cpp.

408{
409 timingcmd::TimingMasterEndpointScanPayload cmd_payload;
410 timingcmd::from_json(hw_cmd.payload, cmd_payload);
411
412 for (auto& endpoint_location : cmd_payload.endpoints)
413 {
414 auto endpoint_address = endpoint_location.address;
415 auto fanout_slot = endpoint_location.fanout_slot;
416 auto sfp_slot = endpoint_location.sfp_slot;
417
418 std::unique_lock<std::mutex> master_sfp_lock(master_sfp_mutex);
419
420 TLOG_DEBUG(1) << get_name() << ": " << hw_cmd.device << " master_endpoint_scan starting: ept adr: " << endpoint_address << ", ept sfp: " << sfp_slot << ", fanout slot: " << fanout_slot;
421
422 auto master_design = get_timing_device<const timing::MasterDesignInterface*>(hw_cmd.device);
423 try
424 {
425 //master_design->get_master_node_plain()->switch_endpoint_sfp(endpoint_address, true);
426
427 if (sfp_slot >= 0)
428 {
429 if (fanout_slot >= 0)
430 {
431 // configure fanout/FIB
432 try
433 {
435 }
436 catch(const UHALDeviceClassIssue& e)
437 {
438 ers::error(e);
439 continue;
440 }
441
442 // slot 0 for board without multiple data tx paths, e.g. FMC, TLU
443 if (fanout_slot != 0)
444 {
445 // configure GIB/MIB
446 try
447 {
448 get_timing_device<const timing::MuxDesignInterface*>(hw_cmd.device)->switch_mux(fanout_slot-1);
449 }
450 catch(const UHALDeviceClassIssue& e)
451 {
452 ers::error(e);
453 continue;
454 }
455 }
456 }
457 else
458 {
459 dynamic_cast<const timing::MuxDesignInterface*>(master_design)->switch_mux(sfp_slot);
460 }
461 }
462
463 auto scan_result = master_design->get_master_node_plain()->scan_endpoint(endpoint_address, true);
464 if (scan_result.alive)
465 {
466 auto current_rtt = scan_result.round_trip_time;
467 ers::info(EndpointRTTMeasurement(ERS_HERE,fanout_slot,sfp_slot,endpoint_address,current_rtt));
468 if (m_monitored_endpoints_round_trip_times.count(endpoint_address))
469 {
470 auto previous_rtt = m_monitored_endpoints_round_trip_times[endpoint_address];
471 if (previous_rtt != current_rtt)
472 {
473 //TLOG() << "New round trip time for endpoint " << endpoint_address << " measured. Previous: "
474 // << m_monitored_endpoints_round_trip_times[endpoint_address] << ", current: " << current_rtt;
475 ers::warning(ChangedEndpointRTTMeasurement(ERS_HERE,fanout_slot,sfp_slot,endpoint_address,current_rtt,previous_rtt));
476 }
477 }
478 else
479 {
480 //TLOG() << "First measured round trip time for endpoint " << endpoint_address << " is: " << current_rtt;
481 }
482 m_monitored_endpoints_round_trip_times[endpoint_address]=current_rtt;
483 }
484 else
485 {
486 ers::error(EndpointUnresponsive(ERS_HERE,fanout_slot,sfp_slot,endpoint_address));
487 //TLOG() << endpoint_address << " endpoint was not alive...";
488 }
489 //master_design->get_master_node_plain()->switch_endpoint_sfp(endpoint_address, false);
490 }
491 catch(std::exception& e)
492 {
493 ers::error(EndpointScanFailure(ERS_HERE,e));
494 master_design->get_master_node_plain()->switch_endpoint_sfp(endpoint_address, false);
495 }
496 }
497}
void info(const Issue &issue)
Definition ers.hpp:95
void error(const Issue &issue)
Definition ers.hpp:81

◆ print_status()

void dunedaq::timinglibs::TimingHardwareManagerBase::print_status ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 360 of file TimingHardwareManagerBase.cpp.

361{
362 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " print status";
363
365 TLOG() << std::endl << design->get_status();
366}

◆ process_hardware_command()

void dunedaq::timinglibs::TimingHardwareManagerBase::process_hardware_command ( timingcmd::TimingHwCmd & timing_hw_cmd)
protectedvirtual

Definition at line 285 of file TimingHardwareManagerBase.cpp.

286{
287 std::ostringstream starting_stream;
288 starting_stream << ": Executing process_hardware_command() callback.";
289 TLOG_DEBUG(0) << get_name() << starting_stream.str();
290
292
293 TLOG_DEBUG(0) << get_name() << ": Received hardware command #" << m_received_hw_commands_counter.load()
294 << ", it is of type: " << timing_hw_cmd.id << ", targeting device: " << timing_hw_cmd.device << ", with payload: " << timing_hw_cmd.payload.dump();
295
296 std::string hw_cmd_name = timing_hw_cmd.id;
297 if (auto cmd = m_timing_hw_cmd_map_.find(hw_cmd_name); cmd != m_timing_hw_cmd_map_.end()) {
298
300
301 TLOG_DEBUG(0) << "Found hw cmd: " << hw_cmd_name;
302 try {
303 std::invoke(cmd->second, timing_hw_cmd);
304 } catch (const std::exception& exception) {
305 ers::error(FailedToExecuteHardwareCommand(ERS_HERE, hw_cmd_name, timing_hw_cmd.device, exception));
307 }
308 } else {
309 ers::error(InvalidHardwareCommandID(ERS_HERE, hw_cmd_name));
311 }
312
313 std::ostringstream exiting_stream;
314 exiting_stream << ": Finished executing process_hardware_command() callback. Received " << m_received_hw_commands_counter.load()
315 << " commands";
316 TLOG_DEBUG(0) << get_name() << exiting_stream.str();
317}

◆ register_common_hw_commands_for_design()

virtual void dunedaq::timinglibs::TimingHardwareManagerBase::register_common_hw_commands_for_design ( )
protectedpure virtual

◆ register_endpoint_hw_commands_for_design()

virtual void dunedaq::timinglibs::TimingHardwareManagerBase::register_endpoint_hw_commands_for_design ( )
protectedpure virtual

◆ register_hsi_hw_commands_for_design()

virtual void dunedaq::timinglibs::TimingHardwareManagerBase::register_hsi_hw_commands_for_design ( )
protectedpure virtual

◆ register_info_gatherer()

void dunedaq::timinglibs::TimingHardwareManagerBase::register_info_gatherer ( uint gather_interval,
const std::string & device_name,
int op_mon_level )
protected

Definition at line 210 of file TimingHardwareManagerBase.cpp.

211{
212 std::string gatherer_name = device_name + "_level_" + std::to_string(op_mon_level);
213 if (m_info_gatherers.find(gatherer_name) == m_info_gatherers.end()) {
214 std::unique_ptr<InfoGatherer> gatherer = std::make_unique<InfoGatherer>(
215 std::bind(&TimingHardwareManagerBase::gather_monitor_data, this, std::placeholders::_1),
216 gather_interval,
217 device_name,
218 op_mon_level);
219
220 TLOG_DEBUG(0) << "Registering info gatherer: " << gatherer_name;
221 m_info_gatherers.emplace(std::make_pair(gatherer_name, std::move(gatherer)));
222 } else {
223 TLOG() << "Skipping registration of " << gatherer_name << ". Already exists.";
224 }
225}

◆ register_master_hw_commands_for_design()

virtual void dunedaq::timinglibs::TimingHardwareManagerBase::register_master_hw_commands_for_design ( )
protectedpure virtual

◆ register_timing_hw_command()

template<class Child >
void dunedaq::timinglibs::TimingHardwareManagerBase::register_timing_hw_command ( const std::string & hw_cmd_id,
void(Child::* )(const timingcmd::TimingHwCmd &) )
protected

Definition at line 5 of file TimingHardwareManagerBase.hxx.

7{
8 using namespace std::placeholders;
9
10 std::string hw_cmd_name = hw_cmd_id;
11 TLOG_DEBUG(0) << "Registering timing hw command id: " << hw_cmd_name << " called with " << typeid(f).name()
12 << std::endl;
13
14 bool done = m_timing_hw_cmd_map_.emplace(hw_cmd_name, std::bind(f, dynamic_cast<Child*>(this), _1)).second;
15 if (!done) {
16 throw TimingHardwareCommandRegistrationFailed(ERS_HERE, hw_cmd_name, get_name());
17 }
18}

◆ send_fl_cmd()

void dunedaq::timinglibs::TimingHardwareManagerBase::send_fl_cmd ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 553 of file TimingHardwareManagerBase.cpp.

554{
555 timingcmd::TimingMasterSendFLCmdCmdPayload cmd_payload;
556 timingcmd::from_json(hw_cmd.payload, cmd_payload);
557
558 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " send fl cmd. Payload: " << hw_cmd.payload.dump()
559 << ", parsed data: " << cmd_payload.fl_cmd_id
560 << ", " << cmd_payload.channel
561 << ", " << cmd_payload.number_of_commands_to_send;
562
564 design->get_master_node_plain()->send_fl_cmd(cmd_payload.fl_cmd_id, cmd_payload.channel, cmd_payload.number_of_commands_to_send);
565}

◆ set_endpoint_delay()

void dunedaq::timinglibs::TimingHardwareManagerBase::set_endpoint_delay ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 541 of file TimingHardwareManagerBase.cpp.

542{
543 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device << " set endpoint delay";
544
545 timingcmd::TimingMasterSetEndpointDelayCmdPayload cmd_payload;
546 timingcmd::from_json(hw_cmd.payload, cmd_payload);
547
549 design->apply_endpoint_delay(cmd_payload.address, cmd_payload.coarse_delay, cmd_payload.fine_delay, cmd_payload.phase_delay, cmd_payload.measure_rtt, cmd_payload.control_sfp, cmd_payload.sfp_mux);
550}

◆ set_timestamp()

void dunedaq::timinglibs::TimingHardwareManagerBase::set_timestamp ( const timingcmd::TimingHwCmd & hw_cmd)
protected

Definition at line 370 of file TimingHardwareManagerBase.cpp.

371{
372 timingcmd::SyncTimestampPayload cmd_payload;
373 timingcmd::from_json(hw_cmd.payload, cmd_payload);
374
375 TLOG_DEBUG(0) << get_name() << ": " << hw_cmd.device
376 << " set timestamp, with supplied ts source: " << cmd_payload.timestamp_source;
377
379 design->sync_timestamp(static_cast<timing::TimestampSource>(cmd_payload.timestamp_source));
380}

◆ start_hw_mon_gathering()

void dunedaq::timinglibs::TimingHardwareManagerBase::start_hw_mon_gathering ( const std::string & device_name = "")
protectedvirtual

Definition at line 228 of file TimingHardwareManagerBase.cpp.

229{
230 // start all gatherers if no device name is given
231 if (!device_name.compare("")) {
232 TLOG_DEBUG(0) << get_name() << " Starting all info gatherers";
233 for (auto it = m_info_gatherers.begin(); it != m_info_gatherers.end(); ++it)
234 it->second.get()->start_gathering_thread();
235 } else {
236 // find gatherer for suppled device name and start it
237 bool gatherer_found=false;
238 for (auto it = m_info_gatherers.lower_bound(device_name); it != m_info_gatherers.end(); ++it) {
239 TLOG_DEBUG(0) << get_name() << " Starting info gatherer: " << it->first;
240 it->second.get()->start_gathering_thread();
241 gatherer_found=true;
242 }
243 if (!gatherer_found) ers::warning(AttemptedToControlNonExantInfoGatherer(ERS_HERE, "start", device_name));
244 }
245}

◆ stop_hw_mon_gathering()

void dunedaq::timinglibs::TimingHardwareManagerBase::stop_hw_mon_gathering ( const std::string & device_name = "")
protectedvirtual

Definition at line 248 of file TimingHardwareManagerBase.cpp.

249{
250 // stop all gatherers if no device name is given
251 if (!device_name.compare("")) {
252 TLOG_DEBUG(0) << get_name() << " Stopping all info gatherers";
253 for (auto it = m_info_gatherers.begin(); it != m_info_gatherers.end(); ++it)
254 it->second.get()->stop_gathering_thread();
255 } else {
256 // find gatherer for suppled device name and stop it
257 bool gatherer_found=false;
258 for (auto it = m_info_gatherers.lower_bound(device_name); it != m_info_gatherers.end(); ++it) {
259 TLOG_DEBUG(0) << get_name() << " Stopping info gatherer: " << it->first;
260 it->second.get()->stop_gathering_thread();
261 gatherer_found=true;
262 }
263 if (!gatherer_found) ers::warning(AttemptedToControlNonExantInfoGatherer(ERS_HERE, "stop", device_name));
264 }
265}

Member Data Documentation

◆ m_accepted_hw_commands_counter

std::atomic<uint64_t> dunedaq::timinglibs::TimingHardwareManagerBase::m_accepted_hw_commands_counter
protected

Definition at line 144 of file TimingHardwareManagerBase.hpp.

◆ m_command_threads

std::map<std::string, std::unique_ptr<std::thread> > dunedaq::timinglibs::TimingHardwareManagerBase::m_command_threads
protected

Definition at line 159 of file TimingHardwareManagerBase.hpp.

◆ m_command_threads_map_mutex

std::mutex dunedaq::timinglibs::TimingHardwareManagerBase::m_command_threads_map_mutex
protected

Definition at line 158 of file TimingHardwareManagerBase.hpp.

◆ m_endpoint_scan_threads_clean_up_thread

std::unique_ptr<dunedaq::utilities::ReusableThread> dunedaq::timinglibs::TimingHardwareManagerBase::m_endpoint_scan_threads_clean_up_thread
protected

Definition at line 163 of file TimingHardwareManagerBase.hpp.

◆ m_failed_hw_commands_counter

std::atomic<uint64_t> dunedaq::timinglibs::TimingHardwareManagerBase::m_failed_hw_commands_counter
protected

Definition at line 146 of file TimingHardwareManagerBase.hpp.

◆ m_gather_interval

uint dunedaq::timinglibs::TimingHardwareManagerBase::m_gather_interval
protected

Definition at line 88 of file TimingHardwareManagerBase.hpp.

◆ m_gather_interval_debug

uint dunedaq::timinglibs::TimingHardwareManagerBase::m_gather_interval_debug
protected

Definition at line 89 of file TimingHardwareManagerBase.hpp.

◆ m_hw_cmd_connection

std::string dunedaq::timinglibs::TimingHardwareManagerBase::m_hw_cmd_connection
protected

Definition at line 82 of file TimingHardwareManagerBase.hpp.

◆ m_hw_command_receiver

std::shared_ptr<source_t> dunedaq::timinglibs::TimingHardwareManagerBase::m_hw_command_receiver
protected

Definition at line 84 of file TimingHardwareManagerBase.hpp.

◆ m_hw_device_map

std::map<std::string, std::unique_ptr<uhal::HwInterface> > dunedaq::timinglibs::TimingHardwareManagerBase::m_hw_device_map
protected

Definition at line 92 of file TimingHardwareManagerBase.hpp.

◆ m_hw_device_map_mutex

std::mutex dunedaq::timinglibs::TimingHardwareManagerBase::m_hw_device_map_mutex
protected

Definition at line 93 of file TimingHardwareManagerBase.hpp.

◆ m_info_gatherers

std::map<std::string, std::unique_ptr<InfoGatherer> > dunedaq::timinglibs::TimingHardwareManagerBase::m_info_gatherers
protected

Definition at line 149 of file TimingHardwareManagerBase.hpp.

◆ m_monitored_device_name_endpoint

std::string dunedaq::timinglibs::TimingHardwareManagerBase::m_monitored_device_name_endpoint
protected

Definition at line 98 of file TimingHardwareManagerBase.hpp.

◆ m_monitored_device_name_hsi

std::string dunedaq::timinglibs::TimingHardwareManagerBase::m_monitored_device_name_hsi
protected

Definition at line 99 of file TimingHardwareManagerBase.hpp.

◆ m_monitored_device_name_master

std::string dunedaq::timinglibs::TimingHardwareManagerBase::m_monitored_device_name_master
protected

Definition at line 96 of file TimingHardwareManagerBase.hpp.

◆ m_monitored_device_names_fanout

std::map<uint, std::string> dunedaq::timinglibs::TimingHardwareManagerBase::m_monitored_device_names_fanout
protected

Definition at line 97 of file TimingHardwareManagerBase.hpp.

◆ m_monitored_endpoints_round_trip_times

std::map<uint,int> dunedaq::timinglibs::TimingHardwareManagerBase::m_monitored_endpoints_round_trip_times
protected

Definition at line 166 of file TimingHardwareManagerBase.hpp.

◆ m_params

const timinglibs::dal::TimingHardwareManagerConf* dunedaq::timinglibs::TimingHardwareManagerBase::m_params
protected

Definition at line 165 of file TimingHardwareManagerBase.hpp.

◆ m_received_hw_commands_counter

std::atomic<uint64_t> dunedaq::timinglibs::TimingHardwareManagerBase::m_received_hw_commands_counter
protected

Definition at line 143 of file TimingHardwareManagerBase.hpp.

◆ m_rejected_hw_commands_counter

std::atomic<uint64_t> dunedaq::timinglibs::TimingHardwareManagerBase::m_rejected_hw_commands_counter
protected

Definition at line 145 of file TimingHardwareManagerBase.hpp.

◆ m_run_endpoint_scan_cleanup_thread

std::atomic<bool> dunedaq::timinglibs::TimingHardwareManagerBase::m_run_endpoint_scan_cleanup_thread
protected

Definition at line 164 of file TimingHardwareManagerBase.hpp.

◆ m_timing_hw_cmd_map_

std::map<timingcmd::TimingHwCmdId, std::function<void(const timingcmd::TimingHwCmd&)> > dunedaq::timinglibs::TimingHardwareManagerBase::m_timing_hw_cmd_map_
protected

Definition at line 112 of file TimingHardwareManagerBase.hpp.

◆ master_sfp_mutex

std::mutex dunedaq::timinglibs::TimingHardwareManagerBase::master_sfp_mutex
protected

Definition at line 160 of file TimingHardwareManagerBase.hpp.


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