From 4e2a00c4f306ea9f6240f52c2437b6e850254d0f Mon Sep 17 00:00:00 2001 From: Ivan Razumov Date: Tue, 4 Jul 2023 16:13:29 +0200 Subject: [PATCH] Fix compilation warnings in MESetBinningUtils --- DQM/EcalCommon/interface/MESetBinningUtils.h | 52 +------------------- DQM/EcalCommon/src/MESetBinningUtils.cc | 7 +-- DQM/EcalCommon/src/MESetBinningUtils2.cc | 2 +- DQM/EcalCommon/src/MESetEcal.cc | 51 +++++++++---------- DQM/EcalCommon/src/MESetNonObject.cc | 32 ++++++------ 5 files changed, 48 insertions(+), 96 deletions(-) diff --git a/DQM/EcalCommon/interface/MESetBinningUtils.h b/DQM/EcalCommon/interface/MESetBinningUtils.h index 71134f6871556..e6f344e2ef6aa 100644 --- a/DQM/EcalCommon/interface/MESetBinningUtils.h +++ b/DQM/EcalCommon/interface/MESetBinningUtils.h @@ -73,57 +73,9 @@ namespace ecaldqm { struct AxisSpecs { int nbins; float low, high; - float *edges; - std::string *labels; + std::vector edges; + std::vector labels; std::string title; - AxisSpecs() : nbins(0), low(0.), high(0.), edges(nullptr), labels(nullptr), title("") {} - AxisSpecs(AxisSpecs const &_specs) - : nbins(_specs.nbins), - low(_specs.low), - high(_specs.high), - edges(nullptr), - labels(nullptr), - title(_specs.title) { - if (_specs.edges) { - edges = new float[nbins + 1]; - for (int i(0); i <= nbins; i++) - edges[i] = _specs.edges[i]; - } - if (_specs.labels) { - labels = new std::string[nbins]; - for (int i(0); i < nbins; i++) - labels[i] = _specs.labels[i]; - } - } - AxisSpecs &operator=(AxisSpecs const &_rhs) { - if (edges) { - delete[] edges; - edges = nullptr; - } - if (labels) { - delete[] labels; - labels = nullptr; - } - nbins = _rhs.nbins; - low = _rhs.low; - high = _rhs.high; - title = _rhs.title; - if (_rhs.edges) { - edges = new float[nbins + 1]; - for (int i(0); i <= nbins; i++) - edges[i] = _rhs.edges[i]; - } - if (_rhs.labels) { - labels = new std::string[nbins]; - for (int i(0); i < nbins; i++) - labels[i] = _rhs.labels[i]; - } - return *this; - } - ~AxisSpecs() { - delete[] edges; - delete[] labels; - } }; AxisSpecs getBinning(EcalElectronicsMapping const *, ObjectType, BinningType, bool, int, unsigned); diff --git a/DQM/EcalCommon/src/MESetBinningUtils.cc b/DQM/EcalCommon/src/MESetBinningUtils.cc index 064a8ac774167..c7ce7d69e4570 100644 --- a/DQM/EcalCommon/src/MESetBinningUtils.cc +++ b/DQM/EcalCommon/src/MESetBinningUtils.cc @@ -832,8 +832,7 @@ namespace ecaldqm { if (_axisParams.existsAs>("edges", false)) { std::vector const &vEdges(_axisParams.getUntrackedParameter>("edges")); axis.nbins = vEdges.size() - 1; - axis.edges = new float[vEdges.size()]; - std::copy(vEdges.begin(), vEdges.end(), axis.edges); + axis.edges.assign(vEdges.begin(), vEdges.end()); } else { axis.nbins = _axisParams.getUntrackedParameter("nbins"); axis.low = _axisParams.getUntrackedParameter("low"); @@ -852,9 +851,7 @@ namespace ecaldqm { if (_axisParams.existsAs>("labels", false)) { std::vector const &labels(_axisParams.getUntrackedParameter>("labels")); if (int(labels.size()) == axis.nbins) { - axis.labels = new std::string[axis.nbins]; - for (int iB(0); iB != axis.nbins; ++iB) - axis.labels[iB] = labels[iB]; + axis.labels = labels; } } diff --git a/DQM/EcalCommon/src/MESetBinningUtils2.cc b/DQM/EcalCommon/src/MESetBinningUtils2.cc index d037e8698c063..1c9644c720677 100644 --- a/DQM/EcalCommon/src/MESetBinningUtils2.cc +++ b/DQM/EcalCommon/src/MESetBinningUtils2.cc @@ -349,7 +349,7 @@ namespace ecaldqm { break; case kProjEta: specs.nbins = nEBEtaBins + 2 * nEEEtaBins; - specs.edges = new float[specs.nbins + 1]; + specs.edges = std::vector(specs.nbins + 1, 0.f); for (int i(0); i <= nEEEtaBins; i++) specs.edges[i] = -3. + (3. - etaBound) / nEEEtaBins * i; for (int i(1); i <= nEBEtaBins; i++) diff --git a/DQM/EcalCommon/src/MESetEcal.cc b/DQM/EcalCommon/src/MESetEcal.cc index af100cf713a72..869283fb93f95 100644 --- a/DQM/EcalCommon/src/MESetEcal.cc +++ b/DQM/EcalCommon/src/MESetEcal.cc @@ -100,11 +100,10 @@ namespace ecaldqm { if (xaxis.nbins == 0) { // uses preset binning::AxisSpecs xdef(binning::getBinning(electronicsMap, actualObject, btype_, isMap, 1, iME)); - if (xaxis.labels || !xaxis.title.empty()) { // PSet specifies title / label only - std::string *labels(xaxis.labels); + if (!xaxis.labels.empty() || !xaxis.title.empty()) { // PSet specifies title / label only + std::vector labels(xaxis.labels); std::string title(xaxis.title); xaxis = xdef; - delete[] xaxis.labels; xaxis.labels = labels; xaxis.title = title; } else @@ -113,11 +112,10 @@ namespace ecaldqm { if (isMap && yaxis.nbins == 0) { binning::AxisSpecs ydef(binning::getBinning(electronicsMap, actualObject, btype_, isMap, 2, iME)); - if (yaxis.labels || !yaxis.title.empty()) { // PSet specifies title / label only - std::string *labels(yaxis.labels); + if (!yaxis.labels.empty() || !yaxis.title.empty()) { // PSet specifies title / label only + std::vector labels(yaxis.labels); std::string title(yaxis.title); yaxis = ydef; - delete[] yaxis.labels; yaxis.labels = labels; yaxis.title = title; } else @@ -149,49 +147,51 @@ namespace ecaldqm { break; case MonitorElement::Kind::TH1F: - if (xaxis.edges) - me = _ibooker.book1D(name, name, xaxis.nbins, xaxis.edges); - else + if (xaxis.edges.empty()) me = _ibooker.book1D(name, name, xaxis.nbins, xaxis.low, xaxis.high); + else + me = _ibooker.book1D(name, name, xaxis.nbins, &(xaxis.edges[0])); break; case MonitorElement::Kind::TPROFILE: - if (xaxis.edges) { + if (xaxis.edges.empty()) { + me = _ibooker.bookProfile(name, name, xaxis.nbins, xaxis.low, xaxis.high, yaxis.low, yaxis.high, ""); + } else { // DQMStore bookProfile interface uses double* for bin edges double *edges(new double[xaxis.nbins + 1]); - std::copy(xaxis.edges, xaxis.edges + xaxis.nbins + 1, edges); + std::copy(xaxis.edges.begin(), xaxis.edges.end(), edges); me = _ibooker.bookProfile(name, name, xaxis.nbins, edges, yaxis.low, yaxis.high, ""); delete[] edges; - } else - me = _ibooker.bookProfile(name, name, xaxis.nbins, xaxis.low, xaxis.high, yaxis.low, yaxis.high, ""); + } break; case MonitorElement::Kind::TH2F: - if (xaxis.edges || yaxis.edges) { + if (xaxis.edges.empty() && yaxis.edges.empty()) { + me = _ibooker.book2D(name, name, xaxis.nbins, xaxis.low, xaxis.high, yaxis.nbins, yaxis.low, yaxis.high); + } else { binning::AxisSpecs *specs[] = {&xaxis, &yaxis}; for (int iSpec(0); iSpec < 2; iSpec++) { - if (!specs[iSpec]->edges) { - specs[iSpec]->edges = new float[specs[iSpec]->nbins + 1]; + if (!specs[iSpec]->edges.empty()) { + specs[iSpec]->edges = std::vector(specs[iSpec]->nbins + 1); int nbins(specs[iSpec]->nbins); double low(specs[iSpec]->low), high(specs[iSpec]->high); for (int i(0); i < nbins + 1; i++) specs[iSpec]->edges[i] = low + (high - low) / nbins * i; } } - me = _ibooker.book2D(name, name, xaxis.nbins, xaxis.edges, yaxis.nbins, yaxis.edges); - } else - me = _ibooker.book2D(name, name, xaxis.nbins, xaxis.low, xaxis.high, yaxis.nbins, yaxis.low, yaxis.high); + me = _ibooker.book2D(name, name, xaxis.nbins, &(xaxis.edges[0]), yaxis.nbins, &(yaxis.edges[0])); + } break; case MonitorElement::Kind::TPROFILE2D: - if (zaxis.edges) { + if (!zaxis.edges.empty()) { zaxis.low = zaxis.edges[0]; zaxis.high = zaxis.edges[zaxis.nbins]; } - if (xaxis.edges || yaxis.edges) + if (!(xaxis.edges.empty() && yaxis.edges.empty())) throw_("Variable bin size for 2D profile not implemented"); me = _ibooker.bookProfile2D(name, name, @@ -220,15 +220,15 @@ namespace ecaldqm { if (isMap) me->setAxisTitle(zaxis.title, 3); - if (xaxis.labels) { + if (!xaxis.labels.empty()) { for (int iBin(1); iBin <= xaxis.nbins; ++iBin) me->setBinLabel(iBin, xaxis.labels[iBin - 1], 1); } - if (yaxis.labels) { + if (!yaxis.labels.empty()) { for (int iBin(1); iBin <= yaxis.nbins; ++iBin) me->setBinLabel(iBin, yaxis.labels[iBin - 1], 2); } - if (zaxis.labels) { + if (!zaxis.labels.empty()) { for (int iBin(1); iBin <= zaxis.nbins; ++iBin) me->setBinLabel(iBin, zaxis.labels[iBin - 1], 3); } @@ -590,7 +590,8 @@ namespace ecaldqm { } bool MESetEcal::isVariableBinning() const { - return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges); + return (xaxis_ && !xaxis_->edges.empty()) || (yaxis_ && !yaxis_->edges.empty()) || + (zaxis_ && !zaxis_->edges.empty()); } std::vector MESetEcal::generatePaths(EcalElectronicsMapping const *electronicsMap) const { diff --git a/DQM/EcalCommon/src/MESetNonObject.cc b/DQM/EcalCommon/src/MESetNonObject.cc index e5c942ff6bdf2..0d1085eb699c4 100644 --- a/DQM/EcalCommon/src/MESetNonObject.cc +++ b/DQM/EcalCommon/src/MESetNonObject.cc @@ -80,10 +80,10 @@ namespace ecaldqm { if (!xaxis_) throw_("No xaxis found for MESetNonObject"); - if (xaxis_->edges) - me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->edges); - else + if (xaxis_->edges.empty()) me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high); + else + me = _ibooker.book1D(name, name, xaxis_->nbins, &(xaxis_->edges[0])); } break; case MonitorElement::Kind::TPROFILE: { @@ -98,32 +98,33 @@ namespace ecaldqm { ylow = yaxis_->low; yhigh = yaxis_->high; } - if (xaxis_->edges) { + if (xaxis_->edges.empty()) { + me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, ""); + } else { // DQMStore bookProfile interface uses double* for bin edges double *edges(new double[xaxis_->nbins + 1]); - std::copy(xaxis_->edges, xaxis_->edges + xaxis_->nbins + 1, edges); + std::copy(xaxis_->edges.begin(), xaxis_->edges.end(), edges); me = _ibooker.bookProfile(name, name, xaxis_->nbins, edges, ylow, yhigh, ""); delete[] edges; - } else - me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, ""); + } } break; case MonitorElement::Kind::TH2F: { if (!xaxis_ || !yaxis_) throw_("No x/yaxis found for MESetNonObject"); - if (!xaxis_->edges || !yaxis_->edges) // unlike MESetEcal, if either of X or Y is not set as - // variable, binning will be fixed + if (xaxis_->edges.empty() && yaxis_->edges.empty()) // unlike MESetEcal, if either of X or Y is not set as + // variable, binning will be fixed me = _ibooker.book2D( name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high); else - me = _ibooker.book2D(name, name, xaxis_->nbins, xaxis_->edges, yaxis_->nbins, yaxis_->edges); + me = _ibooker.book2D(name, name, xaxis_->nbins, &(xaxis_->edges[0]), yaxis_->nbins, &(yaxis_->edges[0])); } break; case MonitorElement::Kind::TPROFILE2D: { if (!xaxis_ || !yaxis_) throw_("No x/yaxis found for MESetNonObject"); - if (xaxis_->edges || yaxis_->edges) + if (!(xaxis_->edges.empty() && yaxis_->edges.empty())) throw_("Variable bin size for 2D profile not implemented"); double high(0.), low(0.); @@ -154,21 +155,21 @@ namespace ecaldqm { if (xaxis_) { me->setAxisTitle(xaxis_->title, 1); - if (xaxis_->labels) { + if (!xaxis_->labels.empty()) { for (int iBin(1); iBin <= xaxis_->nbins; ++iBin) me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1); } } if (yaxis_) { me->setAxisTitle(yaxis_->title, 2); - if (yaxis_->labels) { + if (!yaxis_->labels.empty()) { for (int iBin(1); iBin <= yaxis_->nbins; ++iBin) me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2); } } if (zaxis_) { me->setAxisTitle(zaxis_->title, 3); - if (zaxis_->labels) { + if (!zaxis_->labels.empty()) { for (int iBin(1); iBin <= zaxis_->nbins; ++iBin) me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3); } @@ -319,6 +320,7 @@ namespace ecaldqm { } bool MESetNonObject::isVariableBinning() const { - return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges); + return (xaxis_ && (!xaxis_->edges.empty())) || (yaxis_ && (!yaxis_->edges.empty())) || + (zaxis_ && (!zaxis_->edges.empty())); } } // namespace ecaldqm