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, std::string timing_entity_description, const Vs& ... args)
5{
6 bool conf_commands_sent=false;
7
8 if (!m_hardware_state_recovery_enabled)
9 {
10 TLOG_DEBUG(3) << "State recovery not enabled. Sending configure commands...";
11 send_configure_hardware_commands(data);
12 conf_commands_sent=true;
13 }
14
15 auto time_of_conf = std::chrono::high_resolution_clock::now();
16 while (true)
17 {
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 << ", infos received: " << m_device_infos_received_count;
22
23 if (m_device_ready.load() && m_device_infos_received_count.load())
24 {
25 if (!conf_commands_sent)
26 {
27 TLOG_DEBUG(3) << "State recovered!";
28 }
29 break;
30 }
31
32 if (ms_since_conf > m_device_ready_timeout)
33 {
34 if (conf_commands_sent)
35 {
36 throw T(ERS_HERE,m_timing_device, args...);
37 }
38 else
39 {
40 TLOG_DEBUG(3) << "State not recovered! Sending configure commands...";
41 send_configure_hardware_commands(data);
42 time_of_conf = std::chrono::high_resolution_clock::now();
43 conf_commands_sent=true;
44 }
45 }
46 TLOG_DEBUG(3) << "Waiting for " << timing_entity_description << " " << m_timing_device << " to become ready for (ms) " << ms_since_conf.count();
47 std::this_thread::sleep_for(std::chrono::microseconds(250000));
48 }
49}
50
51}
#define ERS_HERE
static int64_t now()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112