Line data Source code
1 : #include "confmodel/Application.hpp"
2 : #include "confmodel/Resource.hpp"
3 : #include "confmodel/ResourceSet.hpp"
4 : #include "confmodel/Segment.hpp"
5 : #include "confmodel/Session.hpp"
6 :
7 : #include "confmodel/confmodelIssues.hpp"
8 : #include "confmodel/DisabledResources.hpp"
9 :
10 : #include "logging/Logging.hpp"
11 :
12 : #include "confmodel/test_circular_dependency.hpp"
13 :
14 : using namespace dunedaq::confmodel;
15 :
16 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17 :
18 :
19 4 : DisabledResources::DisabledResources(const ResourceSet* root,
20 4 : std::vector<const Resource*> initial_list)
21 : {
22 4 : TLOG_DEBUG(2) << "construct the object from Resource " << root->UID() ;
23 4 : update(root, initial_list);
24 4 : }
25 :
26 :
27 22 : void DisabledResources::update(const ResourceSet* root,
28 : std::vector<const Resource*> initial_list) {
29 :
30 22 : m_disabled.clear();
31 :
32 22 : m_initialised = true;
33 22 : if (initial_list.empty()) {
34 9 : TLOG_DEBUG( 6) << "We have no disabled components";
35 9 : return;
36 : }
37 :
38 : // get list of all root's resource-sets also test any
39 : // circular dependencies between segments and resource sets
40 13 : TestCircularDependency cd_fuse("component \'is-disabled\' status", root);
41 13 : std::vector<const ResourceSet*> resource_sets;
42 13 : fill(*root, resource_sets, cd_fuse);
43 :
44 43 : for (auto & comp : initial_list) {
45 30 : disable(*comp);
46 30 : TLOG_DEBUG(6) << comp->UID() << " is disabled in session";
47 30 : if (const ResourceSet * rs = comp->cast<ResourceSet>()) {
48 5 : disable_children(*rs);
49 : }
50 : }
51 :
52 13 : for (unsigned long count = 1; true; ++count) {
53 20 : const unsigned long num(size()); // Remember current size
54 :
55 20 : TLOG_DEBUG(6) << "before auto-disabling iteration " << count << " the number of disabled components is " << num ;
56 70 : for (const auto& res_set : resource_sets) {
57 50 : if (is_enabled(res_set)) {
58 25 : if (res_set->compute_disabled_state(m_disabled)) {
59 7 : TLOG_DEBUG(6) << "disable custom resource-set- " << res_set->UID() << " because children are disabled" ;
60 7 : disable(*res_set);
61 7 : disable_children(*res_set);
62 : }
63 : }
64 : }
65 :
66 20 : if (size() == num) {
67 13 : TLOG_DEBUG(6) << "after " << count << " iteration(s) auto-disabling algorithm found no newly disabled sets, exiting loop ..." ;
68 13 : break;
69 : }
70 :
71 7 : unsigned int iLimit(1000);
72 7 : if (count > iLimit) {
73 0 : ers::error(ReadMaxAllowedIterations(ERS_HERE, iLimit));
74 0 : break;
75 : }
76 7 : }
77 13 : }
78 :
79 : // fill data from resource sets
80 28 : void DisabledResources::fill(const ResourceSet& rs,
81 : std::vector<const ResourceSet*>& all_resource_sets,
82 : TestCircularDependency& cd_fuse)
83 : {
84 28 : TLOG_DEBUG(6) << "rs.UID=" << rs.UID() << ", class=" << rs.class_name();
85 28 : all_resource_sets.push_back(&rs);
86 28 : auto rptr = &rs;
87 28 : if (rptr->cast<Resource>() == nullptr) {
88 0 : throw (MissingConstructor(ERS_HERE, "Resource", rs.full_name()));
89 : }
90 102 : for (auto & res : rs.contained_resources()) {
91 74 : AddTestOnCircularDependency add_fuse_test(cd_fuse, res);
92 74 : if (const ResourceSet * rs2 = res->cast<ResourceSet>()) {
93 15 : fill(*rs2, all_resource_sets, cd_fuse);
94 : }
95 102 : }
96 28 : }
97 :
98 :
99 :
100 : void
101 20 : DisabledResources::disable_children(const ResourceSet& rs)
102 : {
103 20 : TLOG_DEBUG(6) << "Disabling children of " << rs.UID();
104 80 : for (auto & res : rs.contained_resources()) {
105 60 : TLOG_DEBUG(6) << "Disabling child " << res->UID();
106 60 : disable(*res);
107 60 : if (const auto * rs2 = res->cast<ResourceSet>()) {
108 8 : disable_children(*rs2);
109 : }
110 20 : }
111 20 : }
112 :
|