Skip to content

Commit 1a9718e

Browse files
meiALICEYuanjun Mei
andauthored
[PWGCF] Change and fix according to code check (#17804)
Co-authored-by: Yuanjun Mei <yuanjun.mei@cern.ch>
1 parent 06d94cc commit 1a9718e

1 file changed

Lines changed: 47 additions & 22 deletions

File tree

PWGCF/MultiparticleCorrelations/Tasks/multiparticleCorrelationsMei.cxx

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,30 @@
1919
#include "Common/DataModel/TrackSelectionTables.h" // needed for aod::TracksDCA table
2020

2121
#include <CCDB/BasicCCDBManager.h>
22+
#include <CommonConstants/MathConstants.h>
2223
#include <Framework/AnalysisDataModel.h>
24+
#include <Framework/AnalysisHelpers.h>
2325
#include <Framework/AnalysisTask.h>
24-
#include <Framework/DataTypes.h>
26+
#include <Framework/Configurable.h>
27+
#include <Framework/InitContext.h>
28+
#include <Framework/OutputObjHeader.h>
2529
#include <Framework/runDataProcessing.h>
2630

31+
#include <TCollection.h>
32+
#include <TFile.h>
2733
#include <TGrid.h>
28-
#include <TH1D.h>
34+
#include <TH1.h>
35+
#include <TH2.h>
36+
#include <TIterator.h>
37+
#include <TList.h>
38+
#include <TObject.h>
39+
#include <TString.h>
2940
#include <TSystem.h>
3041

42+
#include <Rtypes.h>
43+
44+
#include <cstddef>
45+
#include <cstdint>
3146
#include <string>
3247
#include <vector>
3348

@@ -116,7 +131,7 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
116131
OutputObjSourceType::OutputObjSource};
117132

118133
// *) CCDB:
119-
Service<ccdb::BasicCCDBManager> ccdb; // support for offline callibration data base, not needed for the time being...
134+
Service<ccdb::BasicCCDBManager> ccdb{}; // support for offline callibration data base, not needed for the time being...
120135

121136
// *) Define configurables:
122137
Configurable<int> centralityEstimator{"centralityEstimator", 0, "centrality estimator: 0=FT0C, 1=FT0M, 2=FV0A, 3=NTPV"};
@@ -202,7 +217,7 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
202217
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
203218
}
204219
if (0 == list->GetEntries()) {
205-
return NULL;
220+
return nullptr;
206221
}
207222

208223
// The object is in the current base list:
@@ -212,26 +227,27 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
212227
}
213228

214229
// Otherwise, search for the object recursively in the nested lists:
215-
TObject* objectIter; // iterator object in the loop below
230+
TObject* objectIter = nullptr; // iterator object in the loop below
216231
TIter next(list);
217232
while ((objectIter = next())) // double round braces are to silence the warnings
218233
{
219-
if (TString(objectIter->ClassName()).EqualTo("TList")) {
220-
objectFinal = getObjectFromList(reinterpret_cast<TList*>(objectIter), objectName);
221-
if (objectFinal)
234+
if (auto* subList = dynamic_cast<TList*>(objectIter)) {
235+
objectFinal = getObjectFromList(subList, objectName);
236+
if (objectFinal) {
222237
return objectFinal;
238+
}
223239
}
224240
} // while(objectIter = next())
225241

226-
return NULL;
242+
return nullptr;
227243
} // TObject* getObjectFromList(TList *list, char *objectName)
228244

229245
TH1D* getHistogramWithWeights(const char* filePath, const char* runNumber)
230246
{
231247
// *) Return value:
232-
TH1D* hist = NULL;
233-
TList* baseList = NULL; // base top-level list in the TFile, e.g. named "ccdb_object"
234-
TList* listWithRuns = NULL; // nested list with run-wise TList's holding run-specific weights
248+
TH1D* hist = nullptr;
249+
TList* baseList = nullptr; // base top-level list in the TFile, e.g. named "ccdb_object"
250+
TList* listWithRuns = nullptr; // nested list with run-wise TList's holding run-specific weights
235251

236252
// *) Determine from filePath if the file is on a local machine, or in home dir AliEn, or in CCDB:
237253
// Algorithm: If filePath begins with "/alice/cern.ch/" then it's in the home dir AliEn;
@@ -240,7 +256,7 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
240256
bool bFileIsInAliEn = false;
241257
bool bFileIsInCCDB = false;
242258

243-
std::string path(cfFileWithWeights);
259+
std::string path(filePath);
244260

245261
if (path.starts_with("/alice/cern.ch/")) {
246262
bFileIsInAliEn = true;
@@ -266,11 +282,11 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
266282

267283
// Finally, from the top-level TList, get the desired nested TList => the technical problem here is that it can be nested at any level,
268284
// for that there is a helper utility function getObjectFromList(...) , see its implementation further below
269-
listWithRuns = reinterpret_cast<TList*>(getObjectFromList(baseList, runNumber));
285+
listWithRuns = dynamic_cast<TList*>(getObjectFromList(baseList, runNumber));
270286
if (!listWithRuns) {
271287
TString runNumberWithLeadingZeroes = "000";
272288
runNumberWithLeadingZeroes += runNumber; // another try, with "000" prepended to run number
273-
listWithRuns = reinterpret_cast<TList*>(getObjectFromList(baseList, runNumberWithLeadingZeroes.Data()));
289+
listWithRuns = dynamic_cast<TList*>(getObjectFromList(baseList, runNumberWithLeadingZeroes.Data()));
274290
if (!listWithRuns) {
275291
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
276292
}
@@ -288,11 +304,11 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
288304
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
289305
}
290306

291-
listWithRuns = reinterpret_cast<TList*>(getObjectFromList(baseList, runNumber));
307+
listWithRuns = dynamic_cast<TList*>(getObjectFromList(baseList, runNumber));
292308
if (!listWithRuns) {
293309
TString runNumberWithLeadingZeroes = "000";
294310
runNumberWithLeadingZeroes += runNumber; // another try, with "000" prepended to run number
295-
listWithRuns = reinterpret_cast<TList*>(getObjectFromList(baseList, runNumberWithLeadingZeroes.Data()));
311+
listWithRuns = dynamic_cast<TList*>(getObjectFromList(baseList, runNumberWithLeadingZeroes.Data()));
296312
if (!listWithRuns) {
297313
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
298314
}
@@ -321,11 +337,11 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
321337
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
322338
}
323339

324-
listWithRuns = reinterpret_cast<TList*>(getObjectFromList(baseList, runNumber));
340+
listWithRuns = dynamic_cast<TList*>(getObjectFromList(baseList, runNumber));
325341
if (!listWithRuns) {
326342
TString runNumberWithLeadingZeroes = "000";
327343
runNumberWithLeadingZeroes += runNumber; // another try, with "000" prepended to run number
328-
listWithRuns = reinterpret_cast<TList*>(getObjectFromList(baseList, runNumberWithLeadingZeroes.Data()));
344+
listWithRuns = dynamic_cast<TList*>(getObjectFromList(baseList, runNumberWithLeadingZeroes.Data()));
329345
if (!listWithRuns) {
330346
// baseList->ls();
331347
// LOGF(fatal, "\033[1;31m%s at line %d : this crash can happen if in the output file there is no list with weights for the current run number = %s\033[0m", __FUNCTION__, __LINE__, tc.fRunNumber.Data());
@@ -346,9 +362,9 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
346362
if (!hist) {
347363
LOGF(fatal, "%s: histogram 'hist1' not found in run list", __FUNCTION__);
348364
}
349-
hist->SetDirectory(0);
365+
hist->SetDirectory(nullptr);
350366
auto histClone = dynamic_cast<TH1D*>(hist->Clone());
351-
histClone->SetDirectory(0);
367+
histClone->SetDirectory(nullptr);
352368

353369
delete baseList; // release back the memory
354370

@@ -398,6 +414,9 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
398414
case ENTPV:
399415
thisCent = collision.centNTPV();
400416
break;
417+
default:
418+
LOG(warning) << "Unknown centrality estimator. Using FT0C as default.";
419+
break; // thisCent is already FT0C
401420
}
402421

403422
auto thisRefMult = collision.multTPC(); // use auto to determine the type
@@ -417,6 +436,9 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
417436
case EMultNTracksPV:
418437
thisRefMult = collision.multNTracksPV();
419438
break;
439+
default:
440+
LOG(warning) << "Unknown multiplicity. Using multTPC as default.";
441+
break; // thisRefMult is already multTPC
420442
}
421443

422444
if constexpr (rs == ERec || rs == ERecAndSim) {
@@ -551,6 +573,9 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
551573
case ENTPV:
552574
thisCent = collision.centNTPV();
553575
break;
576+
default:
577+
LOG(warning) << "Unknown centrality estimator. Using FT0C as default.";
578+
break; // thisCent is already FT0C
554579
}
555580
if constexpr (rs == ERecAndSim || rs == ESim) {
556581
if (!collision.has_mcCollision()) {
@@ -621,7 +646,7 @@ struct MultiparticleCorrelationsMei // this name is used in lower-case format to
621646
tc.fDryRun = cfDryRun;
622647

623648
// *) Book base list:
624-
TList* temp = new TList();
649+
auto* temp = new TList();
625650
temp->SetOwner(true);
626651
fBaseList.setObject(temp);
627652

0 commit comments

Comments
 (0)