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 , m_oks_config_spec(config_spec)
46{
47 TLOG() << "configSpec <" << config_spec << "> session name " << session_name << " application name " << app_name;
48
49 TLOG_DBG(TLVL_SESSION) << "getting session " << session_name;
50 m_session = m_confdb->get<confmodel::Session>(session_name);
51 if (m_session == nullptr) {
52 TLOG() << "Failed to get session " << session_name;
53 throw MissingComponent(ERS_HERE, "Session " + session_name);
54 }
55}
56
57void
58ConfigurationManager::initialize()
59{
60 if (m_initialized) {
61 return;
62 }
63 TLOG_DBG(TLVL_APP) << "getting app " << m_app_name;
64 m_application = m_confdb->get<confmodel::Application>(m_app_name);
65 if (m_application == nullptr) {
66 TLOG() << "Failed to get app " << m_app_name;
67 throw MissingComponent(ERS_HERE, "Application " + m_app_name);
68 }
69
70 TLOG_DBG(TLVL_APP) << "getting modules for app " << m_app_name;
71 auto smart_daq_app = m_application->cast<appmodel::SmartDaqApplication>();
72 if (smart_daq_app) {
73 auto cpos = m_oks_config_spec.find(":") + 1;
74 std::string oksFile = m_oks_config_spec.substr(cpos); // Strip off "oksconflibs:"
75 m_modules = smart_daq_app->generate_modules(m_session);
76
77 for (auto& plan : smart_daq_app->get_action_plans()) {
78 auto cmd = plan->get_command()->get_cmd();
79 TLOG_DBG(TLVL_ACTION_PLAN) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
80 if (m_action_plans.count(cmd)) {
81 throw ActionPlanValidationFailed(
82 ERS_HERE, cmd, "N/A", "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
83 }
84 m_action_plans[cmd] = plan;
85 }
86 } else {
87 auto daq_app = m_application->cast<confmodel::DaqApplication>();
88 if (daq_app) {
89 m_modules = daq_app->get_modules();
90
91 for (auto& plan : daq_app->get_action_plans()) {
92 auto cmd = plan->get_command()->get_cmd();
93 TLOG_DBG(TLVL_ACTION_PLAN) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
94 if (m_action_plans.count(cmd)) {
95 throw ActionPlanValidationFailed(
96 ERS_HERE, cmd, "N/A", "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
97 }
98 m_action_plans[cmd] = plan;
99 }
100 } else {
101 throw(NotADaqApplication(ERS_HERE, m_application->UID()));
102 }
103 }
104
105 m_connsvc_config = m_session->get_connectivity_service();
106
107 std::set<std::string> connectionsAdded;
108 for (auto mod : m_modules) {
109 TLOG_DBG(TLVL_MODULE) << "initialising " << mod->class_name() << " module " << mod->UID();
110 auto connections = mod->get_inputs();
111 auto outputs = mod->get_outputs();
112 connections.insert(connections.end(), outputs.begin(), outputs.end());
113 for (auto con : connections) {
114 auto [c, inserted] = connectionsAdded.insert(con->UID());
115 if (!inserted) {
116 // Already handled this connection, don't add it again
117 continue;
118 }
119 auto queue = m_confdb->cast<confmodel::Queue>(con);
120 if (queue) {
121 TLOG_DBG(TLVL_QUEUE) << "Adding queue " << queue->UID();
122 m_queues.emplace_back(queue);
123 }
124 auto net_con = m_confdb->cast<confmodel::NetworkConnection>(con);
125 if (net_con) {
126 m_networkconnections.emplace_back(net_con);
127 }
128 }
129 }
130
131 m_initialized = true;
132}
133
135ConfigurationManager::action_plan(std::string cmd) const
136{
137 if (m_action_plans.count(cmd)) {
138 return m_action_plans.at(cmd);
139 }
140 return nullptr;
141}
@ TLVL_ACTION_PLAN
#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:119
conffwk entry point
#define TLOG(...)
Definition macro.hpp:22