Skip to content

Commit

Permalink
clang tidy: moved @YanzhaoW's .clang-tidy to neuland, created a globa…
Browse files Browse the repository at this point in the history
…l 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.
  • Loading branch information
klenze authored and jose-luis-rs committed Nov 15, 2023
1 parent 29ff3c6 commit 77deacb
Show file tree
Hide file tree
Showing 49 changed files with 285 additions and 558 deletions.
55 changes: 8 additions & 47 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,50 +1,11 @@
# vi: ft=yaml
Checks: >
-*,
bugprone-*,
cert-dcl21-cpp,
cert-dcl50-cpp,
cert-env33-c,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-build-using-namespace,
google-explicit-constructor,
google-global-names-in-headers,
google-readability-casting,
google-runtime-int,
google-runtime-operator,
hicpp-*,
-hicpp-vararg,
misc-*,
modernize-*,
performance-*,
readability-*,
-hicpp-new-delete-operators,
-modernize-use-trailing-return-type
-*,
cppcoreguidelines-pro-type-cstyle-cast,
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: land
CheckOptions:
- key: bugprone-argument-comment.StrictMode
value: 1
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 4
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 1
- key: readability-identifier-length.IgnoredVariableNames
value: '^it$'
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
value: 'true'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues
value: 'true'
- key: readability-function-cognitive-complexity.Threshold
value: 40
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'true'
...

FormatStyle: 'file'
4 changes: 2 additions & 2 deletions analysis/offline/R3BAnalysisIncomingID.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ InitStatus R3BAnalysisIncomingID::Init()
if (fUseTref)
{
// Get access to trigger data of the LOS
fTriggerLos = (TClonesArray*)mgr->GetObject("LosTriggerTCal");
fTriggerLos = dynamic_cast<TClonesArray*>(mgr->GetObject("LosTriggerTCal"));
R3BLOG_IF(warn, !fTriggerLos, "LosTriggerTCal not found");
}

Expand Down Expand Up @@ -244,7 +244,7 @@ void R3BAnalysisIncomingID::Exec(Option_t* option)
Int_t tHits = fTriggerLos->GetEntriesFast();
for (Int_t ihit = 0; ihit < tHits; ihit++)
{
R3BLosTCalData* hittcal = (R3BLosTCalData*)fTriggerLos->At(ihit);
R3BLosTCalData* hittcal = dynamic_cast<R3BLosTCalData*>(fTriggerLos->At(ihit));
numDet = hittcal->GetDetector();
if (hittcal->GetType() == 0)
trigTimeV[numDet - 1] = hittcal->GetRawTimeNs();
Expand Down
4 changes: 2 additions & 2 deletions analysis/offline/R3BIncomingBeta.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ InitStatus R3BIncomingBeta::Init()
// Get access to Sci2 data at Tcal level
if (fHeader->GetExpId() == 509)
{
fTcalSci2 = (TClonesArray*)mgr->GetObject("Sci2Tcal");
fTcalSci2 = dynamic_cast<TClonesArray*>(mgr->GetObject("Sci2Tcal"));
R3BLOG_IF(warn, !fTcalSci2, "Could not find Sci2Tcal");
}

Expand Down Expand Up @@ -195,7 +195,7 @@ void R3BIncomingBeta::Exec(Option_t* option)
nHits = fTcalSci2->GetEntriesFast();
for (Int_t ihit = 0; ihit < nHits; ihit++)
{
R3BSci2TcalData* hittcal = (R3BSci2TcalData*)fTcalSci2->At(ihit);
R3BSci2TcalData* hittcal = dynamic_cast<R3BSci2TcalData*>(fTcalSci2->At(ihit));
UInt_t numDet = hittcal->GetDetector();
UInt_t ch = hittcal->GetChannel() - 1;
if (numDet > fNumDet)
Expand Down
18 changes: 9 additions & 9 deletions fiber/bunched/R3BBunchedFiberMapped2Cal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ void R3BBunchedFiberMapped2Cal::SetParContainers()
{
FairRuntimeDb* rtdb = FairRuntimeDb::instance();
R3BLOG_IF(fatal, !rtdb, "FairRuntimeDb not found");
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = (R3BTCalPar*)rtdb->getContainer(name); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not get access to " << name << " container"); \
} \
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(rtdb->getContainer(name)); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not get access to " << name << " container"); \
} \
} while (0)

GET_TCALPAR(MAPMT);
Expand Down
24 changes: 12 additions & 12 deletions fiber/bunched/R3BBunchedFiberMapped2CalPar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ InitStatus R3BBunchedFiberMapped2CalPar::Init()
{
// container needs to be created in tcal/R3BTCalContFact.cxx AND R3BTCal needs
// to be set as dependency in CMakeLists.txt in the detector directory.
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer(name); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not get " << name); \
return kFATAL; \
} \
f##NAME##TCalPar->setChanged(); \
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(FairRuntimeDb::instance()->getContainer(name)); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not get " << name); \
return kFATAL; \
} \
f##NAME##TCalPar->setChanged(); \
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
} while (0)

auto rm = FairRootManager::Instance();
Expand Down
6 changes: 3 additions & 3 deletions fiber/mapmt/R3BFiberMAPMTCal2Hit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
******************************************************************************/

#include "R3BFiberMAPMTCal2Hit.h"
#include "R3BCoarseTimeStitch.h"
#include "R3BEventHeader.h"
#include "R3BFiberMAPMTCalData.h"
#include "R3BFiberMAPMTHitData.h"
#include "R3BFiberMAPMTHitPar.h"
#include "R3BFiberMappingPar.h"
#include "R3BLogger.h"
#include "R3BTCalEngine.h"
#include "R3BCoarseTimeStitch.h"

#include "TF1.h"
#include "TH1F.h"
Expand Down Expand Up @@ -648,7 +648,7 @@ void R3BFiberMAPMTCal2Hit::FinishTask()

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

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

Expand Down
18 changes: 9 additions & 9 deletions fiber/mapmt/R3BFiberMAPMTMapped2Cal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ InitStatus R3BFiberMAPMTMapped2Cal::Init()

void R3BFiberMAPMTMapped2Cal::SetParContainers()
{
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer(name); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not get access to " << name << " container."); \
} \
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(FairRuntimeDb::instance()->getContainer(name)); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not get access to " << name << " container."); \
} \
} while (0)
GET_TCALPAR(MAPMT);
GET_TCALPAR(MAPMTTrig);
Expand Down
24 changes: 12 additions & 12 deletions fiber/mapmt/R3BFiberMAPMTMapped2CalPar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ InitStatus R3BFiberMAPMTMapped2CalPar::Init()

// container needs to be created in tcal/R3BTCalContFact.cxx AND R3BTCal needs
// to be set as dependency in CMakeLists.txt in the detector directory.
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer(name); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not find " << name); \
return kFATAL; \
} \
f##NAME##TCalPar->setChanged(); \
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
#define GET_TCALPAR(NAME) \
do \
{ \
auto name = fName + #NAME "TCalPar"; \
f##NAME##TCalPar = dynamic_cast<R3BTCalPar*>(FairRuntimeDb::instance()->getContainer(name)); \
if (!f##NAME##TCalPar) \
{ \
R3BLOG(error, "Could not find " << name); \
return kFATAL; \
} \
f##NAME##TCalPar->setChanged(); \
f##NAME##Engine = new R3BTCalEngine(f##NAME##TCalPar, fMinStats); \
} while (0)
GET_TCALPAR(MAPMT);
GET_TCALPAR(MAPMTTrig);
Expand Down
2 changes: 1 addition & 1 deletion field/R3BFieldInterp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void R3BFieldInterp::init()
_m2 = _np[2];
_n = _np[0] * _np[1] * _np[2];

float* d = (float*)realloc(_data, sizeof(float) * _n);
float* d = reinterpret_cast<float*>(realloc(_data, sizeof(float) * _n));

if (!d)
cout << "-E- Field interpolation, memory allocation failure." << endl;
Expand Down
19 changes: 9 additions & 10 deletions los/calib/R3BLosTCal2Hit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

#include "R3BLosTCal2Hit.h"
#include "FairLogger.h"
#include "FairRuntimeDb.h"
#include "FairRootManager.h"
#include "FairRuntimeDb.h"
#include "R3BCoarseTimeStitch.h"
#include "R3BEventHeader.h"
#include "R3BLosHitData.h"
#include "R3BLosHitPar.h"
Expand All @@ -28,7 +29,6 @@
#include "R3BLosTCalData.h"
#include "R3BTCalEngine.h"
#include "R3BTCalPar.h"
#include "R3BCoarseTimeStitch.h"
#include "TClonesArray.h"
#include "TH1F.h"
#include "TH2F.h"
Expand Down Expand Up @@ -100,7 +100,7 @@ void R3BLosTCal2Hit::SetParContainers()
{
LOG(error) << "FairRuntimeDb not opened!";
}
fLosHit_Par = (R3BLosHitPar*)rtdb->getContainer("LosHitPar");
fLosHit_Par = dynamic_cast<R3BLosHitPar*>(rtdb->getContainer("LosHitPar"));
if (!fLosHit_Par)
{
LOG(error) << "R3BLosTcal2Hit:: Couldn't get handle on R3BLosHitPar container";
Expand Down Expand Up @@ -142,13 +142,13 @@ InitStatus R3BLosTCal2Hit::Init()
if (NULL == mgr)
LOG(error) << "FairRootManager not found";

header = (R3BEventHeader*)mgr->GetObject("EventHeader.");
header = dynamic_cast<R3BEventHeader*>(mgr->GetObject("EventHeader."));
if (!header)
header = (R3BEventHeader*)mgr->GetObject("R3BEventHeader");
header = dynamic_cast<R3BEventHeader*>(mgr->GetObject("R3BEventHeader"));

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

fTCalTriggerItems = (TClonesArray*)mgr->GetObject("LosTriggerTCal");
fTCalTriggerItems = dynamic_cast<TClonesArray*>(mgr->GetObject("LosTriggerTCal"));
if (NULL == fTCalItems)
{
LOG(fatal) << "Branch LosTCal not found";
Expand Down Expand Up @@ -213,7 +213,6 @@ InitStatus R3BLosTCal2Hit::Init()
}
}


SetParameter();
return kSUCCESS;
}
Expand Down Expand Up @@ -247,7 +246,7 @@ void R3BLosTCal2Hit::Exec(Option_t* option)
return;
for (Int_t ihit = 0; ihit < trigHits; ihit++)
{
R3BLosTCalData* hit = (R3BLosTCalData*)fTCalTriggerItems->At(ihit);
R3BLosTCalData* hit = dynamic_cast<R3BLosTCalData*>(fTCalTriggerItems->At(ihit));
Int_t typ = hit->GetType();
trigTime[typ] = hit->GetRawTimeNs();
}
Expand Down Expand Up @@ -284,7 +283,7 @@ void R3BLosTCal2Hit::Exec(Option_t* option)

for (Int_t ihit = 0; ihit < nHits; ihit++)
{
R3BLosTCalData* hit = (R3BLosTCalData*)fTCalItems->At(ihit);
R3BLosTCalData* hit = dynamic_cast<R3BLosTCalData*>(fTCalItems->At(ihit));
Int_t ch = hit->GetChannel();
Int_t typ = hit->GetType();
Int_t det = hit->GetDetector();
Expand Down
50 changes: 50 additions & 0 deletions neuland/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# vi: ft=yaml
Checks: >
-*,
bugprone-*,
cert-dcl21-cpp,
cert-dcl50-cpp,
cert-env33-c,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-build-using-namespace,
google-explicit-constructor,
google-global-names-in-headers,
google-readability-casting,
google-runtime-int,
google-runtime-operator,
hicpp-*,
-hicpp-vararg,
misc-*,
modernize-*,
performance-*,
readability-*,
-hicpp-new-delete-operators,
-modernize-use-trailing-return-type
CheckOptions:
- key: bugprone-argument-comment.StrictMode
value: 1
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 4
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 1
- key: readability-identifier-length.IgnoredVariableNames
value: '^it$'
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
value: 'true'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues
value: 'true'
- key: readability-function-cognitive-complexity.Threshold
value: 40
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'true'

FormatStyle: 'file'
2 changes: 1 addition & 1 deletion r3bsource/base/R3BUcesbSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Int_t R3BUcesbSource::ReadEvent(UInt_t i)
if (raw)
{
int w, j;
const uint32_t* u = (const uint32_t*)raw;
const uint32_t* u = reinterpret_cast<const uint32_t*>(raw);

LOG(info) << " Raw data:";
for (w = 0; w < raw_words; w += 8)
Expand Down
Loading

0 comments on commit 77deacb

Please sign in to comment.