Skip to content

Commit 451eee9

Browse files
authored
[PWGCF] Fix string forming issue (#17567)
1 parent e1f98e8 commit 451eee9

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

PWGCF/FemtoDream/Core/femtoDreamObjectSelection.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <TH1.h>
2626

27+
#include <fmt/format.h>
28+
2729
#include <algorithm>
2830
#include <cstddef>
2931
#include <string>
@@ -52,7 +54,11 @@ class FemtoDreamObjectSelection
5254
void fillSelectionHistogram()
5355
{
5456
int nBins = mSelections.size();
55-
mQAHistogramRegistry->add((static_cast<std::string>(o2::aod::femtodreamparticle::ParticleTypeName[part]) + "/cuthist").c_str(), "; Cut; Value", o2::framework::HistType::kTH1F, {{nBins, 0, static_cast<double>(nBins)}});
57+
// fmt::format, not std::string + const char*: the longest names here are
58+
// exactly 32 characters, so the concatenation crosses std::string's SSO
59+
// boundary and GCC 14 reports the constant-folded copy as
60+
// -Werror=array-bounds= on a buffer that is never actually used.
61+
mQAHistogramRegistry->add(fmt::format("{}/cuthist", o2::aod::femtodreamparticle::ParticleTypeName[part]).c_str(), "; Cut; Value", o2::framework::HistType::kTH1F, {{nBins, 0, static_cast<double>(nBins)}});
5662
auto hist = mQAHistogramRegistry->get<TH1>(HIST(o2::aod::femtodreamparticle::ParticleTypeName[part]) + HIST("/cuthist"));
5763
for (size_t i = 0; i < mSelections.size(); ++i) {
5864
hist->GetXaxis()->SetBinLabel(i + 1, Form("%u", mSelections.at(i).getSelectionVariable()));

PWGCF/FemtoDream/Core/femtoDreamParticleHisto.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <TMath.h>
2929
#include <TPDGCode.h>
3030

31+
#include <fmt/format.h>
32+
3133
#include <cstdlib>
3234
#include <string>
3335
#include <string_view>
@@ -340,7 +342,7 @@ class FemtoDreamParticleHisto
340342
framework::AxisSpec InvMassAxis = {InvMassBins, "M_{inv} (GeV/#it{c}^{2})"};
341343
framework::AxisSpec InvMassCompetingAxis = {InvMassCompetingBins, "M_{inv} (GeV/#it{c}^{2})"};
342344

343-
std::string folderName = (static_cast<std::string>(o2::aod::femtodreamparticle::ParticleTypeName[mParticleType]).c_str() + static_cast<std::string>(mFolderSuffix[mFolderSuffixType])).c_str();
345+
std::string folderName = fmt::format("{}{}", o2::aod::femtodreamparticle::ParticleTypeName[mParticleType], mFolderSuffix[mFolderSuffixType]);
344346

345347
// Fill here the actual histogramms by calling init_base and init_MC
346348
init_base<o2::aod::femtodreamMCparticle::MCType::kRecon>(folderName, tempFitVarAxisTitle, pTAxis, tempFitVarAxis, InvMassAxis, multAxis);

PWGCF/FemtoDream/Core/femtoDreamTrackSelection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <Framework/Logger.h>
3030
#include <ReconstructionDataFormats/PID.h>
3131

32+
#include <fmt/format.h>
33+
3234
#include <array>
3335
#include <cmath>
3436
#include <cstddef>
@@ -313,7 +315,7 @@ void FemtoDreamTrackSelection::init(o2::framework::HistogramRegistry* QAregistry
313315
if (QAregistry && Registry) {
314316
mHistogramRegistry = Registry;
315317
mQAHistogramRegistry = QAregistry;
316-
std::string folderName = static_cast<std::string>(o2::aod::femtodreamparticle::ParticleTypeName[part]) + "/" + static_cast<std::string>(o2::aod::femtodreamparticle::TrackTypeName[tracktype]);
318+
std::string folderName = fmt::format("{}/{}", o2::aod::femtodreamparticle::ParticleTypeName[part], o2::aod::femtodreamparticle::TrackTypeName[tracktype]);
317319

318320
/// check whether the number of selection exceeds the bitmap size
319321
unsigned int nSelections = getNSelections() - getNSelections(femtoDreamTrackSelection::kPIDnSigmaMax);

PWGCF/FemtoDream/Core/femtoDreamV0Selection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <Framework/HistogramSpec.h>
2929
#include <Framework/Logger.h>
3030

31+
#include <fmt/format.h>
32+
3133
#include <array>
3234
#include <cstddef>
3335
#include <cstdlib>
@@ -304,8 +306,8 @@ void FemtoDreamV0Selection::init(o2::framework::HistogramRegistry* QAregistry, o
304306
}
305307
for (int istage = 0; istage < femtoDreamSelection::kNcutStages; istage++) {
306308
std::string folderName =
307-
static_cast<std::string>(o2::aod::femtodreamparticle::ParticleTypeName[part]) + "/" +
308-
static_cast<std::string>(femtoDreamSelection::mCutStage[istage]);
309+
fmt::format("{}/{}", o2::aod::femtodreamparticle::ParticleTypeName[part],
310+
femtoDreamSelection::mCutStage[istage]);
309311
/// \todo initialize histograms for children tracks of v0s
310312
mQAHistogramRegistry->add((folderName + "/hPt").c_str(),
311313
"; #it{p}_{T} (GeV/#it{c}); Entries", o2::framework::HistType::kTH1F,

0 commit comments

Comments
 (0)