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}
55
56std::vector<ValidationReport>
57ConfigurationManager::initialize(bool throw_on_fatal)
58{
59 std::vector<ValidationReport> reports;
60 if (m_initialized) {
61 return reports;
62 }
63 TLOG_DBG(TLVL_APP) << "getting app " << m_app_name;
64 m_application = m_confdb->get<confmodel::DaqApplication>(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 auto daq_app = m_application->cast<confmodel::DaqApplication>();
73 if(!daq_app && !smart_daq_app) {
74 throw(NotADaqApplication(ERS_HERE, m_application->UID()));
75 }
76
77 if (smart_daq_app) {
78 smart_daq_app->generate_modules(m_session);
79 }
80
81 m_modules = m_application->get_modules();
82
83 for (auto& plan : m_application->get_action_plans()) {
84 auto cmd = plan->get_command()->get_cmd();
85 TLOG_DBG(TLVL_ACTION_PLAN) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
86 if (m_action_plans.count(cmd)) {
87 reports.emplace_back(ValidationReport::Severity::Fatal,
88 m_app_name,
89 "N/A",
90 cmd,
91 "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
92 if (throw_on_fatal)
93 throw ActionPlanValidationFailed(
94 ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message());
95 else
96 ers::error(ActionPlanValidationFailed(
97 ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message()));
98 }
99 m_action_plans[cmd] = plan;
100 }
101
102 m_connsvc_config = m_session->get_connectivity_service();
103
104 std::set<std::string> connectionsAdded;
105 for (auto mod : m_modules) {
106 TLOG_DBG(TLVL_MODULE) << "initialising " << mod->class_name() << " module " << mod->UID();
107 auto connections = mod->get_inputs();
108 auto outputs = mod->get_outputs();
109 connections.insert(connections.end(), outputs.begin(), outputs.end());
110 for (auto con : connections) {
111 auto [c, inserted] = connectionsAdded.insert(con->UID());
112 if (!inserted) {
113 // Already handled this connection, don't add it again
114 continue;
115 }
116 auto queue = m_confdb->cast<confmodel::Queue>(con);
117 if (queue) {
118 TLOG_DBG(TLVL_QUEUE) << "Adding queue " << queue->UID();
119 m_queues.emplace_back(queue);
120 }
121 auto net_con = m_confdb->cast<confmodel::NetworkConnection>(con);
122 if (net_con) {
123 m_networkconnections.emplace_back(net_con);
124 }
125 }
126 }
127
128 m_initialized = true;
129 return reports;
130}
131
133ConfigurationManager::get_action_plan(std::string cmd) const
134{
135 if (m_action_plans.count(cmd)) {
136 return m_action_plans.at(cmd);
137 }
138 return nullptr;
139}
@ 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.
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
void error(const Issue &issue)
Definition ers.hpp:81