Skip to content

Commit 6d608d8

Browse files
authored
refactor: Remove raw pointer from portal shell class (#4933)
Remove the raw pointer method from the portal shells and get it from the smart pointers
1 parent 21d3f91 commit 6d608d8

File tree

11 files changed

+130
-187
lines changed

11 files changed

+130
-187
lines changed

Core/include/Acts/Geometry/CuboidPortalShell.hpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ class CuboidPortalShell : public PortalShellBase {
2929
/// Type alias for cuboid volume bounds face enumeration
3030
using Face = CuboidVolumeBounds::Face;
3131

32-
/// Retrieve the portal associated to the given face. Can be nullptr if unset.
33-
/// @param face The face to retrieve the portal for
34-
/// @return The portal associated to the face
35-
virtual Portal* portal(Face face) = 0;
36-
3732
/// Retrieve a shared_ptr for the portal associated to the given face. Can be
3833
/// nullptr if unset.
3934
/// @param face The face to retrieve the portal for
4035
/// @return The portal associated to the face
41-
virtual std::shared_ptr<Portal> portalPtr(Face face) = 0;
36+
virtual std::shared_ptr<Portal> portal(Face face) = 0;
4237

4338
/// Set the portal associated to the given face.
4439
/// @param portal The portal to set
@@ -71,10 +66,7 @@ class SingleCuboidPortalShell : public CuboidPortalShell {
7166
std::size_t size() const final;
7267

7368
/// @copydoc CuboidPortalShell::portal
74-
Portal* portal(Face face) final;
75-
76-
/// @copydoc CuboidPortalShell::portalPtr
77-
std::shared_ptr<Portal> portalPtr(Face face) final;
69+
std::shared_ptr<Portal> portal(Face face) final;
7870

7971
/// @copydoc CuboidPortalShell::setPortal
8072
void setPortal(std::shared_ptr<Portal> portal, Face face) final;
@@ -117,10 +109,7 @@ class CuboidStackPortalShell final : public CuboidPortalShell {
117109
std::size_t size() const override;
118110

119111
/// @copydoc CuboidPortalShell::portal
120-
Portal* portal(Face face) override;
121-
122-
/// @copydoc CuboidPortalShell::portalPtr
123-
std::shared_ptr<Portal> portalPtr(Face face) override;
112+
std::shared_ptr<Portal> portal(Face face) override;
124113

125114
/// @copydoc CuboidPortalShell::setPortal
126115
void setPortal(std::shared_ptr<Portal> portal, Face face) override;

Core/include/Acts/Geometry/CylinderPortalShell.hpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,11 @@ class CylinderPortalShell : public PortalShellBase {
2828

2929
using enum CylinderVolumeBounds::Face;
3030

31-
/// Retrieve the portal associated to the given face. Can be nullptr if unset.
32-
/// @param face The face to retrieve the portal for
33-
/// @return The portal associated to the face
34-
virtual Portal* portal(Face face) = 0;
35-
3631
/// Retrieve a shared_ptr for the portal associated to the given face. Can be
3732
/// nullptr if unset.
3833
/// @param face The face to retrieve the portal for
3934
/// @return The portal associated to the face
40-
virtual std::shared_ptr<Portal> portalPtr(Face face) = 0;
35+
virtual std::shared_ptr<Portal> portal(Face face) = 0;
4136

4237
/// Set the portal associated to the given face.
4338
/// @param portal The portal to set
@@ -73,10 +68,7 @@ class SingleCylinderPortalShell : public CylinderPortalShell {
7368
std::size_t size() const final;
7469

7570
/// @copydoc CylinderPortalShell::portal
76-
Portal* portal(Face face) final;
77-
78-
/// @copydoc CylinderPortalShell::portalPtr
79-
std::shared_ptr<Portal> portalPtr(Face face) final;
71+
std::shared_ptr<Portal> portal(Face face) final;
8072

8173
/// @copydoc CylinderPortalShell::setPortal
8274
void setPortal(std::shared_ptr<Portal> portal, Face face) final;
@@ -150,10 +142,7 @@ class CylinderStackPortalShell : public CylinderPortalShell {
150142
std::size_t size() const final;
151143

152144
/// @copydoc CylinderPortalShell::portal
153-
Portal* portal(Face face) final;
154-
155-
/// @copydoc CylinderPortalShell::portalPtr
156-
std::shared_ptr<Portal> portalPtr(Face face) final;
145+
std::shared_ptr<Portal> portal(Face face) final;
157146

158147
/// @copydoc CylinderPortalShell::setPortal
159148
void setPortal(std::shared_ptr<Portal> portal, Face face) final;

Core/include/Acts/Geometry/TrapezoidPortalShell.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,11 @@ class TrapezoidPortalShell : public PortalShellBase {
2727

2828
using enum TrapezoidVolumeBounds::Face;
2929

30-
/// Retrieve the portal associated to the given face. Can be nullptr if unset.
31-
/// @param face The face to retrieve the portal for
32-
/// @return The portal associated to the face
33-
virtual Portal* portal(Face face) = 0;
34-
3530
/// Retrieve a shared_ptr for the portal associated to the given face. Can be
3631
/// nullptr if unset.
3732
/// @param face The face to retrieve the portal for
3833
/// @return The portal associated to the face
39-
virtual std::shared_ptr<Portal> portalPtr(Face face) = 0;
34+
virtual std::shared_ptr<Portal> portal(Face face) = 0;
4035

4136
/// Set the portal associated to the given face.
4237
/// @param portal The portal to set
@@ -69,10 +64,7 @@ class SingleTrapezoidPortalShell : public TrapezoidPortalShell {
6964
std::size_t size() const override;
7065

7166
/// @copydoc TrapezoidPortalShell::portal
72-
Portal* portal(Face face) override;
73-
74-
/// @copydoc TrapezoidPortalShell::portalPtr
75-
std::shared_ptr<Portal> portalPtr(Face face) override;
67+
std::shared_ptr<Portal> portal(Face face) override;
7668

7769
/// @copydoc TrapezoidPortalShell::setPortal
7870
void setPortal(std::shared_ptr<Portal> portal, Face face) override;

Core/src/Geometry/CuboidPortalShell.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void CuboidPortalShell::fill(TrackingVolume& volume) {
3131
using enum CuboidVolumeBounds::Face;
3232
for (Face face : {NegativeZFace, PositiveZFace, NegativeXFace, PositiveXFace,
3333
NegativeYFace, PositiveYFace}) {
34-
const auto& portalAtFace = portalPtr(face);
34+
const auto& portalAtFace = portal(face);
3535
if (portalAtFace != nullptr) {
3636
portalAtFace->fill(volume);
3737
volume.addPortal(portalAtFace);
@@ -67,11 +67,7 @@ SingleCuboidPortalShell::SingleCuboidPortalShell(TrackingVolume& volume)
6767
handle(PositiveYFace, positiveFaceZX);
6868
}
6969

70-
Portal* SingleCuboidPortalShell::portal(Face face) {
71-
return portalPtr(face).get();
72-
}
73-
74-
std::shared_ptr<Portal> SingleCuboidPortalShell::portalPtr(Face face) {
70+
std::shared_ptr<Portal> SingleCuboidPortalShell::portal(Face face) {
7571
return m_portals.at(toUnderlying(face));
7672
}
7773

@@ -183,9 +179,8 @@ CuboidStackPortalShell::CuboidStackPortalShell(
183179

184180
auto merge = [&](Face face) {
185181
std::vector<std::shared_ptr<Portal>> portals;
186-
std::ranges::transform(
187-
m_shells, std::back_inserter(portals),
188-
[face](auto* shell) { return shell->portalPtr(face); });
182+
std::ranges::transform(m_shells, std::back_inserter(portals),
183+
[face](auto* shell) { return shell->portal(face); });
189184

190185
auto merged = std::accumulate(
191186
std::next(portals.begin()), portals.end(), portals.front(),
@@ -216,7 +211,7 @@ CuboidStackPortalShell::CuboidStackPortalShell(
216211
ACTS_VERBOSE("Fusing " << shellA->label() << " and " << shellB->label());
217212

218213
auto fused = std::make_shared<Portal>(Portal::fuse(
219-
gctx, *shellA->portalPtr(faceA), *shellB->portalPtr(faceB), logger));
214+
gctx, *shellA->portal(faceA), *shellB->portal(faceB), logger));
220215

221216
assert(fused != nullptr && "Invalid fused portal");
222217
assert(fused->isValid() && "Fused portal is invalid");
@@ -240,15 +235,11 @@ std::size_t CuboidStackPortalShell::size() const {
240235
return 6;
241236
}
242237

243-
Portal* CuboidStackPortalShell::portal(Face face) {
244-
return portalPtr(face).get();
245-
}
246-
247-
std::shared_ptr<Portal> CuboidStackPortalShell::portalPtr(Face face) {
238+
std::shared_ptr<Portal> CuboidStackPortalShell::portal(Face face) {
248239
if (face == m_backFace) {
249-
return m_shells.back()->portalPtr(face);
240+
return m_shells.back()->portal(face);
250241
} else {
251-
return m_shells.front()->portalPtr(face);
242+
return m_shells.front()->portal(face);
252243
}
253244
}
254245

Core/src/Geometry/CylinderPortalShell.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Acts {
2525
void CylinderPortalShell::fill(TrackingVolume& volume) {
2626
for (Face face : {PositiveDisc, NegativeDisc, OuterCylinder, InnerCylinder,
2727
NegativePhiPlane, PositivePhiPlane}) {
28-
const auto& portalAtFace = portalPtr(face);
28+
const auto& portalAtFace = portal(face);
2929
if (portalAtFace != nullptr) {
3030
portalAtFace->fill(volume);
3131
volume.addPortal(portalAtFace);
@@ -84,11 +84,7 @@ SingleCylinderPortalShell::SingleCylinderPortalShell(TrackingVolume& volume)
8484
}
8585
}
8686

87-
Portal* SingleCylinderPortalShell::portal(Face face) {
88-
return portalPtr(face).get();
89-
}
90-
91-
std::shared_ptr<Portal> SingleCylinderPortalShell::portalPtr(Face face) {
87+
std::shared_ptr<Portal> SingleCylinderPortalShell::portal(Face face) {
9288
return m_portals.at(toUnderlying(face));
9389
}
9490

@@ -155,9 +151,8 @@ CylinderStackPortalShell::CylinderStackPortalShell(
155151

156152
auto merge = [&](Face face) {
157153
std::vector<std::shared_ptr<Portal>> portals;
158-
std::ranges::transform(
159-
m_shells, std::back_inserter(portals),
160-
[face](auto* shell) { return shell->portalPtr(face); });
154+
std::ranges::transform(m_shells, std::back_inserter(portals),
155+
[face](auto* shell) { return shell->portal(face); });
161156

162157
auto merged = std::accumulate(
163158
std::next(portals.begin()), portals.end(), portals.front(),
@@ -186,7 +181,7 @@ CylinderStackPortalShell::CylinderStackPortalShell(
186181
ACTS_VERBOSE("Fusing " << shellA->label() << " and " << shellB->label());
187182

188183
auto fused = std::make_shared<Portal>(Portal::fuse(
189-
gctx, *shellA->portalPtr(faceA), *shellB->portalPtr(faceB), logger));
184+
gctx, *shellA->portal(faceA), *shellB->portal(faceB), logger));
190185

191186
assert(fused != nullptr && "Invalid fused portal");
192187
assert(fused->isValid() && "Fused portal is invalid");
@@ -246,21 +241,17 @@ std::size_t CylinderStackPortalShell::size() const {
246241
return m_hasInnerCylinder ? 4 : 3;
247242
}
248243

249-
Portal* CylinderStackPortalShell::portal(Face face) {
250-
return portalPtr(face).get();
251-
}
252-
253-
std::shared_ptr<Portal> CylinderStackPortalShell::portalPtr(Face face) {
244+
std::shared_ptr<Portal> CylinderStackPortalShell::portal(Face face) {
254245
if (m_direction == AxisDirection::AxisR) {
255246
switch (face) {
256247
case NegativeDisc:
257-
return m_shells.front()->portalPtr(NegativeDisc);
248+
return m_shells.front()->portal(NegativeDisc);
258249
case PositiveDisc:
259-
return m_shells.front()->portalPtr(PositiveDisc);
250+
return m_shells.front()->portal(PositiveDisc);
260251
case OuterCylinder:
261-
return m_shells.back()->portalPtr(OuterCylinder);
252+
return m_shells.back()->portal(OuterCylinder);
262253
case InnerCylinder:
263-
return m_shells.front()->portalPtr(InnerCylinder);
254+
return m_shells.front()->portal(InnerCylinder);
264255
case NegativePhiPlane:
265256
[[fallthrough]];
266257
case PositivePhiPlane:
@@ -274,13 +265,13 @@ std::shared_ptr<Portal> CylinderStackPortalShell::portalPtr(Face face) {
274265
} else {
275266
switch (face) {
276267
case NegativeDisc:
277-
return m_shells.front()->portalPtr(NegativeDisc);
268+
return m_shells.front()->portal(NegativeDisc);
278269
case PositiveDisc:
279-
return m_shells.back()->portalPtr(PositiveDisc);
270+
return m_shells.back()->portal(PositiveDisc);
280271
case OuterCylinder:
281272
[[fallthrough]];
282273
case InnerCylinder:
283-
return m_shells.front()->portalPtr(face);
274+
return m_shells.front()->portal(face);
284275
case NegativePhiPlane:
285276
[[fallthrough]];
286277
case PositivePhiPlane:

Core/src/Geometry/TrapezoidPortalShell.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Acts {
1717
void TrapezoidPortalShell::fill(TrackingVolume& volume) {
1818
for (Face face : {NegativeZFaceXY, PositiveZFaceXY, TrapezoidFaceAlpha,
1919
TrapezoidFaceBeta, NegativeYFaceZX, PositiveYFaceZX}) {
20-
const auto& portalAtFace = portalPtr(face);
20+
const auto& portalAtFace = portal(face);
2121
if (portalAtFace != nullptr) {
2222
portalAtFace->fill(volume);
2323
volume.addPortal(portalAtFace);
@@ -46,11 +46,7 @@ SingleTrapezoidPortalShell::SingleTrapezoidPortalShell(TrackingVolume& volume)
4646
}
4747
}
4848

49-
Portal* SingleTrapezoidPortalShell::portal(Face face) {
50-
return portalPtr(face).get();
51-
}
52-
53-
std::shared_ptr<Portal> SingleTrapezoidPortalShell::portalPtr(Face face) {
49+
std::shared_ptr<Portal> SingleTrapezoidPortalShell::portal(Face face) {
5450
return m_portals.at(toUnderlying(face));
5551
}
5652

Core/src/Geometry/detail/MaterialDesignator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CylinderProtoDesignator : public DesignatorBase {
9090
using enum CylinderVolumeBounds::Face;
9191

9292
for (const auto& [face, loc0, loc1] : m_binning) {
93-
auto* portal = cylShell->portal(face);
93+
auto* portal = cylShell->portal(face).get();
9494
if (portal == nullptr) {
9595
ACTS_ERROR(prefix << "Portal is nullptr");
9696
throw std::runtime_error("Portal is nullptr");
@@ -197,7 +197,7 @@ class CuboidProtoDesignator : public DesignatorBase {
197197
using enum CuboidVolumeBounds::Face;
198198

199199
for (const auto& [face, loc0, loc1] : m_binning) {
200-
auto* portal = cuboidShell->portal(face);
200+
auto* portal = cuboidShell->portal(face).get();
201201
if (portal == nullptr) {
202202
ACTS_ERROR(prefix << "Portal is nullptr");
203203
throw std::runtime_error("Portal is nullptr");
@@ -287,7 +287,7 @@ class ISurfaceMaterialDesignator : public DesignatorBase {
287287
}
288288

289289
for (const auto& [face, material] : m_materials) {
290-
auto* portal = concreteShell->portal(face);
290+
auto* portal = concreteShell->portal(face).get();
291291
if (portal == nullptr) {
292292
ACTS_ERROR(prefix << "Portal is nullptr");
293293
throw std::runtime_error("Portal is nullptr");

0 commit comments

Comments
 (0)