-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Code cleanliness improvements in follow-up to #31722 #33865
Code cleanliness improvements in follow-up to #31722 #33865
Conversation
…sw#614) Used accessors in all cases. This commit does not change the memory layout of the class. Also fixed C-style casts (reinterpret casts are needed here). cms-sw#31722 (comment) cms-sw#31722 (comment)
Also made the type explicit. cms-patatrack#615 (comment)
-code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-33865/22895
Code check has found code style and quality issues which could be resolved by applying following patch(s)
|
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-33865/22898
|
A new Pull Request was created by @ericcano (Eric Cano) for master. It involves the following packages: CUDADataFormats/Track @perrotta, @makortel, @slava77, @cmsbuild, @fwyzard, @jpata can you please review it and eventually sign? Thanks. cms-bot commands are listed here |
#ifndef CUDADataFormats_Track_TrackHeterogeneousT_H | ||
#define CUDADataFormats_Track_TrackHeterogeneousT_H | ||
#ifndef CUDADataFormats_Track_PixelTrackHeterogeneousT_h | ||
#define CUDADataFormats_Track_PixelTrackHeterogeneousT_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why PIXEL?
is not specific to pixel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this is a mix-up.
constexpr auto chi2(int32_t i) const { return chi2_(i); } | ||
|
||
// stateAtBS accessors | ||
constexpr TrajectoryStateSoAT<S> &stateAtBS() { return stateAtBS_; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already discussed. I strongly disagree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the consequence of applying the coding rule 4.25 which requires only one of each public, protected and private section. (It can be waived under special circumstances, though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a question of "special circumstances". Coding rules were written at a time of naive OOD. This is DDD. This is a struct composed of SoAs. A new type of beast. Old rules do not apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the consequence of applying the coding rule 4.25 which requires only one of each public, protected and private section. (It can be waived under special circumstances, though).
4.25 is Each class may have only one each of public, protected, and private sections, which must be declared in that order.
was it something from section 7 instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, also. Rule 7.4 stipulates that structs should be real PODs with no getters and setters, and that applied here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never understood why a POD looses its "podness" with trivial getters or setters:
what's the difference btw constepxr float A::x() const; and constexpr float x(A const&); ?
Different are constructors or destructor that definitively defy Podness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me 7.4 (and in particular the linked C.131 from the C++ Core Guidelines) does not instruct against a struct with public data members and non-setter/getter member functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never understood why a POD looses its "podness" with trivial getters or setters:
With C++ standard definitionsof POD (or now TrivialType) "podness" is not lost with regular member functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. So no reason CMS shall be more restrictive than Standard.
@@ -25,12 +25,12 @@ struct TrajectoryStateSoAT { | |||
auto cov = covariance(i); | |||
cov(0) = ccov(0, 0); | |||
cov(1) = ccov(0, 1); | |||
cov(2) = b * float(ccov(0, 2)); | |||
cov(2) = b * static_cast<float>(ccov(0, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, do not see the reason to add static_cast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is purely switching to C++ syntax for the cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just adding useless characters. I claim that for intrinsic type "C-type cast" is more readable and more appropriate.
There is NO other type of cast that can be applied here. The semantic MUST be the of "C-type cast". Not of any C++ cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any use case where it should translate to a reinterpret_cast
? There is no dynamic cast for sure with intrisic types and no const correctness issue with an rvalue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, reinterpret_cast between double and float is invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just adding useless characters. I claim that for intrinsic type "C-type cast" is more readable and more appropriate.
There is NO other type of cast that can be applied here. The semantic MUST be the of "C-type cast". Not of any C++ cast.
I propose to get an exception in the rule clarified after some discussion in the core group.
@cms-sw/core-l2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule 4.15 already allows exceptions, and admittedly explicit narrowing conversions within floating point types falls on the low-risk side of C-style casts.
The C++ Core Guidelines advocates for gsl::narrow_cast
(from the guidelines support library). While that describes the intent well, it wouldn't help towards "adding useless characters".
// store tracks | ||
storeTracks(ev, tracks, *httopo); | ||
} | ||
DEFINE_FWK_MODULE(PixelTrackProducer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already said I was takling care of this in my PR that is coming soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can keep this PR on hold and apply on top of yours when it is in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this PR should be closed. None of the modification in here is neither essential nor an improvement.
@@ -133,8 +133,8 @@ void PixelTrackProducerFromSoA::produce(edm::StreamID streamID, | |||
const auto &tsoa = *iEvent.get(tokenTrack_); | |||
|
|||
auto const *quality = tsoa.qualityData(); | |||
auto const &fit = tsoa.stateAtBS; | |||
auto const &hitIndices = tsoa.hitIndices; | |||
auto const &fit = tsoa.stateAtBS(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as noted before, (and discussed already also in CORE, there is no agreement that this is a better syntax for SOA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also a consequence of the 4.25 rule which forces to choose between direct member access in struct style or using accessors, and this class was a in-between.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are very good reason why some members are directly accessed and other through a get functon. For instance it let user to think was is going on! It avoids obfuscations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the question meant: is there any chance we want this to ever be a reinterpret_cast
?
If not, then using a static_cast
is more accurate than a C cast (that can apply all of static_cast
, reinterpret_cast
and const_cast
at once).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that specific case we want the compiler to emit a conversion (by value!). We want a temporary float created there!
equivalent to float tmp = f;
no more, no less. nothing fancy. As in good old C code (or assembler).
I prefer to introduce such an intermediate statement than use a C++ cast that has not place in math expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reinterpret_cast accepted is reinterpret_cast<long long int&>(x) and this is funny as it is equivalent to type punning that is undef behavior. in C++20 they have introduced (at last, after having made undef behavior all C-style idioms!) bit_cast that is equivalent to a memcpy which is the correct semantic. In short nobody uses reinterpret_cast
among intrinsic type.
-1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look this morning, and I'm not sure there are (m)any uncontroversial changes left...
#ifndef CUDADataFormats_Track_PixelTrackHeterogeneousT_h | ||
#define CUDADataFormats_Track_PixelTrackHeterogeneousT_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifndef CUDADataFormats_Track_PixelTrackHeterogeneousT_h | |
#define CUDADataFormats_Track_PixelTrackHeterogeneousT_h | |
#ifndef CUDADataFormats_Track_interface_TrackSoAHeterogeneousT_h | |
#define CUDADataFormats_Track_interface_TrackSoAHeterogeneousT_h |
@@ -70,4 +91,4 @@ namespace pixelTrack { | |||
|
|||
} // namespace pixelTrack | |||
|
|||
#endif // CUDADataFormats_Track_TrackHeterogeneousT_H | |||
#endif // CUDADataFormats_Track_PixelTrackHeterogeneousT_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#endif // CUDADataFormats_Track_PixelTrackHeterogeneousT_h | |
#endif // CUDADataFormats_Track_interface_TrackSoAHeterogeneousT_h |
produces<reco::TrackExtraCollection>(); | ||
} | ||
|
||
~PixelTrackProducer() override {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~PixelTrackProducer() override {} | |
~PixelTrackProducer() override = default; |
@ericcano |
Given the controversial changes based on coding rules that can be waved and the conflicts with PR #34250, I will close the PR, but keep the underlying issue in patatrack (cms-patatrack#616) open, so we can come back to it after. |
PR description:
CMSSW #31722 Patatrack integration - Pixel track reconstruction (10/N) was merged with extra comments to be addressed.
This PR addresses the code cleanliness related comments.
PR validation:
The code was run in workflows (step3 and step4):
The workflow results where then compared using the plots generated by
makeTrackValidationPlots.py
. The CPU workflows gave results identical to the baseline integration build. The GPU workflows displayed slight variations, but the variations are also present between multiple runs of the same version (baseline or this branch).Unit tests were fine except one problem not related the this branch and followed up in #33797