Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CI test for clang formatting #342

Merged
merged 10 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/clang-format-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2025 CERN
# SPDX-License-Identifier: Apache-2.0


name: Clang-Format Check

on: [pull_request, push]

jobs:
clang-format-check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

# 1) Add the official LLVM repository for clang-format, the highest available version for ubuntu-22 is clang 19
- name: Add LLVM apt repo (Clang 19)
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main"
sudo apt-get update

# 2) Install latest version
- name: Install clang-format
run: |
sudo apt-get install -y clang-format-19
clang-format-19 --version

# 3) Check formatting
- name: Check formatting
run: |
# Specify file extensions to be checked
FILES=$(git ls-files '*.cpp' '*.h' '*.cu' '*.cuh' '*.hh' '*.cc' '*.icc')

# '-n' checks if files need reformatting
# '--Werror' throws an error if formatting is incorrect
clang-format-19 -style=file -n --Werror $FILES
2 changes: 1 addition & 1 deletion examples/AsyncExample/Histograms.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ void registerHisto(std::shared_ptr<Histo> histo)
HistoWriter::GetInstance().RegisterHisto(histo);
}

} // namespace AsyncExHistos
} // namespace AsyncExHistos
6 changes: 3 additions & 3 deletions examples/AsyncExample/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ int main(int argc, char **argv)
AdePT = false;
} else if (argument == "--output") {
AsyncExHistos::HistoWriter::GetInstance().SetFilename(argv[++i]);
// TODO: Properly pass the seed to AdePT with a macro command
// } else if (argument == "--seed") {
// AsyncAdePT::AdeptIntegration::fAdePTSeed = std::stoll(argv[++i]);
// TODO: Properly pass the seed to AdePT with a macro command
// } else if (argument == "--seed") {
// AsyncAdePT::AdeptIntegration::fAdePTSeed = std::stoll(argv[++i]);
} else {
G4Exception("main", "Unknown argument", FatalErrorInArgument,
("Unknown argument passed to " + G4String(argv[0]) + " : " + argument + "\n" + helpMsg).c_str());
Expand Down
4 changes: 1 addition & 3 deletions examples/AsyncExample/include/PrimaryGeneratorAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction {
public:
PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction(), fParticleGun{new ParticleGun()} {}
virtual ~PrimaryGeneratorAction() = default;
virtual void GeneratePrimaries(G4Event * aEvent) final {
fParticleGun->GeneratePrimaries(aEvent);
}
virtual void GeneratePrimaries(G4Event *aEvent) final { fParticleGun->GeneratePrimaries(aEvent); }

private:
/// Particle gun
Expand Down
2 changes: 1 addition & 1 deletion examples/AsyncExample/include/TrackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TrackingAction : public G4UserTrackingAction {

public:
TrackingAction();
~TrackingAction(){};
~TrackingAction() {};

virtual void PreUserTrackingAction(const G4Track *);
virtual void PostUserTrackingAction(const G4Track *);
Expand Down
5 changes: 1 addition & 4 deletions examples/AsyncExample/src/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ DetectorConstruction::DetectorConstruction()

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::~DetectorConstruction()
{

}
DetectorConstruction::~DetectorConstruction() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Expand Down
14 changes: 6 additions & 8 deletions examples/AsyncExample/src/PrimaryGeneratorMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ void PrimaryGeneratorMessenger::SetNewValue(G4UIcommand *command, G4String newVa
while ((str = tkn()) != "") {
token_vector->push_back(str);
}
//The particle type is mandatory and must be the first argument
// The particle type is mandatory and must be the first argument
G4ParticleDefinition *pd = nullptr;
float weight = -1;
double energy = -1;
float weight = -1;
double energy = -1;
if (token_vector->size() >= 1) {
pd = G4ParticleTable::GetParticleTable()->FindParticle((*token_vector)[0]);
}
Expand All @@ -160,12 +160,10 @@ void PrimaryGeneratorMessenger::SetNewValue(G4UIcommand *command, G4String newVa
}

for (unsigned int i = 1; i < token_vector->size(); i++) {
if((*token_vector)[i] == "weight")
{
if ((*token_vector)[i] == "weight") {
weight = stof((*token_vector)[++i]);
}
if((*token_vector)[i] == "energy")
{
if ((*token_vector)[i] == "energy") {
const auto value = stof((*token_vector)[++i]);
energy = value * G4UnitDefinition::GetValueOf((*token_vector)[++i]);
}
Expand All @@ -191,4 +189,4 @@ void PrimaryGeneratorMessenger::SetNewValue(G4UIcommand *command, G4String newVa
}
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
2 changes: 1 addition & 1 deletion examples/Example1/include/SteppingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ private:
int fNumSteps{0};
};

#endif
#endif
2 changes: 1 addition & 1 deletion examples/Example1/include/TrackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TrackingAction : public G4UserTrackingAction {

public:
TrackingAction();
~TrackingAction(){};
~TrackingAction() {};

virtual void PreUserTrackingAction(const G4Track *);
virtual void PostUserTrackingAction(const G4Track *);
Expand Down
9 changes: 4 additions & 5 deletions examples/Example1/src/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::DetectorConstruction(bool allSensitive) : fAllSensitive(allSensitive), G4VUserDetectorConstruction()
DetectorConstruction::DetectorConstruction(bool allSensitive)
: fAllSensitive(allSensitive), G4VUserDetectorConstruction()
{
fDetectorMessenger = new DetectorMessenger(this);
}
Expand Down Expand Up @@ -95,7 +96,7 @@ void DetectorConstruction::ConstructSDandField()
int nd = lvol->GetNoDaughters();
numTouchables++;

if(fAllSensitive) // For easier validation of geometries with no SD info, we may set all volumes as sensitive
if (fAllSensitive) // For easier validation of geometries with no SD info, we may set all volumes as sensitive
{
// Record the PV
if (caloSD->fSensitivePhysicalVolumes.find(pvol) == caloSD->fSensitivePhysicalVolumes.end()) {
Expand All @@ -110,9 +111,7 @@ void DetectorConstruction::ConstructSDandField()
caloSD->fSensitiveLogicalVolumes.push_back(lvol);
}
numSensitiveTouchables++;
}
else
{
} else {
// Check if the LogicalVolume is marked as sensitive in the geometry
auto aAuxInfoList = fParser.GetVolumeAuxiliaryInformation(lvol);
for (auto iaux = aAuxInfoList.begin(); iaux != aAuxInfoList.end(); iaux++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/Example1/src/SteppingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ void SteppingAction::UserSteppingAction(const G4Step *theStep)
G4cout << "Warning: Killing track over 10000 steps" << G4endl;
theStep->GetTrack()->SetTrackStatus(fStopAndKill);
}
}
}
2 changes: 1 addition & 1 deletion examples/IntegrationBenchmark/include/Run.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ private:
RunAction *fRunAction;
};

#endif
#endif
2 changes: 1 addition & 1 deletion examples/IntegrationBenchmark/include/SimpleHit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public:
G4int fType = -1;
/// These hits will be associated to PhysicalVolumes
G4String fPhysicalVolumeName = "";
G4int fPhysicalVolumeId = -1;
G4int fPhysicalVolumeId = -1;
};

typedef G4THitsCollection<SimpleHit> SimpleHitsCollection;
Expand Down
2 changes: 1 addition & 1 deletion examples/IntegrationBenchmark/include/SteppingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ private:
int fNumSteps{0};
};

#endif
#endif
2 changes: 1 addition & 1 deletion examples/IntegrationBenchmark/include/TrackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TrackingAction : public G4UserTrackingAction {

public:
TrackingAction();
~TrackingAction(){};
~TrackingAction() {};

virtual void PreUserTrackingAction(const G4Track *);
virtual void PostUserTrackingAction(const G4Track *);
Expand Down
9 changes: 4 additions & 5 deletions examples/IntegrationBenchmark/src/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::DetectorConstruction(bool allSensitive) : fAllSensitive(allSensitive), G4VUserDetectorConstruction()
DetectorConstruction::DetectorConstruction(bool allSensitive)
: fAllSensitive(allSensitive), G4VUserDetectorConstruction()
{
fDetectorMessenger = new DetectorMessenger(this);
}
Expand Down Expand Up @@ -95,7 +96,7 @@ void DetectorConstruction::ConstructSDandField()
int nd = lvol->GetNoDaughters();
numTouchables++;

if(fAllSensitive) // For easier validation of geometries with no SD info, we may set all volumes as sensitive
if (fAllSensitive) // For easier validation of geometries with no SD info, we may set all volumes as sensitive
{
// Record the PV
if (caloSD->fSensitivePhysicalVolumes.find(pvol) == caloSD->fSensitivePhysicalVolumes.end()) {
Expand All @@ -110,9 +111,7 @@ void DetectorConstruction::ConstructSDandField()
caloSD->fSensitiveLogicalVolumes.push_back(lvol);
}
numSensitiveTouchables++;
}
else
{
} else {
// Check if the LogicalVolume is marked as sensitive in the geometry
auto aAuxInfoList = fParser.GetVolumeAuxiliaryInformation(lvol);
for (auto iaux = aAuxInfoList.begin(); iaux != aAuxInfoList.end(); iaux++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/IntegrationBenchmark/src/SteppingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ void SteppingAction::UserSteppingAction(const G4Step *theStep)
G4cout << "Warning: Killing track over 10000 steps" << G4endl;
theStep->GetTrack()->SetTrackStatus(fStopAndKill);
}
}
}
4 changes: 2 additions & 2 deletions examples/common/src/FTFP_BERT_AdePT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ FTFP_BERT_AdePT::FTFP_BERT_AdePT(G4int ver)
// EM Physics

// Register the EM physics to use for tracking on CPU
// Note: The EM processes for e-, e+ and gammas are registered, but not used as the
// Note: The EM processes for e-, e+ and gammas are registered, but not used as the
// partices are tracked by the specialized tracking manager
RegisterPhysics(new G4EmStandardPhysics());

// Register the AdePT physics
// Note: The AdePT tracking manager uses the G4HepEM tracking manager outside of GPU regions
RegisterPhysics(new AdePTPhysics(ver));
Expand Down
4 changes: 2 additions & 2 deletions examples/common/src/FTFP_BERT_HepEm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ FTFP_BERT_HepEm::FTFP_BERT_HepEm(G4int ver)
SetVerboseLevel(ver);

// EM Physics
// Note: The EM processes for e-, e+ and gammas are registered, but not used as the
// Note: The EM processes for e-, e+ and gammas are registered, but not used as the
// partices are tracked by the specialized tracking manager
RegisterPhysics( new G4EmStandardPhysics(ver));
RegisterPhysics(new G4EmStandardPhysics(ver));

// Register the HepEM physics
RegisterPhysics(new HepEMPhysics(ver));
Expand Down
5 changes: 1 addition & 4 deletions examples/common/src/HepMC3G4Interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
#include <HepMC3/GenParticle.h>

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
HepMC3G4Interface::~HepMC3G4Interface()
{

}
HepMC3G4Interface::~HepMC3G4Interface() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool HepMC3G4Interface::CheckVertexInsideWorld(const G4ThreeVector &pos) const
Expand Down
6 changes: 3 additions & 3 deletions examples/common/src/ParticleGunMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void ParticleGunMessenger::SetNewValue(G4UIcommand *command, G4String newValue)
}
// The particle type is mandatory and must be the first argument
G4ParticleDefinition *pd = nullptr;
float weight = -1;
double energy = -1;
float weight = -1;
double energy = -1;
if (token_vector.size() >= 1) {
pd = G4ParticleTable::GetParticleTable()->FindParticle(token_vector[0]);
} else {
Expand Down Expand Up @@ -154,4 +154,4 @@ void ParticleGunMessenger::SetNewValue(G4UIcommand *command, G4String newValue)
}
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
2 changes: 1 addition & 1 deletion include/AdePT/base/ResourceManagement.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ struct CudaDeleter<cudaEvent_t> {

} // namespace AsyncAdePT

#endif // RESOURCE_MANAGEMENT_CUH
#endif // RESOURCE_MANAGEMENT_CUH
2 changes: 1 addition & 1 deletion include/AdePT/base/ResourceManagement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ using unique_ptr_cuda = std::unique_ptr<T, Deleter>;

} // namespace AsyncAdePT

#endif // RESOURCE_MANAGEMENT_HH
#endif // RESOURCE_MANAGEMENT_HH
Loading