FairRootGroup / FairRoot

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

Change operator< from FairTimeStamp* to FairTimeStamp& #1526

Closed TobiasStockmanns closed 4 months ago

TobiasStockmanns commented 4 months ago

The behaviour of the FairTimeStamp::operator< does no follow standard behaviour by dealing with the FairTimeStamp* instead of a FairTimeStamp&. This is fixed in this merge request. Should fix issue #1519.

Describe your proposal.

Mention any issue this PR resolves or is related to.


Checklist:

Summary by CodeRabbit

coderabbitai[bot] commented 4 months ago
Walkthrough ## Walkthrough The update to the `FairTimeStamp` class involves transitioning the `operator<` method to utilize a reference parameter instead of a pointer. This change enhances code clarity and efficiency by directly utilizing the `fTimeStamp` member variable for comparisons. ## Changes | File Path | Change Summary | |-----------|----------------| | `.../event/FairTimeStamp.h` | Modified `operator<` to use a reference parameter in `FairTimeStamp`. | ## Possibly related issues - **FairRootGroup/FairRoot#1519**: This issue highlights a warning related to method hiding stemming from overloaded virtual functions. The adjustment in the PR, altering the method signature of `operator<`, may potentially address this warning by eliminating the overloaded method that previously accepted a pointer.

Recent Review Details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 44391b2234a1c145a2048175d4bf3985984ded8d and 4d4707c7684de9ef7ba17d75885b161b61b2a697.
Files selected for processing (2) * CHANGELOG.md (1 hunks) * fairroot/base/event/FairTimeStamp.h (2 hunks)
Additional Context Used
LanguageTool (18)
CHANGELOG.md (18)
Near line 13: Unpaired symbol: ‘]’ seems to be missing Context: ...# Breaking Changes * CMake * Dropped [our custom `FindROOT.cmake`](https://git... --- Near line 53: ‘was in conflict with’ might be wordy. Consider a shorter alternative. Context: ...pped build switch `BUILD_UNITTESTS`, it was in conflict with the CMake standard switch [`BUILD_T... --- Near line 54: Unpaired symbol: ‘]’ seems to be missing Context: ...lict with the CMake standard switch [`BUILD_TESTING` from the CTest module](h... --- Near line 146: Consider inserting a comma after an introductory phrase for better readability. Context: ...es * Allow running without output sink. In this case even persistent branches would not be s... --- Near line 154: A comma may be missing after the conjunctive/linking adverb ‘Also’. Context: ... the Base into the Online library. * Also the MBS/LMD related source classes were... --- Near line 156: With the singular noun ‘one’, use the verb “is”. Context: ...ne library. * If one of these classes are used in your code, you need to link... --- Near line 174: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym. Context: ... being set, rewrite it accordingly. * If your code has specific C++ needs, consi... --- Near line 175: Possible missing comma found. Context: ... CMake's `target_compile_features()`. * Dropped `CHECK_EXTERNAL_PACKAGE_INSTALL_DIR` ... --- Near line 177: This word is normally spelled as one. Context: ...`USE_PATH_INFO` CMake option. It was an anti-pattern. Don't use it! * Dropped `ROOT_GENERATE... --- Near line 193: The word “opt-in” is a noun. The verb is spelled with a space. Context: ...on Boost.Serialization. The user must opt-in to the previously baseline Boost serial... --- Near line 193: You used an adverb (‘previously’) instead of an adjective, or a noun (‘baseline’) instead of another adjective. Context: ...ialization. The user must opt-in to the previously baseline Boost serialization support by includ... --- Near line 206: The conjunction “so that” does not have a comma in front. Context: ...y require some API, please file an issue, so that we can see how to handle this. * Depre... --- Near line 218: Loose punctuation mark. Context: ...tion`. * `FairRadMapManager::Instance`, `FairRadLenManager::Instance` * `Fair... --- Near line 222: Loose punctuation mark. Context: ...thing. * `FairTask::*InputPersistance`: There's no getter for `fInputPersis... --- Near line 229: Loose punctuation mark. Context: ...ConstructASCIIGeometry(T*, TString, U*)`, use `FairModule::ConstructASCIIGeom... --- Near line 255: Possible missing comma found. Context: ...se` style naming. For those using the targets this change will not be visible. * Test... --- Near line 256: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause. Context: ...ing Geant3 have been disabled by default, because those tests have a probability > 0 fo... --- Near line 258: The word ‘anyways’ is informal American English. Did you mean “anyway”? Context: ... for failing. If you want to run them anyways, pass `-DENABLE_GEANT3_TESTING=ON` to...
Additional comments not posted (1)
fairroot/base/event/FairTimeStamp.h (1)
`77-77`: Change in `operator<` from pointer to reference type is correctly implemented. This change simplifies the comparison logic and aligns with C++ best practices by avoiding pointer arithmetic and potential null pointer dereferencing issues.
--- 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

@TobiasStockmanns,

I don't understand why the operator is needed at all. I is neither used in FairRoot nor PandaRoot which was checked by Radek and me independently. Radek simply removed the function, I add the function with =delete. In both cases we did not see any compilation errors. To cross-check I add a test which uses the operator< and this file shows the following error message during compilation

/opt/fairroot/source/v19.0/tests/base/event/test_FairTimeStamp.cxx:20:9: error: overload resolution selected deleted operator '<'
   if (a<b) { a=2.;}
       ~^~
/opt/fairroot/source/v19.0/fairroot/base/event/FairTimeStamp.h:63:11: note: candidate function has been explicitly deleted
     bool operator<(const FairTimeStamp& rValue) = delete;
          ^
/opt/fairsoft/jan24/include/root/TString.h:778:15: note: candidate function not viable: no known conversion from 'FairTimeStamp' to 'const TString' for 1st argument
inline Bool_t operator<(const TString &s1, const TString &s2)
              ^
/opt/fairsoft/jan24/include/root/TString.h:794:15: note: candidate function not viable: no known conversion from 'FairTimeStamp' to 'const TString' for 1st argument
inline Bool_t operator<(const TString &s1, const char *s2)
              ^
/opt/fairsoft/jan24/include/root/TString.h:812:15: note: candidate function not viable: no known conversion from 'FairTimeStamp' to 'const char *' for 1st argument
inline Bool_t operator<(const char *s1, const TString &s2)
              ^
/opt/fairroot/source/v19.0/fairroot/base/event/FairTimeStamp.h:64:11: note: candidate function not viable: no known conversion from 'FairTimeStamp' to 'const FairTimeStamp *' for 1st argument; take the address of the argument with &
     bool operator<(const FairTimeStamp* rValue) = delete;
          ^

I don't see the need for the overloaded function and would propose to simply delete it or at least set it as deprecated.

TobiasStockmanns commented 4 months ago

The original idea why I defined bool operator<(const FairTimeStamp* rValue) was to be able to sort a container of FairTimeStamp* with this operator. Unfortunately this does not work because the sort will always use the memory location and not the FairTimeStamp::operator<. So this implementation does not make any sense. Nevertheless I think it is good to have an bool operator<(const FairTimeStamp& rValue) defined, because for time based simulations and reconstructions a sorting by the time stamp is mandatory and this should be supported by the code. In addition the virtual should be removed.

karabowi commented 4 months ago

@coderabbitai construct short CHANGELOG message for this PR. @TobiasStockmanns , can you squash into one commit?

coderabbitai[bot] commented 4 months ago

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

@karabowi, here's a short CHANGELOG message for PR #1526:

- Updated `FairTimeStamp::operator<` to use references instead of pointers, aligning with standard C++ practices and enhancing safety. This change supports accurate timestamp-based sorting in simulations and reconstructions.

Let me know if you need any further modifications or additional information!

karabowi commented 4 months ago

Please rebase and squash things.

Done.