Skip to content

Commit 41ffb37

Browse files
authored
Merge pull request #90 from DUNE-DAQ/gcrone/enable_disable_methods
Add enable and disable methods to ResourceTree
2 parents c325ced + 10448f1 commit 41ffb37

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

pybindsrc/dal_methods.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ namespace dunedaq::confmodel::python {
5959
return apps;
6060
}
6161

62+
63+
void disable_component(Configuration& db,
64+
const std::string& session_id,
65+
const std::string& component_id) {
66+
auto session_ptr = const_cast<dunedaq::confmodel::Session*>(db.get<dunedaq::confmodel::Session>(session_id));
67+
auto component_ptr = db.get<dunedaq::confmodel::Resource>(component_id);
68+
if (session_ptr == nullptr) {
69+
throw (std::runtime_error(std::format("Session {} not found", session_id)));
70+
}
71+
if (component_ptr == nullptr) {
72+
throw (std::runtime_error(std::format("Component {} not found", component_id)));
73+
}
74+
session_ptr->disable(component_ptr);
75+
}
76+
void enable_component(Configuration& db,
77+
const std::string& session_id,
78+
const std::string& component_id) {
79+
auto session_ptr = const_cast<dunedaq::confmodel::Session*>(db.get<dunedaq::confmodel::Session>(session_id));
80+
auto component_ptr = db.get<dunedaq::confmodel::Resource>(component_id);
81+
if (session_ptr == nullptr) {
82+
throw (std::runtime_error(std::format("Session {} not found", session_id)));
83+
}
84+
if (component_ptr == nullptr) {
85+
throw (std::runtime_error(std::format("Component {} not found", component_id)));
86+
}
87+
session_ptr->enable(component_ptr);
88+
}
89+
90+
6291
bool component_disabled(Configuration& db,
6392
const std::string& session_id,
6493
const std::string& component_id) {
@@ -111,11 +140,11 @@ namespace dunedaq::confmodel::python {
111140
return app->construct_commandline_parameters(db, session);
112141
}
113142

114-
std::vector<std::string> rc_application_construct_commandline_parameters(const Configuration& db,
143+
std::vector<std::string> rc_application_construct_commandline_parameters(Configuration& db,
115144
const std::string& session_id,
116145
const std::string& app_id) {
117-
const auto* app = const_cast<Configuration&>(db).get<dunedaq::confmodel::RCApplication>(app_id);
118-
const auto* session = const_cast<Configuration&>(db).get<dunedaq::confmodel::Session>(session_id);
146+
const auto* app = db.get<dunedaq::confmodel::RCApplication>(app_id);
147+
const auto* session = db.get<dunedaq::confmodel::Session>(session_id);
119148
return app->construct_commandline_parameters(db, session);
120149
}
121150

@@ -179,6 +208,9 @@ register_dal_methods(py::module& m)
179208
m.def("session_get_all_applications", &session_get_all_applications, "Get list of ALL applications (regardless of enabled/disabled state) in the requested session");
180209
m.def("session_get_enabled_applications", &session_get_enabled_applications, "Get list of enabled applications in the requested session");
181210

211+
m.def("disable_component", &disable_component, "Disable a Resource-derived object (e.g. a Segment)");
212+
m.def("enable_component", &enable_component, "Enable a Resource-derived object (e.g. a Segment)");
213+
182214
m.def("component_disabled", &component_disabled, "Determine if a Resource-derived object (e.g. a Segment) has been disabled");
183215
m.def("component_get_parents", &component_get_parents, "Get the Resource-derived class instances of the parent(s) of the Resource-derived object in question");
184216
m.def("daqapp_get_used_resources", &daq_application_get_used_hostresources, "Get list of HostResources used by DAQApplication");

schema/confmodel/dunedaq.schema.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
<oks-schema>
8282

83-
<info name="" type="" num-of-items="49" oks-format="schema" oks-version="862f2957270" created-by="jcfree" created-on="mu2edaq13.fnal.gov" creation-time="20230123T223700" last-modified-by="gjc" last-modified-on="latitude" last-modification-time="20250923T103939"/>
83+
<info name="" type="" num-of-items="49" oks-format="schema" oks-version="862f2957270" created-by="jcfree" created-on="mu2edaq13.fnal.gov" creation-time="20230123T223700" last-modified-by="gjc" last-modified-on="latitude" last-modification-time="20260218T122834"/>
8484

8585
<class name="ActionPlan" description="A set of steps for an application to carry out a command">
8686
<attribute name="execution_policy" description="How the application should dispatch the command to modules matched by each step of the ActionPlan" type="enum" range="modules-in-parallel,modules-in-series" init-value="modules-in-parallel"/>
@@ -369,6 +369,12 @@
369369
<method name="resource_root" description="Pure virtual method to get the ResourceSet at the root of the ResourceTree.">
370370
<method-implementation language="c++" prototype="virtual const ResourceSet* resource_root() const = 0" body=""/>
371371
</method>
372+
<method name="disable" description="Add a component to the disabled relationship and recalculate the disabled tree">
373+
<method-implementation language="c++" prototype="void disable(const Resource*)" body=""/>
374+
</method>
375+
<method name="enable" description="">
376+
<method-implementation language="c++" prototype="void enable(const Resource*)" body=""/>
377+
</method>
372378
</class>
373379

374380
<class name="Segment" description="Logical sub division of the configuration that can be enabled/disabled as a group">

src/dalMethods.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,34 @@ std::string OpMonURI::get_URI( const std::string & /* app */) const {
392392
return "stdout://";
393393
}
394394

395+
396+
// ========================================================================
397+
void ResourceTree::disable(const Resource* res) {
398+
auto disabled_vec = get_disabled();
399+
for (auto disabled_resource : disabled_vec) {
400+
if (disabled_resource == res) {
401+
return;
402+
}
403+
}
404+
disabled_vec.push_back(res);
405+
406+
set_disabled(disabled_vec);
407+
configuration().update<ResourceTree>({UID()}, {}, {});
408+
409+
m_disabled_resources.update(resource_root(), disabled_vec);
410+
}
411+
void ResourceTree::enable(const Resource* res) {
412+
auto disabled_vec = get_disabled();
413+
auto count = std::erase(disabled_vec, res);
414+
if (count == 0) {
415+
return;
416+
}
417+
set_disabled(disabled_vec);
418+
configuration().update<ResourceTree>({UID()}, {}, {});
419+
420+
m_disabled_resources.update(resource_root(), disabled_vec);
421+
}
422+
395423
bool Resource::is_disabled(const dunedaq::confmodel::ResourceTree& holder) const {
396424
return (!holder.disabled_components().is_enabled(this));
397425
}

0 commit comments

Comments
 (0)