-
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
Changes from all commits
07c25b6
7467e17
7222e8a
c52e732
01043c8
e783810
323eca7
4ed484d
0eb287c
e1541ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||
#ifndef CUDADataFormats_Track_TrackHeterogeneousT_H | ||||||||||
#define CUDADataFormats_Track_TrackHeterogeneousT_H | ||||||||||
#ifndef CUDADataFormats_Track_PixelTrackHeterogeneousT_h | ||||||||||
#define CUDADataFormats_Track_PixelTrackHeterogeneousT_h | ||||||||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
#include "CUDADataFormats/Track/interface/TrajectoryStateSoAT.h" | ||||||||||
#include "HeterogeneousCore/CUDAUtilities/interface/HistoContainer.h" | ||||||||||
|
@@ -19,39 +19,60 @@ class TrackSoAHeterogeneousT { | |||||||||
using hindex_type = uint32_t; | ||||||||||
using HitContainer = cms::cuda::OneToManyAssoc<hindex_type, S + 1, 5 * S>; | ||||||||||
|
||||||||||
// quality accessors | ||||||||||
constexpr Quality quality(int32_t i) const { return reinterpret_cast<Quality>(quality_(i)); } | ||||||||||
constexpr Quality &quality(int32_t i) { return reinterpret_cast<Quality &>(quality_(i)); } | ||||||||||
constexpr Quality const *qualityData() const { return reinterpret_cast<Quality const *>(quality_.data()); } | ||||||||||
constexpr Quality *qualityData() { return reinterpret_cast<Quality *>(quality_.data()); } | ||||||||||
|
||||||||||
// chi2 accessors | ||||||||||
constexpr auto &chi2(int32_t i) { return chi2_(i); } | ||||||||||
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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
4.25 is was it something from section 7 instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe reason will be displayed to describe this comment to others. Learn more. Ok. So no reason CMS shall be more restrictive than Standard. |
||||||||||
constexpr TrajectoryStateSoAT<S> const &stateAtBS() const { return stateAtBS_; } | ||||||||||
// eta accessors | ||||||||||
constexpr auto &eta(int32_t i) { return eta_(i); } | ||||||||||
constexpr auto eta(int32_t i) const { return eta_(i); } | ||||||||||
// pt accessors | ||||||||||
constexpr auto &pt(int32_t i) { return pt_(i); } | ||||||||||
constexpr auto pt(int32_t i) const { return pt_(i); } | ||||||||||
|
||||||||||
constexpr float charge(int32_t i) const { return std::copysign(1.f, stateAtBS_.state(i)(2)); } | ||||||||||
constexpr float phi(int32_t i) const { return stateAtBS_.state(i)(0); } | ||||||||||
constexpr float tip(int32_t i) const { return stateAtBS_.state(i)(1); } | ||||||||||
constexpr float zip(int32_t i) const { return stateAtBS_.state(i)(4); } | ||||||||||
|
||||||||||
// hitIndices accessors | ||||||||||
constexpr auto &hitIndices() { return hitIndices_; } | ||||||||||
constexpr auto const &hitIndices() const { return hitIndices_; } | ||||||||||
|
||||||||||
// detInndices accessor | ||||||||||
constexpr int nHits(int i) const { return detIndices_.size(i); } | ||||||||||
constexpr auto &detIndices() { return detIndices_; } | ||||||||||
constexpr auto const &detIndices() const { return detIndices_; } | ||||||||||
|
||||||||||
// state at the detector of the outermost hit | ||||||||||
// representation to be decided... | ||||||||||
// not yet filled on GPU | ||||||||||
// TrajectoryStateSoA<S> stateAtOuterDet; | ||||||||||
private: | ||||||||||
// Always check quality is at least loose! | ||||||||||
// CUDA does not support enums in __lgc ... | ||||||||||
private: | ||||||||||
eigenSoA::ScalarSoA<uint8_t, S> quality_; | ||||||||||
|
||||||||||
public: | ||||||||||
constexpr Quality quality(int32_t i) const { return (Quality)(quality_(i)); } | ||||||||||
constexpr Quality &quality(int32_t i) { return (Quality &)(quality_(i)); } | ||||||||||
constexpr Quality const *qualityData() const { return (Quality const *)(quality_.data()); } | ||||||||||
constexpr Quality *qualityData() { return (Quality *)(quality_.data()); } | ||||||||||
|
||||||||||
// this is chi2/ndof as not necessarely all hits are used in the fit | ||||||||||
eigenSoA::ScalarSoA<float, S> chi2; | ||||||||||
|
||||||||||
constexpr int nHits(int i) const { return detIndices.size(i); } | ||||||||||
eigenSoA::ScalarSoA<float, S> chi2_; | ||||||||||
|
||||||||||
// State at the Beam spot | ||||||||||
// phi,tip,1/pt,cotan(theta),zip | ||||||||||
TrajectoryStateSoAT<S> stateAtBS; | ||||||||||
eigenSoA::ScalarSoA<float, S> eta; | ||||||||||
eigenSoA::ScalarSoA<float, S> pt; | ||||||||||
constexpr float charge(int32_t i) const { return std::copysign(1.f, stateAtBS.state(i)(2)); } | ||||||||||
constexpr float phi(int32_t i) const { return stateAtBS.state(i)(0); } | ||||||||||
constexpr float tip(int32_t i) const { return stateAtBS.state(i)(1); } | ||||||||||
constexpr float zip(int32_t i) const { return stateAtBS.state(i)(4); } | ||||||||||
|
||||||||||
// state at the detector of the outermost hit | ||||||||||
// representation to be decided... | ||||||||||
// not yet filled on GPU | ||||||||||
// TrajectoryStateSoA<S> stateAtOuterDet; | ||||||||||
TrajectoryStateSoAT<S> stateAtBS_; | ||||||||||
eigenSoA::ScalarSoA<float, S> eta_; | ||||||||||
eigenSoA::ScalarSoA<float, S> pt_; | ||||||||||
|
||||||||||
HitContainer hitIndices; | ||||||||||
HitContainer detIndices; | ||||||||||
HitContainer hitIndices_; | ||||||||||
HitContainer detIndices_; | ||||||||||
}; | ||||||||||
|
||||||||||
namespace pixelTrack { | ||||||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#ifndef CUDADataFormats_Track_TrajectoryStateSOAT_H | ||
#define CUDADataFormats_Track_TrajectoryStateSOAT_H | ||
#ifndef CUDADataFormats_Track_TrajectoryStateSoAT_h | ||
#define CUDADataFormats_Track_TrajectoryStateSoAT_h | ||
|
||
#include <Eigen/Dense> | ||
#include "HeterogeneousCore/CUDAUtilities/interface/eigenSoA.h" | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any use case where it should translate to a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
I propose to get an exception in the rule clarified after some discussion in the core group. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
cov(4) = cov(3) = 0; | ||
cov(5) = ccov(1, 1); | ||
cov(6) = b * float(ccov(1, 2)); | ||
cov(6) = b * static_cast<float>(ccov(1, 2)); | ||
cov(8) = cov(7) = 0; | ||
cov(9) = b * b * float(ccov(2, 2)); | ||
cov(9) = b * b * static_cast<float>(ccov(2, 2)); | ||
cov(11) = cov(10) = 0; | ||
cov(12) = lcov(0, 0); | ||
cov(13) = lcov(0, 1); | ||
|
@@ -56,4 +56,4 @@ struct TrajectoryStateSoAT { | |
} | ||
}; | ||
|
||
#endif // CUDADataFormats_Track_TrajectoryStateSOAT_H | ||
#endif // CUDADataFormats_Track_TrajectoryStateSoAT_h |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,38 +15,60 @@ | |||||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||||||
#include "Geometry/Records/interface/TrackerTopologyRcd.h" | ||||||
|
||||||
#include "PixelTrackProducer.h" | ||||||
#include "FWCore/Framework/interface/stream/EDProducer.h" | ||||||
#include "RecoPixelVertexing/PixelTrackFitting/interface/PixelTrackReconstruction.h" | ||||||
#include "Geometry/Records/interface/TrackerTopologyRcd.h" | ||||||
#include "storeTracks.h" | ||||||
|
||||||
#include "FWCore/PluginManager/interface/ModuleDef.h" | ||||||
#include "FWCore/Framework/interface/MakerMacros.h" | ||||||
|
||||||
namespace edm { | ||||||
class Event; | ||||||
class EventSetup; | ||||||
class ParameterSet; | ||||||
class ConfigurationDescriptions; | ||||||
} // namespace edm | ||||||
class TrackerTopology; | ||||||
|
||||||
using namespace pixeltrackfitting; | ||||||
using edm::ParameterSet; | ||||||
|
||||||
PixelTrackProducer::PixelTrackProducer(const ParameterSet& cfg) : theReconstruction(cfg, consumesCollector()) { | ||||||
edm::LogInfo("PixelTrackProducer") << " construction..."; | ||||||
produces<reco::TrackCollection>(); | ||||||
produces<TrackingRecHitCollection>(); | ||||||
produces<reco::TrackExtraCollection>(); | ||||||
} | ||||||
class PixelTrackProducer : public edm::stream::EDProducer<> { | ||||||
public: | ||||||
explicit PixelTrackProducer(const edm::ParameterSet& cfg) | ||||||
: theReconstruction(cfg, consumesCollector()), htTopoToken_(esConsumes()) { | ||||||
edm::LogInfo("PixelTrackProducer") << " construction..."; | ||||||
produces<reco::TrackCollection>(); | ||||||
produces<TrackingRecHitCollection>(); | ||||||
produces<reco::TrackExtraCollection>(); | ||||||
} | ||||||
|
||||||
~PixelTrackProducer() override {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||||||
edm::ParameterSetDescription desc; | ||||||
|
||||||
PixelTrackProducer::~PixelTrackProducer() {} | ||||||
desc.add<std::string>("passLabel", "pixelTracks"); // What is this? It is not used anywhere in this code. | ||||||
PixelTrackReconstruction::fillDescriptions(desc); | ||||||
|
||||||
void PixelTrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||||||
edm::ParameterSetDescription desc; | ||||||
descriptions.add("pixelTracks", desc); | ||||||
} | ||||||
|
||||||
desc.add<std::string>("passLabel", "pixelTracks"); // What is this? It is not used anywhere in this code. | ||||||
PixelTrackReconstruction::fillDescriptions(desc); | ||||||
void produce(edm::Event& ev, const edm::EventSetup& es) override { | ||||||
LogDebug("PixelTrackProducer, produce") << "event# :" << ev.id(); | ||||||
|
||||||
descriptions.add("pixelTracks", desc); | ||||||
} | ||||||
TracksWithTTRHs tracks; | ||||||
theReconstruction.run(tracks, ev, es); | ||||||
auto htTopo = es.getData(htTopoToken_); | ||||||
|
||||||
void PixelTrackProducer::produce(edm::Event& ev, const edm::EventSetup& es) { | ||||||
LogDebug("PixelTrackProducer, produce") << "event# :" << ev.id(); | ||||||
// store tracks | ||||||
storeTracks(ev, tracks, htTopo); | ||||||
} | ||||||
|
||||||
TracksWithTTRHs tracks; | ||||||
theReconstruction.run(tracks, ev, es); | ||||||
edm::ESHandle<TrackerTopology> httopo; | ||||||
es.get<TrackerTopologyRcd>().get(httopo); | ||||||
private: | ||||||
PixelTrackReconstruction theReconstruction; | ||||||
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> htTopoToken_; | ||||||
}; | ||||||
|
||||||
// store tracks | ||||||
storeTracks(ev, tracks, *httopo); | ||||||
} | ||||||
DEFINE_FWK_MODULE(PixelTrackProducer); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
auto const &hitIndices = tsoa.hitIndices(); | ||
auto maxTracks = tsoa.stride(); | ||
|
||
int32_t nt = 0; | ||
|
This file was deleted.
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.