ATLASRECTS-5781: First try for the first part. Cleaning up the strawCaches
ATLASRECTS-5781 (ATR-22378) : First try Not sure if works 100% (CI will prb tell us more)
The main changes:
- CxxUtils::CachedUniquePtrT<
std::vector<std::unique_ptr<Trk::StraightLineSurface>>>
m_strawSurfaces{};
- CxxUtils::CachedUniquePtrT<std::vector<std::unique_ptr<SurfaceCache>>>
m_strawSurfacesCache{};
+ std::vector<CxxUtils::CachedUniquePtr<Trk::StraightLineSurface>> m_strawSurfaces{};
+ std::vector<CxxUtils::CachedUniquePtr<SurfaceCache>> m_strawSurfacesCache{};
This means we can and do eagerly initialize the vectors since we can not the size during constuctions of an object. so these go
TRT_BaseElement::createStrawSurfaces() const
{
auto strawSurfaces = std::make_unique<
std::vector<std::unique_ptr<Trk::StraightLineSurface>>>(nStraws());
m_strawSurfaces.set(std::move(strawSurfaces));
}
void
TRT_BaseElement::createStrawSurfacesCache() const
{
auto strawSurfacesCache =
std::make_unique<std::vector<std::unique_ptr<SurfaceCache>>>(nStraws());
m_strawSurfacesCache.set(std::move(strawSurfacesCache));
}
and we have
m_nstraws = m_descriptor->nStraws();
m_strawSurfaces.resize(m_nstraws);
m_strawSurfacesCache.resize(m_nstraws);
Due to discussion in !38322 (merged) and the JIRA we might want to be sure that the inner ptr are CachedUniquePtr
The above two combined give us
const Amg::Transform3D&
TRT_BaseElement::strawTransform(unsigned int straw) const
{
if (!m_strawSurfacesCache[straw]) {
Identifier id = m_idHelper->straw_id(identify(), straw);
createSurfaceCache(id);
}
// forward the transform of the cache
return *(m_strawSurfacesCache[straw]->transform());
}
instead of
const Amg::Transform3D& TRT_BaseElement::strawTransform(unsigned int straw) const
{
if (!m_strawSurfacesCache) {createStrawSurfacesCache();}
SurfaceCache* sCachePtr = (*m_strawSurfacesCache)[straw].get();
if (!sCachePtr) {
Identifier id = m_idHelper->straw_id(identify(), straw);
createSurfaceCache(id);
sCachePtr = (*m_strawSurfacesCache)[straw].get();
}
// forward the transform of the cache
return *(sCachePtr->transform());
}
mutable std::vector<const Trk::Surface*> m_surfaces ATLAS_THREAD_SAFE; // Guarded by m_mutex
mutable std::mutex m_mutex;
becomes
//Cache of vector of non owning pointers for the straw surfaces
CxxUtils::CachedValue<std::vector<const Trk::Surface*>> m_surfaces;
I also used nullptr
, default
/delete
, used a bit more unique_ptr
Plus some other indentation aesthetic changes.
Mentiong @oda