Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • athena athena
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Jira
    • Jira
  • Merge requests 179
    • Merge requests 179
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Issue
    • Repository
  • Activity
  • Graph
  • Commits
Collapse sidebar
  • atlas
  • athenaathena
  • Merge requests
  • !50023

Closed
Created Jan 28, 2022 by Christos Anastopoulos@christosDeveloper
  • Report abuse
Report abuse

Draft: Use CxxUtils::span to reduce const_cast in TrkGeometry

  • Overview 3
  • Commits 4
  • Pipelines 1
  • Changes 28

Hey @ssnyder

this is not to be merged per se, as is at least. As I include the full CxxUtils::span but wanted to see if the "trick" can work

So on top of the span we can do now.

 /** Return all objects of the Array non-const T*/
  const std::vector<T*>& arrayObjects()
  {
    createArrayCache();
    return (*m_arrayObjects);
  }

  /** Return all objects of the Array const T*/
  using const_ptr_span = CxxUtils::span<const T* const>;
  const_ptr_span arrayObjects() const
  {
    createArrayCache();
    return (&*m_arrayObjects.begin(), &*m_arrayObjects.end());
  }

The end product of all of these (span , plus overloads)

  // get a reference surface
  -  const std::vector<const Trk::Surface*>& surfaces =
        m_surfaceArray->arrayObjects();
   + CxxUtils::span<Trk::Surface const * const> surfaces =  std::as_const(*m_surfaceArray).arrayObjects();


  if (m_surfaceArray) {
   - const std::vector<const Trk::Surface*>& surfaces =
        m_surfaceArray->arrayObjects();
   + CxxUtils::span<Trk::Surface const * const > surfaces = std::as_const(*m_surfaceArray).arrayObjects();

  // set the subsurface representation, usually already owned by DetElement
  if (m_surfaceArray) {
 -  const std::vector<const Trk::Surface*>& surfaces =
        m_surfaceArray->arrayObjects();
 -  for (const auto *sIter : surfaces) {
 +  const std::vector<Trk::Surface*>& surfaces = m_surfaceArray->arrayObjects();
 +  for (auto *sIter : surfaces) {
      if (sIter && (*sIter).owner() == Trk::noOwn) {
 -      const_cast<Trk::Surface&>((*sIter)).setOwner(Trk::TGOwn);
 +     (*sIter).setOwner(Trk::TGOwn);

The 2 first are from const methods the last one is non-const one . Of course one will need to do the Volume/Geometry also like the Layer.

Let me ping @sroe . Anyhow needs to go over a bit of code still but seems there is a chance to get rid of quite a few const_cast in TrkGeometry

Edited Jan 28, 2022 by Christos Anastopoulos
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: try_to_fix_const_correct_issue_Geo