Skip to content

Commit 0877ccf

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 0877ccf

48 files changed

Lines changed: 495 additions & 495 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎PWGLF/DataModel/LFStrangenessTables.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ enum EventSelectionFlags {
5858
kNsel // counter
5959
};
6060

61-
DECLARE_SOA_COLUMN(TotalNbrOfCollisions, totalNbrOfCollisions, int); //! total number of analysed collisions
62-
DECLARE_SOA_COLUMN(TotalNbrOfSelCollisions, totalNbrOfSelCollisions, int); //! total number of selected collisions
61+
DECLARE_SOA_COLUMN(TotalNbrOfCollisions, totalNbrOfCollisions, int); //! total number of analysed collisions
62+
DECLARE_SOA_COLUMN(TotalNbrOfSelCollisions, totalNbrOfSelCollisions, int); //! total number of selected collisions
6363
DECLARE_SOA_COLUMN(TotalIsTriggerTVXCollisions, totalIsTriggerTVXCollisions, int); //! N selected collisions after applying IsTriggerTVX
6464
DECLARE_SOA_COLUMN(TotalNoITSROFBorderCollisions, totalNoITSROFBorderCollisions, int); //! N selected collisions after applying IsTriggerTVX, NoITSROF
6565
DECLARE_SOA_COLUMN(TotalNoTFBorderCollisions, totalNoTFBorderCollisions, int); //! N selected collisions after applying IsTriggerTVX, NoITSROF, NoTF
@@ -585,7 +585,7 @@ DECLARE_SOA_TABLE_VERSIONED(DauTrackExtras_003, "AOD", "DAUTRACKEXTRA", 3, //! d
585585
track::v001::ITSClsSizeInLayer<track::ITSClusterSizes>,
586586
track::v001::ITSClusterMap<track::ITSClusterSizes>,
587587
track::v001::ITSNCls<track::ITSClusterSizes>,
588-
track::v001::IsITSAfterburner<track::v001::DetectorMap, track::ITSChi2NCl>,
588+
track::v001::IsITSAfterburner<dautrack::DetectorMap, track::ITSChi2NCl>,
589589
/*compatibility*/ dautrack::HasITSTracker<dautrack::DetectorMap, track::ITSChi2NCl>,
590590
/*compatibility*/ dautrack::HasITSAfterburner<dautrack::DetectorMap, track::ITSChi2NCl>,
591591

‎PWGLF/TableProducer/Common/lfTPCPID.cxx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct bbParams {
203203
void setValues(TList* l)
204204
{
205205
const char* bbname = Form("BBParameter_%s", name.c_str());
206-
TH1F* h = static_cast<TH1F*>(l->FindObject(bbname));
206+
TH1F* h = dynamic_cast<TH1F*>(l->FindObject(bbname));
207207
if (!h) {
208208
l->ls();
209209
LOG(fatal) << "bbParams `" << name << "` :: did not find BetheBloch parametrization " << bbname << " in the input list";
@@ -237,9 +237,9 @@ struct bbParams {
237237
} else {
238238
TString cn = obj->ClassName();
239239
if (cn.Contains("TF1")) {
240-
postCorrectionFun = static_cast<TF1*>(l->FindObject(obj->GetName()));
240+
postCorrectionFun = dynamic_cast<TF1*>(l->FindObject(obj->GetName()));
241241
} else if (cn.Contains("TGraph")) {
242-
postCorrection = static_cast<TGraph*>(l->FindObject(obj->GetName()));
242+
postCorrection = dynamic_cast<TGraph*>(l->FindObject(obj->GetName()));
243243
} else {
244244
LOG(fatal) << "Cannot hanlde class " << cn << " for post calib object " << objname;
245245
}
@@ -255,9 +255,9 @@ struct bbParams {
255255
} else {
256256
TString cn = obj->ClassName();
257257
if (cn.Contains("TF1")) {
258-
postCorrectionFunSigma = static_cast<TF1*>(l->FindObject(obj->GetName()));
258+
postCorrectionFunSigma = dynamic_cast<TF1*>(l->FindObject(obj->GetName()));
259259
} else if (cn.Contains("TGraph")) {
260-
postCorrectionSigma = static_cast<TGraph*>(l->FindObject(obj->GetName()));
260+
postCorrectionSigma = dynamic_cast<TGraph*>(l->FindObject(obj->GetName()));
261261
} else {
262262
LOG(fatal) << "Cannot hanlde class " << cn << " for post calib sigma object " << objname;
263263
}
@@ -349,7 +349,7 @@ struct bbParams {
349349
if (!f->IsOpen()) {
350350
LOG(fatal) << "The input file " << f->GetName() << " is not open";
351351
}
352-
TList* l = static_cast<TList*>(f->Get("ccdb_object"));
352+
TList* l = dynamic_cast<TList*>(f->Get("ccdb_object"));
353353
if (!l) {
354354
f->ls();
355355
LOG(fatal) << "The input file " << post << " does not contain the TList ccdb_object";

‎PWGLF/TableProducer/Nuspex/he3HadronFemto.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ struct he3HadronFemto {
14071407
he3Hadcand.flags |= Flags::kMixedPair;
14081408
}
14091409

1410-
LOG(info) << "He3 flags: " << int(he3Hadcand.flagsHe3) << ", Hadron flags: " << int(he3Hadcand.flagsHad) << ", Pair flags: " << int(he3Hadcand.flags);
1410+
LOG(info) << "He3 flags: " << static_cast<int>(he3Hadcand.flagsHe3) << ", Hadron flags: " << static_cast<int>(he3Hadcand.flagsHad) << ", Pair flags: " << static_cast<int>(he3Hadcand.flags);
14111411
if (!settingFillPrimariesMc && (he3Hadcand.flags == Flags::kBothPrimaries)) {
14121412
continue;
14131413
}

‎PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ struct HyperNucleus {
254254
}
255255
return vec;
256256
};
257-
const char* motherName() { return name.Contains("->") ? ((TString)name(0, name.First("-"))).Data() : name.Data(); }
258-
const char* daughterNames() { return name.Contains("->") ? ((TString)name(name.First("-") + 2, name.Length())).Data() : ""; }
257+
const char* motherName() { return name.Contains("->") ? (TString(name(0, name.First("-")))).Data() : name.Data(); }
258+
const char* daughterNames() { return name.Contains("->") ? (TString(name(name.First("-") + 2, name.Length()))).Data() : ""; }
259259
}; // struct HyperNucleus
260260

261261
struct DaughterKf {

‎PWGLF/TableProducer/Nuspex/nucleiSpectra.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ struct nucleiSpectra {
513513
ccdb->setLocalObjectValidityChecking();
514514
ccdb->setFatalWhenNull(false);
515515

516-
const AxisSpec centAxis{cfgCentralityBins, fmt::format("{} percentile", (std::string)nuclei::centDetectorNames[cfgCentralityEstimator])};
516+
const AxisSpec centAxis{cfgCentralityBins, fmt::format("{} percentile", std::string(nuclei::centDetectorNames[cfgCentralityEstimator]))};
517517
const AxisSpec nSigmaAxes[2]{{cfgNsigmaTPCbins, "n#sigma_{TPC}"}, {cfgNsigmaTOFbins, "n#sigma_{TOF}"}};
518518
const AxisSpec tofMassAxis{cfgTOFmassBins, "TOF mass - PDG mass"};
519519
const AxisSpec ptResAxis{cfgMomResBins, "#Delta#it{p}_{T}/#it{p}_{T}"};
@@ -1181,7 +1181,7 @@ struct nucleiSpectra {
11811181
track.itsChi2NCl() > cfgTrackCut.ITSchi2ClusMax) {
11821182
continue;
11831183
}
1184-
double expBethe{common::BetheBlochAleph(static_cast<double>(track.tpcInnerParam() * 2. / o2::constants::physics::MassHelium3), cfgBetheBlochParams->get(4, 0u), cfgBetheBlochParams->get(4, 1u), cfgBetheBlochParams->get(4, 2u), cfgBetheBlochParams->get(4, 3u), cfgBetheBlochParams->get(4, 4u))};
1184+
double expBethe{common::BetheBlochAleph((track.tpcInnerParam() * 2. / o2::constants::physics::MassHelium3), cfgBetheBlochParams->get(4, 0u), cfgBetheBlochParams->get(4, 1u), cfgBetheBlochParams->get(4, 2u), cfgBetheBlochParams->get(4, 3u), cfgBetheBlochParams->get(4, 4u))};
11851185
double expSigma{expBethe * cfgBetheBlochParams->get(4, 5u)};
11861186
double nSigmaTPC{(track.tpcSignal() - expBethe) / expSigma};
11871187
int iC = track.signed1Pt() > 0;

‎PWGLF/TableProducer/Nuspex/threebodymcfinder.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ struct threebodymcfinder {
6969
void init(InitContext&)
7070
{
7171
// initialize histograms
72-
const AxisSpec axisNTimesCollRecoed{(int)10, -0.5f, +9.5f, ""};
73-
const AxisSpec axisPt{(int)100, +0.0f, +10.0f, "p_{T} (GeV/c)"};
72+
const AxisSpec axisNTimesCollRecoed{10, -0.5f, +9.5f, ""};
73+
const AxisSpec axisPt{100, +0.0f, +10.0f, "p_{T} (GeV/c)"};
7474

7575
histos.add("hNTimesCollRecoed", "hNTimesCollRecoed", kTH1F, {axisNTimesCollRecoed});
7676
histos.add("hNDaughters", "hNDaughters", kTH1F, {axisNTimesCollRecoed});

‎PWGLF/TableProducer/QC/flowQC.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ struct flowQC {
178178
const AxisSpec centFT0mAxis{cfgCentralityBins, "FT0M percentile"};
179179
const AxisSpec centFV0aAxis{cfgCentralityBins, "FV0A percentile"};
180180

181-
const AxisSpec centAxis{cfgCentralityBins, fmt::format("{} percentile", (std::string)centDetectorNames[cfgCentralityEstimator])};
181+
const AxisSpec centAxis{cfgCentralityBins, fmt::format("{} percentile", std::string(centDetectorNames[cfgCentralityEstimator]))};
182182

183183
const char* qLabel = cfgQuadraticResponse ? "Q^{2}" : "Q";
184184

‎PWGLF/TableProducer/Resonances/cksspinalignment.cxx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ struct cksspinalignment {
468468

469469
auto postrack = v0.template posTrack_as<FullTrackCandidates>();
470470
auto negtrack = v0.template negTrack_as<FullTrackCandidates>();
471-
const auto posId = static_cast<int64_t>(postrack.globalIndex());
472-
const auto negId = static_cast<int64_t>(negtrack.globalIndex());
471+
const auto posId = postrack.globalIndex();
472+
const auto negId = negtrack.globalIndex();
473473

474474
ROOT::Math::PxPyPzMVector pionPos(v0.pxpos(), v0.pypos(), v0.pzpos(), o2::constants::physics::MassPionCharged);
475475
ROOT::Math::PxPyPzMVector pionNeg(v0.pxneg(), v0.pyneg(), v0.pzneg(), o2::constants::physics::MassPionCharged);
@@ -485,8 +485,8 @@ struct cksspinalignment {
485485
static_cast<float>(k0s.M()),
486486
static_cast<float>(v0.v0cosPA()),
487487
static_cast<float>(v0.v0radius()),
488-
static_cast<float>(std::abs(v0.dcapostopv())),
489-
static_cast<float>(std::abs(v0.dcanegtopv())),
488+
std::abs(v0.dcapostopv()),
489+
std::abs(v0.dcanegtopv()),
490490
// static_cast<float>(std::abs(v0.dcaV0daughters())),
491491
// lifetime,
492492
posId,

‎PWGLF/TableProducer/Resonances/resonanceInitializer.cxx‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ struct ResonanceInitializer {
255255

256256
EventPlaneHelper helperEP;
257257

258-
int evtPlRefAId = static_cast<int>(cfgEvtPl / 10000);
259-
int evtPlRefBId = static_cast<int>((cfgEvtPl - evtPlRefAId * 10000) / 100);
258+
int evtPlRefAId = (cfgEvtPl / 10000);
259+
int evtPlRefBId = ((cfgEvtPl - evtPlRefAId * 10000) / 100);
260260
int evtPlDetId = cfgEvtPl - evtPlRefAId * 10000 - evtPlRefBId * 100;
261261

262262
// MC Resonance parent filter
@@ -793,18 +793,18 @@ struct ResonanceInitializer {
793793
v0.py(),
794794
v0.pz(),
795795
childIDs,
796-
(int8_t)(v0.template posTrack_as<TrackType>().tpcNSigmaPi() * 10),
797-
(int8_t)(v0.template posTrack_as<TrackType>().tpcNSigmaKa() * 10),
798-
(int8_t)(v0.template posTrack_as<TrackType>().tpcNSigmaPr() * 10),
799-
(int8_t)(v0.template negTrack_as<TrackType>().tpcNSigmaPi() * 10),
800-
(int8_t)(v0.template negTrack_as<TrackType>().tpcNSigmaKa() * 10),
801-
(int8_t)(v0.template negTrack_as<TrackType>().tpcNSigmaPr() * 10),
802-
(int8_t)(v0.template negTrack_as<TrackType>().tofNSigmaPi() * 10),
803-
(int8_t)(v0.template negTrack_as<TrackType>().tofNSigmaKa() * 10),
804-
(int8_t)(v0.template negTrack_as<TrackType>().tofNSigmaPr() * 10),
805-
(int8_t)(v0.template posTrack_as<TrackType>().tofNSigmaPi() * 10),
806-
(int8_t)(v0.template posTrack_as<TrackType>().tofNSigmaKa() * 10),
807-
(int8_t)(v0.template posTrack_as<TrackType>().tofNSigmaPr() * 10),
796+
static_cast<int8_t>(v0.template posTrack_as<TrackType>().tpcNSigmaPi() * 10),
797+
static_cast<int8_t>(v0.template posTrack_as<TrackType>().tpcNSigmaKa() * 10),
798+
static_cast<int8_t>(v0.template posTrack_as<TrackType>().tpcNSigmaPr() * 10),
799+
static_cast<int8_t>(v0.template negTrack_as<TrackType>().tpcNSigmaPi() * 10),
800+
static_cast<int8_t>(v0.template negTrack_as<TrackType>().tpcNSigmaKa() * 10),
801+
static_cast<int8_t>(v0.template negTrack_as<TrackType>().tpcNSigmaPr() * 10),
802+
static_cast<int8_t>(v0.template negTrack_as<TrackType>().tofNSigmaPi() * 10),
803+
static_cast<int8_t>(v0.template negTrack_as<TrackType>().tofNSigmaKa() * 10),
804+
static_cast<int8_t>(v0.template negTrack_as<TrackType>().tofNSigmaPr() * 10),
805+
static_cast<int8_t>(v0.template posTrack_as<TrackType>().tofNSigmaPi() * 10),
806+
static_cast<int8_t>(v0.template posTrack_as<TrackType>().tofNSigmaKa() * 10),
807+
static_cast<int8_t>(v0.template posTrack_as<TrackType>().tofNSigmaPr() * 10),
808808
v0.v0cosPA(),
809809
v0.dcaV0daughters(),
810810
v0.dcapostopv(),
@@ -845,24 +845,24 @@ struct ResonanceInitializer {
845845
casc.py(),
846846
casc.pz(),
847847
childIDs,
848-
(int8_t)(casc.template posTrack_as<TrackType>().tpcNSigmaPi() * 10),
849-
(int8_t)(casc.template posTrack_as<TrackType>().tpcNSigmaKa() * 10),
850-
(int8_t)(casc.template posTrack_as<TrackType>().tpcNSigmaPr() * 10),
851-
(int8_t)(casc.template negTrack_as<TrackType>().tpcNSigmaPi() * 10),
852-
(int8_t)(casc.template negTrack_as<TrackType>().tpcNSigmaKa() * 10),
853-
(int8_t)(casc.template negTrack_as<TrackType>().tpcNSigmaPr() * 10),
854-
(int8_t)(casc.template bachelor_as<TrackType>().tpcNSigmaPi() * 10),
855-
(int8_t)(casc.template bachelor_as<TrackType>().tpcNSigmaKa() * 10),
856-
(int8_t)(casc.template bachelor_as<TrackType>().tpcNSigmaPr() * 10),
857-
(int8_t)(casc.template posTrack_as<TrackType>().tofNSigmaPi() * 10),
858-
(int8_t)(casc.template posTrack_as<TrackType>().tofNSigmaKa() * 10),
859-
(int8_t)(casc.template posTrack_as<TrackType>().tofNSigmaPr() * 10),
860-
(int8_t)(casc.template negTrack_as<TrackType>().tofNSigmaPi() * 10),
861-
(int8_t)(casc.template negTrack_as<TrackType>().tofNSigmaKa() * 10),
862-
(int8_t)(casc.template negTrack_as<TrackType>().tofNSigmaPr() * 10),
863-
(int8_t)(casc.template bachelor_as<TrackType>().tofNSigmaPi() * 10),
864-
(int8_t)(casc.template bachelor_as<TrackType>().tofNSigmaKa() * 10),
865-
(int8_t)(casc.template bachelor_as<TrackType>().tofNSigmaPr() * 10),
848+
static_cast<int8_t>(casc.template posTrack_as<TrackType>().tpcNSigmaPi() * 10),
849+
static_cast<int8_t>(casc.template posTrack_as<TrackType>().tpcNSigmaKa() * 10),
850+
static_cast<int8_t>(casc.template posTrack_as<TrackType>().tpcNSigmaPr() * 10),
851+
static_cast<int8_t>(casc.template negTrack_as<TrackType>().tpcNSigmaPi() * 10),
852+
static_cast<int8_t>(casc.template negTrack_as<TrackType>().tpcNSigmaKa() * 10),
853+
static_cast<int8_t>(casc.template negTrack_as<TrackType>().tpcNSigmaPr() * 10),
854+
static_cast<int8_t>(casc.template bachelor_as<TrackType>().tpcNSigmaPi() * 10),
855+
static_cast<int8_t>(casc.template bachelor_as<TrackType>().tpcNSigmaKa() * 10),
856+
static_cast<int8_t>(casc.template bachelor_as<TrackType>().tpcNSigmaPr() * 10),
857+
static_cast<int8_t>(casc.template posTrack_as<TrackType>().tofNSigmaPi() * 10),
858+
static_cast<int8_t>(casc.template posTrack_as<TrackType>().tofNSigmaKa() * 10),
859+
static_cast<int8_t>(casc.template posTrack_as<TrackType>().tofNSigmaPr() * 10),
860+
static_cast<int8_t>(casc.template negTrack_as<TrackType>().tofNSigmaPi() * 10),
861+
static_cast<int8_t>(casc.template negTrack_as<TrackType>().tofNSigmaKa() * 10),
862+
static_cast<int8_t>(casc.template negTrack_as<TrackType>().tofNSigmaPr() * 10),
863+
static_cast<int8_t>(casc.template bachelor_as<TrackType>().tofNSigmaPi() * 10),
864+
static_cast<int8_t>(casc.template bachelor_as<TrackType>().tofNSigmaKa() * 10),
865+
static_cast<int8_t>(casc.template bachelor_as<TrackType>().tofNSigmaPr() * 10),
866866
casc.v0cosPA(collision.posX(), collision.posY(), collision.posZ()),
867867
casc.casccosPA(collision.posX(), collision.posY(), collision.posZ()),
868868
casc.dcaV0daughters(),

0 commit comments

Comments
 (0)