From 03683e1ff8584c197aca06d973bb366982d4d6c5 Mon Sep 17 00:00:00 2001 From: shahoian Date: Mon, 3 Jun 2024 13:52:45 +0200 Subject: [PATCH] Do not throw on merging non-initialized flat histors --- DataFormats/common/src/FlatHisto1D.cxx | 5 +++-- DataFormats/common/src/FlatHisto2D.cxx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DataFormats/common/src/FlatHisto1D.cxx b/DataFormats/common/src/FlatHisto1D.cxx index 1313da72da8b7..8e04c2c58614e 100644 --- a/DataFormats/common/src/FlatHisto1D.cxx +++ b/DataFormats/common/src/FlatHisto1D.cxx @@ -40,9 +40,10 @@ FlatHisto1D& FlatHisto1D::operator=(const FlatHisto1D& rhs) if (this == &rhs) { return *this; } - if (!rhs.canFill()) { + if (!rhs.canFill() && rhs.getNBins()) { // was initialized throw std::runtime_error("trying to copy read-only histogram"); - } else { + } + if (rhs.getNBins()) { mContainer = rhs.mContainer; init(gsl::span(mContainer.data(), mContainer.size())); } diff --git a/DataFormats/common/src/FlatHisto2D.cxx b/DataFormats/common/src/FlatHisto2D.cxx index b06241ff8d193..aa064eee10bca 100644 --- a/DataFormats/common/src/FlatHisto2D.cxx +++ b/DataFormats/common/src/FlatHisto2D.cxx @@ -43,9 +43,10 @@ FlatHisto2D& FlatHisto2D::operator=(const FlatHisto2D& rhs) if (this == &rhs) { return *this; } - if (!rhs.canFill()) { + if (!rhs.canFill() && rhs.getNBins()) { // was initialized throw std::runtime_error("trying to copy read-only histogram"); - } else { + } + if (rhs.getNBins()) { mContainer = rhs.mContainer; init(gsl::span(mContainer.data(), mContainer.size())); }