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
Replace swap_or_assign with move in edm::Wrapper<T> constructor #22069
Conversation
…tails::DetSetVectorTrans! Needed because std::atomic does not have move constructor (or assignment operator).
…pCache, RegionsSeedingHitSets, IntermediateHit{Doublets,Triplets}
…lets} as unnecessary
The code-checks are being triggered in jenkins. |
-code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-22069/3189 Code check has found code style and quality issues which could be resolved by applying a patch in https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-22069/3189/git-diff.patch You can run |
+1 The following merge commits were also included on top of IB + this PR after doing git cms-merge-topic: |
Comparison job queued. |
Comparison is ready Comparison Summary:
|
+1
|
@civanch @perrozzi @efeyazgan could you please check? |
@@ -24,6 +24,27 @@ class LHEEventProduct { | |||
LHEEventProduct(const lhef::HEPEUP &hepeup, | |||
const double originalXWGTUP) : | |||
hepeup_(hepeup), originalXWGTUP_(originalXWGTUP) {} | |||
LHEEventProduct(LHEEventProduct&& other) { |
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.
may I ask what are these additions used for?
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.
LHEEventProduct(LHEEventProduct&& other)
is a move constructor and LHEEventProduct& operator=(LHEEventProduct&& other)
is a move assignment operator. They need to be explicitly defined for LHEEventProduct
because of auto_ptr
member.
Motivation (from PR description) is to replace the current pre-C++11 "swap-or-copy" idiom inside edm::Wrapper
with move in order to not require move-only products to define swap()
when compiler-generated move constructor and assignment operator are enough.
+1 |
+1 |
+1 |
merge |
originalXWGTUP_ = std::move(originalXWGTUP_); | ||
scales_ = std::move(scales_); | ||
npLO_ = std::move(npLO_); | ||
npNLO_ = std::move(npNLO_); |
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.
Hi @makortel , I'm MC generator validator of PdmV group. While validating 10_1_0_pre2, I've found that some informations such as npLO & npNLO are missing in generated MC samples. It seems that a bug is introduced from this PR, especially SimDataFormats package. I tried adding other
. in L32-35 & L42-45, but simply adding it could not fix the issue. May I ask you to review this PR? Any questions would be appreciated.
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.
@SanghyunKo Whoops, that's certainly a bug (sorry about that). But I'm puzzled why adding other.
on the right-hand sides of lines 32-35 and 42-45 would not fix the issue. Could you give me a (simple) recipe how to check myself whether the bug is fixed or not?
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.
@SanghyunKo
I see the other
was already added by #22429 (merged in 10_1_0_pre3). I'm nevertheless interested to double-check if the fix actually works or not, so
Could you give me a (simple) recipe how to check myself whether the bug is fixed or not?
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.
@makortel Here I attached link to dropbox that contains simple command that I used to test it, python configuration file and some example of generated LHE file in pre1 & pre2 respectively. I'm also puzzled but let's cross-check it first.
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.
@makortel Sorry, I should have checked pre3 before reporting this. I've just checked it with pre3 and it seems that somehow this issue is fixed in pre3.
Also I've just confirmed that adding other.
fixed the issue in pre2. Maybe I did something wrong while compiling it previously. Anyway, thanks for the reference to #22429.
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.
@SanghyunKo
Thanks for letting me know you got it to work as well (I can also confirm it with the test you provided).
This PR suggests to replace
swap_or_assign()
with move assignment in the constructor ofedm::Wrapper<T>
in order to benefit from compiler-generated move constructor+assignment operator for move-only products instead of having to explicitly write theswap()
method every time (I got annoyed and after consultation with @Dr15Jones proceeded for a PR). Here theswap()
was anyway used for a "move" before C++11.I had to add the move constructor and assignment operators to handful of classes because they were not generated automatically by the compiler (mostly because of deleted copy constructor+assignment operator). There were a few more complex cases:
edmNew::DetSetVectorTrans
needed explicit move constructor+assignment operator because of atomic member variable (which are not movable), logic is as inswap()
MeasurementTrackerEvent
needed explicit move constructor+assignment operator because of the use of a boolean member variable to denote ownership of pointersInLHEEventProduct
I replacedneeded explicit move constructor+assignment operator because ofauto_ptr<PDF>
member withunique_ptr<PTR>
, after which the compiler-generated move constructor+assignment operator work out of the boxauto_ptr
and anywayauto_ptr
was deprecated in C++11 and removed in C++17For all touched product classes I removed the
swap()
as unnecessary, except foredmNew::DetSetVector(Trans)
where theswap()
is used also elsewhere (andswap()
is still part of thestd::vector
interface so for interface compatibility it makes sense to keep it).Tested with limited matrix in 10_0_0, no changes expected.