Line data Source code
1 : /**
2 : * @file ConfigurationManager.cpp ConfigurationManager class
3 : * implementation
4 : *
5 : * This is part of the DUNE DAQ Software Suite, copyright 2023.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 :
10 : #include "appfwk/ConfigurationManager.hpp"
11 :
12 : #include "appmodel/SmartDaqApplication.hpp"
13 : #include "conffwk/Configuration.hpp"
14 : #include "confmodel/DaqApplication.hpp"
15 : #include "confmodel/DaqModule.hpp"
16 : #include "confmodel/DaqModulesGroupByType.hpp"
17 : #include "confmodel/FSMCommand.hpp"
18 : #include "confmodel/NetworkConnection.hpp"
19 : #include "confmodel/Queue.hpp"
20 : #include "confmodel/ResourceSet.hpp"
21 : #include "confmodel/Service.hpp"
22 : #include "confmodel/Session.hpp"
23 :
24 : #include <set>
25 : #include <string>
26 :
27 : using namespace dunedaq::appfwk;
28 :
29 : enum
30 : {
31 : TLVL_SESSION = 5,
32 : TLVL_APP = 6,
33 : TLVL_MODULE = 7,
34 : TLVL_QUEUE = 8,
35 : TLVL_ACTION_PLAN = 9,
36 :
37 : };
38 :
39 44 : ConfigurationManager::ConfigurationManager(std::string const& config_spec,
40 : std::string const& app_name,
41 44 : std::string const& session_name)
42 44 : : m_confdb(new conffwk::Configuration(config_spec))
43 44 : , m_app_name(app_name)
44 88 : , m_session_name(session_name)
45 : {
46 88 : TLOG() << "configSpec <" << config_spec << "> session name " << session_name << " application name " << app_name;
47 :
48 44 : TLOG_DBG(TLVL_SESSION) << "getting session " << session_name;
49 44 : m_session = m_confdb->get<confmodel::Session>(session_name);
50 44 : if (m_session == nullptr) {
51 2 : TLOG() << "Failed to get session " << session_name;
52 1 : throw MissingComponent(ERS_HERE, "Session " + session_name);
53 : }
54 43 : m_helper = std::make_shared<appmodel::ConfigurationHelper>(m_session);
55 51 : }
56 :
57 : std::vector<ValidationReport>
58 149 : ConfigurationManager::initialize(bool throw_on_fatal)
59 : {
60 149 : std::vector<ValidationReport> reports;
61 149 : if (m_initialized) {
62 : return reports;
63 : }
64 38 : TLOG_DBG(TLVL_APP) << "getting app " << m_app_name;
65 38 : m_application = m_confdb->get<confmodel::DaqApplication>(m_app_name);
66 38 : if (m_application == nullptr) {
67 2 : TLOG() << "Failed to get app " << m_app_name;
68 1 : throw MissingComponent(ERS_HERE, "Application " + m_app_name);
69 : }
70 :
71 37 : TLOG_DBG(TLVL_APP) << "getting modules for app " << m_app_name;
72 37 : auto daq_app = m_application->cast<confmodel::DaqApplication>();
73 37 : if(daq_app == nullptr) {
74 0 : throw(NotADaqApplication(ERS_HERE, m_application->UID()));
75 : }
76 :
77 37 : auto smart_daq_app = m_application->cast<appmodel::SmartDaqApplication>();
78 37 : if (smart_daq_app != nullptr) {
79 0 : smart_daq_app->generate_modules(m_helper);
80 : }
81 :
82 37 : m_modules = m_application->get_modules();
83 :
84 73 : for (auto& plan : m_application->get_action_plans()) {
85 37 : auto cmd = plan->get_command()->get_cmd();
86 37 : TLOG_DBG(TLVL_ACTION_PLAN) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
87 37 : if (m_action_plans.count(cmd)) {
88 1 : reports.emplace_back(ValidationReport::Severity::Fatal,
89 : m_app_name,
90 : "N/A",
91 : cmd,
92 2 : "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
93 1 : if (throw_on_fatal)
94 1 : throw ActionPlanValidationFailed(
95 1 : ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message());
96 : else
97 0 : ers::error(ActionPlanValidationFailed(
98 0 : ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message()));
99 : }
100 36 : m_action_plans[cmd] = plan;
101 37 : }
102 :
103 36 : m_connsvc_config = m_session->get_connectivity_service();
104 :
105 36 : std::set<std::string> connectionsAdded;
106 93 : for (auto mod : m_modules) {
107 57 : TLOG_DBG(TLVL_MODULE) << "initialising " << mod->class_name() << " module " << mod->UID();
108 57 : auto connections = mod->get_inputs();
109 57 : auto outputs = mod->get_outputs();
110 57 : connections.insert(connections.end(), outputs.begin(), outputs.end());
111 171 : for (auto con : connections) {
112 114 : auto [c, inserted] = connectionsAdded.insert(con->UID());
113 114 : if (!inserted) {
114 : // Already handled this connection, don't add it again
115 45 : continue;
116 : }
117 69 : auto queue = m_confdb->cast<confmodel::Queue>(con);
118 69 : if (queue) {
119 45 : TLOG_DBG(TLVL_QUEUE) << "Adding queue " << queue->UID();
120 45 : m_queues.emplace_back(queue);
121 : }
122 69 : auto net_con = m_confdb->cast<confmodel::NetworkConnection>(con);
123 69 : if (net_con) {
124 24 : m_networkconnections.emplace_back(net_con);
125 : }
126 : }
127 57 : }
128 :
129 36 : m_initialized = true;
130 36 : return reports;
131 38 : }
132 :
133 : const dunedaq::confmodel::ActionPlan*
134 15 : ConfigurationManager::get_action_plan(std::string cmd) const
135 : {
136 15 : if (m_action_plans.count(cmd)) {
137 12 : return m_action_plans.at(cmd);
138 : }
139 : return nullptr;
140 : }
|