Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ProtoLayer can (optionally) hold mutable surfaces #4030

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

paulgessinger
Copy link
Member

@paulgessinger paulgessinger commented Jan 14, 2025

In the Gen3 building context, using mutable pointers makes more sense since we store as much as possible internally as mutable.

This is implemented in a API backwards compatible way, because the Gen1 building assumes the opposite.

PLEASE DESCRIBE YOUR CHANGES.
THIS MESSAGE ENDS UP AS THE COMMIT MESSAGE.
DO NOT USE @-MENTIONS HERE!

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

Summary by CodeRabbit

  • Refactor

    • Restructured ProtoLayer class to improve modularity and flexibility
    • Introduced template-based approach for handling const and non-const surface pointers
    • Moved core functionality into a base class with enhanced parameter calculation methods
  • New Features

    • Added support for both const and mutable surface operations
    • Implemented more flexible surface handling in geometry components
  • Tests

    • Updated unit tests to support const and non-const ProtoLayer scenarios
    • Enhanced test coverage for different surface pointer types

In the Gen3 building context, using mutable pointers makes more sense
since we store as much as possible internally as mutable.

This is implemented in a API backwards compatible way, because the Gen1
building assumes the opposite.
Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

In the realm of geometry, a transformation most profound has occurred! The ProtoLayer class in the Acts library has undergone a metamorphosis, evolving into a more flexible and modular structure. A new base class ProtoLayerBase emerges, accompanied by a templated ProtoLayerT that supports both const and non-const surface pointers. The changes enhance the class's ability to handle surfaces with greater adaptability, introducing a more sophisticated approach to layer representation.

Changes

File Change Summary
Core/include/Acts/Geometry/ProtoLayer.hpp - Introduced ProtoLayerBase as a new base class
- Created templated ProtoLayerT with const/non-const support
- Updated method signatures for surface handling
- Added MutableProtoLayer for mutable operations
Core/src/Geometry/ProtoLayer.cpp - Moved ProtoLayer to Acts::detail namespace
- Refactored methods into ProtoLayerBase
- Removed original constructors and measure method
- Added measureImpl method
Tests/UnitTests/Core/Geometry/ProtoLayerTests.cpp - Introduced templated testProtoLayer function
- Modified test cases to support const and non-const testing
- Updated surface type handling

Suggested labels

Component - Core, Infrastructure, Changes Performance

Suggested reviewers

  • benjaminhuth

Poem

In layers of code, a transformation grows 🌱
Surfaces dance, flexibility flows 🌊
Const and mutable, a template's embrace 🤗
ProtoLayer evolves with elegant grace 🚀
Geometry's wisdom, in lines of delight! ✨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Component - Core Affects the Core module label Jan 14, 2025
@github-actions github-actions bot added this to the next milestone Jan 14, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (7)
Core/src/Geometry/ProtoLayer.cpp (3)

25-27: Clarify the comment, we should.

The comment "To prevent problematic isInsidePolygon check for straw surfaces with only one lseg" may benefit from rephrasing for clarity. Consider explaining why lseg is set to 2 for Straw surfaces.


46-64: Consistent use of parameter names, important it is.

The parameter addenv is misspelled in comments as "enevlope." Correct the spelling for consistency and readability.

- /// @param addenv The steering if enevlope is added or not
+ /// @param addenv The steering if envelope is added or not

68-70: Avoid unnecessary copies, we should.

Passing Extent& extent by non-const reference is acceptable, but ensure no unnecessary copies occur when using it.

Core/include/Acts/Geometry/ProtoLayer.hpp (3)

28-29: Plan for deprecation, we must.

The comment suggests that ProtoLayerBase will go away once Gen1 geometry is removed. Ensure there is a clear plan and timeline for this deprecation to avoid future technical debt.


40-63: Enhance documentation, beneficial it would be.

Provide more detailed descriptions for the methods min, max, medium, and range. Explain the purpose and usage of the addenv parameter in greater detail.


95-110: Simplify the constructor logic, we can.

The conditional compilation using if constexpr improves efficiency. However, consider unifying the logic to reduce code duplication.

Tests/UnitTests/Core/Geometry/ProtoLayerTests.cpp (1)

81-88: Typedef for clarity, consider we should.

Improving readability by creating a type alias for the complex std::shared_ptr type may help.

using SharedSurfacePtr = std::shared_ptr<std::conditional_t<IsConst, const Surface, Surface>>;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b473181 and 748698d.

📒 Files selected for processing (3)
  • Core/include/Acts/Geometry/ProtoLayer.hpp (4 hunks)
  • Core/src/Geometry/ProtoLayer.cpp (1 hunks)
  • Tests/UnitTests/Core/Geometry/ProtoLayerTests.cpp (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unused_files
  • GitHub Check: linux_ubuntu_extra (ubuntu2204_clang, 20)
  • GitHub Check: missing_includes
  • GitHub Check: macos
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20)
  • GitHub Check: build_debug
  • GitHub Check: linux_ubuntu
  • GitHub Check: docs
🔇 Additional comments (3)
Core/src/Geometry/ProtoLayer.cpp (1)

21-41: Proper encapsulation of measureImpl, you have achieved.

The refactoring of measure into measureImpl enhances modularity and reusability. Well done, it is.

Tests/UnitTests/Core/Geometry/ProtoLayerTests.cpp (2)

39-42: Commendable use of templates, it is.

Templating testProtoLayer allows testing of both const and non-const versions efficiently. Excellent approach, you have employed.


168-174: Ensure both test cases cover all scenarios, we must.

While you test both const and non-const versions, verify that all code paths and edge cases are thoroughly tested in both.

Comment on lines +36 to +39
for (const auto& dT : {-0.5 * thickness, 0.5 * thickness}) {
Transform3 dtransform = transform * Translation3{dT * sfNormal};
extent.extend(sfPolyhedron.extent(dtransform));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Ensure thread safety, we must.

If this code is executed in a multi-threaded context, modifying extent without proper synchronization may lead to data races.

Propose adding synchronization mechanisms if necessary.

+ // Ensure thread safety
+ std::lock_guard<std::mutex> lock(extentMutex);
  extent.extend(sfPolyhedron.extent(dtransform));

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +176 to +188
void add(const GeometryContext& gctx, SurfaceType& surface) {
m_surfaces.push_back(&surface);
std::vector<const Surface*> constSurfaces;
if constexpr (!IsConst) {
constSurfaces.reserve(m_surfaces.size());
for (auto* sf : m_surfaces) {
constSurfaces.push_back(sf);
}
measureImpl(gctx, constSurfaces, extent, transform);
} else {
measureImpl(gctx, m_surfaces, extent, transform);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reevaluate the need for multiple measureImpl calls, we should.

Each time add is called, measureImpl recalculates the entire extent. For performance optimization, consider updating the extent incrementally or deferring the full recalculation until necessary.
[performance]

Copy link

📊: Physics performance monitoring for 748698d

Full contents

physmon summary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Core Affects the Core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant