Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation warnings in MESet* #42188

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 3 additions & 50 deletions DQM/EcalCommon/interface/MESetBinningUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,57 +73,10 @@ namespace ecaldqm {
struct AxisSpecs {
int nbins;
float low, high;
float *edges;
std::string *labels;
std::vector<float> edges;
std::vector<std::string> 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() : nbins(0), low(0.), high(0.), edges(0), labels(0), title("") { ; };
};

AxisSpecs getBinning(EcalElectronicsMapping const *, ObjectType, BinningType, bool, int, unsigned);
Expand Down
7 changes: 2 additions & 5 deletions DQM/EcalCommon/src/MESetBinningUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,7 @@ namespace ecaldqm {
if (_axisParams.existsAs<std::vector<double>>("edges", false)) {
std::vector<double> const &vEdges(_axisParams.getUntrackedParameter<std::vector<double>>("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<int>("nbins");
axis.low = _axisParams.getUntrackedParameter<double>("low");
Expand All @@ -852,9 +851,7 @@ namespace ecaldqm {
if (_axisParams.existsAs<std::vector<std::string>>("labels", false)) {
std::vector<std::string> const &labels(_axisParams.getUntrackedParameter<std::vector<std::string>>("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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion DQM/EcalCommon/src/MESetBinningUtils2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
51 changes: 26 additions & 25 deletions DQM/EcalCommon/src/MESetEcal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> labels(xaxis.labels);
std::string title(xaxis.title);
xaxis = xdef;
delete[] xaxis.labels;
xaxis.labels = labels;
xaxis.title = title;
} else
Expand All @@ -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<string> labels(yaxis.labels);
std::string title(yaxis.title);
yaxis = ydef;
delete[] yaxis.labels;
yaxis.labels = labels;
yaxis.title = title;
} else
Expand Down Expand Up @@ -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<float>(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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<std::string> MESetEcal::generatePaths(EcalElectronicsMapping const *electronicsMap) const {
Expand Down
32 changes: 17 additions & 15 deletions DQM/EcalCommon/src/MESetNonObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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.);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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