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

Code cleanliness improvements in follow-up to #31722 #33865

Conversation

ericcano
Copy link
Contributor

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):

  • 11634.501 (CPU)
  • 11634.502 (GPU)
  • 11634.505 (CPU)
  • 11634.506 (GPU)

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

@cmsbuild
Copy link
Contributor

-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)

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-33865/22898

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @ericcano (Eric Cano) for master.

It involves the following packages:

CUDADataFormats/Track
RecoPixelVertexing/PixelTrackFitting
RecoPixelVertexing/PixelTriplets
RecoTracker/TkSeedGenerator

@perrotta, @makortel, @slava77, @cmsbuild, @fwyzard, @jpata can you please review it and eventually sign? Thanks.
@makortel, @felicepantaleo, @GiacomoSguazzoni, @JanFSchulte, @rovere, @VinInn, @gpetruc, @ebrondol, @mtosi, @dgulhan this is something you requested to watch as well.
@silviodonato, @dpiparo, @qliphy you are the release manager for this.

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
Copy link
Contributor

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

Copy link
Contributor Author

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_; }
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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));
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@fwyzard fwyzard Jun 8, 2021

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

Copy link
Contributor

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.

Copy link
Contributor

@VinInn VinInn Jun 8, 2021

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.

@VinInn
Copy link
Contributor

VinInn commented May 27, 2021

-1
We already discussed that this is NOT the time for all these changes in orthography.
In particular changes in the interface of POD and SoA are not based on any agreed guideline (and this was discussed and agreed in CORE)

@slava77
Copy link
Contributor

slava77 commented Jun 7, 2021

@ericcano
There is a "-1" from @VinInn , which is apparently for a part of the changes.
Is there a fraction of changes that can still go ahead?
please clarify your plans for this PR.
Thank you.

@ericcano
Copy link
Contributor Author

ericcano commented Jun 8, 2021

@slava77 , I propose to leave the 2 PRs on hold while @VinInn is working on code modifications and re-cherry-pick the syntactic fixes on top.

@slava77
Copy link
Contributor

slava77 commented Jun 18, 2021

@slava77 , I propose to leave the 2 PRs on hold while @VinInn is working on code modifications and re-cherry-pick the syntactic fixes on top.

#33889 was merged; now we have a conflict here.
So, it looks like the uncontroversial changes from this and 33864 can now go ahead

Copy link
Contributor

@fwyzard fwyzard left a 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...

Comment on lines +1 to +2
#ifndef CUDADataFormats_Track_PixelTrackHeterogeneousT_h
#define CUDADataFormats_Track_PixelTrackHeterogeneousT_h
Copy link
Contributor

@fwyzard fwyzard Jun 18, 2021

Choose a reason for hiding this comment

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

Suggested change
#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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#endif // CUDADataFormats_Track_PixelTrackHeterogeneousT_h
#endif // CUDADataFormats_Track_interface_TrackSoAHeterogeneousT_h

produces<reco::TrackExtraCollection>();
}

~PixelTrackProducer() override {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
~PixelTrackProducer() override {}
~PixelTrackProducer() override = default;

@slava77
Copy link
Contributor

slava77 commented Jun 24, 2021

@ericcano
please clarify on the status of this PR.
Thank you.

@cmsbuild cmsbuild mentioned this pull request Jun 25, 2021
@ericcano
Copy link
Contributor Author

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.

@ericcano ericcano closed this Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants