Skip to content

Commit 80cb346

Browse files
committed
clang tidy: moved @YanzhaoW's .clang-tidy to neuland, created a global clang-tidy with coreguidelines-pro-type-cstyle-cast only, fixed that in the existing codebase (except for neuland and califa), again.
+clang-format-15 changes +Fixed clang-tidy warnings.
1 parent 29ff3c6 commit 80cb346

Some content is hidden

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

49 files changed

+285
-558
lines changed

.clang-tidy

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,11 @@
1-
# vi: ft=yaml
21
Checks: >
3-
-*,
4-
bugprone-*,
5-
cert-dcl21-cpp,
6-
cert-dcl50-cpp,
7-
cert-env33-c,
8-
cert-err34-c,
9-
cert-err52-cpp,
10-
cert-err60-cpp,
11-
cert-flp30-c,
12-
cert-msc50-cpp,
13-
cert-msc51-cpp,
14-
clang-analyzer-*,
15-
cppcoreguidelines-*,
16-
-cppcoreguidelines-pro-type-reinterpret-cast,
17-
google-build-using-namespace,
18-
google-explicit-constructor,
19-
google-global-names-in-headers,
20-
google-readability-casting,
21-
google-runtime-int,
22-
google-runtime-operator,
23-
hicpp-*,
24-
-hicpp-vararg,
25-
misc-*,
26-
modernize-*,
27-
performance-*,
28-
readability-*,
29-
-hicpp-new-delete-operators,
30-
-modernize-use-trailing-return-type
31-
2+
-*,
3+
cppcoreguidelines-pro-type-cstyle-cast,
4+
WarningsAsErrors: ''
5+
HeaderFilterRegex: ''
6+
AnalyzeTemporaryDtors: false
7+
FormatStyle: none
8+
User: land
329
CheckOptions:
33-
- key: bugprone-argument-comment.StrictMode
34-
value: 1
35-
- key: bugprone-easily-swappable-parameters.MinimumLength
36-
value: 4
37-
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
38-
value: 1
39-
- key: readability-identifier-length.IgnoredVariableNames
40-
value: '^it$'
41-
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
42-
value: 'true'
43-
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues
44-
value: 'true'
45-
- key: readability-function-cognitive-complexity.Threshold
46-
value: 40
47-
- key: readability-function-cognitive-complexity.IgnoreMacros
48-
value: 'true'
10+
...
4911

50-
FormatStyle: 'file'

analysis/offline/R3BAnalysisIncomingID.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ InitStatus R3BAnalysisIncomingID::Init()
157157
if (fUseTref)
158158
{
159159
// Get access to trigger data of the LOS
160-
fTriggerLos = (TClonesArray*)mgr->GetObject("LosTriggerTCal");
160+
fTriggerLos = dynamic_cast<TClonesArray*>(mgr->GetObject("LosTriggerTCal"));
161161
R3BLOG_IF(warn, !fTriggerLos, "LosTriggerTCal not found");
162162
}
163163

@@ -244,7 +244,7 @@ void R3BAnalysisIncomingID::Exec(Option_t* option)
244244
Int_t tHits = fTriggerLos->GetEntriesFast();
245245
for (Int_t ihit = 0; ihit < tHits; ihit++)
246246
{
247-
R3BLosTCalData* hittcal = (R3BLosTCalData*)fTriggerLos->At(ihit);
247+
R3BLosTCalData* hittcal = dynamic_cast<R3BLosTCalData*>(fTriggerLos->At(ihit));
248248
numDet = hittcal->GetDetector();
249249
if (hittcal->GetType() == 0)
250250
trigTimeV[numDet - 1] = hittcal->GetRawTimeNs();

analysis/offline/R3BIncomingBeta.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ InitStatus R3BIncomingBeta::Init()
123123
// Get access to Sci2 data at Tcal level
124124
if (fHeader->GetExpId() == 509)
125125
{
126-
fTcalSci2 = (TClonesArray*)mgr->GetObject("Sci2Tcal");
126+
fTcalSci2 = dynamic_cast<TClonesArray*>(mgr->GetObject("Sci2Tcal"));
127127
R3BLOG_IF(warn, !fTcalSci2, "Could not find Sci2Tcal");
128128
}
129129

@@ -195,7 +195,7 @@ void R3BIncomingBeta::Exec(Option_t* option)
195195
nHits = fTcalSci2->GetEntriesFast();
196196
for (Int_t ihit = 0; ihit < nHits; ihit++)
197197
{
198-
R3BSci2TcalData* hittcal = (R3BSci2TcalData*)fTcalSci2->At(ihit);
198+
R3BSci2TcalData* hittcal = dynamic_cast<R3BSci2TcalData*>(fTcalSci2->At(ihit));
199199
UInt_t numDet = hittcal->GetDetector();
200200
UInt_t ch = hittcal->GetChannel() - 1;
201201
if (numDet > fNumDet)

fiber/bunched/R3BBunchedFiberMapped2Cal.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ void R3BBunchedFiberMapped2Cal::SetParContainers()
123123
{
124124
FairRuntimeDb* rtdb = FairRuntimeDb::instance();
125125
R3BLOG_IF(fatal, !rtdb, "FairRuntimeDb not found");
126-
#define GET_TCALPAR(NAME) \
127-
do \
128-
{ \
129-
auto name = fName + #NAME "TCalPar"; \
130-
f##NAME##TCalPar = (R3BTCalPar*)rtdb->getContainer(name); \
131-
if (!f##NAME##TCalPar) \
132-
{ \
133-
R3BLOG(error, "Could not get access to " << name << " container"); \
134-
} \
126+
#define GET_TCALPAR(NAME) \
127+
do \
128+
{ \
129+
auto name = fName + #NAME "TCalPar"; \
130+
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(rtdb->getContainer(name)); \
131+
if (!f##NAME##TCalPar) \
132+
{ \
133+
R3BLOG(error, "Could not get access to " << name << " container"); \
134+
} \
135135
} while (0)
136136

137137
GET_TCALPAR(MAPMT);

fiber/bunched/R3BBunchedFiberMapped2CalPar.cxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ InitStatus R3BBunchedFiberMapped2CalPar::Init()
5858
{
5959
// container needs to be created in tcal/R3BTCalContFact.cxx AND R3BTCal needs
6060
// to be set as dependency in CMakeLists.txt in the detector directory.
61-
#define GET_TCALPAR(NAME) \
62-
do \
63-
{ \
64-
auto name = fName + #NAME "TCalPar"; \
65-
f##NAME##TCalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer(name); \
66-
if (!f##NAME##TCalPar) \
67-
{ \
68-
R3BLOG(error, "Could not get " << name); \
69-
return kFATAL; \
70-
} \
71-
f##NAME##TCalPar->setChanged(); \
72-
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
61+
#define GET_TCALPAR(NAME) \
62+
do \
63+
{ \
64+
auto name = fName + #NAME "TCalPar"; \
65+
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(FairRuntimeDb::instance()->getContainer(name)); \
66+
if (!f##NAME##TCalPar) \
67+
{ \
68+
R3BLOG(error, "Could not get " << name); \
69+
return kFATAL; \
70+
} \
71+
f##NAME##TCalPar->setChanged(); \
72+
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
7373
} while (0)
7474

7575
auto rm = FairRootManager::Instance();

fiber/mapmt/R3BFiberMAPMTCal2Hit.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
******************************************************************************/
1313

1414
#include "R3BFiberMAPMTCal2Hit.h"
15+
#include "R3BCoarseTimeStitch.h"
1516
#include "R3BEventHeader.h"
1617
#include "R3BFiberMAPMTCalData.h"
1718
#include "R3BFiberMAPMTHitData.h"
1819
#include "R3BFiberMAPMTHitPar.h"
1920
#include "R3BFiberMappingPar.h"
2021
#include "R3BLogger.h"
2122
#include "R3BTCalEngine.h"
22-
#include "R3BCoarseTimeStitch.h"
2323

2424
#include "TF1.h"
2525
#include "TH1F.h"
@@ -648,7 +648,7 @@ void R3BFiberMAPMTCal2Hit::FinishTask()
648648

649649
// time offset
650650
R3BFiberMAPMTHitModulePar* par2 = fCalPar->GetModuleParAt(i);
651-
auto proj2 = (TH1F*)fh_dt_Fib_raw->ProjectionY("", i, i, 0);
651+
auto proj2 = fh_dt_Fib_raw->ProjectionY("", i, i, 0);
652652
// par2->SetOffsetUp(0.5 * proj2->GetBinCenter(proj2->GetMaximumBin()));
653653
auto Max = proj2->GetXaxis()->GetBinCenter(proj2->GetMaximumBin());
654654
TF1* fGauss = new TF1("fgaus", "gaus", Max - 8., Max + 8.);
@@ -660,7 +660,7 @@ void R3BFiberMAPMTCal2Hit::FinishTask()
660660

661661
// tsync
662662
// R3BFiberMAPMTHitModulePar* par3 = fCalPar->GetModuleParAt(i);
663-
auto proj3 = (TH1F*)fh_Fib_ToF_raw->ProjectionY("", i, i, 0);
663+
auto proj3 = fh_Fib_ToF_raw->ProjectionY("", i, i, 0);
664664
auto sync = proj3->GetXaxis()->GetBinCenter(proj3->GetMaximumBin());
665665
par2->SetSync(sync);
666666

fiber/mapmt/R3BFiberMAPMTMapped2Cal.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ InitStatus R3BFiberMAPMTMapped2Cal::Init()
7373

7474
void R3BFiberMAPMTMapped2Cal::SetParContainers()
7575
{
76-
#define GET_TCALPAR(NAME) \
77-
do \
78-
{ \
79-
auto name = fName + #NAME "TCalPar"; \
80-
f##NAME##TCalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer(name); \
81-
if (!f##NAME##TCalPar) \
82-
{ \
83-
R3BLOG(error, "Could not get access to " << name << " container."); \
84-
} \
76+
#define GET_TCALPAR(NAME) \
77+
do \
78+
{ \
79+
auto name = fName + #NAME "TCalPar"; \
80+
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(FairRuntimeDb::instance()->getContainer(name)); \
81+
if (!f##NAME##TCalPar) \
82+
{ \
83+
R3BLOG(error, "Could not get access to " << name << " container."); \
84+
} \
8585
} while (0)
8686
GET_TCALPAR(MAPMT);
8787
GET_TCALPAR(MAPMTTrig);

fiber/mapmt/R3BFiberMAPMTMapped2CalPar.cxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ InitStatus R3BFiberMAPMTMapped2CalPar::Init()
6060

6161
// container needs to be created in tcal/R3BTCalContFact.cxx AND R3BTCal needs
6262
// to be set as dependency in CMakeLists.txt in the detector directory.
63-
#define GET_TCALPAR(NAME) \
64-
do \
65-
{ \
66-
auto name = fName + #NAME "TCalPar"; \
67-
f##NAME##TCalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer(name); \
68-
if (!f##NAME##TCalPar) \
69-
{ \
70-
R3BLOG(error, "Could not find " << name); \
71-
return kFATAL; \
72-
} \
73-
f##NAME##TCalPar->setChanged(); \
74-
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
63+
#define GET_TCALPAR(NAME) \
64+
do \
65+
{ \
66+
auto name = fName + #NAME "TCalPar"; \
67+
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(FairRuntimeDb::instance()->getContainer(name)); \
68+
if (!f##NAME##TCalPar) \
69+
{ \
70+
R3BLOG(error, "Could not find " << name); \
71+
return kFATAL; \
72+
} \
73+
f##NAME##TCalPar->setChanged(); \
74+
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
7575
} while (0)
7676
GET_TCALPAR(MAPMT);
7777
GET_TCALPAR(MAPMTTrig);

field/R3BFieldInterp.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void R3BFieldInterp::init()
4747
_m2 = _np[2];
4848
_n = _np[0] * _np[1] * _np[2];
4949

50-
float* d = (float*)realloc(_data, sizeof(float) * _n);
50+
float* d = reinterpret_cast<float*>(realloc(_data, sizeof(float) * _n));
5151

5252
if (!d)
5353
cout << "-E- Field interpolation, memory allocation failure." << endl;

los/calib/R3BLosTCal2Hit.cxx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
#include "R3BLosTCal2Hit.h"
2020
#include "FairLogger.h"
21-
#include "FairRuntimeDb.h"
2221
#include "FairRootManager.h"
22+
#include "FairRuntimeDb.h"
23+
#include "R3BCoarseTimeStitch.h"
2324
#include "R3BEventHeader.h"
2425
#include "R3BLosHitData.h"
2526
#include "R3BLosHitPar.h"
@@ -28,7 +29,6 @@
2829
#include "R3BLosTCalData.h"
2930
#include "R3BTCalEngine.h"
3031
#include "R3BTCalPar.h"
31-
#include "R3BCoarseTimeStitch.h"
3232
#include "TClonesArray.h"
3333
#include "TH1F.h"
3434
#include "TH2F.h"
@@ -100,7 +100,7 @@ void R3BLosTCal2Hit::SetParContainers()
100100
{
101101
LOG(error) << "FairRuntimeDb not opened!";
102102
}
103-
fLosHit_Par = (R3BLosHitPar*)rtdb->getContainer("LosHitPar");
103+
fLosHit_Par = dynamic_cast<R3BLosHitPar*>(rtdb->getContainer("LosHitPar"));
104104
if (!fLosHit_Par)
105105
{
106106
LOG(error) << "R3BLosTcal2Hit:: Couldn't get handle on R3BLosHitPar container";
@@ -142,13 +142,13 @@ InitStatus R3BLosTCal2Hit::Init()
142142
if (NULL == mgr)
143143
LOG(error) << "FairRootManager not found";
144144

145-
header = (R3BEventHeader*)mgr->GetObject("EventHeader.");
145+
header = dynamic_cast<R3BEventHeader*>(mgr->GetObject("EventHeader."));
146146
if (!header)
147-
header = (R3BEventHeader*)mgr->GetObject("R3BEventHeader");
147+
header = dynamic_cast<R3BEventHeader*>(mgr->GetObject("R3BEventHeader"));
148148

149-
fTCalItems = (TClonesArray*)mgr->GetObject("LosTCal");
149+
fTCalItems = dynamic_cast<TClonesArray*>(mgr->GetObject("LosTCal"));
150150

151-
fTCalTriggerItems = (TClonesArray*)mgr->GetObject("LosTriggerTCal");
151+
fTCalTriggerItems = dynamic_cast<TClonesArray*>(mgr->GetObject("LosTriggerTCal"));
152152
if (NULL == fTCalItems)
153153
{
154154
LOG(fatal) << "Branch LosTCal not found";
@@ -213,7 +213,6 @@ InitStatus R3BLosTCal2Hit::Init()
213213
}
214214
}
215215

216-
217216
SetParameter();
218217
return kSUCCESS;
219218
}
@@ -247,7 +246,7 @@ void R3BLosTCal2Hit::Exec(Option_t* option)
247246
return;
248247
for (Int_t ihit = 0; ihit < trigHits; ihit++)
249248
{
250-
R3BLosTCalData* hit = (R3BLosTCalData*)fTCalTriggerItems->At(ihit);
249+
R3BLosTCalData* hit = dynamic_cast<R3BLosTCalData*>(fTCalTriggerItems->At(ihit));
251250
Int_t typ = hit->GetType();
252251
trigTime[typ] = hit->GetRawTimeNs();
253252
}
@@ -284,7 +283,7 @@ void R3BLosTCal2Hit::Exec(Option_t* option)
284283

285284
for (Int_t ihit = 0; ihit < nHits; ihit++)
286285
{
287-
R3BLosTCalData* hit = (R3BLosTCalData*)fTCalItems->At(ihit);
286+
R3BLosTCalData* hit = dynamic_cast<R3BLosTCalData*>(fTCalItems->At(ihit));
288287
Int_t ch = hit->GetChannel();
289288
Int_t typ = hit->GetType();
290289
Int_t det = hit->GetDetector();

neuland/.clang-tidy

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# vi: ft=yaml
2+
Checks: >
3+
-*,
4+
bugprone-*,
5+
cert-dcl21-cpp,
6+
cert-dcl50-cpp,
7+
cert-env33-c,
8+
cert-err34-c,
9+
cert-err52-cpp,
10+
cert-err60-cpp,
11+
cert-flp30-c,
12+
cert-msc50-cpp,
13+
cert-msc51-cpp,
14+
clang-analyzer-*,
15+
cppcoreguidelines-*,
16+
-cppcoreguidelines-pro-type-reinterpret-cast,
17+
google-build-using-namespace,
18+
google-explicit-constructor,
19+
google-global-names-in-headers,
20+
google-readability-casting,
21+
google-runtime-int,
22+
google-runtime-operator,
23+
hicpp-*,
24+
-hicpp-vararg,
25+
misc-*,
26+
modernize-*,
27+
performance-*,
28+
readability-*,
29+
-hicpp-new-delete-operators,
30+
-modernize-use-trailing-return-type
31+
32+
CheckOptions:
33+
- key: bugprone-argument-comment.StrictMode
34+
value: 1
35+
- key: bugprone-easily-swappable-parameters.MinimumLength
36+
value: 4
37+
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
38+
value: 1
39+
- key: readability-identifier-length.IgnoredVariableNames
40+
value: '^it$'
41+
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
42+
value: 'true'
43+
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues
44+
value: 'true'
45+
- key: readability-function-cognitive-complexity.Threshold
46+
value: 40
47+
- key: readability-function-cognitive-complexity.IgnoreMacros
48+
value: 'true'
49+
50+
FormatStyle: 'file'

r3bsource/base/R3BUcesbSource.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ Int_t R3BUcesbSource::ReadEvent(UInt_t i)
294294
if (raw)
295295
{
296296
int w, j;
297-
const uint32_t* u = (const uint32_t*)raw;
297+
const uint32_t* u = reinterpret_cast<const uint32_t*>(raw);
298298

299299
LOG(info) << " Raw data:";
300300
for (w = 0; w < raw_words; w += 8)

0 commit comments

Comments
 (0)