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

Replace swap_or_assign with move in edm::Wrapper<T> constructor #22069

Merged
merged 16 commits into from Feb 23, 2018

Conversation

makortel
Copy link
Contributor

@makortel makortel commented Feb 1, 2018

This PR suggests to replace swap_or_assign() with move assignment in the constructor of edm::Wrapper<T> in order to benefit from compiler-generated move constructor+assignment operator for move-only products instead of having to explicitly write the swap() method every time (I got annoyed and after consultation with @Dr15Jones proceeded for a PR). Here the swap() 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 in swap()
  • MeasurementTrackerEvent needed explicit move constructor+assignment operator because of the use of a boolean member variable to denote ownership of pointers
  • In LHEEventProduct I replaced auto_ptr<PDF> member with unique_ptr<PTR>, after which the compiler-generated move constructor+assignment operator work out of the box needed explicit move constructor+assignment operator because of auto_ptr
    • and anyway auto_ptr was deprecated in C++11 and removed in C++17

For all touched product classes I removed the swap() as unnecessary, except for edmNew::DetSetVector(Trans) where the swap() is used also elsewhere (and swap() is still part of the std::vector interface so for interface compatibility it makes sense to keep it).

Tested with limited matrix in 10_0_0, no changes expected.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 1, 2018

The code-checks are being triggered in jenkins.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 1, 2018

-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
e.g. curl https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-22069/3189/git-diff.patch | patch -p1

You can run scram build code-checks to apply code checks directly

@cmsbuild
Copy link
Contributor

@cmsbuild
Copy link
Contributor

Comparison job queued.

@cmsbuild
Copy link
Contributor

Comparison is ready
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-22069/26189/summary.html

Comparison Summary:

  • No significant changes to the logs found
  • Reco comparison results: 0 differences found in the comparisons
  • DQMHistoTests: Total files compared: 28
  • DQMHistoTests: Total histograms compared: 2498032
  • DQMHistoTests: Total failures: 1
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 2497855
  • DQMHistoTests: Total skipped: 176
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 1.05999999998 KiB( 23 files compared)
  • Checked 115 log files, 9 edm output root files, 28 DQM output files

@perrotta
Copy link
Contributor

+1

@fabiocos
Copy link
Contributor

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

@perrozzi perrozzi Feb 22, 2018

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?

Copy link
Contributor Author

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.

@perrozzi
Copy link
Contributor

+1

@civanch
Copy link
Contributor

civanch commented Feb 22, 2018

+1

@fabiocos
Copy link
Contributor

+1

@fabiocos
Copy link
Contributor

merge

@cmsbuild cmsbuild merged commit 740adde into cms-sw:master Feb 23, 2018
originalXWGTUP_ = std::move(originalXWGTUP_);
scales_ = std::move(scales_);
npLO_ = std::move(npLO_);
npNLO_ = std::move(npNLO_);
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Link to dropbox

Copy link
Contributor

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.

Copy link
Contributor Author

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

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.

None yet