GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/clas12/SectorFinder/Algorithm.cc
Date: 2025-01-05 09:03:17
Exec Total Coverage
Lines: 78 82 95.1%
Functions: 5 5 100.0%
Branches: 87 149 58.4%

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