Line data Source code
1 : #include "confmodel/Application.hpp"
2 : #include "confmodel/ExcludableEntity.hpp"
3 : #include "confmodel/ExcludableEntitySet.hpp"
4 : #include "confmodel/Segment.hpp"
5 : #include "confmodel/Session.hpp"
6 :
7 : #include "confmodel/ExcludedEntities.hpp"
8 : #include "confmodel/confmodelIssues.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 5 : ExcludedEntities::ExcludedEntities(const ExcludableEntitySet* root, std::vector<const ExcludableEntity*> initial_list)
19 : {
20 5 : TLOG_DEBUG(2) << "construct the object from ExcludableEntity " << root->UID();
21 5 : update(root, initial_list);
22 5 : }
23 :
24 : void
25 24 : ExcludedEntities::update(const ExcludableEntitySet* root, std::vector<const ExcludableEntity*> initial_list)
26 : {
27 :
28 24 : m_excluded.clear();
29 :
30 24 : m_initialised = true;
31 :
32 : // get list of all root's entities-sets also test any
33 : // circular dependencies between segments and entity sets
34 24 : TestCircularDependency cd_fuse("component \'is-excluded\' status", root);
35 24 : std::vector<const ExcludableEntitySet*> sets;
36 24 : std::set<const ExcludableEntity*> simple_entities;
37 24 : fill(*root, sets, simple_entities, cd_fuse);
38 :
39 54 : for (auto& comp : initial_list) {
40 30 : exclude(*comp);
41 30 : TLOG_DEBUG(6) << comp->UID() << " is excluded in session";
42 30 : if (const ExcludableEntitySet* rs = comp->cast<ExcludableEntitySet>()) {
43 5 : exclude_children(*rs);
44 : }
45 : }
46 :
47 24 : for (unsigned long count = 1; true; ++count) {
48 32 : const unsigned long num(size()); // Remember current size
49 :
50 32 : TLOG_DEBUG(6) << "before auto-exclusion iteration " << count << " the number of excluded components is " << num;
51 153 : for (const auto& set : sets) {
52 121 : if (is_included(set)) {
53 96 : if (set->compute_excluded_state(m_excluded)) {
54 7 : TLOG_DEBUG(6) << "Exclude custom entity-set- " << set->UID() << " because children are excluded";
55 7 : exclude(*set);
56 7 : exclude_children(*set);
57 : }
58 : }
59 : }
60 :
61 227 : for (auto& en : simple_entities) {
62 195 : if (is_included(en) && en->compute_excluded_state(m_excluded)) {
63 1 : TLOG_DEBUG(6) << "Marking " << en->UID() << " as excluded\n";
64 1 : exclude(*en);
65 : }
66 : }
67 :
68 32 : if (size() == num) {
69 24 : TLOG_DEBUG(6) << "after " << count
70 24 : << " iteration(s) auto-exclusion algorithm found no newly excluded sets, exiting loop ...";
71 24 : break;
72 : }
73 :
74 8 : unsigned int iLimit(1000);
75 8 : if (count > iLimit) {
76 0 : ers::error(ReadMaxAllowedIterations(ERS_HERE, iLimit));
77 0 : break;
78 : }
79 8 : }
80 24 : }
81 :
82 : // fill data from entities sets
83 : void
84 98 : ExcludedEntities::fill(const ExcludableEntitySet& es,
85 : std::vector<const ExcludableEntitySet*>& all_sets,
86 : std::set<const ExcludableEntity*>& simple_entities,
87 : TestCircularDependency& cd_fuse)
88 : {
89 98 : TLOG_DEBUG(6) << "es.UID=" << es.UID() << ", class=" << es.class_name();
90 98 : all_sets.push_back(&es);
91 98 : auto rptr = &es;
92 98 : if (rptr->cast<ExcludableEntity>() == nullptr) {
93 0 : throw(MissingConstructor(ERS_HERE, "ExcludableEntity", es.full_name()));
94 : }
95 339 : for (auto& res : es.contained_excludable_entities()) {
96 241 : AddTestOnCircularDependency add_fuse_test(cd_fuse, res);
97 241 : if (const ExcludableEntitySet* es2 = res->cast<ExcludableEntitySet>()) {
98 74 : fill(*es2, all_sets, simple_entities, cd_fuse);
99 : } else {
100 167 : simple_entities.insert(res);
101 : }
102 339 : }
103 98 : }
104 :
105 : void
106 20 : ExcludedEntities::exclude_children(const ExcludableEntitySet& rs)
107 : {
108 20 : TLOG_DEBUG(6) << "Excluding children of " << rs.UID();
109 80 : for (auto& res : rs.contained_excludable_entities()) {
110 60 : TLOG_DEBUG(6) << "Excluding child " << res->UID();
111 60 : exclude(*res);
112 60 : if (const auto* rs2 = res->cast<ExcludableEntitySet>()) {
113 8 : exclude_children(*rs2);
114 : }
115 20 : }
116 20 : }
|