FairRootGroup / FairRoot

C++ simulation, reconstruction and analysis framework for particle physics experiments
http://fairroot.gsi.de
Other
57 stars 96 forks source link

Improve geo classes #1527

Closed fuhlig1 closed 3 months ago

fuhlig1 commented 4 months ago

Improve the Geo classes in the example directory. Move duplicate code into the base class FairGeoSet. In the constructors use setter functions instead to access data members of the base classes directly. Use fmt library for name generation and parsing to get rid of sprintf. Add and improve unit tests for these classes,


Checklist:

Summary by CodeRabbit

coderabbitai[bot] commented 4 months ago
Walkthrough ## Walkthrough This update streamlines geometry management in various simulation classes by standardizing the setting of names and module counts through dedicated methods. It removes outdated methods and variables, enhancing code clarity and maintainability. The changes also include updates to the build system to accommodate these modifications and introduce new tests to ensure consistency in geometry naming conventions. ## Changes | Files | Changes | |-------|---------| | `CMakeLists.txt`, `tests/examples/CMakeLists.txt`, `tests/examples/simulation/rutherford/CMakeLists.txt` | Updated build configurations and added new test suites. | | `.../src/PixelGeo.cxx`, `.../src/FairTestDetectorGeo.cxx`, `.../src/FairTutPropGeo.cxx`, `.../src/FairTutorialDet1Geo.cxx`, `.../src/FairTutorialDet2Geo.cxx`, `.../src/FairTutorialDet4Geo.cxx`, `.../src/FairRutherfordGeo.cxx` | Constructors modified to use `SetName` and `setMaxModules`. Removed `getModuleName` and `getEleName`. | | `.../src/PixelGeo.h`, `.../src/FairTestDetectorGeo.h`, `.../src/FairTutPropGeo.h`, `.../src/FairTutorialDet1Geo.h`, `.../src/FairTutorialDet2Geo.h`, `.../src/FairTutorialDet4Geo.h`, `.../src/FairRutherfordGeo.h` | Removed obsolete declarations and methods. Updated copyright years. | | `fairroot/geobase/FairGeoSet.cxx`, `fairroot/geobase/FairGeoSet.h` | Introduced new methods and member variables for improved module management and string formatting. | | `examples/common/geometry/target_rutherford.geo` | Renamed geometry entity from "targ" to "target1". | | `tests/geobase/checks_FairGeoSet.h` | Modified test generation logic for improved test coverage. | This table summarizes the key files affected by the update, highlighting the nature of the changes and their impact on the project structure and functionality.

Recent Review Details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between d0891a5379cb51f01eae4a4a30d36e58dd28aaec and 85f4ec37d6d1d4c4eab24a6e50e9a979a5251111.
Files selected for processing (22) * CMakeLists.txt (2 hunks) * examples/MQ/pixelDetector/src/PixelGeo.cxx (1 hunks) * examples/MQ/pixelDetector/src/PixelGeo.h (2 hunks) * examples/advanced/Tutorial3/simulation/FairTestDetectorGeo.cxx (1 hunks) * examples/advanced/Tutorial3/simulation/FairTestDetectorGeo.h (2 hunks) * examples/advanced/propagator/src/FairTutPropGeo.cxx (1 hunks) * examples/advanced/propagator/src/FairTutPropGeo.h (2 hunks) * examples/common/geometry/target_rutherford.geo (1 hunks) * examples/simulation/Tutorial1/src/FairTutorialDet1Geo.cxx (1 hunks) * examples/simulation/Tutorial1/src/FairTutorialDet1Geo.h (2 hunks) * examples/simulation/Tutorial2/src/FairTutorialDet2Geo.cxx (1 hunks) * examples/simulation/Tutorial2/src/FairTutorialDet2Geo.h (2 hunks) * examples/simulation/Tutorial4/src/mc/FairTutorialDet4Geo.cxx (1 hunks) * examples/simulation/Tutorial4/src/mc/FairTutorialDet4Geo.h (2 hunks) * examples/simulation/rutherford/src/FairRutherfordGeo.cxx (1 hunks) * examples/simulation/rutherford/src/FairRutherfordGeo.h (2 hunks) * fairroot/geobase/FairGeoSet.cxx (3 hunks) * fairroot/geobase/FairGeoSet.h (4 hunks) * tests/examples/CMakeLists.txt (1 hunks) * tests/examples/simulation/rutherford/CMakeLists.txt (1 hunks) * tests/examples/simulation/rutherford/test_FairRutherfordGeo.cxx (1 hunks) * tests/geobase/checks_FairGeoSet.h (3 hunks)
Files skipped from review due to trivial changes (1) * examples/common/geometry/target_rutherford.geo
Files skipped from review as they are similar to previous changes (21) * CMakeLists.txt * examples/MQ/pixelDetector/src/PixelGeo.cxx * examples/MQ/pixelDetector/src/PixelGeo.h * examples/advanced/Tutorial3/simulation/FairTestDetectorGeo.cxx * examples/advanced/Tutorial3/simulation/FairTestDetectorGeo.h * examples/advanced/propagator/src/FairTutPropGeo.cxx * examples/advanced/propagator/src/FairTutPropGeo.h * examples/simulation/Tutorial1/src/FairTutorialDet1Geo.cxx * examples/simulation/Tutorial1/src/FairTutorialDet1Geo.h * examples/simulation/Tutorial2/src/FairTutorialDet2Geo.cxx * examples/simulation/Tutorial2/src/FairTutorialDet2Geo.h * examples/simulation/Tutorial4/src/mc/FairTutorialDet4Geo.cxx * examples/simulation/Tutorial4/src/mc/FairTutorialDet4Geo.h * examples/simulation/rutherford/src/FairRutherfordGeo.cxx * examples/simulation/rutherford/src/FairRutherfordGeo.h * fairroot/geobase/FairGeoSet.cxx * fairroot/geobase/FairGeoSet.h * tests/examples/CMakeLists.txt * tests/examples/simulation/rutherford/CMakeLists.txt * tests/examples/simulation/rutherford/test_FairRutherfordGeo.cxx * tests/geobase/checks_FairGeoSet.h
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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.` 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 as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
fuhlig1 commented 4 months ago

@coderabbitai generate unit testing code for examples/MQ/pixelDetector/src/PixelGeo.cxx and examples/MQ/pixelDetector/src/PixelGeo.h

coderabbitai[bot] commented 4 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@fuhlig1, here is the unit testing code for PixelGeo.cxx and PixelGeo.h using Google Test. This test suite checks the correct initialization of the PixelGeo object, ensuring that the name and maximum modules are set as expected in the constructor.

#include <gtest/gtest.h>
#include "PixelGeo.h"

class PixelGeoTest : public ::testing::Test {
protected:
    PixelGeo* pixelGeo;

    void SetUp() override {
        pixelGeo = new PixelGeo();
    }

    void TearDown() override {
        delete pixelGeo;
    }
};

TEST_F(PixelGeoTest, ConstructorTest) {
    EXPECT_EQ(pixelGeo->GetName(), "Pixel");
    EXPECT_EQ(pixelGeo->GetMaxModules(), 10);
}

This test suite includes:

Make sure to include Google Test in your project to compile and run this test. If you need further assistance or additional tests, feel free to ask!

Analysis chain
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Fetch the contents of PixelGeo.cxx and PixelGeo.h cat examples/MQ/pixelDetector/src/PixelGeo.cxx cat examples/MQ/pixelDetector/src/PixelGeo.h ``` Length of output: 1811
fuhlig1 commented 4 months ago

@coderabbitai, generate unit testing code for examples/MQ/pixelDetector/src/PixelGeo.cxx and examples/MQ/pixelDetector/src/PixelGeo.h. Take also the base class fairroot/geobase/FairGeoSet.cxx and fairroot/geobase/FairGeoSet.h into account

coderabbitai[bot] commented 4 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@fuhlig1, based on the provided source code for PixelGeo and FairGeoSet, I have generated a more comprehensive unit testing code that includes tests for both the derived class PixelGeo and the base class FairGeoSet. This will help ensure that the integration and inheritance aspects are correctly handled.

Here's the unit testing code using Google Test:

#include <gtest/gtest.h>
#include "PixelGeo.h"
#include "FairGeoSet.h"

class PixelGeoTest : public ::testing::Test {
protected:
    PixelGeo* pixelGeo;
    FairGeoSet* fairGeoSet;

    void SetUp() override {
        pixelGeo = new PixelGeo();
        fairGeoSet = pixelGeo;  // Upcast to base class to test base class functionality
    }

    void TearDown() override {
        delete pixelGeo;
    }
};

TEST_F(PixelGeoTest, ConstructorTest) {
    // Test the constructor of PixelGeo
    EXPECT_EQ(pixelGeo->GetName(), "Pixel");
    EXPECT_EQ(pixelGeo->GetMaxModules(), 10);
}

TEST_F(PixelGeoTest, BaseClassConstructorTest) {
    // Test the constructor of the base class FairGeoSet via PixelGeo
    EXPECT_EQ(fairGeoSet->GetMaxModules(), 10);  // Assuming GetMaxModules is a public method in FairGeoSet
}

TEST_F(PixelGeoTest, ModuleManagement) {
    // Test module management functions if applicable
    int modules[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
    fairGeoSet->setModules(-1, modules);
    int* retrievedModules = fairGeoSet->getModules();
    for (int i = 0; i < 10; ++i) {
        EXPECT_EQ(retrievedModules[i], modules[i]);
    }
}

// Additional tests can be added here to cover more functionalities

This test suite includes:

Make sure to include Google Test in your project to compile and run these tests. If you need further assistance or additional tests, feel free to ask!

Analysis chain
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Fetch the contents of PixelGeo.cxx, PixelGeo.h, FairGeoSet.cxx, and FairGeoSet.h cat examples/MQ/pixelDetector/src/PixelGeo.cxx cat examples/MQ/pixelDetector/src/PixelGeo.h cat fairroot/geobase/FairGeoSet.cxx cat fairroot/geobase/FairGeoSet.h ``` Length of output: 23325
karabowi commented 3 months ago

We will address the requested changes for v19.2.