DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DisabledResources.cpp
Go to the documentation of this file.
6
9
10#include "logging/Logging.hpp"
11
13
14using namespace dunedaq::confmodel;
15
17
18
20 std::vector<const Resource*> initial_list)
21{
22 TLOG_DEBUG(2) << "construct the object from Resource " << root->UID() ;
23 update(root, initial_list);
24}
25
26
28 std::vector<const Resource*> initial_list) {
29
30 m_disabled.clear();
31
32 m_initialised = true;
33
34 // get list of all root's resource-sets also test any
35 // circular dependencies between segments and resource sets
36 TestCircularDependency cd_fuse("component \'is-disabled\' status", root);
37 std::vector<const ResourceSet*> resource_sets;
38 std::set<const Resource*> simple_resources;
39 fill(*root, resource_sets, simple_resources, cd_fuse);
40
41 for (auto & comp : initial_list) {
42 disable(*comp);
43 TLOG_DEBUG(6) << comp->UID() << " is disabled in session";
44 if (const ResourceSet * rs = comp->cast<ResourceSet>()) {
46 }
47 }
48
49 for (unsigned long count = 1; true; ++count) {
50 const unsigned long num(size()); // Remember current size
51
52 TLOG_DEBUG(6) << "before auto-disabling iteration " << count << " the number of disabled components is " << num ;
53 for (const auto& res_set : resource_sets) {
54 if (is_enabled(res_set)) {
55 if (res_set->compute_disabled_state(m_disabled)) {
56 TLOG_DEBUG(6) << "disable custom resource-set- " << res_set->UID() << " because children are disabled" ;
57 disable(*res_set);
58 disable_children(*res_set);
59 }
60 }
61 }
62
63 for (auto& res : simple_resources) {
64 if (is_enabled(res) && res->compute_disabled_state(m_disabled)) {
65 TLOG_DEBUG(6) << "Marking " << res->UID() << " as disabled\n";
66 disable(*res);
67 }
68 }
69
70 if (size() == num) {
71 TLOG_DEBUG(6) << "after " << count << " iteration(s) auto-disabling algorithm found no newly disabled sets, exiting loop ..." ;
72 break;
73 }
74
75 unsigned int iLimit(1000);
76 if (count > iLimit) {
77 ers::error(ReadMaxAllowedIterations(ERS_HERE, iLimit));
78 break;
79 }
80 }
81}
82
83// fill data from resource sets
85 std::vector<const ResourceSet*>& all_resource_sets,
86 std::set<const Resource*>& simple_resources,
88{
89 TLOG_DEBUG(6) << "rs.UID=" << rs.UID() << ", class=" << rs.class_name();
90 all_resource_sets.push_back(&rs);
91 auto rptr = &rs;
92 if (rptr->cast<Resource>() == nullptr) {
93 throw (MissingConstructor(ERS_HERE, "Resource", rs.full_name()));
94 }
95 for (auto & res : rs.contained_resources()) {
96 AddTestOnCircularDependency add_fuse_test(cd_fuse, res);
97 if (const ResourceSet * rs2 = res->cast<ResourceSet>()) {
98 fill(*rs2, all_resource_sets, simple_resources, cd_fuse);
99 } else {
100 simple_resources.insert(res);
101 }
102 }
103}
104
105
106
107void
109{
110 TLOG_DEBUG(6) << "Disabling children of " << rs.UID();
111 for (auto & res : rs.contained_resources()) {
112 TLOG_DEBUG(6) << "Disabling child " << res->UID();
113 disable(*res);
114 if (const auto * rs2 = res->cast<ResourceSet>()) {
115 disable_children(*rs2);
116 }
117 }
118}
119
#define ERS_HERE
std::string full_name() const noexcept
const TARGET * cast() const noexcept
Casts object to different class.
const std::string & class_name() const noexcept
const std::string & UID() const noexcept
void fill(const ResourceSet &rs, std::vector< const ResourceSet * > &all_resource_sets, std::set< const Resource * > &simple_resources, TestCircularDependency &cd_fuse)
bool is_enabled(const Resource *component) const
void update(const ResourceSet *root, std::vector< const Resource * > initial_list)
void disable(const Resource &component)
virtual std::vector< const Resource * > contained_resources() const =0
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
void error(const Issue &issue)
Definition ers.hpp:92