DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigurationManager.cpp
Go to the documentation of this file.
1
11
19#include "confmodel/Queue.hpp"
21#include "confmodel/Service.hpp"
22#include "confmodel/Session.hpp"
23
24#include <set>
25#include <string>
26
27using namespace dunedaq::appfwk;
28
29enum
30{
36
37};
38
39ConfigurationManager::ConfigurationManager(std::string const& config_spec,
40 std::string const& app_name,
41 std::string const& session_name)
42 : m_confdb(new conffwk::Configuration(config_spec))
43 , m_app_name(app_name)
44 , m_session_name(session_name)
45{
46 TLOG() << "configSpec <" << config_spec << "> session name " << session_name << " application name " << app_name;
47
48 TLOG_DBG(TLVL_SESSION) << "getting session " << session_name;
49 m_session = m_confdb->get<confmodel::Session>(session_name);
50 if (m_session == nullptr) {
51 TLOG() << "Failed to get session " << session_name;
52 throw MissingComponent(ERS_HERE, "Session " + session_name);
53 }
54 m_helper = std::make_shared<appmodel::ConfigurationHelper>(m_session);
55}
56
57std::vector<ValidationReport>
58ConfigurationManager::initialize(bool throw_on_fatal)
59{
60 std::vector<ValidationReport> reports;
61 if (m_initialized) {
62 return reports;
63 }
64 TLOG_DBG(TLVL_APP) << "getting app " << m_app_name;
65 m_application = m_confdb->get<confmodel::DaqApplication>(m_app_name);
66 if (m_application == nullptr) {
67 TLOG() << "Failed to get app " << m_app_name;
68 throw MissingComponent(ERS_HERE, "Application " + m_app_name);
69 }
70
71 TLOG_DBG(TLVL_APP) << "getting modules for app " << m_app_name;
72 auto daq_app = m_application->cast<confmodel::DaqApplication>();
73 if(daq_app == nullptr) {
74 throw(NotADaqApplication(ERS_HERE, m_application->UID()));
75 }
76
77 auto smart_daq_app = m_application->cast<appmodel::SmartDaqApplication>();
78 if (smart_daq_app != nullptr) {
79 smart_daq_app->generate_modules(m_helper);
80 }
81
82 m_modules = m_application->get_modules();
83
84 for (auto& plan : m_application->get_action_plans()) {
85 auto cmd = plan->get_command()->get_cmd();
86 TLOG_DBG(TLVL_ACTION_PLAN) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
87 if (m_action_plans.count(cmd)) {
88 reports.emplace_back(ValidationReport::Severity::Fatal,
89 m_app_name,
90 "N/A",
91 cmd,
92 "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
93 if (throw_on_fatal)
94 throw ActionPlanValidationFailed(
95 ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message());
96 else
97 ers::error(ActionPlanValidationFailed(
98 ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message()));
99 }
100 m_action_plans[cmd] = plan;
101 }
102
103 m_connsvc_config = m_session->get_connectivity_service();
104
105 std::set<std::string> connectionsAdded;
106 for (auto mod : m_modules) {
107 TLOG_DBG(TLVL_MODULE) << "initialising " << mod->class_name() << " module " << mod->UID();
108 auto connections = mod->get_inputs();
109 auto outputs = mod->get_outputs();
110 connections.insert(connections.end(), outputs.begin(), outputs.end());
111 for (auto con : connections) {
112 auto [c, inserted] = connectionsAdded.insert(con->UID());
113 if (!inserted) {
114 // Already handled this connection, don't add it again
115 continue;
116 }
117 auto queue = m_confdb->cast<confmodel::Queue>(con);
118 if (queue) {
119 TLOG_DBG(TLVL_QUEUE) << "Adding queue " << queue->UID();
120 m_queues.emplace_back(queue);
121 }
122 auto net_con = m_confdb->cast<confmodel::NetworkConnection>(con);
123 if (net_con) {
124 m_networkconnections.emplace_back(net_con);
125 }
126 }
127 }
128
129 m_initialized = true;
130 return reports;
131}
132
134ConfigurationManager::get_action_plan(std::string cmd) const
135{
136 if (m_action_plans.count(cmd)) {
137 return m_action_plans.at(cmd);
138 }
139 return nullptr;
140}
@ TLVL_ACTION_PLAN
#define ERS_HERE
const TARGET * cast() const noexcept
Casts object to different class.
const std::vector< const dunedaq::confmodel::DaqModule * > & get_modules() const
Get "modules" relationship value.
conffwk entry point
#define TLOG(...)
Definition macro.hpp:22
void error(const Issue &issue)
Definition ers.hpp:81