Skip to content

Commit 63796cf

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 31acdb7 commit 63796cf

26 files changed

Lines changed: 189 additions & 189 deletions

‎PWGDQ/Core/CutsLibrary.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7489,7 +7489,7 @@ std::vector<AnalysisCut*> o2::aod::dqcuts::GetCutsFromJSON(const char* json)
74897489
// Check that the json is parsed correctly
74907490
rapidjson::ParseResult ok = document.Parse(json);
74917491
if (!ok) {
7492-
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")";
7492+
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")"; // NOLINT(google-readability-casting)
74937493
return cuts;
74947494
}
74957495

@@ -7873,7 +7873,7 @@ o2::aod::dqmlcuts::BdtScoreConfig o2::aod::dqmlcuts::GetBdtScoreCutsAndConfigFro
78737873
// Check that the json is parsed correctly
78747874
rapidjson::ParseResult ok = document.Parse(json);
78757875
if (!ok) {
7876-
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")";
7876+
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")"; // NOLINT(google-readability-casting)
78777877
return {};
78787878
}
78797879

‎PWGDQ/Core/HistogramsLibrary.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ void o2::aod::dqhistograms::AddHistogramsFromJSON(HistogramManager* hm, const ch
27882788
rapidjson::Document document;
27892789
rapidjson::ParseResult ok = document.Parse(json);
27902790
if (!ok) {
2791-
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")";
2791+
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")"; // NOLINT(google-readability-casting)
27922792
TString str = "";
27932793
for (int i = ok.Offset() - 30; i < static_cast<int>(ok.Offset()) + 50; i++) {
27942794
if ((i >= 0) && (i < static_cast<int>(strlen(json)))) {

‎PWGDQ/Core/MCSignalLibrary.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ std::vector<MCSignal*> o2::aod::dqmcsignals::GetMCSignalsFromJSON(const char* js
21092109
str += json[i];
21102110
}
21112111
}
2112-
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")" << " **** Parsing error is somewhere here: " << str.Data();
2112+
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")" << " **** Parsing error is somewhere here: " << str.Data(); // NOLINT(google-readability-casting)
21132113
return signals;
21142114
}
21152115

‎PWGDQ/Core/VarManager.h‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ void VarManager::FillPropagateMuon(const T& muon, const C& collision, float* val
19081908
}
19091909

19101910
if constexpr ((fillMap & ReducedMuonCov) > 0) {
1911-
if (muon.filteringFlags() & (uint8_t(1) << VarManager::kMuonIsPropagated)) { // the muon is already propagated, so nothing to do
1911+
if (muon.filteringFlags() & (static_cast<uint8_t>(1) << VarManager::kMuonIsPropagated)) { // the muon is already propagated, so nothing to do
19121912
return;
19131913
}
19141914
}
@@ -3146,26 +3146,26 @@ void VarManager::FillTrack(T const& track, float* values)
31463146
values[kOrphanTrack] = static_cast<float>((track.flags() & o2::aod::track::OrphanTrack) > 0); // NOTE: This is NOT for Run-2
31473147
}
31483148
if (fgUsedVars[kIsSPDfirst]) {
3149-
values[kIsSPDfirst] = static_cast<float>((track.itsClusterMap() & uint8_t(1)) > 0);
3149+
values[kIsSPDfirst] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(1)) > 0);
31503150
}
31513151
if (fgUsedVars[kIsSPDboth]) {
3152-
values[kIsSPDboth] = static_cast<float>((track.itsClusterMap() & uint8_t(3)) > 0);
3152+
values[kIsSPDboth] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(3)) > 0);
31533153
}
31543154
if (fgUsedVars[kIsSPDany]) {
3155-
values[kIsSPDany] = static_cast<float>((track.itsClusterMap() & uint8_t(1)) || (track.itsClusterMap() & uint8_t(2)));
3155+
values[kIsSPDany] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(1)) || (track.itsClusterMap() & static_cast<uint8_t>(2)));
31563156
}
31573157
if (fgUsedVars[kITSClusterMap]) {
31583158
values[kITSClusterMap] = track.itsClusterMap();
31593159
}
31603160

31613161
if (fgUsedVars[kIsITSibFirst]) {
3162-
values[kIsITSibFirst] = static_cast<float>((track.itsClusterMap() & uint8_t(1)) > 0);
3162+
values[kIsITSibFirst] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(1)) > 0);
31633163
}
31643164
if (fgUsedVars[kIsITSibAny]) {
3165-
values[kIsITSibAny] = static_cast<float>((track.itsClusterMap() & (1 << uint8_t(0))) > 0 || (track.itsClusterMap() & (1 << uint8_t(1))) > 0 || (track.itsClusterMap() & (1 << uint8_t(2))) > 0);
3165+
values[kIsITSibAny] = static_cast<float>((track.itsClusterMap() & (1 << static_cast<uint8_t>(0))) > 0 || (track.itsClusterMap() & (1 << static_cast<uint8_t>(1))) > 0 || (track.itsClusterMap() & (1 << static_cast<uint8_t>(2))) > 0);
31663166
}
31673167
if (fgUsedVars[kIsITSibAll]) {
3168-
values[kIsITSibAll] = static_cast<float>((track.itsClusterMap() & (1 << uint8_t(0))) > 0 && (track.itsClusterMap() & (1 << uint8_t(1))) > 0 && (track.itsClusterMap() & (1 << uint8_t(2))) > 0);
3168+
values[kIsITSibAll] = static_cast<float>((track.itsClusterMap() & (1 << static_cast<uint8_t>(0))) > 0 && (track.itsClusterMap() & (1 << static_cast<uint8_t>(1))) > 0 && (track.itsClusterMap() & (1 << static_cast<uint8_t>(2))) > 0);
31693169
}
31703170

31713171
values[kTrackTime] = track.trackTime();
@@ -3274,17 +3274,17 @@ void VarManager::FillTrack(T const& track, float* values)
32743274
// Quantities based on the dalitz selections
32753275
if constexpr ((fillMap & DalitzBits) > 0) {
32763276
for (int i = 0; i < 8; i++) {
3277-
values[kIsDalitzLeg + i] = static_cast<float>(track.dalitzBits() & (uint8_t(1) << i));
3277+
values[kIsDalitzLeg + i] = static_cast<float>(track.dalitzBits() & (static_cast<uint8_t>(1) << i));
32783278
}
32793279
}
32803280

32813281
// Quantities based on the V0 selections
32823282
if constexpr ((fillMap & TrackV0Bits) > 0) {
3283-
values[kIsLegFromGamma] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsConversionLeg));
3284-
values[kIsLegFromK0S] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsK0sLeg));
3285-
values[kIsLegFromLambda] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsLambdaLeg));
3286-
values[kIsLegFromAntiLambda] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsALambdaLeg));
3287-
values[kIsLegFromOmega] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsOmegaLeg));
3283+
values[kIsLegFromGamma] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsConversionLeg));
3284+
values[kIsLegFromK0S] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsK0sLeg));
3285+
values[kIsLegFromLambda] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsLambdaLeg));
3286+
values[kIsLegFromAntiLambda] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsALambdaLeg));
3287+
values[kIsLegFromOmega] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsOmegaLeg));
32883288
values[kIsProtonFromLambdaAndAntiLambda] = static_cast<float>((values[kIsLegFromLambda] * track.sign() > 0) || (values[kIsLegFromAntiLambda] * (-track.sign()) > 0));
32893289
}
32903290

@@ -3899,12 +3899,12 @@ void VarManager::FillPair(T1 const& t1, T2 const& t2, float* values)
38993899
}
39003900

39013901
// polarization parameters
3902-
bool useHE = fgUsedVars[kCosThetaHE] || fgUsedVars[kPhiHE]; // helicity frame
3903-
bool useCS = fgUsedVars[kCosThetaCS] || fgUsedVars[kPhiCS]; // Collins-Soper frame
3902+
bool useHE = fgUsedVars[kCosThetaHE] || fgUsedVars[kPhiHE]; // helicity frame
3903+
bool useCS = fgUsedVars[kCosThetaCS] || fgUsedVars[kPhiCS]; // Collins-Soper frame
39043904
bool useGJB1 = fgUsedVars[kCosThetaGJB1] || fgUsedVars[kPhiGJB1]; // Gottfried-Jackson frame, beam 1 (+z)
39053905
bool useGJB2 = fgUsedVars[kCosThetaGJB2] || fgUsedVars[kPhiGJB2]; // Gottfried-Jackson frame, beam 2 (-z)
3906-
bool usePP = fgUsedVars[kCosThetaPP]; // production plane frame
3907-
bool useRM = fgUsedVars[kCosThetaRM]; // Random frame
3906+
bool usePP = fgUsedVars[kCosThetaPP]; // production plane frame
3907+
bool useRM = fgUsedVars[kCosThetaRM]; // Random frame
39083908

39093909
if (useHE || useCS || useGJB1 || useGJB2 || usePP || useRM) {
39103910
ROOT::Math::Boost boostv12{v12.BoostToCM()};
@@ -4460,12 +4460,12 @@ void VarManager::FillPairME(T1 const& t1, T2 const& t2, float* values)
44604460
}
44614461

44624462
// polarization parameters
4463-
bool useHE = fgUsedVars[kCosThetaHE] || fgUsedVars[kPhiHE]; // helicity frame
4464-
bool useCS = fgUsedVars[kCosThetaCS] || fgUsedVars[kPhiCS]; // Collins-Soper frame
4463+
bool useHE = fgUsedVars[kCosThetaHE] || fgUsedVars[kPhiHE]; // helicity frame
4464+
bool useCS = fgUsedVars[kCosThetaCS] || fgUsedVars[kPhiCS]; // Collins-Soper frame
44654465
bool useGJB1 = fgUsedVars[kCosThetaGJB1] || fgUsedVars[kPhiGJB1]; // Gottfried-Jackson frame, beam 1 (+z)
44664466
bool useGJB2 = fgUsedVars[kCosThetaGJB2] || fgUsedVars[kPhiGJB2]; // Gottfried-Jackson frame, beam 2 (-z)
4467-
bool usePP = fgUsedVars[kCosThetaPP]; // production plane frame
4468-
bool useRM = fgUsedVars[kCosThetaRM]; // Random frame
4467+
bool usePP = fgUsedVars[kCosThetaPP]; // production plane frame
4468+
bool useRM = fgUsedVars[kCosThetaRM]; // Random frame
44694469

44704470
if (useHE || useCS || useGJB1 || useGJB2 || usePP || useRM) {
44714471
ROOT::Math::Boost boostv12{v12.BoostToCM()};
@@ -4888,12 +4888,12 @@ void VarManager::FillPairMC(T1 const& t1, T2 const& t2, float* values)
48884888
values[kMCP2] = t2.p();
48894889

48904890
// polarization parameters
4891-
bool useHE = fgUsedVars[kMCCosThetaHE] || fgUsedVars[kMCPhiHE]; // helicity frame
4892-
bool useCS = fgUsedVars[kMCCosThetaCS] || fgUsedVars[kMCPhiCS]; // Collins-Soper frame
4891+
bool useHE = fgUsedVars[kMCCosThetaHE] || fgUsedVars[kMCPhiHE]; // helicity frame
4892+
bool useCS = fgUsedVars[kMCCosThetaCS] || fgUsedVars[kMCPhiCS]; // Collins-Soper frame
48934893
bool useGJB1 = fgUsedVars[kMCCosThetaGJB1] || fgUsedVars[kMCPhiGJB1]; // Gottfried-Jackson frame, beam 1 (+z)
48944894
bool useGJB2 = fgUsedVars[kMCCosThetaGJB2] || fgUsedVars[kMCPhiGJB2]; // Gottfried-Jackson frame, beam 2 (-z)
4895-
bool usePP = fgUsedVars[kMCCosThetaPP]; // production plane frame
4896-
bool useRM = fgUsedVars[kMCCosThetaRM]; // Random frame
4895+
bool usePP = fgUsedVars[kMCCosThetaPP]; // production plane frame
4896+
bool useRM = fgUsedVars[kMCCosThetaRM]; // Random frame
48974897

48984898
if (useHE || useCS || useGJB1 || useGJB2 || usePP || useRM) {
48994899
ROOT::Math::Boost boostv12{v12.BoostToCM()};
@@ -7767,12 +7767,12 @@ void VarManager::FillPairAlice3(T1 const& t1, T2 const& t2, float* values)
77677767
}
77687768

77697769
// polarization parameters
7770-
bool useHE = fgUsedVars[kCosThetaHE] || fgUsedVars[kPhiHE]; // helicity frame
7771-
bool useCS = fgUsedVars[kCosThetaCS] || fgUsedVars[kPhiCS]; // Collins-Soper frame
7770+
bool useHE = fgUsedVars[kCosThetaHE] || fgUsedVars[kPhiHE]; // helicity frame
7771+
bool useCS = fgUsedVars[kCosThetaCS] || fgUsedVars[kPhiCS]; // Collins-Soper frame
77727772
bool useGJB1 = fgUsedVars[kCosThetaGJB1] || fgUsedVars[kPhiGJB1]; // Gottfried-Jackson frame, beam 1 (+z)
77737773
bool useGJB2 = fgUsedVars[kCosThetaGJB2] || fgUsedVars[kPhiGJB2]; // Gottfried-Jackson frame, beam 2 (-z)
7774-
bool usePP = fgUsedVars[kCosThetaPP]; // production plane frame
7775-
bool useRM = fgUsedVars[kCosThetaRM]; // Random frame
7774+
bool usePP = fgUsedVars[kCosThetaPP]; // production plane frame
7775+
bool useRM = fgUsedVars[kCosThetaRM]; // Random frame
77767776

77777777
if (useHE || useCS || useGJB1 || useGJB2 || usePP || useRM) {
77787778
ROOT::Math::Boost boostv12{v12.BoostToCM()};

‎PWGDQ/Macros/evalMchTrackingEfficiency.cxx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ void evalMchTrackingEfficiency(const char* inFile = "AnalysisResults.root", cons
4646
{
4747
// read ouput from the taskComputeMchEfficiency
4848
TFile* file = TFile::Open(inFile, "read");
49-
TDirectoryFile* dir = reinterpret_cast<TDirectoryFile*>(file->Get("task-muon-mch-trk-efficiency"));
50-
THnF* hHitsEtaPtPhi = reinterpret_cast<THnF*>(dir->Get("hHitsEtaPtPhi"));
49+
TDirectoryFile* dir = dynamic_cast<TDirectoryFile*>(file->Get("task-muon-mch-trk-efficiency"));
50+
THnF* hHitsEtaPtPhi = dynamic_cast<THnF*>(dir->Get("hHitsEtaPtPhi"));
5151

5252
// retrieve the eta/pt/phi axis binning configuration
5353
const int etaAx = 1, ptAx = 2, phiAx = 3;
@@ -274,7 +274,7 @@ double computeEfficiencyPerChamber(THnF* hnf, int iAxis, int iCh, double binLimi
274274
hnf->GetAxis(iAxis)->SetRangeUser(binLimits[0], binLimits[1]);
275275

276276
// Project onto the Nhits axis
277-
TH1F* htmp = reinterpret_cast<TH1F*>(hnf->Projection(0));
277+
TH1F* htmp = dynamic_cast<TH1F*>(hnf->Projection(0)); // FIXME: invalid cast
278278
double NhitPairing[16];
279279
for (int i = 0; i < 16; i++) {
280280
NhitPairing[i] = 0;
@@ -322,7 +322,7 @@ double computeEfficiencyPerChamber(THnF* hnf, const int iAxis[3], int iCh, doubl
322322
}
323323

324324
// Project onto the Nhits axis
325-
TH1F* htmp = reinterpret_cast<TH1F*>(hnf->Projection(0));
325+
TH1F* htmp = dynamic_cast<TH1F*>(hnf->Projection(0)); // FIXME: invalid cast
326326
double NhitPairing[16];
327327
for (int i = 0; i < 16; i++) {
328328
NhitPairing[i] = 0;

0 commit comments

Comments
 (0)