GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/SectorFinder/Algorithm.cc
Date: 2025-03-24 18:50:00
Exec Total Coverage
Lines: 78 82 95.1%
Functions: 5 5 100.0%
Branches: 86 147 58.5%

Line Branch Exec Source
1 #include "Algorithm.h"
2
3 namespace iguana::clas12 {
4
5 REGISTER_IGUANA_ALGORITHM(SectorFinder, "REC::Particle::Sector");
6
7 5 void SectorFinder::Start(hipo::banklist& banks)
8 {
9
10 // define options, their default values, and cache them
11 5 ParseYAMLConfig();
12
2/4
✓ Branch 0 (4→5) taken 5 times.
✗ Branch 1 (4→57) not taken.
✓ Branch 2 (5→6) taken 5 times.
✗ Branch 3 (5→55) not taken.
10 o_bankname_charged = GetOptionScalar<std::string>("bank_charged");
13
2/4
✓ Branch 0 (11→12) taken 5 times.
✗ Branch 1 (11→61) not taken.
✓ Branch 2 (12→13) taken 5 times.
✗ Branch 3 (12→59) not taken.
10 o_bankname_uncharged = GetOptionScalar<std::string>("bank_uncharged");
14
15 bool setDefaultBanks=false;
16 // get expected bank indices
17
3/4
✓ Branch 0 (18→19) taken 5 times.
✗ Branch 1 (18→63) not taken.
✓ Branch 2 (20→21) taken 1 times.
✓ Branch 3 (20→23) taken 4 times.
5 b_particle = GetBankIndex(banks, "REC::Particle");
18
2/2
✓ Branch 0 (20→21) taken 1 times.
✓ Branch 1 (20→23) taken 4 times.
5 if(o_bankname_charged != "default") {
19 1 b_user_charged = GetBankIndex(banks, o_bankname_charged);
20 1 userSpecifiedBank_charged = true;
21 }
22 else {
23
1/2
✓ Branch 0 (24→25) taken 4 times.
✗ Branch 1 (24→65) not taken.
4 b_calorimeter = GetBankIndex(banks, "REC::Calorimeter");
24
1/2
✓ Branch 0 (27→28) taken 4 times.
✗ Branch 1 (27→67) not taken.
4 b_track = GetBankIndex(banks, "REC::Track");
25
1/2
✓ Branch 0 (30→31) taken 4 times.
✗ Branch 1 (30→69) not taken.
4 b_scint = GetBankIndex(banks, "REC::Scintillator");
26 setDefaultBanks = true;
27 4 userSpecifiedBank_charged = false;
28 }
29
30
1/2
✗ Branch 0 (33→34) not taken.
✓ Branch 1 (33→36) taken 5 times.
5 if(o_bankname_uncharged != "default") {
31 b_user_uncharged = GetBankIndex(banks, o_bankname_uncharged);
32 userSpecifiedBank_uncharged = true;
33 }
34 else {
35 //avoid setting default banks twice
36
2/2
✓ Branch 0 (36→37) taken 1 times.
✓ Branch 1 (36→47) taken 4 times.
5 if(!setDefaultBanks){
37
1/2
✓ Branch 0 (38→39) taken 1 times.
✗ Branch 1 (38→71) not taken.
1 b_calorimeter = GetBankIndex(banks, "REC::Calorimeter");
38
1/2
✓ Branch 0 (41→42) taken 1 times.
✗ Branch 1 (41→73) not taken.
1 b_track = GetBankIndex(banks, "REC::Track");
39
1/2
✓ Branch 0 (44→45) taken 1 times.
✗ Branch 1 (44→75) not taken.
1 b_scint = GetBankIndex(banks, "REC::Scintillator");
40 setDefaultBanks = true;
41 }
42 5 userSpecifiedBank_uncharged = false;
43 }
44
45 // create the output bank
46
1/2
✓ Branch 0 (49→50) taken 5 times.
✗ Branch 1 (49→77) not taken.
5 auto result_schema = CreateBank(banks, b_result, "REC::Particle::Sector");
47
1/2
✓ Branch 0 (51→52) taken 5 times.
✗ Branch 1 (51→79) not taken.
5 i_sector = result_schema.getEntryOrder("sector");
48
1/2
✓ Branch 0 (52→53) taken 5 times.
✗ Branch 1 (52→79) not taken.
5 i_pindex = result_schema.getEntryOrder("pindex");
49 5 }
50
51 4100 void SectorFinder::Run(hipo::banklist& banks) const
52 {
53
1/2
✓ Branch 0 (3→4) taken 4100 times.
✗ Branch 1 (3→111) not taken.
4100 auto& particleBank = GetBank(banks, b_particle, "REC::Particle");
54
2/4
✓ Branch 0 (6→7) taken 4100 times.
✗ Branch 1 (6→113) not taken.
✗ Branch 2 (8→9) not taken.
✓ Branch 3 (8→13) taken 4100 times.
8200 auto& resultBank = GetBank(banks, b_result, "REC::Particle::Sector");
55
56 std::vector<int> sectors_uncharged;
57 std::vector<int> pindices_uncharged;
58
1/2
✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→13) taken 4100 times.
4100 if(userSpecifiedBank_uncharged){
59 auto const& userBank = GetBank(banks, b_user_uncharged);
60 GetListsSectorPindex(userBank,sectors_uncharged,pindices_uncharged);
61 }
62
63 std::vector<int> sectors_charged;
64 std::vector<int> pindices_charged;
65
2/2
✓ Branch 0 (13→14) taken 1000 times.
✓ Branch 1 (13→18) taken 3100 times.
4100 if(userSpecifiedBank_charged){
66
2/6
✓ Branch 0 (14→15) taken 1000 times.
✗ Branch 1 (14→155) not taken.
✓ Branch 2 (15→16) taken 1000 times.
✗ Branch 3 (15→117) not taken.
✗ Branch 4 (155→156) not taken.
✗ Branch 5 (155→158) not taken.
1000 auto const& userBank = GetBank(banks, b_user_charged);
67
1/2
✓ Branch 0 (17→18) taken 1000 times.
✗ Branch 1 (17→155) not taken.
1000 GetListsSectorPindex(userBank,sectors_charged,pindices_charged);
68 }
69
70 std::vector<int> sectors_track;
71 std::vector<int> pindices_track;
72
3/4
✓ Branch 0 (18→19) taken 1000 times.
✓ Branch 1 (18→20) taken 3100 times.
✓ Branch 2 (19→20) taken 1000 times.
✗ Branch 3 (19→24) not taken.
4100 if(!userSpecifiedBank_charged || !userSpecifiedBank_uncharged){
73
2/6
✓ Branch 0 (20→21) taken 4100 times.
✗ Branch 1 (20→147) not taken.
✓ Branch 2 (21→22) taken 4100 times.
✗ Branch 3 (21→119) not taken.
✗ Branch 4 (147→148) not taken.
✗ Branch 5 (147→150) not taken.
4100 auto const& trackBank = GetBank(banks, b_track);
74
1/2
✓ Branch 0 (23→24) taken 4100 times.
✗ Branch 1 (23→147) not taken.
4100 GetListsSectorPindex(trackBank,sectors_track,pindices_track);
75 }
76
77 std::vector<int> sectors_cal;
78 std::vector<int> pindices_cal;
79
3/4
✓ Branch 0 (24→25) taken 1000 times.
✓ Branch 1 (24→26) taken 3100 times.
✓ Branch 2 (25→26) taken 1000 times.
✗ Branch 3 (25→30) not taken.
4100 if(!userSpecifiedBank_charged || !userSpecifiedBank_uncharged){
80
2/6
✓ Branch 0 (26→27) taken 4100 times.
✗ Branch 1 (26→139) not taken.
✓ Branch 2 (27→28) taken 4100 times.
✗ Branch 3 (27→121) not taken.
✗ Branch 4 (139→140) not taken.
✗ Branch 5 (139→142) not taken.
4100 auto const& calBank = GetBank(banks, b_calorimeter);
81
1/2
✓ Branch 0 (29→30) taken 4100 times.
✗ Branch 1 (29→139) not taken.
4100 GetListsSectorPindex(calBank,sectors_cal,pindices_cal);
82 }
83
84 std::vector<int> sectors_scint;
85 std::vector<int> pindices_scint;
86
3/4
✓ Branch 0 (30→31) taken 1000 times.
✓ Branch 1 (30→32) taken 3100 times.
✓ Branch 2 (31→32) taken 1000 times.
✗ Branch 3 (31→36) not taken.
4100 if(!userSpecifiedBank_charged || !userSpecifiedBank_uncharged){
87
2/4
✓ Branch 0 (32→33) taken 4100 times.
✗ Branch 1 (32→131) not taken.
✓ Branch 2 (33→34) taken 4100 times.
✗ Branch 3 (33→123) not taken.
4100 auto const& scintBank = GetBank(banks, b_scint);
88
1/2
✓ Branch 0 (35→36) taken 4100 times.
✗ Branch 1 (35→131) not taken.
4100 GetListsSectorPindex(scintBank,sectors_scint,pindices_scint);
89 }
90
91
92 // sync new bank with particle bank, and fill it with zeroes
93
1/2
✓ Branch 0 (36→37) taken 4100 times.
✗ Branch 1 (36→131) not taken.
4100 resultBank.setRows(particleBank.getRows());
94
3/6
✓ Branch 0 (37→38) taken 4100 times.
✗ Branch 1 (37→131) not taken.
✓ Branch 2 (38→39) taken 4100 times.
✗ Branch 3 (38→131) not taken.
✓ Branch 4 (39→40) taken 4100 times.
✗ Branch 5 (39→131) not taken.
4100 resultBank.getMutableRowList().setList(particleBank.getRowList());
95
2/2
✓ Branch 0 (44→41) taken 29274 times.
✓ Branch 1 (44→45) taken 4100 times.
33374 for(int row = 0; row < resultBank.getRows(); row++){
96 29274 resultBank.putInt(i_sector, row, 0);
97 29274 resultBank.putShort(i_pindex, row, static_cast<int16_t>(row));
98 }
99
100
101
2/2
✓ Branch 0 (76→46) taken 29274 times.
✓ Branch 1 (76→77) taken 4100 times.
33374 for(int row = 0; row < particleBank.getRows(); row++) {
102 29274 int charge=particleBank.getInt("charge",row);
103
104
2/2
✓ Branch 0 (47→48) taken 15787 times.
✓ Branch 1 (47→49) taken 13487 times.
29274 bool userSp = charge==0 ? userSpecifiedBank_uncharged : userSpecifiedBank_charged;
105 std::vector<int>& sct_us = charge==0 ? sectors_uncharged : sectors_charged;
106 std::vector<int>& pin_us = charge==0 ? pindices_uncharged : pindices_charged;
107
108
109
110
2/2
✓ Branch 0 (50→51) taken 25980 times.
✓ Branch 1 (50→52) taken 3294 times.
29274 if(userSp){
111
1/2
✓ Branch 0 (52→53) taken 3294 times.
✗ Branch 1 (52→131) not taken.
3294 int sect=GetSector(sct_us, pin_us,row);
112
2/2
✓ Branch 0 (53→54) taken 1804 times.
✓ Branch 1 (53→75) taken 1490 times.
3294 if (sect!=-1){
113 1804 resultBank.putInt(i_sector, row, sect);
114 1804 resultBank.putShort(i_pindex, row, static_cast<int16_t>(row));
115 }
116 } else {
117 enum det_enum {kTrack, kScint, kCal, nDet}; // try to get sector from these detectors, in this order
118
2/2
✓ Branch 0 (74→56) taken 63504 times.
✓ Branch 1 (74→75) taken 9962 times.
73466 for(int d = 0; d < nDet; d++) {
119 int sect = -1;
120 std::string det_name;
121
3/3
✓ Branch 0 (56→57) taken 25980 times.
✓ Branch 1 (56→59) taken 20398 times.
✓ Branch 2 (56→61) taken 17126 times.
63504 switch(d) {
122 25980 case kTrack:
123
1/2
✓ Branch 0 (57→58) taken 25980 times.
✗ Branch 1 (57→127) not taken.
25980 sect=GetSector(sectors_track, pindices_track,row);
124 det_name="track";
125 break;
126 20398 case kScint:
127
1/2
✓ Branch 0 (59→60) taken 20398 times.
✗ Branch 1 (59→127) not taken.
20398 sect=GetSector(sectors_scint, pindices_scint,row);
128 det_name="scint";
129 break;
130 17126 case kCal:
131
1/2
✓ Branch 0 (61→62) taken 17126 times.
✗ Branch 1 (61→127) not taken.
17126 sect=GetSector(sectors_cal, pindices_cal,row);
132 det_name="cal";
133 break;
134 }
135
2/2
✓ Branch 0 (63→64) taken 16018 times.
✓ Branch 1 (63→72) taken 47486 times.
63504 if(sect != -1) {
136
1/2
✓ Branch 0 (66→67) taken 16018 times.
✗ Branch 1 (66→125) not taken.
16018 m_log->Trace("{} pindex {} sect {}", det_name, row, sect);
137 16018 resultBank.putInt(i_sector, row, sect);
138 16018 resultBank.putShort(i_pindex, row, static_cast<int16_t>(row));
139 break;
140 }
141 }
142 }
143 }
144
145
4/8
✓ Branch 0 (77→78) taken 4100 times.
✗ Branch 1 (77→131) not taken.
✓ Branch 2 (78→79) taken 4100 times.
✗ Branch 3 (78→129) not taken.
✓ Branch 4 (80→81) taken 3742 times.
✓ Branch 5 (80→83) taken 358 times.
✗ Branch 6 (131→132) not taken.
✗ Branch 7 (131→134) not taken.
8200 ShowBank(resultBank, Logger::Header("CREATED BANK"));
146 4100 }
147
148 13300 void SectorFinder::GetListsSectorPindex(hipo::bank const& bank, std::vector<int>& sectors, std::vector<int>& pindices) const
149 {
150
2/2
✓ Branch 0 (21→4) taken 65420 times.
✓ Branch 1 (21→22) taken 13300 times.
78720 for(auto const& row : bank.getRowList()) {
151 //check that we're only using FD detectors
152 //eg have "sectors" in CND which we don't want to add here
153 65420 int det=bank.getByte("detector",row);
154
2/2
✓ Branch 0 (14→15) taken 50579 times.
✓ Branch 1 (14→20) taken 14841 times.
65420 if (listFDDets.find(det) != listFDDets.end()) {
155 50579 sectors.push_back(bank.getInt("sector", row));
156 50579 pindices.push_back(bank.getShort("pindex", row));
157 }
158 }
159 13300 }
160
161 66798 int SectorFinder::GetSector(std::vector<int> const& sectors, std::vector<int> const& pindices, int const pindex) const
162 {
163
2/2
✓ Branch 0 (8→3) taken 249821 times.
✓ Branch 1 (8→9) taken 48976 times.
298797 for(std::size_t i=0;i<sectors.size();i++){
164
2/2
✓ Branch 0 (4→5) taken 17822 times.
✓ Branch 1 (4→7) taken 231999 times.
249821 if (pindices.at(i)==pindex){
165 17822 return sectors.at(i);
166 }
167 }
168 return -1;
169 }
170
171 3 void SectorFinder::Stop()
172 {
173 3 }
174
175 }
176