GCC Code Coverage Report


Directory: ./
File: src/detID/detectorID.cc
Date: 2025-09-01 06:19:01
Exec Total Coverage
Lines: 21 60 35.0%
Functions: 3 11 27.3%
Branches: 22 49 44.9%

Line Branch Exec Source
1 #include "na64detID/detectorID.hh"
2 #include "na64util/selector.hh"
3 #include "na64detID/wireID.hh"
4 #include "na64detID/cellID.hh"
5 #include "na64detID/TBName.hh"
6
7 namespace na64dp {
8
9 DetID::DetID(PlaneKey dpk) : DetID( dpk.id ) {}
10
11 bool
12 DetID::matches(const DetID & did) const {
13 // TODO: re-implement following stuff on bitmasks for speed
14 if( is_chip_set() && did.is_chip_set()
15 && chip() != did.chip() ) {
16 return false;
17 }
18 if( is_kin_set() && did.is_kin_set()
19 && kin() != did.kin() ) {
20 return false;
21 }
22 if( is_number_set() && did.is_number_set()
23 && number() != did.number() ) {
24 return false;
25 }
26 if( is_payload_set() && did.is_payload_set()
27 && number() != did.number() ) {
28 return false;
29 }
30 return true;
31 }
32
33
34 namespace util {
35 namespace detector_id_getters {
36
37 // Extern resolver, relying on dynamic DetectorNaming instance provided by
38 // void-ptr
39 static int
40 44 _dynamic_name_resolve( const char * name
41 , const void * nameMappingsObject
42 , dsul::CodeVal_t * value ) {
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 assert(nameMappingsObject);
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 assert(name);
45 44 const nameutils::DetectorNaming & nm
46 = *reinterpret_cast<const nameutils::DetectorNaming *>(nameMappingsObject);
47
48
3/6
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 44 times.
44 if( name[0] != '\0' && (name[1] == '\0' || name[2] == '\0') ) { // projection for APV detectors
49 WireID::Projection pj = WireID::proj_code( name[0] );
50 if( name[1] != '\0' && pj != WireID::kUnknown ) {
51 if( name[1] == '2' ) {
52 *value = WireID::adjoint_proj_code(pj);
53 return 1;
54 } else if( name[1] != '1' ) {
55 pj = WireID::kUnknown;
56 }
57 }
58 if( WireID::kUnknown != pj ) {
59 *value = pj;
60 return 1;
61 }
62 }
63 { // chip
64
4/4
✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 42 times.
132 if( nm.has_chip(name) ) {
65
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 *value = nm.chip_id(name);
66 2 return 1;
67 }
68 }
69 { // kin
70
4/4
✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 19 times.
126 if( nm.has_kin( name ) ) {
71
2/2
✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
46 auto kinID = nm.kin_id(name);
72 23 DetID did( kinID.first // chip
73 23 , kinID.second // kin
74 , 0x0 // station number
75 , 0x0 // payload
76
1/1
✓ Branch 1 taken 23 times.
23 );
77 23 *value = did;
78 23 return 1;
79 }
80 }
81
82 19 return 0;
83 }
84
85 // Static getter -- chip identifier
86 static dsul::CodeVal_t
87 1 _get_chip( dsul::Principal_t pv ) {
88
1/1
✓ Branch 2 taken 1 times.
1 return DetID(reinterpret_cast<uintptr_t>(pv)).chip();
89 }
90
91 // Static getter -- detector type (kin)
92 static dsul::CodeVal_t
93 12 _get_kin( dsul::Principal_t pv ) {
94 // To make difference between detector kins with same numerical ID that
95 // corresponds to different chips (i.e. to accomplish user's expectation
96 // for case of expression "kin == MM" with, say, id(MM) = 1 and
97 // id(ECAL) = 1) we have to compose the kin's value accounting chip id
98 12 DetID did(reinterpret_cast<uintptr_t>(pv));
99
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
12 return DetID(did.chip(), did.kin(), 0, 0);
100 }
101
102 // Static getter -- station number
103 static dsul::CodeVal_t
104 _get_station_number( dsul::Principal_t pv ) {
105 DetID did(reinterpret_cast<uintptr_t>(pv));
106 if( ! did.is_number_set() ) return 0;
107 return did.number();
108 }
109
110 // Dynamic getter -- projection code for APV detectors
111 static dsul::CodeVal_t
112 _apv_get_projection( dsul::Principal_t pv ) {
113 return WireID(DetID(reinterpret_cast<uintptr_t>(pv)).payload()).proj();
114 }
115
116 // Dynamic getter -- wire number for APV detectors
117 static dsul::CodeVal_t
118 _apv_get_wire_no( dsul::Principal_t pv ) {
119 return WireID(DetID(reinterpret_cast<uintptr_t>(pv)).payload()).wire_no();
120 }
121
122 // Dynamic getter -- x-index for SADC segmentation detectors
123 static dsul::CodeVal_t
124 _sadc_get_x_idx( dsul::Principal_t pv ) {
125 return CellID(DetID(reinterpret_cast<uintptr_t>(pv)).payload()).get_x();
126 }
127
128 // Dynamic getter -- x-index for SADC segmentation detectors
129 static dsul::CodeVal_t
130 _sadc_get_y_idx( dsul::Principal_t pv ) {
131 return CellID(DetID(reinterpret_cast<uintptr_t>(pv)).payload()).get_y();
132 }
133
134 static dsul::CodeVal_t
135 _sadc_get_z_idx( dsul::Principal_t pv ) {
136 return CellID(DetID(reinterpret_cast<uintptr_t>(pv)).payload()).get_z();
137 }
138
139 static const na64dpsu_SymDefinition _detIDGetters[] = {
140 { "+", { .resolve_name = _dynamic_name_resolve }, "common external getter" },
141 { "$chip", { _get_chip }, "detector chip identifier (static)" },
142 { "$kin", { _get_kin }, "detector kin identifier (static)" },
143 { "$number", { _get_station_number }, "number of detector station" },
144 { "~projection", { _apv_get_projection }, "detector plane projection code (dynamic, for APV detectors only)" },
145 { "~wireNo", { _apv_get_wire_no }, "wire number (dynamic, for APV detectors only)" },
146 { "~xIdx", { _sadc_get_x_idx }, "X-index of cell (dynamic, for SADC detectors only)" },
147 { "~yIdx", { _sadc_get_y_idx }, "Y-index of cell (dynamic, for SADC detectors only)" },
148 { "~zIdx", { _sadc_get_z_idx }, "Z-index of cell (dynamic, for SADC detectors only)" },
149 { NULL, { NULL }, NULL }
150 };
151
152 } // namespace detector_id_getters
153
154 const na64dpsu_SymDefinition * gDetIDGetters = detector_id_getters::_detIDGetters;
155
156 } // namespace util
157
158 }
159
160