|
[Rivet-svn] rivet: Protect Cutflow against vector overflowsRivet Mercurial rivet at projects.hepforge.orgThu Apr 26 16:45:01 BST 2018
details: https://rivet.hepforge.org/hg/rivet/rev/e4e3b9c96f09 branches: release-2-6-x changeset: 6280:e4e3b9c96f09 user: Andy Buckley <andy at insectnation.org> date: Thu Apr 26 16:41:13 2018 +0100 description: Protect Cutflow against vector overflows diffs (truncated from 78 to 50 lines): --- a/include/Rivet/Tools/Cutflow.hh Thu Apr 26 16:27:57 2018 +0100 +++ b/include/Rivet/Tools/Cutflow.hh Thu Apr 26 16:41:13 2018 +0100 @@ -21,14 +21,14 @@ /// @brief Fill the pre-cut counter void fillinit(double weight=1.) { - counts[0] += weight; + counts.front() += weight; } /// @brief Fill the @a {icut}'th post-cut counter, starting at icut=1 for first cut /// /// @note Returns the cut result to allow 'side-effect' cut-flow filling in an if-statement bool fill(size_t icut, bool cutresult=true, double weight=1.) { - if (cutresult) counts[icut] += weight; + if (cutresult) counts.at(icut) += weight; return cutresult; } @@ -53,9 +53,9 @@ bool fill(const vector<bool>& cutresults, double weight=1.) { if (cutresults.size() != ncuts) throw RangeError("Number of filled cut results needs to match the Cutflow construction"); - counts[0] += 1; + counts.front() += 1; for (size_t i = 0; i < ncuts; ++i) { - if (cutresults[i]) counts[i+1] += weight; else break; + if (cutresults[i]) counts.at(i+1) += weight; else break; } return all(cutresults); } @@ -76,7 +76,7 @@ throw RangeError("Number of filled cut results needs to match the Cutflow construction"); const size_t offset = counts.size() - cutresults.size(); for (size_t i = 0; i < cutresults.size(); ++i) { - if (cutresults[i]) counts[offset+i] += weight; else break; + if (cutresults[i]) counts.at(offset+i) += weight; else break; } return all(cutresults); } @@ -88,13 +88,13 @@ /// Scale the cutflow weights so that the weight count after cut @a icut is @a norm void normalize(double norm, size_t icut=0) { - scale(norm/counts[icut]); + scale(norm/counts.at(icut)); } /// Create a string representation string str() const {
More information about the Rivet-svn mailing list |