GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/AlgorithmSequence.cc
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 37 53 69.8%
Functions: 7 10 70.0%
Branches: 24 56 42.9%

Line Branch Exec Source
1 #include "AlgorithmSequence.h"
2
3 namespace iguana {
4
5 REGISTER_IGUANA_ALGORITHM(AlgorithmSequence);
6
7 20 void AlgorithmSequence::Start(hipo::banklist& banks)
8 {
9
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 20 times.
52 for(auto const& algo : m_sequence)
10 32 algo->Start(banks);
11 20 }
12 19100 void AlgorithmSequence::Run(hipo::banklist& banks) const
13 {
14
2/2
✓ Branch 0 taken 29300 times.
✓ Branch 1 taken 19100 times.
48400 for(auto const& algo : m_sequence)
15 29300 algo->Run(banks);
16 19100 }
17 12 void AlgorithmSequence::Stop()
18 {
19
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 12 times.
29 for(auto const& algo : m_sequence)
20 17 algo->Stop();
21 12 }
22
23 32 void AlgorithmSequence::Add(std::string const& class_name, std::string const& instance_name)
24 {
25 32 auto algo = AlgorithmFactory::Create(class_name);
26
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if(algo == nullptr) {
27 m_log->Error("algorithm '{}' does not exist", class_name);
28 throw std::runtime_error("AlgorithmFactory cannot create non-existent algorithm");
29 }
30
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 algo->SetName(instance_name == "" ? class_name : instance_name);
31
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 Add(std::move(algo));
32 32 }
33
34 32 void AlgorithmSequence::Add(algo_t&& algo)
35 {
36 32 auto algoName = algo->GetName();
37
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 m_algo_names.insert({algoName, m_sequence.size()});
38 // prepend sequence name to algorithm name
39
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
64 algo->SetName(m_name + "|" + algoName);
40 // append algorithm to the sequence
41
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 m_sequence.push_back(std::move(algo));
42 // check for duplicate algorithm name
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if(m_algo_names.size() < m_sequence.size()) {
44 m_log->Error("Duplicate algorithm name '{}' detected; please make sure all of your algorithms have unique names", algoName);
45 throw std::runtime_error("cannot Add algorithm");
46 }
47 32 }
48
49 11 void AlgorithmSequence::SetName(std::string_view name)
50 {
51 // change the `m_name+"|"` prefix of each algorithm
52
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 11 times.
25 for(auto const& algo : m_sequence) {
53 14 auto algoName = algo->GetName();
54
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(auto pos{algoName.find("|")}; pos != algoName.npos)
55
3/6
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
42 algo->SetName(std::string(name) + algoName.substr(pos));
56 else
57 algo->SetName(std::string(name) + "|" + algoName);
58 }
59 // then change the object name
60 11 Algorithm::SetName(name);
61 11 }
62
63 11 void AlgorithmSequence::PrintSequence(Logger::Level level) const
64 {
65 11 m_log->Print(level, "algorithms in this sequence:");
66
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 11 times.
25 for(auto const& algo : m_sequence)
67
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 m_log->Print(level, " - {}", algo->GetName());
68 11 }
69
70 void AlgorithmSequence::SetConfigFileForEachAlgorithm(std::string const& name)
71 {
72 for(auto const& algo : m_sequence)
73 algo->SetConfigFile(name);
74 }
75
76 void AlgorithmSequence::SetConfigDirectoryForEachAlgorithm(std::string const& name)
77 {
78 for(auto const& algo : m_sequence)
79 algo->SetConfigDirectory(name);
80 }
81
82 void AlgorithmSequence::ForEachAlgorithm(std::function<void(algo_t&)> func)
83 {
84 for(auto& algo : m_sequence)
85 func(algo);
86 }
87
88 }
89