GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 74.1% 80 / 0 / 108
Functions: 87.5% 7 / 0 / 8
Branches: 45.5% 115 / 0 / 253

src/iguana/algorithms/clas12/SectorFinder/Algorithm.cc
Line Branch Exec Source
1 #include "Algorithm.h"
2
3 namespace iguana::clas12 {
4
5 REGISTER_IGUANA_ALGORITHM(SectorFinder, "REC::Particle::Sector");
6
7 9 void SectorFinder::ConfigHook()
8 {
9
5/10
✓ Branch 3 → 4 taken 9 times.
✗ Branch 3 → 34 not taken.
✓ Branch 4 → 5 taken 9 times.
✗ Branch 4 → 32 not taken.
✓ Branch 13 → 14 taken 9 times.
✓ Branch 13 → 16 taken 9 times.
✓ Branch 16 → 17 taken 9 times.
✗ Branch 16 → 46 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 38 not taken.
27 o_bankname_charged = GetOptionScalar<std::string>({"bank_charged"});
10 try {
11
4/8
✓ Branch 17 → 18 taken 9 times.
✗ Branch 17 → 41 not taken.
✓ Branch 18 → 19 taken 9 times.
✗ Branch 18 → 39 not taken.
✓ Branch 27 → 28 taken 9 times.
✓ Branch 27 → 30 taken 9 times.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 45 not taken.
27 o_bankname_neutral = GetOptionScalar<std::string>({"bank_neutral"});
12 }
13 catch(std::runtime_error const& ex) {
14 m_log->Warn("searching instead for configuration parameter named 'bank_uncharged'...");
15 o_bankname_neutral = GetOptionScalar<std::string>({"bank_uncharged"});
16 m_log->Warn("...found 'bank_uncharged' and using it; note that 'bank_uncharged' has been renamed to 'bank_neutral', please update your configuration");
17 }
18 9 }
19
20 9 void SectorFinder::StartHook(hipo::banklist& banks)
21 {
22 bool setDefaultBanks = false;
23 // get expected bank indices
24
2/4
✓ Branch 3 → 4 taken 9 times.
✗ Branch 3 → 72 not taken.
✓ Branch 4 → 5 taken 9 times.
✗ Branch 4 → 7 not taken.
9 b_particle = GetBankIndex(banks, "REC::Particle");
25
2/2
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 12 taken 8 times.
9 if(o_bankname_charged != "default") {
26 1 b_user_charged = GetBankIndex(banks, o_bankname_charged);
27 1 userSpecifiedBank_charged = true;
28 }
29 else {
30
2/4
✓ Branch 13 → 14 taken 8 times.
✗ Branch 13 → 78 not taken.
✓ Branch 14 → 15 taken 8 times.
✗ Branch 14 → 17 not taken.
8 b_track = GetBankIndex(banks, "REC::Track");
31
2/4
✓ Branch 20 → 21 taken 8 times.
✗ Branch 20 → 84 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 24 taken 8 times.
8 b_calorimeter = GetBankIndex(banks, "REC::Calorimeter");
32
2/4
✓ Branch 27 → 28 taken 8 times.
✗ Branch 27 → 90 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 31 taken 8 times.
8 b_scint = GetBankIndex(banks, "REC::Scintillator");
33 setDefaultBanks = true;
34 8 userSpecifiedBank_charged = false;
35 }
36
37
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 37 taken 9 times.
9 if(o_bankname_neutral != "default") {
38 b_user_neutral = GetBankIndex(banks, o_bankname_neutral);
39 userSpecifiedBank_neutral = true;
40 }
41 else {
42 // avoid setting default banks twice
43
2/2
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 60 taken 8 times.
9 if(!setDefaultBanks) {
44
2/4
✓ Branch 39 → 40 taken 1 time.
✗ Branch 39 → 96 not taken.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 43 not taken.
1 b_track = GetBankIndex(banks, "REC::Track");
45
2/4
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 102 not taken.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 50 taken 1 time.
1 b_calorimeter = GetBankIndex(banks, "REC::Calorimeter");
46
2/4
✓ Branch 53 → 54 taken 1 time.
✗ Branch 53 → 108 not taken.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 57 taken 1 time.
2 b_scint = GetBankIndex(banks, "REC::Scintillator");
47 setDefaultBanks = true;
48 }
49 9 userSpecifiedBank_neutral = false;
50 }
51
52 // create the output bank
53
1/2
✓ Branch 62 → 63 taken 9 times.
✗ Branch 62 → 114 not taken.
9 auto result_schema = CreateBank(banks, b_result, "REC::Particle::Sector");
54
1/2
✓ Branch 68 → 69 taken 9 times.
✗ Branch 68 → 120 not taken.
9 i_sector = result_schema.getEntryOrder("sector");
55
1/2
✓ Branch 69 → 70 taken 9 times.
✗ Branch 69 → 120 not taken.
9 i_pindex = result_schema.getEntryOrder("pindex");
56 9 }
57
58 3853 bool SectorFinder::RunHook(hipo::banklist& banks) const
59 {
60
3/4
✓ Branch 2 → 3 taken 882 times.
✓ Branch 2 → 4 taken 2971 times.
✓ Branch 3 → 4 taken 882 times.
✗ Branch 3 → 5 not taken.
3853 auto includeDefaultBanks = !(userSpecifiedBank_charged && userSpecifiedBank_neutral);
61
3/6
✓ Branch 13 → 14 taken 3853 times.
✗ Branch 13 → 18 not taken.
✓ Branch 18 → 19 taken 3853 times.
✗ Branch 18 → 21 not taken.
✓ Branch 23 → 24 taken 3853 times.
✗ Branch 23 → 70 not taken.
11559 return RunImpl(
62
2/4
✓ Branch 21 → 22 taken 3853 times.
✗ Branch 21 → 76 not taken.
✓ Branch 22 → 23 taken 3853 times.
✗ Branch 22 → 70 not taken.
3853 &GetBank(banks, b_particle, "REC::Particle"),
63
3/8
✓ Branch 19 → 20 taken 3853 times.
✗ Branch 19 → 83 not taken.
✓ Branch 20 → 21 taken 3853 times.
✗ Branch 20 → 77 not taken.
✓ Branch 29 → 30 taken 3853 times.
✗ Branch 29 → 36 not taken.
✗ Branch 76 → 77 not taken.
✗ Branch 76 → 83 not taken.
7706 includeDefaultBanks ? &GetBank(banks, b_track, "REC::Track") : nullptr,
64
3/8
✓ Branch 16 → 17 taken 3853 times.
✗ Branch 16 → 91 not taken.
✓ Branch 17 → 18 taken 3853 times.
✗ Branch 17 → 85 not taken.
✓ Branch 36 → 37 taken 3853 times.
✗ Branch 36 → 43 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 91 not taken.
7706 includeDefaultBanks ? &GetBank(banks, b_calorimeter, "REC::Calorimeter") : nullptr,
65
5/12
✓ Branch 14 → 15 taken 3853 times.
✗ Branch 14 → 99 not taken.
✓ Branch 15 → 16 taken 3853 times.
✗ Branch 15 → 93 not taken.
✓ Branch 43 → 44 taken 3853 times.
✗ Branch 43 → 50 not taken.
✓ Branch 50 → 51 taken 882 times.
✓ Branch 50 → 57 taken 2971 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 99 not taken.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 107 not taken.
11559 includeDefaultBanks ? &GetBank(banks, b_scint, "REC::Scintillator") : nullptr,
66
3/4
✓ Branch 10 → 11 taken 882 times.
✓ Branch 10 → 13 taken 2971 times.
✓ Branch 12 → 13 taken 882 times.
✗ Branch 12 → 101 not taken.
4735 userSpecifiedBank_charged ? &GetBank(banks, b_user_charged) : nullptr,
67
1/4
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 3853 times.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 109 not taken.
3853 userSpecifiedBank_neutral ? &GetBank(banks, b_user_neutral) : nullptr,
68
1/2
✓ Branch 6 → 7 taken 3853 times.
✗ Branch 6 → 116 not taken.
7706 &GetBank(banks, b_result, "REC::Particle::Sector"));
69 }
70
71 3946 bool SectorFinder::RunImpl(
72 hipo::bank const* particleBank,
73 hipo::bank const* trackBank,
74 hipo::bank const* calBank,
75 hipo::bank const* scintBank,
76 hipo::bank const* userChargedBank,
77 hipo::bank const* userNeutralBank,
78 hipo::bank* resultBank) const
79 {
80 3946 resultBank->reset(); // IMPORTANT: always first `reset` the created bank(s)
81
82 std::vector<int> sectors_track;
83 std::vector<int> pindices_track;
84 std::vector<int> sectors_cal;
85 std::vector<int> pindices_cal;
86 std::vector<int> sectors_scint;
87 std::vector<int> pindices_scint;
88 std::vector<int> sectors_user_neutral;
89 std::vector<int> pindices_user_neutral;
90 std::vector<int> sectors_user_charged;
91 std::vector<int> pindices_user_charged;
92
93
3/4
✓ Branch 3 → 4 taken 882 times.
✓ Branch 3 → 5 taken 3064 times.
✓ Branch 4 → 5 taken 882 times.
✗ Branch 4 → 13 not taken.
3946 if(!userSpecifiedBank_charged || !userSpecifiedBank_neutral) {
94
2/4
✓ Branch 5 → 6 taken 3946 times.
✗ Branch 5 → 10 not taken.
✓ Branch 6 → 7 taken 3946 times.
✗ Branch 6 → 10 not taken.
3946 if(trackBank != nullptr && calBank != nullptr && scintBank != nullptr) {
95
1/2
✓ Branch 7 → 8 taken 3946 times.
✗ Branch 7 → 108 not taken.
3946 GetListsSectorPindex(*trackBank, sectors_track, pindices_track);
96
1/2
✓ Branch 8 → 9 taken 3946 times.
✗ Branch 8 → 108 not taken.
3946 GetListsSectorPindex(*scintBank, sectors_scint, pindices_scint);
97
1/2
✓ Branch 9 → 13 taken 3946 times.
✗ Branch 9 → 108 not taken.
3946 GetListsSectorPindex(*calBank, sectors_cal, pindices_cal);
98 }
99 else
100 throw std::runtime_error("SectorFinder::RunImpl called with unexpected null pointer to either the track, calorimeter, or scintillator bank(s); please contact the maintainers");
101 }
102
103
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 19 taken 3946 times.
3946 if(userSpecifiedBank_neutral) {
104 if(userNeutralBank != nullptr)
105 GetListsSectorPindex(*userNeutralBank, sectors_user_neutral, pindices_user_neutral);
106 else
107 throw std::runtime_error("SectorFinder::RunImpl called with unexpected null pointer to a user-specified bank; please contact the maintainers");
108 }
109
110
2/2
✓ Branch 19 → 20 taken 882 times.
✓ Branch 19 → 25 taken 3064 times.
3946 if(userSpecifiedBank_charged) {
111
1/2
✓ Branch 20 → 21 taken 882 times.
✗ Branch 20 → 22 not taken.
882 if(userChargedBank != nullptr)
112
1/2
✓ Branch 21 → 25 taken 882 times.
✗ Branch 21 → 108 not taken.
882 GetListsSectorPindex(*userChargedBank, sectors_user_charged, pindices_user_charged);
113 else
114 throw std::runtime_error("SectorFinder::RunImpl called with unexpected null pointer to a user-specified bank; please contact the maintainers");
115 }
116
117 // trace logging
118
2/4
✓ Branch 25 → 26 taken 3946 times.
✗ Branch 25 → 108 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 38 taken 3946 times.
3946 if(m_log->GetLevel() <= Logger::Level::trace) {
119 m_log->Trace("pindices_track = {}", fmt::join(pindices_track, ","));
120 m_log->Trace("sectors_track = {}", fmt::join(sectors_track, ","));
121 m_log->Trace("pindices_scint = {}", fmt::join(pindices_scint, ","));
122 m_log->Trace("sectors_scint = {}", fmt::join(sectors_scint, ","));
123 m_log->Trace("pindices_cal = {}", fmt::join(pindices_cal, ","));
124 m_log->Trace("sectors_cal = {}", fmt::join(sectors_cal, ","));
125 m_log->Trace("pindices_user_neutral = {}", fmt::join(pindices_user_neutral, ","));
126 m_log->Trace("sectors_user_neutral = {}", fmt::join(sectors_user_neutral, ","));
127 m_log->Trace("pindices_user_charged = {}", fmt::join(pindices_user_charged, ","));
128 m_log->Trace("sectors_user_charged = {}", fmt::join(sectors_user_charged, ","));
129 }
130
131 // sync new bank with particle bank
132
1/2
✓ Branch 38 → 39 taken 3946 times.
✗ Branch 38 → 108 not taken.
3946 resultBank->setRows(particleBank->getRows());
133
3/6
✓ Branch 39 → 40 taken 3946 times.
✗ Branch 39 → 108 not taken.
✓ Branch 40 → 41 taken 3946 times.
✗ Branch 40 → 108 not taken.
✓ Branch 41 → 42 taken 3946 times.
✗ Branch 41 → 108 not taken.
3946 resultBank->getMutableRowList().setList(particleBank->getRowList());
134
135 // some downstream algorithms may still need sector info, so obtain sector for _all_ particles,
136 // not just the ones that were filtered out (use `.getRows()` rather than `.getRowList()`)
137
2/2
✓ Branch 55 → 43 taken 28462 times.
✓ Branch 55 → 56 taken 3946 times.
32408 for(int row = 0; row < particleBank->getRows(); row++) {
138
139 28462 auto charge = particleBank->getInt("charge", row);
140 int sect = UNKNOWN_SECTOR;
141
142 // if user-specified bank
143
4/4
✓ Branch 44 → 45 taken 15039 times.
✓ Branch 44 → 46 taken 13423 times.
✓ Branch 47 → 48 taken 3003 times.
✓ Branch 47 → 51 taken 25459 times.
28462 if(charge == 0 ? userSpecifiedBank_neutral : userSpecifiedBank_charged)
144
2/4
✓ Branch 48 → 49 taken 3003 times.
✗ Branch 48 → 50 not taken.
✓ Branch 50 → 52 taken 3003 times.
✗ Branch 50 → 108 not taken.
6006 sect = GetSector(
145 charge == 0 ? sectors_user_neutral : sectors_user_charged,
146 charge == 0 ? pindices_user_neutral : pindices_user_charged,
147 row);
148 else // if not user-specified bank, use the standard method
149
1/2
✓ Branch 51 → 52 taken 25459 times.
✗ Branch 51 → 108 not taken.
25459 sect = GetStandardSector(
150 sectors_track,
151 pindices_track,
152 sectors_cal,
153 pindices_cal,
154 sectors_scint,
155 pindices_scint,
156 row);
157
158 28462 resultBank->putInt(i_sector, row, sect);
159 28462 resultBank->putShort(i_pindex, row, static_cast<int16_t>(row));
160 }
161
162
4/8
✓ Branch 56 → 57 taken 3946 times.
✗ Branch 56 → 108 not taken.
✓ Branch 59 → 60 taken 3946 times.
✗ Branch 59 → 102 not taken.
✓ Branch 65 → 66 taken 752 times.
✓ Branch 65 → 68 taken 3194 times.
✗ Branch 108 → 109 not taken.
✗ Branch 108 → 111 not taken.
11838 ShowBank(*resultBank, Logger::Header("CREATED BANK"));
163 3946 return true;
164 }
165
166 12720 void SectorFinder::GetListsSectorPindex(hipo::bank const& bank, std::vector<int>& sectors, std::vector<int>& pindices) const
167 {
168
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 12720 times.
12720 if(m_log->GetLevel() <= Logger::Level::trace) {
169 m_log->Trace("called `GetListsSectorPindex` for the following bank:");
170 bank.show();
171 }
172
2/2
✓ Branch 25 → 8 taken 63672 times.
✓ Branch 25 → 26 taken 12720 times.
76392 for(auto const& row : bank.getRowList()) {
173 // check that we're only using FD detectors
174 // eg have "sectors" in CND which we don't want to add here
175 63672 auto det = bank.getByte("detector", row);
176
2/2
✓ Branch 18 → 19 taken 50571 times.
✓ Branch 18 → 24 taken 13101 times.
63672 if(listFDDets.find(det) != listFDDets.end()) {
177 50571 sectors.push_back(bank.getInt("sector", row));
178 50571 pindices.push_back(bank.getShort("pindex", row));
179 }
180 }
181 12720 }
182
183 65130 int SectorFinder::GetSector(std::vector<int> const& sectors, std::vector<int> const& pindices, int const& pindex_particle) const
184 {
185
2/2
✓ Branch 10 → 3 taken 248522 times.
✓ Branch 10 → 11 taken 47079 times.
591202 for(std::size_t i = 0; i < sectors.size(); i++) {
186
2/2
✓ Branch 4 → 5 taken 18051 times.
✓ Branch 4 → 7 taken 230471 times.
248522 if(pindices.at(i) == pindex_particle) {
187
2/2
✓ Branch 6 → 11 taken 35 times.
✓ Branch 6 → 12 taken 18016 times.
18051 auto sect = sectors.at(i);
188
2/2
✓ Branch 6 → 11 taken 35 times.
✓ Branch 6 → 12 taken 18016 times.
18051 return IsValidSector(sect) ? sect : UNKNOWN_SECTOR;
189 }
190 }
191 return UNKNOWN_SECTOR; // pindex not found
192 }
193
194 25838 int SectorFinder::GetStandardSector(
195 std::vector<int> const& sectors_track,
196 std::vector<int> const& pindices_track,
197 std::vector<int> const& sectors_cal,
198 std::vector<int> const& pindices_cal,
199 std::vector<int> const& sectors_scint,
200 std::vector<int> const& pindices_scint,
201 int const& pindex_particle) const
202 {
203 enum det_enum { kTrack,
204 kScint,
205 kCal,
206 nDet }; // try to get sector from these detectors, in this order
207
2/2
✓ Branch 33 → 3 taken 62127 times.
✓ Branch 33 → 34 taken 9491 times.
71618 for(int d = 0; d < nDet; d++) {
208 int sect = UNKNOWN_SECTOR;
209 std::string det_name;
210
3/3
✓ Branch 3 → 4 taken 25838 times.
✓ Branch 3 → 6 taken 19780 times.
✓ Branch 3 → 8 taken 16509 times.
62127 switch(d) {
211 25838 case kTrack:
212
1/2
✓ Branch 4 → 5 taken 25838 times.
✗ Branch 4 → 41 not taken.
25838 sect = GetSector(sectors_track, pindices_track, pindex_particle);
213 det_name = "track";
214 break;
215 19780 case kScint:
216
1/2
✓ Branch 6 → 7 taken 19780 times.
✗ Branch 6 → 41 not taken.
19780 sect = GetSector(sectors_scint, pindices_scint, pindex_particle);
217 det_name = "scint";
218 break;
219 16509 case kCal:
220
1/2
✓ Branch 8 → 9 taken 16509 times.
✗ Branch 8 → 41 not taken.
16509 sect = GetSector(sectors_cal, pindices_cal, pindex_particle);
221 det_name = "cal";
222 break;
223 }
224
5/12
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 62127 times.
✓ Branch 14 → 15 taken 62127 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 62127 times.
✗ Branch 15 → 18 not taken.
✓ Branch 20 → 21 taken 16347 times.
✓ Branch 20 → 27 taken 45780 times.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 38 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 44 not taken.
186381 m_log->Trace("{} pindex {} sect {}", det_name, pindex_particle, sect);
225
2/2
✓ Branch 20 → 21 taken 16347 times.
✓ Branch 20 → 27 taken 45780 times.
62127 if(IsValidSector(sect)) // return this sector number; if not valid, continue to next detector in `det_enum`
226 return sect;
227 }
228 return UNKNOWN_SECTOR; // not found in any detector in `det_enum`
229 }
230
231 std::vector<int> SectorFinder::GetStandardSector(
232 std::vector<int> const& sectors_track,
233 std::vector<int> const& pindices_track,
234 std::vector<int> const& sectors_cal,
235 std::vector<int> const& pindices_cal,
236 std::vector<int> const& sectors_scint,
237 std::vector<int> const& pindices_scint,
238 std::vector<int> const& pindices_particle) const
239 {
240 std::vector<int> sect_list;
241 for(auto const& pindex : pindices_particle)
242 sect_list.push_back(GetStandardSector(
243 sectors_track,
244 pindices_track,
245 sectors_cal,
246 pindices_cal,
247 sectors_scint,
248 pindices_scint,
249 pindex));
250 return sect_list;
251 }
252
253 }
254