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())); }