GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/AlgorithmSequence.cc
Date: 2025-11-25 17:57:04
Coverage Exec Excl Total
Lines: 63.8% 44 0 69
Functions: 71.4% 10 0 14
Branches: 30.0% 33 0 110

Line Branch Exec Source
1 #include "AlgorithmSequence.h"
2
3 namespace iguana {
4
5 REGISTER_IGUANA_ALGORITHM(AlgorithmSequence);
6
7 27 void AlgorithmSequence::Start(hipo::banklist& banks)
8 {
9
2/2
✓ Branch 5 → 3 taken 44 times.
✓ Branch 5 → 6 taken 27 times.
71 for(auto const& algo : m_sequence)
10 44 algo->Start(banks);
11 27 }
12
13 25100 bool AlgorithmSequence::Run(hipo::banklist& banks) const
14 {
15
2/2
✓ Branch 6 → 3 taken 32731 times.
✓ Branch 6 → 7 taken 16061 times.
48792 for(auto const& algo : m_sequence) {
16
2/2
✓ Branch 4 → 5 taken 23692 times.
✓ Branch 4 → 7 taken 9039 times.
32731 if(!algo->Run(banks))
17 return false;
18 }
19 return true;
20 }
21
22 18 void AlgorithmSequence::Stop()
23 {
24
2/2
✓ Branch 5 → 3 taken 28 times.
✓ Branch 5 → 6 taken 18 times.
46 for(auto const& algo : m_sequence)
25 28 algo->Stop();
26 18 }
27
28 44 void AlgorithmSequence::Add(std::string const& algo_class_name, std::string const& algo_instance_name)
29 {
30 44 auto algo = AlgorithmFactory::Create(algo_class_name);
31
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 17 taken 44 times.
44 if(algo == nullptr) {
32 m_log->Error("algorithm '{}' does not exist", algo_class_name);
33 throw std::runtime_error("AlgorithmFactory cannot create non-existent algorithm");
34 }
35
3/4
✓ Branch 17 → 18 taken 3 times.
✓ Branch 17 → 19 taken 41 times.
✓ Branch 21 → 22 taken 44 times.
✗ Branch 21 → 35 not taken.
88 algo->SetName(algo_instance_name == "" ? algo_class_name : algo_instance_name);
36
1/2
✓ Branch 22 → 23 taken 44 times.
✗ Branch 22 → 35 not taken.
44 Add(std::move(algo));
37 44 }
38
39 44 void AlgorithmSequence::Add(algo_t&& algo)
40 {
41 44 auto algoName = algo->GetName();
42
1/2
✓ Branch 14 → 15 taken 44 times.
✗ Branch 14 → 81 not taken.
44 m_algo_names.insert({algoName, m_sequence.size()});
43 // prepend sequence name to algorithm name
44
2/4
✓ Branch 14 → 15 taken 44 times.
✗ Branch 14 → 81 not taken.
✓ Branch 21 → 22 taken 44 times.
✗ Branch 21 → 61 not taken.
88 algo->SetName(m_name + "|" + algoName);
45 // append algorithm to the sequence
46
1/2
✓ Branch 32 → 33 taken 44 times.
✗ Branch 32 → 81 not taken.
44 m_sequence.push_back(std::move(algo));
47 // check for duplicate algorithm name
48
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 49 taken 44 times.
44 if(m_algo_names.size() < m_sequence.size()) {
49 m_log->Error("Duplicate algorithm name '{}' detected; please make sure all of your algorithms have unique names", algoName);
50 throw std::runtime_error("cannot Add algorithm");
51 }
52 44 }
53
54 16 void AlgorithmSequence::SetName(std::string_view name)
55 {
56 // change the `m_name+"|"` prefix of each algorithm
57
2/2
✓ Branch 61 → 3 taken 22 times.
✓ Branch 61 → 62 taken 16 times.
38 for(auto const& algo : m_sequence) {
58 22 auto algoName = algo->GetName();
59
1/2
✓ Branch 4 → 5 taken 22 times.
✗ Branch 4 → 28 not taken.
22 if(auto pos{algoName.find("|")}; pos != algoName.npos)
60
4/10
✓ Branch 5 → 6 taken 22 times.
✗ Branch 5 → 100 not taken.
✓ Branch 8 → 9 taken 22 times.
✗ Branch 8 → 70 not taken.
✓ Branch 11 → 12 taken 22 times.
✗ Branch 11 → 64 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 25 taken 22 times.
✗ Branch 76 → 77 not taken.
✗ Branch 76 → 79 not taken.
110 algo->SetName(std::string(name) + algoName.substr(pos));
61 else
62 algo->SetName(std::string(name) + "|" + algoName);
63 }
64 // then change the object name
65 16 Algorithm::SetName(name);
66 16 }
67
68 std::vector<std::string> AlgorithmSequence::GetCreatedBankNames(std::string const& algo_instance_name) const noexcept(false)
69 {
70 if(auto it{m_algo_names.find(algo_instance_name)}; it != m_algo_names.end())
71 return m_sequence[it->second]->GetCreatedBankNames();
72 m_log->Error("cannot find algorithm '{}' in sequence", algo_instance_name);
73 throw std::runtime_error("GetCreatedBankNames failed");
74 }
75
76 19 std::string AlgorithmSequence::GetCreatedBankName(std::string const& algo_instance_name) const noexcept(false)
77 {
78
1/2
✓ Branch 5 → 6 taken 19 times.
✗ Branch 5 → 9 not taken.
19 if(auto it{m_algo_names.find(algo_instance_name)}; it != m_algo_names.end())
79 19 return m_sequence[it->second]->GetCreatedBankName();
80 m_log->Error("cannot find algorithm '{}' in sequence", algo_instance_name);
81 throw std::runtime_error("GetCreatedBankName failed");
82 }
83
84 17 void AlgorithmSequence::PrintSequence(Logger::Level level) const
85 {
86 17 m_log->Print(level, "algorithms in this sequence:");
87
2/2
✓ Branch 12 → 4 taken 25 times.
✓ Branch 12 → 13 taken 17 times.
42 for(auto const& algo : m_sequence)
88
3/6
✓ Branch 5 → 6 taken 25 times.
✗ Branch 5 → 14 not taken.
✓ Branch 6 → 7 taken 3 times.
✓ Branch 6 → 9 taken 22 times.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 17 not taken.
50 m_log->Print(level, " - {}", algo->GetName());
89 17 }
90
91 void AlgorithmSequence::SetConfigFileForEachAlgorithm(std::string const& name)
92 {
93 for(auto const& algo : m_sequence)
94 algo->SetConfigFile(name);
95 }
96
97 void AlgorithmSequence::SetConfigDirectoryForEachAlgorithm(std::string const& name)
98 {
99 for(auto const& algo : m_sequence)
100 algo->SetConfigDirectory(name);
101 }
102
103 void AlgorithmSequence::ForEachAlgorithm(std::function<void(algo_t&)> func)
104 {
105 for(auto& algo : m_sequence)
106 func(algo);
107 }
108
109 22 hipo::banklist::size_type AlgorithmSequence::GetBankIndex(
110 hipo::banklist& banks,
111 std::string const& bank_name,
112 std::string const& algo_instance_name) const noexcept(false)
113 {
114
1/2
✓ Branch 5 → 6 taken 22 times.
✗ Branch 5 → 9 not taken.
22 if(auto it{m_algo_names.find(algo_instance_name)}; it != m_algo_names.end())
115 22 return m_sequence.at(it->second)->GetBankIndex(banks, bank_name);
116 m_log->Error("cannot find algorithm '{}' in sequence", algo_instance_name);
117 throw std::runtime_error("cannot Get algorithm");
118 }
119
120 4 hipo::banklist::size_type AlgorithmSequence::GetCreatedBankIndex(
121 hipo::banklist& banks,
122 std::string const& algo_instance_name) const noexcept(false)
123 {
124
1/2
✓ Branch 3 → 4 taken 4 times.
✗ Branch 3 → 10 not taken.
8 return GetBankIndex(banks, GetCreatedBankName(algo_instance_name), algo_instance_name);
125 }
126
127 }
128