FairRoot icon indicating copy to clipboard operation
FairRoot copied to clipboard

Change operator< from FairTimeStamp* to FairTimeStamp&

Open TobiasStockmanns opened this issue 1 year ago • 5 comments

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

  • Refactor
    • Updated the comparison method in the timestamp functionality to enhance reliability and performance.

TobiasStockmanns avatar Apr 22 '24 08:04 TobiasStockmanns

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
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>.
    • 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 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.

coderabbitai[bot] avatar Apr 22 '24 08:04 coderabbitai[bot]

@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.

fuhlig1 avatar Apr 24 '24 10:04 fuhlig1

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.

TobiasStockmanns avatar Apr 24 '24 13:04 TobiasStockmanns

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

karabowi avatar Apr 30 '24 08:04 karabowi

[!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!

coderabbitai[bot] avatar Apr 30 '24 08:04 coderabbitai[bot]

Please rebase and squash things.

Done.

karabowi avatar May 13 '24 11:05 karabowi