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
29ConfigurationManager::ConfigurationManager(std::string& config_spec, std::string& app_name, std::string& session_name)
30 : m_confdb(new conffwk::Configuration(config_spec))
31 , m_app_name(app_name)
32 , m_session_name(session_name)
33 , m_oks_config_spec(config_spec)
34{
35 TLOG() << "configSpec <" << config_spec << "> session name " << session_name << " application name " << app_name;
36
37 TLOG_DBG(5) << "getting session " << session_name;
38 m_session = m_confdb->get<confmodel::Session>(session_name);
39 if (m_session == nullptr) {
40 TLOG() << "Failed to get session " << session_name;
41 throw MissingComponent(ERS_HERE, "Session " + session_name);
42 }
43}
44
45void
46ConfigurationManager::initialize()
47{
48 if (m_initialized) {
49 return;
50 }
51 TLOG_DBG(5) << "getting app " << m_app_name;
52 m_application = m_confdb->get<confmodel::Application>(m_app_name);
53 if (m_application == nullptr) {
54 TLOG() << "Failed to get app " << m_app_name;
55 throw MissingComponent(ERS_HERE, "Application " + m_app_name);
56 }
57
58 TLOG_DBG(5) << "getting modules for app " << m_app_name;
59 auto smart_daq_app = m_application->cast<appmodel::SmartDaqApplication>();
60 if (smart_daq_app) {
61 auto cpos = m_oks_config_spec.find(":") + 1;
62 std::string oksFile = m_oks_config_spec.substr(cpos); // Strip off "oksconflibs:"
63 m_modules = smart_daq_app->generate_modules(m_session);
64
65 for (auto& plan : smart_daq_app->get_action_plans()) {
66 auto cmd = plan->get_command()->get_cmd();
67 TLOG_DBG(6) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
68 if (m_action_plans.count(cmd)) {
69 throw ActionPlanValidationFailed(
70 ERS_HERE, cmd, "N/A", "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
71 }
72 for (auto& step : plan->get_steps()) {
73 auto step_by_type = step->cast<confmodel::DaqModulesGroupByType>();
74 if (step_by_type == nullptr) {
75 throw ActionPlanValidationFailed(
76 ERS_HERE, cmd, "N/A", "ActionPlans for SmartDaqApplications must use DaqModulesGroupByType");
77 }
78 }
79 m_action_plans[cmd] = plan;
80 }
81 } else {
82 auto daq_app = m_application->cast<confmodel::DaqApplication>();
83 if (daq_app) {
84 m_modules = daq_app->get_modules();
85
86 for (auto& plan : daq_app->get_action_plans()) {
87 auto cmd = plan->get_command()->get_cmd();
88 TLOG_DBG(6) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
89 if (m_action_plans.count(cmd)) {
90 throw ActionPlanValidationFailed(
91 ERS_HERE, cmd, "N/A", "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
92 }
93 m_action_plans[cmd] = plan;
94 }
95 } else {
96 throw(NotADaqApplication(ERS_HERE, m_application->UID()));
97 }
98 }
99
100 m_connsvc_config = m_session->get_connectivity_service();
101
102 std::set<std::string> connectionsAdded;
103 for (auto mod : m_modules) {
104 TLOG() << "initialising " << mod->class_name() << " module " << mod->UID();
105 auto connections = mod->get_inputs();
106 auto outputs = mod->get_outputs();
107 connections.insert(connections.end(), outputs.begin(), outputs.end());
108 for (auto con : connections) {
109 auto [c, inserted] = connectionsAdded.insert(con->UID());
110 if (!inserted) {
111 // Already handled this connection, don't add it again
112 continue;
113 }
114 auto queue = m_confdb->cast<confmodel::Queue>(con);
115 if (queue) {
116 TLOG() << "Adding queue " << queue->UID();
117 m_queues.emplace_back(queue);
118 }
119 auto net_con = m_confdb->cast<confmodel::NetworkConnection>(con);
120 if (net_con) {
121 m_networkconnections.emplace_back(net_con);
122 }
123 }
124 }
125
126 m_initialized = true;
127}
128
130ConfigurationManager::action_plan(std::string cmd) const
131{
132 if (m_action_plans.count(cmd)) {
133 return m_action_plans.at(cmd);
134 }
135 return nullptr;
136}
#define ERS_HERE
const TARGET * cast() const noexcept
Casts object to different class.
virtual std::vector< const dunedaq::conffwk::DalObject * > get(const std::string &name, bool upcast_unregistered=true) const
Get values of relationships and results of some algorithms as a vector of dunedaq::conffwk::DalObject...
Definition Session.cpp:117
conffwk entry point
#define TLOG(...)
Definition macro.hpp:22