DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TimingController.hxx
Go to the documentation of this file.
2template<class T, class... Vs>
3void
4TimingController::configure_hardware_or_recover_state(const nlohmann::json& data,
5 std::string timing_entity_description,
6 const Vs&... args)
7{
8 bool conf_commands_sent = false;
9
10 if (!m_hardware_state_recovery_enabled) {
11 TLOG_DEBUG(3) << "State recovery not enabled. Sending configure commands...";
12 send_configure_hardware_commands(static_cast<CommandData_t>(data));
13 conf_commands_sent = true;
14 }
15
16 auto time_of_conf = std::chrono::high_resolution_clock::now();
17 while (true) {
18 auto now = std::chrono::high_resolution_clock::now();
19 auto ms_since_conf = std::chrono::duration_cast<std::chrono::milliseconds>(now - time_of_conf);
20
21 TLOG_DEBUG(3) << timing_entity_description << " (" << m_timing_device << ") ready: " << m_device_ready
22 << ", infos received: " << m_device_infos_received_count;
23
24 if (m_device_ready.load() && m_device_infos_received_count.load()) {
25 if (!conf_commands_sent) {
26 TLOG_DEBUG(3) << "State recovered!";
27 }
28 break;
29 }
30
31 if (ms_since_conf > m_device_ready_timeout) {
32 if (conf_commands_sent) {
33 throw T(ERS_HERE, m_timing_device, args...);
34 } else {
35 TLOG_DEBUG(3) << "State not recovered! Sending configure commands...";
36 send_configure_hardware_commands(static_cast<CommandData_t>(data));
37 time_of_conf = std::chrono::high_resolution_clock::now();
38 conf_commands_sent = true;
39 }
40 }
41 TLOG_DEBUG(3) << "Waiting for " << timing_entity_description << " " << m_timing_device
42 << " to become ready for (ms) " << ms_since_conf.count();
43 std::this_thread::sleep_for(std::chrono::microseconds(250000));
44 }
45}
46
47}
#define ERS_HERE
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116