Skip to content

Commit 5e9ff40

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 dc12526 commit 5e9ff40

25 files changed

Lines changed: 172 additions & 172 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
@@ -2758,7 +2758,7 @@ void o2::aod::dqhistograms::AddHistogramsFromJSON(HistogramManager* hm, const ch
27582758
rapidjson::Document document;
27592759
rapidjson::ParseResult ok = document.Parse(json);
27602760
if (!ok) {
2761-
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")";
2761+
LOG(fatal) << "JSON parse error: " << rapidjson::GetParseErrorFunc(ok.Code()) << " (" << ok.Offset() << ")"; // NOLINT(google-readability-casting)
27622762
TString str = "";
27632763
for (int i = ok.Offset() - 30; i < static_cast<int>(ok.Offset()) + 50; i++) {
27642764
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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ void VarManager::FillPropagateMuon(const T& muon, const C& collision, float* val
18961896
}
18971897

18981898
if constexpr ((fillMap & ReducedMuonCov) > 0) {
1899-
if (muon.filteringFlags() & (uint8_t(1) << VarManager::kMuonIsPropagated)) { // the muon is already propagated, so nothing to do
1899+
if (muon.filteringFlags() & (static_cast<uint8_t>(1) << VarManager::kMuonIsPropagated)) { // the muon is already propagated, so nothing to do
19001900
return;
19011901
}
19021902
}
@@ -3134,26 +3134,26 @@ void VarManager::FillTrack(T const& track, float* values)
31343134
values[kOrphanTrack] = static_cast<float>((track.flags() & o2::aod::track::OrphanTrack) > 0); // NOTE: This is NOT for Run-2
31353135
}
31363136
if (fgUsedVars[kIsSPDfirst]) {
3137-
values[kIsSPDfirst] = static_cast<float>((track.itsClusterMap() & uint8_t(1)) > 0);
3137+
values[kIsSPDfirst] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(1)) > 0);
31383138
}
31393139
if (fgUsedVars[kIsSPDboth]) {
3140-
values[kIsSPDboth] = static_cast<float>((track.itsClusterMap() & uint8_t(3)) > 0);
3140+
values[kIsSPDboth] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(3)) > 0);
31413141
}
31423142
if (fgUsedVars[kIsSPDany]) {
3143-
values[kIsSPDany] = static_cast<float>((track.itsClusterMap() & uint8_t(1)) || (track.itsClusterMap() & uint8_t(2)));
3143+
values[kIsSPDany] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(1)) || (track.itsClusterMap() & static_cast<uint8_t>(2)));
31443144
}
31453145
if (fgUsedVars[kITSClusterMap]) {
31463146
values[kITSClusterMap] = track.itsClusterMap();
31473147
}
31483148

31493149
if (fgUsedVars[kIsITSibFirst]) {
3150-
values[kIsITSibFirst] = static_cast<float>((track.itsClusterMap() & uint8_t(1)) > 0);
3150+
values[kIsITSibFirst] = static_cast<float>((track.itsClusterMap() & static_cast<uint8_t>(1)) > 0);
31513151
}
31523152
if (fgUsedVars[kIsITSibAny]) {
3153-
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);
3153+
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);
31543154
}
31553155
if (fgUsedVars[kIsITSibAll]) {
3156-
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);
3156+
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);
31573157
}
31583158

31593159
values[kTrackTime] = track.trackTime();
@@ -3262,17 +3262,17 @@ void VarManager::FillTrack(T const& track, float* values)
32623262
// Quantities based on the dalitz selections
32633263
if constexpr ((fillMap & DalitzBits) > 0) {
32643264
for (int i = 0; i < 8; i++) {
3265-
values[kIsDalitzLeg + i] = static_cast<float>(track.dalitzBits() & (uint8_t(1) << i));
3265+
values[kIsDalitzLeg + i] = static_cast<float>(track.dalitzBits() & (static_cast<uint8_t>(1) << i));
32663266
}
32673267
}
32683268

32693269
// Quantities based on the V0 selections
32703270
if constexpr ((fillMap & TrackV0Bits) > 0) {
3271-
values[kIsLegFromGamma] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsConversionLeg));
3272-
values[kIsLegFromK0S] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsK0sLeg));
3273-
values[kIsLegFromLambda] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsLambdaLeg));
3274-
values[kIsLegFromAntiLambda] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsALambdaLeg));
3275-
values[kIsLegFromOmega] = static_cast<float>(track.pidbit() & (uint8_t(1) << VarManager::kIsOmegaLeg));
3271+
values[kIsLegFromGamma] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsConversionLeg));
3272+
values[kIsLegFromK0S] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsK0sLeg));
3273+
values[kIsLegFromLambda] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsLambdaLeg));
3274+
values[kIsLegFromAntiLambda] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsALambdaLeg));
3275+
values[kIsLegFromOmega] = static_cast<float>(track.pidbit() & (static_cast<uint8_t>(1) << VarManager::kIsOmegaLeg));
32763276
values[kIsProtonFromLambdaAndAntiLambda] = static_cast<float>((values[kIsLegFromLambda] * track.sign() > 0) || (values[kIsLegFromAntiLambda] * (-track.sign()) > 0));
32773277
}
32783278

‎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)