|
[Rivet-svn] rivet: Fix tricky object lifetime bug affecting WFinder usersRivet Mercurial rivet at projects.hepforge.orgFri Jun 22 19:00:02 BST 2018
details: https://rivet.hepforge.org/hg/rivet/rev/1c2c3599115e branches: release-2-6-x changeset: 6342:1c2c3599115e user: David Grellscheid <david.grellscheid at durham.ac.uk> date: Fri Jun 22 18:51:03 2018 +0100 description: Fix tricky object lifetime bug affecting WFinder users So far, taking a const reference to WFinder::constituentLepton() or ...Neutrino() was unsafe, since they internally rely on returning a temporary value from the filter_select() tools which goes out of scope immediately. Projections need to store such temporaries themselves in member variables. diffs (truncated from 79 to 50 lines): --- a/include/Rivet/Projections/WFinder.hh Thu Jun 21 22:59:23 2018 +0100 +++ b/include/Rivet/Projections/WFinder.hh Fri Jun 22 18:51:03 2018 +0100 @@ -101,20 +101,20 @@ /// @brief Access to the Ws' constituent clustered leptons /// @note Either size 0 if no boson was found or 1 if one boson was found - const Particles constituentLeptons() const; + const Particles& constituentLeptons() const { return _leptons; } /// brief Access to the W's constituent clustered lepton (assuming it exists) /// @todo C++17 std::optional... - const Particle constituentLepton() const { return constituentLeptons().front(); } + const Particle& constituentLepton() const { return _leptons.front(); } /// Access to the Ws' constituent neutrinos /// /// @note Either size 0 if no boson was found or 1 if one boson was found /// @note The neutrino can't be perfecly reconstructed -- this is a pseudo-nu from the MET. - const Particles constituentNeutrinos() const; + const Particles& constituentNeutrinos() const { return _neutrinos; } /// Access to the W's constituent neutrino (assuming it exists) /// @note The neutrino can't be perfecly reconstructed -- this is a pseudo-nu from the MET. - const Particle constituentNeutrino() const { return constituentNeutrinos().front(); } + const Particle& constituentNeutrino() const { return _neutrinos.front(); } /// Access to the particles other than the W leptons and clustered photons @@ -167,6 +167,9 @@ /// Charged lepton flavour PdgId _pid; + /// Result caches. Will be filled by project() + Particles _leptons, _neutrinos; + }; --- a/src/Projections/WFinder.cc Thu Jun 21 22:59:23 2018 +0100 +++ b/src/Projections/WFinder.cc Fri Jun 22 18:51:03 2018 +0100 @@ -72,18 +72,6 @@ - const Particles WFinder::constituentLeptons() const { - if (empty()) return Particles(); - return boson().constituents(isChargedLepton); - } - - - const Particles WFinder::constituentNeutrinos() const {
More information about the Rivet-svn mailing list |