From e0f1717b397a57b8801a379980e526f39a0e1c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Thu, 22 Oct 2026 19:03:50 +0200 Subject: [PATCH] Fix casts Fixes C-style, redundant, wrong, and dangerous casts (found by Clang-Tidy and cpplint). - Remove redundant casts. (`readability-redundant-casting`) - Remove `const_cast`. (`cppcoreguidelines-pro-type-const-cast`) - Replace C-style casts with `static_cast`. (`google-readability-casting`, cpplint: `readability/casting`) - Replace unsafe C-style casts with `dynamic_cast`. (`cppcoreguidelines-pro-type-cstyle-cast`) - Replace `static_cast` in downcasts with `dynamic_cast`. (`cppcoreguidelines-pro-type-static-cast-downcast`) - Replace `reinterpret_cast` with `static_cast` or `dynamic_cast`. (`cppcoreguidelines-pro-type-reinterpret-cast`) - Replace two-step casting through `void*` with `reinterpret_cast`. (`bugprone-casting-through-void`) --- Tutorials/ML/applyMlSelection.cxx | 2 +- Tutorials/OpenData/flowAnalysis.cxx | 4 ++-- Tutorials/PWGCF/EventPlane/src/spectatorPlaneTutorial.cxx | 8 ++++---- Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask3.cxx | 4 ++-- Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask4.cxx | 4 ++-- Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask5.cxx | 4 ++-- .../PWGCF/FlowGenericFramework/src/flowGFWTutorial.cxx | 2 +- Tutorials/PWGEM/Cocktail/plotLFCocktail.C | 6 +++--- Tutorials/PWGLF/Resonance/resonancesCombine.cxx | 4 ++-- Tutorials/PWGUD/UDTutorial_02b.cxx | 2 +- Tutorials/src/configurableObjects.cxx | 6 +++--- Tutorials/src/extendedTables.cxx | 2 +- Tutorials/src/reweighting.cxx | 2 +- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Tutorials/ML/applyMlSelection.cxx b/Tutorials/ML/applyMlSelection.cxx index 2bee237ab3e..766b4252795 100644 --- a/Tutorials/ML/applyMlSelection.cxx +++ b/Tutorials/ML/applyMlSelection.cxx @@ -82,7 +82,7 @@ struct applyMlSelection { void init(InitContext const&) { // Add histograms vs pT (only for selected candidates) - auto vbins = (std::vector)binsPtMl; + auto vbins = std::vector(binsPtMl); registry.add("hMassAfterSelVsPt", "Ds candidates;inv. mass (KK#pi) (GeV/#it{c}^{2});entries", {HistType::kTH2F, {{100, 1.77, 2.17}, {vbins, "#it{p}_{T} (GeV/#it{c})"}}}); registry.add("hPromptScoreAfterSelVsPt", "Prompt score after selection;BDT first score;entries", {HistType::kTH2F, {{100, 0., 1.}, {vbins, "#it{p}_{T} (GeV/#it{c})"}}}); diff --git a/Tutorials/OpenData/flowAnalysis.cxx b/Tutorials/OpenData/flowAnalysis.cxx index 35bc2c2021c..6f71ff609c5 100644 --- a/Tutorials/OpenData/flowAnalysis.cxx +++ b/Tutorials/OpenData/flowAnalysis.cxx @@ -87,8 +87,8 @@ struct flow_base { HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; - Filter collisionFilter = (aod::collision::flags & (uint16_t)aod::collision::CollisionFlagsRun2::Run2VertexerTracks) == (uint16_t)aod::collision::CollisionFlagsRun2::Run2VertexerTracks; - Filter trackFilter = ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == (uint8_t)true)); + Filter collisionFilter = (aod::collision::flags & static_cast(aod::collision::CollisionFlagsRun2::Run2VertexerTracks)) == static_cast(aod::collision::CollisionFlagsRun2::Run2VertexerTracks); + Filter trackFilter = ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast(true))); void fillAPt(double trackpt, double cent, double vn, double sinHarm, double cosHarm) { diff --git a/Tutorials/PWGCF/EventPlane/src/spectatorPlaneTutorial.cxx b/Tutorials/PWGCF/EventPlane/src/spectatorPlaneTutorial.cxx index d99a16fb996..8e2ef19f665 100644 --- a/Tutorials/PWGCF/EventPlane/src/spectatorPlaneTutorial.cxx +++ b/Tutorials/PWGCF/EventPlane/src/spectatorPlaneTutorial.cxx @@ -77,7 +77,7 @@ struct SpectatorPlaneTutorial { float dcaZMax = 2.0; Filter collisionFilter = nabs(aod::collision::posZ) < vtxZ; - Filter trackFilter = nabs(aod::track::eta) < etaMax && aod::track::pt > ptMin&& aod::track::pt < ptMax && ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == (uint8_t) true)) && nabs(aod::track::dcaXY) < dcaXYMax&& nabs(aod::track::dcaZ) < dcaZMax; + Filter trackFilter = nabs(aod::track::eta) < etaMax && aod::track::pt > ptMin&& aod::track::pt < ptMax && ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast(true))) && nabs(aod::track::dcaXY) < dcaXYMax&& nabs(aod::track::dcaZ) < dcaZMax; using GeneralCollisions = soa::Join; using UnfilteredTracks = soa::Join; @@ -182,9 +182,9 @@ struct SpectatorPlaneTutorial { // Get QQ-correlations from CCDB if (cfgCCDBdir_QQ.value.empty() == false) { TList* list = ccdb->getForTimeStamp(cfgCCDBdir_QQ.value, bc.timestamp()); - TProfile* qAqCX = reinterpret_cast(list->FindObject("qAqCX")); - TProfile* qAqCY = reinterpret_cast(list->FindObject("qAqCY")); - TProfile* qAqCXY = reinterpret_cast(list->FindObject("qAqCXY")); + TProfile* qAqCX = dynamic_cast(list->FindObject("qAqCX")); + TProfile* qAqCY = dynamic_cast(list->FindObject("qAqCY")); + TProfile* qAqCXY = dynamic_cast(list->FindObject("qAqCXY")); // The sum is qAqCXY corrQQx = qAqCX->GetBinContent(centrality); corrQQy = qAqCY->GetBinContent(centrality); diff --git a/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask3.cxx b/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask3.cxx index 112b4d053b5..f31e4ad46d0 100644 --- a/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask3.cxx +++ b/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask3.cxx @@ -69,8 +69,8 @@ struct CFTutorialTask3 { // Partitions for particle 1 and particle 2 // add PID selection to partition definition - Partition PartsOne = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne); - Partition PartsTwo = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo); + Partition PartsOne = (aod::femtodreamparticle::partType == static_cast(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne); + Partition PartsTwo = (aod::femtodreamparticle::partType == static_cast(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo); HistogramRegistry HistRegistry{"FemtoTutorial", {}, OutputObjHandlingPolicy::AnalysisObject}; diff --git a/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask4.cxx b/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask4.cxx index fdfcf410147..28db4793c05 100644 --- a/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask4.cxx +++ b/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask4.cxx @@ -69,8 +69,8 @@ struct CFTutorialTask4 { Configurable ConfPIDThresholdPartTwo{"ConfPIDThresholdPartTwo", 0.75, "Particle 2 - Momentum threshold for TPC to TPCTOF PID"}; /// Partitions for particle 1 and particle 2 - Partition PartsOne = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne); - Partition PartsTwo = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo); + Partition PartsOne = (aod::femtodreamparticle::partType == static_cast(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne); + Partition PartsTwo = (aod::femtodreamparticle::partType == static_cast(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo); HistogramRegistry HistRegistry{"FemtoTutorial", {}, OutputObjHandlingPolicy::AnalysisObject}; diff --git a/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask5.cxx b/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask5.cxx index be71808ecf5..24f5edeaf85 100644 --- a/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask5.cxx +++ b/Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask5.cxx @@ -73,9 +73,9 @@ struct CFTutorialTask5 { Configurable ConfPIDThresholdPartTwo{"ConfPIDThresholdPartTwo", 0.75, "Particle 2 - Momentum threshold for TPC to TPCTOF PID"}; /// Partitions for particle 1 and particle 2 - Partition PartsOne = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne) && ifnode(aod::femtodreamparticle::pt < ConfPIDThresholdPartOne, ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCPartOne), ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCTOFPartOne)); + Partition PartsOne = (aod::femtodreamparticle::partType == static_cast(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne) && ifnode(aod::femtodreamparticle::pt < ConfPIDThresholdPartOne, ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCPartOne), ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCTOFPartOne)); - Partition PartsTwo = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo) && ifnode(aod::femtodreamparticle::pt < ConfPIDThresholdPartTwo, ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCPartTwo), ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCTOFPartTwo)); + Partition PartsTwo = (aod::femtodreamparticle::partType == static_cast(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo) && ifnode(aod::femtodreamparticle::pt < ConfPIDThresholdPartTwo, ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCPartTwo), ncheckbit(aod::femtodreamparticle::pidcut, ConfPIDTPCTOFPartTwo)); HistogramRegistry HistRegistry{"FemtoTutorial", {}, OutputObjHandlingPolicy::AnalysisObject}; diff --git a/Tutorials/PWGCF/FlowGenericFramework/src/flowGFWTutorial.cxx b/Tutorials/PWGCF/FlowGenericFramework/src/flowGFWTutorial.cxx index 02d8c89d063..49dfc3e4a81 100644 --- a/Tutorials/PWGCF/FlowGenericFramework/src/flowGFWTutorial.cxx +++ b/Tutorials/PWGCF/FlowGenericFramework/src/flowGFWTutorial.cxx @@ -64,7 +64,7 @@ struct GfwTutorial { ConfigurableAxis axisMultiplicity{"axisMultiplicity", {VARIABLE_WIDTH, 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90}, "centrality axis for histograms"}; Filter collisionFilter = nabs(aod::collision::posZ) < cfgCutVertex; - Filter trackFilter = (nabs(aod::track::eta) < cfgCutEta) && (aod::track::pt > cfgCutPtMin) && (aod::track::pt < cfgCutPtMax) && ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == (uint8_t)true)) && (aod::track::tpcChi2NCl < cfgCutChi2prTPCcls); + Filter trackFilter = (nabs(aod::track::eta) < cfgCutEta) && (aod::track::pt > cfgCutPtMin) && (aod::track::pt < cfgCutPtMax) && ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast(true))) && (aod::track::tpcChi2NCl < cfgCutChi2prTPCcls); // Connect to ccdb Service ccdb; diff --git a/Tutorials/PWGEM/Cocktail/plotLFCocktail.C b/Tutorials/PWGEM/Cocktail/plotLFCocktail.C index 31974fe47d0..dcb56b9dfa1 100644 --- a/Tutorials/PWGEM/Cocktail/plotLFCocktail.C +++ b/Tutorials/PWGEM/Cocktail/plotLFCocktail.C @@ -34,8 +34,8 @@ void loadHistos(TFile* file, TH1F* hists[], const TString& name_extra, int rebin int nEvents) { for (int i = 0; i < nHists; i++) { - hists[i] = (TH1F*)file->GetDirectory("em-lmee-lf-cocktail") - ->Get(TString("mee") + name_extra + histNames[i]); + hists[i] = dynamic_cast(file->GetDirectory("em-lmee-lf-cocktail") + ->Get(TString("mee") + name_extra + histNames[i])); hists[i]->Rebin(rebin); hists[i]->Scale(1. / nEvents); hists[i]->SetTitle(histLegends[i]); @@ -48,7 +48,7 @@ void plotLFCocktail(const TString& filename = "AnalysisResults.root", int rebin TFile* file = TFile::Open(filename.Data()); TH1I* hNEvents = - (TH1I*)file->GetDirectory("em-lmee-lf-cocktail")->Get("NEvents"); + dynamic_cast(file->GetDirectory("em-lmee-lf-cocktail")->Get("NEvents")); int nEvents = hNEvents->GetBinContent(1); loadHistos(file, mee, "", rebin, nEvents); diff --git a/Tutorials/PWGLF/Resonance/resonancesCombine.cxx b/Tutorials/PWGLF/Resonance/resonancesCombine.cxx index 29b34cd6e44..6d45fc3dd7a 100644 --- a/Tutorials/PWGLF/Resonance/resonancesCombine.cxx +++ b/Tutorials/PWGLF/Resonance/resonancesCombine.cxx @@ -66,8 +66,8 @@ struct ResonanceCombine { double massKa = o2::constants::physics::MassKPlus; EventPlaneHelper helperEP; - int evtPlRefAId = static_cast(cfgEvtPl / 10000); - int evtPlRefBId = static_cast((cfgEvtPl - evtPlRefAId * 10000) / 100); + int evtPlRefAId = (cfgEvtPl / 10000); + int evtPlRefBId = ((cfgEvtPl - evtPlRefAId * 10000) / 100); int evtPlDetId = cfgEvtPl - evtPlRefAId * 10000 - evtPlRefBId * 100; void init(o2::framework::InitContext&) diff --git a/Tutorials/PWGUD/UDTutorial_02b.cxx b/Tutorials/PWGUD/UDTutorial_02b.cxx index 1d060b44f27..f80ccb1ccd1 100644 --- a/Tutorials/PWGUD/UDTutorial_02b.cxx +++ b/Tutorials/PWGUD/UDTutorial_02b.cxx @@ -62,7 +62,7 @@ struct UDTutorial02b { void init(InitContext&) { - anaPars = (DGAnaparHolder)DGPars; + anaPars = DGAnaparHolder(DGPars); pidsel.init(anaPars); if (verbose) { LOGF(info, ""); diff --git a/Tutorials/src/configurableObjects.cxx b/Tutorials/src/configurableObjects.cxx index a0941834e8d..ad02482613d 100644 --- a/Tutorials/src/configurableObjects.cxx +++ b/Tutorials/src/configurableObjects.cxx @@ -98,11 +98,11 @@ struct ConfigurableObjectDemo { LOGF(info, "max_eta: %f; min_clusters: %d", (float)trackcuts.max_eta, (int)trackcuts.min_clusters); LOGF(info, "Cut1 bins: %s; Cut2 bins: %s", printArray(cut->getBins()), printArray(mutable_cut->getBins())); LOGF(info, "Cut1 labels: %s; Cut2 labels: %s", printArray(cut->getLabels()), printArray(mutable_cut->getLabels())); - auto vec = (std::vector)array; + auto vec = std::vector(array); LOGF(info, "Array: %s", printArray(vec).c_str()); - auto dvec = (std::vector)darray; + auto dvec = std::vector(darray); LOGF(info, "Double array: %s", printArray(dvec).c_str()); - auto fvec = (std::vector)farray; + auto fvec = std::vector(farray); LOGF(info, "Float array: %s", printArray(fvec).c_str()); LOGF(info, "Matrix: %s", printMatrix((Array2D)vmatrix)); LOGF(info, "Labeled float array:\n %s\n %s\n %s", printArray(vla->getLabelsRows()), printArray(vla->getLabelsCols()), printMatrix(vla->getData())); diff --git a/Tutorials/src/extendedTables.cxx b/Tutorials/src/extendedTables.cxx index 96bf680ff28..574d9edb2d0 100644 --- a/Tutorials/src/extendedTables.cxx +++ b/Tutorials/src/extendedTables.cxx @@ -121,7 +121,7 @@ struct SpawnDynamicColumns { void init(InitContext&) { - cextable.projectors[0] = (float)factor * aod::track::p * aod::track::p; + cextable.projectors[0] = factor.value * aod::track::p * aod::track::p; } void process(aod::Tracks const& tracks) diff --git a/Tutorials/src/reweighting.cxx b/Tutorials/src/reweighting.cxx index b2622385cb3..4319a587858 100644 --- a/Tutorials/src/reweighting.cxx +++ b/Tutorials/src/reweighting.cxx @@ -107,7 +107,7 @@ struct CreateWeights { void init(InitContext&) { - auto path = (std::string)onnxModel; + auto path = std::string(onnxModel); /// create session onnxSession = std::make_shared(env, path.c_str(), sessionOptions); /// adjust input shape to use row-by-row model application