Skip to content

Commit b395529

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 b395529

10 files changed

Lines changed: 35 additions & 35 deletions

‎EventFiltering/PWGHF/HFFilterHelpers.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ inline void HfFilterHelper::setTpcRecalibMaps(o2::framework::Service<o2::ccdb::B
20042004

20052005
for (size_t iMap = 0; iMap < mapNames.size(); iMap++) {
20062006

2007-
mHistMapPiPrKaDe[iMap] = reinterpret_cast<TH3F*>(calibList->FindObject(mapNames[iMap].data()));
2007+
mHistMapPiPrKaDe[iMap] = dynamic_cast<TH3F*>(calibList->FindObject(mapNames[iMap].data()));
20082008
if (!mHistMapPiPrKaDe[iMap]) {
20092009
LOG(fatal) << "Cannot find histogram: " << mapNames[iMap].data();
20102010
return;

‎EventFiltering/PWGJE/jetFilter.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct jetFilter {
9898
void init(o2::framework::InitContext&)
9999
{
100100
triggerJetR = TMath::Nint(cfgJetR * 100.0f);
101-
trackSelection = jetderiveddatautilities::initialiseTrackSelection(static_cast<std::string>(trackSelections));
101+
trackSelection = jetderiveddatautilities::initialiseTrackSelection(trackSelections);
102102
eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(static_cast<std::string>(evSel));
103103

104104
spectra.add("fCollZpos", "collision z position", HistType::kTH1F,

‎EventFiltering/PWGUD/diffractionBCFilter.cxx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ struct tracksWGTInBCs {
112112
LOGF(debug, " Number of BCs %d", atr.bc().size());
113113
if (atr.bc().size() > 0) {
114114
auto firstCompatibleBC = atr.bc().begin().globalBC();
115-
closestBC = (uint64_t)(firstCompatibleBC +
116-
(track.trackTime() / o2::constants::lhc::LHCBunchSpacingNS));
115+
closestBC = static_cast<uint64_t>(firstCompatibleBC +
116+
(track.trackTime() / o2::constants::lhc::LHCBunchSpacingNS));
117117
// update tracksInBCList
118118
LOGF(debug, "closestBC %d", closestBC);
119-
tracksInBCList[closestBC].emplace_back((int32_t)track.globalIndex());
119+
tracksInBCList[closestBC].emplace_back(static_cast<int32_t>(track.globalIndex()));
120120
}
121121
} else {
122122
// registry.get<TH1>(HIST("barrelTracks"))->Fill(2., 1.);
@@ -128,7 +128,7 @@ struct tracksWGTInBCs {
128128

129129
// update tracksInBCList
130130
LOGF(debug, "closestBC %d", closestBC);
131-
tracksInBCList[closestBC].emplace_back((int32_t)track.globalIndex());
131+
tracksInBCList[closestBC].emplace_back(static_cast<int32_t>(track.globalIndex()));
132132
}
133133
}
134134
LOGF(debug, "track finished.\n");
@@ -195,12 +195,12 @@ struct tracksWGTInBCs {
195195
LOGF(debug, " Number of BCs %d", aftr.bc().size());
196196
if (aftr.bc().size() > 0) {
197197
auto firstCompatibleBC = aftr.bc().begin().globalBC();
198-
closestBC = (uint64_t)(firstCompatibleBC +
199-
(fwdTrack.trackTime() / o2::constants::lhc::LHCBunchSpacingNS));
198+
closestBC = static_cast<uint64_t>(firstCompatibleBC +
199+
(fwdTrack.trackTime() / o2::constants::lhc::LHCBunchSpacingNS));
200200

201201
// update fwdTracksWGTInBCList
202202
LOGF(debug, "closestBC %d", closestBC);
203-
fwdTracksWGTInBCList[closestBC].emplace_back((int32_t)fwdTrack.globalIndex());
203+
fwdTracksWGTInBCList[closestBC].emplace_back(static_cast<int32_t>(fwdTrack.globalIndex()));
204204
}
205205
} else {
206206
// registry.get<TH1>(HIST("forwardTracks"))->Fill(2., 1.);
@@ -212,7 +212,7 @@ struct tracksWGTInBCs {
212212

213213
// update fwdTracksWGTInBCList
214214
LOGF(debug, "closestBC %d", closestBC);
215-
fwdTracksWGTInBCList[closestBC].emplace_back((int32_t)fwdTrack.globalIndex());
215+
fwdTracksWGTInBCList[closestBC].emplace_back(static_cast<int32_t>(fwdTrack.globalIndex()));
216216
}
217217
}
218218
LOGF(debug, "FwdTrack finished.\n");
@@ -282,7 +282,7 @@ struct DGBCFilterRun3 {
282282

283283
void init(InitContext&)
284284
{
285-
diffCuts = (DGCutparHolder)DGCuts;
285+
diffCuts = DGCutparHolder(DGCuts);
286286
}
287287

288288
// some general Collisions and Tracks filter

‎EventFiltering/PWGUD/diffractionFilter.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ struct DGFilterRun3 {
8989
{
9090
// reset collision counter
9191
collCounter = 0;
92-
verbose = (int64_t)Verbose;
92+
verbose = static_cast<int64_t>(Verbose);
9393
if (verbose <= 0) {
9494
verbose = 1000000000000;
9595
}
9696

9797
// cut holder
98-
diffCuts = (DGCutparHolder)diffCutsHolder;
98+
diffCuts = DGCutparHolder(diffCutsHolder);
9999

100100
// create histograms
101101
// stat

‎EventFiltering/macros/cefpOutputChecker.C‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
void cefpOutputChecker(std::string histoFile = "AnalysisResults.root", std::string treeFile = "AO2D.root")
2222
{
2323
TFile referenceFile(histoFile.data());
24-
TH1* refScalers = (TH1*)referenceFile.Get("central-event-filter-task/scalers/mScalers");
25-
TH1* refFilters = (TH1*)referenceFile.Get("central-event-filter-task/scalers/mFiltered");
24+
TH1* refScalers = dynamic_cast<TH1*>(referenceFile.Get("central-event-filter-task/scalers/mScalers"));
25+
TH1* refFilters = dynamic_cast<TH1*>(referenceFile.Get("central-event-filter-task/scalers/mFiltered"));
2626

2727
TFile outputFile("cefpOutputChecker.root", "recreate");
28-
TH1* newFilters = (TH1*)refFilters->Clone("newFilters");
29-
TH1* newScalers = (TH1*)refScalers->Clone("newScalers");
28+
TH1* newFilters = dynamic_cast<TH1*>(refFilters->Clone("newFilters"));
29+
TH1* newScalers = dynamic_cast<TH1*>(refScalers->Clone("newScalers"));
3030
newFilters->Reset();
3131
newScalers->Reset();
3232

3333
TFile inputFile(treeFile.data());
3434
for (auto key : *(inputFile.GetListOfKeys())) {
35-
TTree* cefpTree = (TTree*)inputFile.Get(Form("%s/O2cefpdecision", key->GetName()));
35+
TTree* cefpTree = dynamic_cast<TTree*>(inputFile.Get(Form("%s/O2cefpdecision", key->GetName())));
3636
if (!cefpTree)
3737
continue;
3838
ULong64_t fCefpSelected, fCefpTriggered;

‎EventFiltering/macros/checkBCrangesSkimming.C‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,28 +620,28 @@ void checkBCrangesSkimming(std::string AnaFileName = "AnalysisResults.root", std
620620
TH1D *hOriginalSinglesRatio, *hOriginalDoublesRatio, *hOriginalMultiplesRatio;
621621
TH1D *hSkimmedSinglesRatio, *hSkimmedDoublesRatio, *hSkimmedMultiplesRatio;
622622

623-
hTriggerEff = reinterpret_cast<TH1D*>(hSkimmedTotal.Clone("hTriggerEff"));
623+
hTriggerEff = dynamic_cast<TH1D*>(hSkimmedTotal.Clone("hTriggerEff"));
624624
hTriggerEff->SetTitle((runNumber + " skimmed efficiency;; Skimmed / Original").data());
625625
hTriggerEff->Divide(&hOriginalTotal);
626626
hTriggerMatchesRatio.Divide(&hOriginalSingles);
627627
hTriggerSingleMatchesRatio.Divide(&hOriginalSingles);
628-
hOriginalSinglesRatio = reinterpret_cast<TH1D*>(hOriginalSingles.Clone("hOriginalSinglesRatio"));
628+
hOriginalSinglesRatio = dynamic_cast<TH1D*>(hOriginalSingles.Clone("hOriginalSinglesRatio"));
629629
hOriginalSinglesRatio->SetTitle((runNumber + " Original;;Singles / Total").data());
630630
hOriginalSinglesRatio->Divide(&hOriginalTotal);
631-
hOriginalDoublesRatio = reinterpret_cast<TH1D*>(hOriginalDoubles.Clone("hOriginalDoublesRatio"));
631+
hOriginalDoublesRatio = dynamic_cast<TH1D*>(hOriginalDoubles.Clone("hOriginalDoublesRatio"));
632632
hOriginalDoublesRatio->SetTitle((runNumber + " Original;;Doubles / Total").data());
633633
hOriginalDoublesRatio->Divide(&hOriginalTotal);
634-
hOriginalMultiplesRatio = reinterpret_cast<TH1D*>(hOriginalMultiples.Clone("hOriginalMultiplesRatio"));
634+
hOriginalMultiplesRatio = dynamic_cast<TH1D*>(hOriginalMultiples.Clone("hOriginalMultiplesRatio"));
635635
hOriginalMultiplesRatio->SetTitle((runNumber + " Original;;Multiples / Total").data());
636636
hOriginalMultiplesRatio->Divide(&hOriginalTotal);
637637

638-
hSkimmedSinglesRatio = reinterpret_cast<TH1D*>(hSkimmedSingles.Clone("hSkimmedSinglesRatio"));
638+
hSkimmedSinglesRatio = dynamic_cast<TH1D*>(hSkimmedSingles.Clone("hSkimmedSinglesRatio"));
639639
hSkimmedSinglesRatio->SetTitle((runNumber + " Skimmed;;Singles / Total").data());
640640
hSkimmedSinglesRatio->Divide(&hSkimmedTotal);
641-
hSkimmedDoublesRatio = reinterpret_cast<TH1D*>(hSkimmedDoubles.Clone("hSkimmedDoublesRatio"));
641+
hSkimmedDoublesRatio = dynamic_cast<TH1D*>(hSkimmedDoubles.Clone("hSkimmedDoublesRatio"));
642642
hSkimmedDoublesRatio->SetTitle((runNumber + " Skimmed;;Doubles / Total").data());
643643
hSkimmedDoublesRatio->Divide(&hSkimmedTotal);
644-
hSkimmedMultiplesRatio = reinterpret_cast<TH1D*>(hSkimmedMultiples.Clone("hSkimmedMultiplesRatio"));
644+
hSkimmedMultiplesRatio = dynamic_cast<TH1D*>(hSkimmedMultiples.Clone("hSkimmedMultiplesRatio"));
645645
hSkimmedMultiplesRatio->SetTitle((runNumber + " Skimmed;;Multiples / Total").data());
646646
hSkimmedMultiplesRatio->Divide(&hSkimmedTotal);
647647

‎EventFiltering/macros/checkSkimming.C‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void checkSkimming(const std::string& listName = "period.txt", bool skipDownscal
124124
std::string original_path = line.substr(0, pos);
125125
std::string skimmed_path = line.substr(pos + 1);
126126
checkSkimming(original_path, skimmed_path, outputFile, skipDownscaled);
127-
TH1* hRatio = (TH1*)gDirectory->Get("hRatio");
127+
TH1* hRatio = dynamic_cast<TH1*>(gDirectory->Get("hRatio"));
128128
hRatio->Draw();
129129
std::string suffix = counter == 0 ? "(" : (counter == lineCounter - 1 ? ")" : "");
130130
c1.Print((periodName + ".pdf" + suffix).data());

‎EventFiltering/macros/getMenu.C‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::vector<std::string> getMenuForPeriod(std::string period)
6969

7070
TGrid::Connect("alien://");
7171
TFile* scalersFile = TFile::Open((std::string("alien://") + firstLine).data(), "READ");
72-
TH1D* counters = (TH1D*)scalersFile->Get("central-event-filter-task/scalers/mFiltered");
72+
TH1D* counters = dynamic_cast<TH1D*>(scalersFile->Get("central-event-filter-task/scalers/mFiltered"));
7373
TAxis* axis = counters->GetXaxis();
7474

7575
std::vector<std::string> binLabels(axis->GetNbins() - 2);

‎EventFiltering/macros/selectivityPlot.C‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void selectivityPlot(int runNumber = 550781, const TString& inputfile = "Analysi
4545
Canvas_1->SetFrameBorderMode(0);
4646

4747
TFile* file = new TFile(inputfile.Data());
48-
TH1D* mFiltered = (TH1D*)file->Get("central-event-filter-task/scalers/mFiltered");
48+
TH1D* mFiltered = dynamic_cast<TH1D*>(file->Get("central-event-filter-task/scalers/mFiltered"));
4949
double nEvents = mFiltered->GetBinContent(1);
5050
mFiltered->Scale(1. / nEvents);
5151
mFiltered->SetLineColor(2);

‎EventFiltering/macros/uploadOTSobjects.C‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ void uploadOTSobjects(std::string inputList, const std::string& passName, bool u
6767
auto orbitResetTimestamp = (*ctp)[0];
6868
path = useAlien ? "alien://" + path : path;
6969
std::unique_ptr<TFile> scalersFile{TFile::Open((path + "/AnalysisResults_fullrun.root").data(), "READ")};
70-
TH1* scalers = static_cast<TH1*>(scalersFile->Get("central-event-filter-task/scalers/mScalers"));
71-
TH1* filters = static_cast<TH1*>(scalersFile->Get("central-event-filter-task/scalers/mFiltered"));
70+
TH1* scalers = dynamic_cast<TH1*>(scalersFile->Get("central-event-filter-task/scalers/mScalers"));
71+
TH1* filters = dynamic_cast<TH1*>(scalersFile->Get("central-event-filter-task/scalers/mFiltered"));
7272
api.storeAsTFile(scalers, baseCCDBpath + "FilterCounters", metadata, duration.first, duration.second + 1);
7373
api.storeAsTFile(filters, baseCCDBpath + "SelectionCounters", metadata, duration.first, duration.second + 1);
74-
TH1* hCounterTVX = static_cast<TH1*>(scalersFile->Get("bc-selection-task/hCounterTVX"));
74+
TH1* hCounterTVX = dynamic_cast<TH1*>(scalersFile->Get("bc-selection-task/hCounterTVX"));
7575
if (!hCounterTVX) {
76-
hCounterTVX = static_cast<TH1*>(scalersFile->Get("lumi-task/hCounterTVX"));
76+
hCounterTVX = dynamic_cast<TH1*>(scalersFile->Get("lumi-task/hCounterTVX"));
7777
if (!hCounterTVX) {
78-
hCounterTVX = static_cast<TH1*>(scalersFile->Get("eventselection-run3/luminosity/hCounterTVX"));
78+
hCounterTVX = dynamic_cast<TH1*>(scalersFile->Get("eventselection-run3/luminosity/hCounterTVX"));
7979
if (!hCounterTVX) {
8080
std::cout << "No hCounterTVX histogram found in the file, skipping upload for run " << runString << std::endl;
8181
continue;
@@ -88,7 +88,7 @@ void uploadOTSobjects(std::string inputList, const std::string& passName, bool u
8888
std::unique_ptr<TFile> bcRangesFile{TFile::Open((path + "/bcRanges_fullrun.root").data(), "READ")};
8989
int Nmax = 0;
9090
for (auto key : *(bcRangesFile->GetListOfKeys())) {
91-
TTree* cefpTree = static_cast<TTree*>(bcRangesFile->Get(Form("%s/selectedBC", key->GetName())));
91+
TTree* cefpTree = dynamic_cast<TTree*>(bcRangesFile->Get(Form("%s/selectedBC", key->GetName())));
9292
if (!cefpTree)
9393
continue;
9494
ZorroHelper bci;
@@ -134,7 +134,7 @@ void uploadOTSobjects(std::string inputList, const std::string& passName, bool u
134134
auto bcNext{nextHelper.bcAOD < nextHelper.bcEvSel ? nextHelper.bcAOD : nextHelper.bcEvSel};
135135
if (bcNext - bcEnd > 2001 / o2::constants::lhc::LHCBunchSpacingMUS) { /// ensure a gap of 2ms between chunks
136136
chunk.insert(chunk.begin(), zorroHelpers.begin() + helperIndex, zorroHelpers.begin() + endIndex + 1);
137-
endTS = (orbitResetTimestamp + int64_t(bcEnd * o2::constants::lhc::LHCBunchSpacingNS * 1e-3)) / 1000 + 1;
137+
endTS = (orbitResetTimestamp + static_cast<int64_t>(bcEnd * o2::constants::lhc::LHCBunchSpacingNS * 1e-3)) / 1000 + 1;
138138
break;
139139
}
140140
bcEnd = nextHelper.bcAOD > nextHelper.bcEvSel ? nextHelper.bcAOD : nextHelper.bcEvSel;

0 commit comments

Comments
 (0)