Skip to content

Commit 949ea8b

Browse files
committed
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`)
1 parent 7900bb8 commit 949ea8b

13 files changed

Lines changed: 25 additions & 25 deletions

File tree

‎Tutorials/ML/applyMlSelection.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct applyMlSelection {
8282
void init(InitContext const&)
8383
{
8484
// Add histograms vs pT (only for selected candidates)
85-
auto vbins = (std::vector<double>)binsPtMl;
85+
auto vbins = std::vector<double>(binsPtMl);
8686
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})"}}});
8787
registry.add("hPromptScoreAfterSelVsPt", "Prompt score after selection;BDT first score;entries", {HistType::kTH2F, {{100, 0., 1.}, {vbins, "#it{p}_{T} (GeV/#it{c})"}}});
8888

‎Tutorials/OpenData/flowAnalysis.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ struct flow_base {
8787

8888
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
8989

90-
Filter collisionFilter = (aod::collision::flags & (uint16_t)aod::collision::CollisionFlagsRun2::Run2VertexerTracks) == (uint16_t)aod::collision::CollisionFlagsRun2::Run2VertexerTracks;
91-
Filter trackFilter = ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == (uint8_t)true));
90+
Filter collisionFilter = (aod::collision::flags & static_cast<uint16_t>(aod::collision::CollisionFlagsRun2::Run2VertexerTracks)) == static_cast<uint16_t>(aod::collision::CollisionFlagsRun2::Run2VertexerTracks);
91+
Filter trackFilter = ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast<uint8_t>(true)));
9292

9393
void fillAPt(double trackpt, double cent, double vn, double sinHarm, double cosHarm)
9494
{

‎Tutorials/PWGCF/EventPlane/src/spectatorPlaneTutorial.cxx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct SpectatorPlaneTutorial {
7777
float dcaZMax = 2.0;
7878

7979
Filter collisionFilter = nabs(aod::collision::posZ) < vtxZ;
80-
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;
80+
Filter trackFilter = nabs(aod::track::eta) < etaMax && aod::track::pt > ptMin&& aod::track::pt < ptMax && ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast<uint8_t>(true))) && nabs(aod::track::dcaXY) < dcaXYMax&& nabs(aod::track::dcaZ) < dcaZMax;
8181
using GeneralCollisions = soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::CentFT0Cs>;
8282
using UnfilteredTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::TrackSelection, aod::TracksDCA>;
8383

@@ -182,9 +182,9 @@ struct SpectatorPlaneTutorial {
182182
// Get QQ-correlations from CCDB
183183
if (cfgCCDBdir_QQ.value.empty() == false) {
184184
TList* list = ccdb->getForTimeStamp<TList>(cfgCCDBdir_QQ.value, bc.timestamp());
185-
TProfile* qAqCX = reinterpret_cast<TProfile*>(list->FindObject("qAqCX"));
186-
TProfile* qAqCY = reinterpret_cast<TProfile*>(list->FindObject("qAqCY"));
187-
TProfile* qAqCXY = reinterpret_cast<TProfile*>(list->FindObject("qAqCXY"));
185+
TProfile* qAqCX = dynamic_cast<TProfile*>(list->FindObject("qAqCX"));
186+
TProfile* qAqCY = dynamic_cast<TProfile*>(list->FindObject("qAqCY"));
187+
TProfile* qAqCXY = dynamic_cast<TProfile*>(list->FindObject("qAqCXY"));
188188
// The sum is qAqCXY
189189
corrQQx = qAqCX->GetBinContent(centrality);
190190
corrQQy = qAqCY->GetBinContent(centrality);

‎Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask3.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ struct CFTutorialTask3 {
6969

7070
// Partitions for particle 1 and particle 2
7171
// add PID selection to partition definition
72-
Partition<FilteredFDParts> PartsOne = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne);
73-
Partition<FilteredFDParts> PartsTwo = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo);
72+
Partition<FilteredFDParts> PartsOne = (aod::femtodreamparticle::partType == static_cast<uint8_t>(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne);
73+
Partition<FilteredFDParts> PartsTwo = (aod::femtodreamparticle::partType == static_cast<uint8_t>(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo);
7474

7575
HistogramRegistry HistRegistry{"FemtoTutorial", {}, OutputObjHandlingPolicy::AnalysisObject};
7676

‎Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask4.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ struct CFTutorialTask4 {
6969
Configurable<float> ConfPIDThresholdPartTwo{"ConfPIDThresholdPartTwo", 0.75, "Particle 2 - Momentum threshold for TPC to TPCTOF PID"};
7070

7171
/// Partitions for particle 1 and particle 2
72-
Partition<FilteredFDParts> PartsOne = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne);
73-
Partition<FilteredFDParts> PartsTwo = (aod::femtodreamparticle::partType == uint8_t(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo);
72+
Partition<FilteredFDParts> PartsOne = (aod::femtodreamparticle::partType == static_cast<uint8_t>(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartOne) == ConfCutPartOne);
73+
Partition<FilteredFDParts> PartsTwo = (aod::femtodreamparticle::partType == static_cast<uint8_t>(aod::femtodreamparticle::ParticleType::kTrack)) && ((aod::femtodreamparticle::cut & ConfCutPartTwo) == ConfCutPartTwo);
7474

7575
HistogramRegistry HistRegistry{"FemtoTutorial", {}, OutputObjHandlingPolicy::AnalysisObject};
7676

‎Tutorials/PWGCF/FemtoFramework/src/CFTutorialTask5.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ struct CFTutorialTask5 {
7373
Configurable<float> ConfPIDThresholdPartTwo{"ConfPIDThresholdPartTwo", 0.75, "Particle 2 - Momentum threshold for TPC to TPCTOF PID"};
7474

7575
/// Partitions for particle 1 and particle 2
76-
Partition<FilteredFDParts> 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));
76+
Partition<FilteredFDParts> PartsOne = (aod::femtodreamparticle::partType == static_cast<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));
7777

78-
Partition<FilteredFDParts> 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));
78+
Partition<FilteredFDParts> PartsTwo = (aod::femtodreamparticle::partType == static_cast<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));
7979

8080
HistogramRegistry HistRegistry{"FemtoTutorial", {}, OutputObjHandlingPolicy::AnalysisObject};
8181

‎Tutorials/PWGCF/FlowGenericFramework/src/flowGFWTutorial.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct GfwTutorial {
6464
ConfigurableAxis axisMultiplicity{"axisMultiplicity", {VARIABLE_WIDTH, 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90}, "centrality axis for histograms"};
6565

6666
Filter collisionFilter = nabs(aod::collision::posZ) < cfgCutVertex;
67-
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);
67+
Filter trackFilter = (nabs(aod::track::eta) < cfgCutEta) && (aod::track::pt > cfgCutPtMin) && (aod::track::pt < cfgCutPtMax) && ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast<uint8_t>(true))) && (aod::track::tpcChi2NCl < cfgCutChi2prTPCcls);
6868

6969
// Connect to ccdb
7070
Service<ccdb::BasicCCDBManager> ccdb;

‎Tutorials/PWGEM/Cocktail/plotLFCocktail.C‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void loadHistos(TFile* file, TH1F* hists[], const TString& name_extra, int rebin
3434
int nEvents)
3535
{
3636
for (int i = 0; i < nHists; i++) {
37-
hists[i] = (TH1F*)file->GetDirectory("em-lmee-lf-cocktail")
38-
->Get(TString("mee") + name_extra + histNames[i]);
37+
hists[i] = dynamic_cast<TH1F*>(file->GetDirectory("em-lmee-lf-cocktail")
38+
->Get(TString("mee") + name_extra + histNames[i]));
3939
hists[i]->Rebin(rebin);
4040
hists[i]->Scale(1. / nEvents);
4141
hists[i]->SetTitle(histLegends[i]);
@@ -48,7 +48,7 @@ void plotLFCocktail(const TString& filename = "AnalysisResults.root", int rebin
4848
TFile* file = TFile::Open(filename.Data());
4949

5050
TH1I* hNEvents =
51-
(TH1I*)file->GetDirectory("em-lmee-lf-cocktail")->Get("NEvents");
51+
dynamic_cast<TH1I*>(file->GetDirectory("em-lmee-lf-cocktail")->Get("NEvents"));
5252
int nEvents = hNEvents->GetBinContent(1);
5353

5454
loadHistos(file, mee, "", rebin, nEvents);

‎Tutorials/PWGLF/Resonance/resonancesCombine.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ struct ResonanceCombine {
6666
double massKa = o2::constants::physics::MassKPlus;
6767

6868
EventPlaneHelper helperEP;
69-
int evtPlRefAId = static_cast<int>(cfgEvtPl / 10000);
70-
int evtPlRefBId = static_cast<int>((cfgEvtPl - evtPlRefAId * 10000) / 100);
69+
int evtPlRefAId = (cfgEvtPl / 10000);
70+
int evtPlRefBId = ((cfgEvtPl - evtPlRefAId * 10000) / 100);
7171
int evtPlDetId = cfgEvtPl - evtPlRefAId * 10000 - evtPlRefBId * 100;
7272

7373
void init(o2::framework::InitContext&)

‎Tutorials/PWGUD/UDTutorial_02b.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct UDTutorial02b {
6262

6363
void init(InitContext&)
6464
{
65-
anaPars = (DGAnaparHolder)DGPars;
65+
anaPars = DGAnaparHolder(DGPars);
6666
pidsel.init(anaPars);
6767
if (verbose) {
6868
LOGF(info, "<UDTutorial02>");

0 commit comments

Comments
 (0)