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

Tidy headers #1534

Merged
merged 14 commits into from
Dec 4, 2024
10 changes: 9 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Checks: |
-performance-avoid-endl
-performance-unnecessary-value-param
-performance-enum-size
-performance-noexcept-destructor
cppcoreguidelines-*
-cppcoreguidelines-owning-memory
-cppcoreguidelines-narrowing-conversions
Expand All @@ -25,21 +26,28 @@ Checks: |
-cppcoreguidelines-noexcept-swap
-cppcoreguidelines-noexcept-move-operations
-cppcoreguidelines-noexcept-destructor
-cppcoreguidelines-virtual-class-destructor
-cppcoreguidelines-c-copy-assignment-signature
-cppcoreguidelines-missing-std-forward
-cppcoreguidelines-special-member-functions
bugprone-*
-bugprone-sizeof-expression
-bugprone-narrowing-conversions
-bugprone-macro-parentheses
-bugprone-easily-swappable-parameters
-bugprone-implicit-widening-of-multiplication-result
-bugprone-exception-escape
WarningsAsErrors: '*'
CheckOptions:
cppcoreguidelines-macro-usage.CheckCapsOnly: true
cppcoreguidelines-avoid-do-while.IgnoreMacros: true
cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true
cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
cppcoreguidelines-avoid-non-const-global-variables.AllowInternalLinkage: true
performance-move-const-arg.CheckTriviallyCopyableMove: false
performance-move-const-arg.CheckMoveToConstRef: false
HeaderFilterRegex: ''

HeaderFilterRegex: '(example|app|src/(accel|celeritas|corecel|orange|geocel))/.*\.hh$'
FormatStyle: file
...
2 changes: 1 addition & 1 deletion app/celer-g4/ActionInitialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace app
* The parameters will be distributed to worker threads and all the actions.
*/
ActionInitialization::ActionInitialization(SPParams params)
: params_{std::move(params)}, init_shared_{true}
: params_{std::move(params)}
{
CELER_EXPECT(params_);

Expand Down
2 changes: 1 addition & 1 deletion app/celer-g4/ActionInitialization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ActionInitialization final : public G4VUserActionInitialization
SPParams params_;
SPDiagnostics diagnostics_;
int num_events_{0};
mutable bool init_shared_;
mutable bool init_shared_{true};
};

//---------------------------------------------------------------------------//
Expand Down
1 change: 0 additions & 1 deletion app/celer-g4/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ void DetectorConstruction::ConstructSDandField()
* Apply a function to the range of volumes for each detector.
*/
template<class F>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
void DetectorConstruction::foreach_detector(F&& apply_to_range) const
{
auto start = detectors_.begin();
Expand Down
7 changes: 0 additions & 7 deletions app/celer-g4/RootIO.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ class RootIO
private:
// Construct by initializing TFile and TTree on each worker thread
RootIO();
RootIO(RootIO&&) = default;

// Assignment operator
RootIO& operator=(RootIO&&) = default;

// Default destructor
~RootIO() = default;

//// HELPER FUNCTIONS ////

Expand Down
2 changes: 1 addition & 1 deletion app/celer-g4/SensitiveDetector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace app
* Construct with sensitive detector name.
*/
SensitiveDetector::SensitiveDetector(std::string name)
: G4VSensitiveDetector(name), hcid_{-1}, collection_{nullptr}
: G4VSensitiveDetector(name)
{
this->collectionName.insert(name);
}
Expand Down
4 changes: 2 additions & 2 deletions app/celer-g4/SensitiveDetector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class SensitiveDetector final : public G4VSensitiveDetector
bool ProcessHits(G4Step*, G4TouchableHistory*) final;

private:
int hcid_;
SensitiveHitsCollection* collection_;
int hcid_{-1};
SensitiveHitsCollection* collection_{nullptr};
};

//---------------------------------------------------------------------------//
Expand Down
1 change: 1 addition & 0 deletions src/accel/HepMC3PrimaryGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class HepMC3PrimaryGenerator final : public G4VPrimaryGenerator
explicit HepMC3PrimaryGenerator(std::string const& filename);

CELER_DELETE_COPY_MOVE(HepMC3PrimaryGenerator);
~HepMC3PrimaryGenerator() final = default;

//! Add primaries to Geant4 event
void GeneratePrimaryVertex(G4Event* g4_event) final;
Expand Down
3 changes: 2 additions & 1 deletion src/accel/RZMapMagneticField.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class RZMapMagneticField : public G4MagneticField
inline explicit RZMapMagneticField(SPConstFieldParams field_params);

// Calculate values of the magnetic field vector
inline void GetFieldValue(double const point[3], double* field) const;
inline void
GetFieldValue(double const point[3], double* field) const override;

private:
SPConstFieldParams params_;
Expand Down
2 changes: 1 addition & 1 deletion src/accel/SetupOptionsMessenger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SetupOptionsMessenger : public G4UImessenger
explicit SetupOptionsMessenger(SetupOptions* options);

// Default destructor
~SetupOptionsMessenger();
~SetupOptionsMessenger() override;

protected:
void SetNewValue(G4UIcommand* command, G4String newValue) override;
Expand Down
2 changes: 2 additions & 0 deletions src/accel/detail/HitProcessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>
#include <G4TouchableHandle.hh>

#include "corecel/Macros.hh"
#include "celeritas/Types.hh"
#include "celeritas/geo/GeoFwd.hh"
#include "celeritas/user/DetectorSteps.hh"
Expand Down Expand Up @@ -81,6 +82,7 @@ class HitProcessor

// Log on destruction
~HitProcessor();
CELER_DEFAULT_MOVE_DELETE_COPY(HitProcessor);

// Process CPU-generated hits
void operator()(StepStateHostRef const&);
Expand Down
2 changes: 1 addition & 1 deletion src/accel/detail/LevelTouchableUpdater.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LevelTouchableUpdater final : public TouchableUpdaterInterface
explicit LevelTouchableUpdater(SPConstGeo);

// Destroy pointers
~LevelTouchableUpdater();
~LevelTouchableUpdater() final;

// Update from a particular detector step
bool operator()(DetectorStepOutput const& out,
Expand Down
2 changes: 1 addition & 1 deletion src/accel/detail/NaviTouchableUpdater.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class NaviTouchableUpdater final : public TouchableUpdaterInterface
G4VPhysicalVolume const* world);

// Default external deleter
~NaviTouchableUpdater();
~NaviTouchableUpdater() final;

// Update from a particular detector step
bool operator()(DetectorStepOutput const& out,
Expand Down
12 changes: 6 additions & 6 deletions src/celeritas/Types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ using IsotopeId = OpaqueId<struct IsotopeRecord>;

//! Opaque index of a material modified by physics options
// TODO: rename to PhysMatId; equivalent to "material cuts couple"
using MaterialId = OpaqueId<class Material_>;
using MaterialId = OpaqueId<struct Material_>;

//! Opaque index of model in the list of physics processes
using ModelId = OpaqueId<class Model>;
using ModelId = OpaqueId<struct Model_>;

//! Opaque index to a material with optical properties
using OpticalMaterialId = OpaqueId<struct OpticalMaterial_>;
Expand All @@ -52,7 +52,7 @@ using OpticalMaterialId = OpaqueId<struct OpticalMaterial_>;
using ParticleId = OpaqueId<struct Particle_>;

//! Opaque index of physics process
using ProcessId = OpaqueId<class Process>;
using ProcessId = OpaqueId<struct Process_>;

//! Unique ID (for an event) of a track among all primaries and secondaries
using TrackId = OpaqueId<struct Track_>;
Expand All @@ -61,6 +61,9 @@ using TrackId = OpaqueId<struct Track_>;
// (detailed type aliases)
//---------------------------------------------------------------------------//

//! Opaque index of particle-nucleon cascade channel
using ChannelId = OpaqueId<struct Channel_>;

//! Opaque index for mapping volume-specific "sensitive detector" objects
using DetectorId = OpaqueId<struct Detector_>;

Expand All @@ -79,9 +82,6 @@ using ParticleModelId = OpaqueId<ModelId>;
//! Opaque index of electron subshell
using SubshellId = OpaqueId<struct Subshell_>;

//! Opaque index of particle-nucleon cascade channel
using ChannelId = OpaqueId<struct Channel_>;

//---------------------------------------------------------------------------//
// ENUMERATIONS
//---------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/alongstep/AlongStepGeneralLinearAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AlongStepGeneralLinearAction final : public CoreStepActionInterface
SPConstMsc msc);

// Default destructor
~AlongStepGeneralLinearAction();
~AlongStepGeneralLinearAction() final;

// Launch kernel with host data
void step(CoreParams const&, CoreStateHost&) const final;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/alongstep/AlongStepUniformMscAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AlongStepUniformMscAction final : public CoreStepActionInterface
SPConstMsc msc);

// Default destructor
~AlongStepUniformMscAction();
~AlongStepUniformMscAction() final;

// Launch kernel with host data
void step(CoreParams const&, CoreStateHost&) const final;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/xs/RBDiffXsCalculator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ RBDiffXsCalculator::RBDiffXsCalculator(RelativisticBremRef const& shared,
, material_(material)
, element_(material.make_element_view(elcomp_id))
, total_energy_(value_as<Energy>(particle.total_energy()))
, dielectric_suppression_(shared.dielectric_suppression())
{
real_type density_factor = material.electron_density()
* detail::migdal_constant();
Expand All @@ -133,7 +134,6 @@ RBDiffXsCalculator::RBDiffXsCalculator(RelativisticBremRef const& shared,
* value_as<detail::MevPerLen>(detail::lpm_constant());
real_type lpm_threshold = lpm_energy * std::sqrt(density_factor);
enable_lpm_ = (shared.enable_lpm && (total_energy_ > lpm_threshold));
dielectric_suppression_ = shared.dielectric_suppression();
}

//---------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/ext/GeantImporter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class GeantImporter final : public ImporterInterface
ImportData operator()(DataSelection const& selection);

//! Fill all available data from Geant4
ImportData operator()() { return (*this)(DataSelection{}); }
ImportData operator()() final { return (*this)(DataSelection{}); }

private:
// Optional setup if celeritas handles initialization
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/ext/RootImporter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RootImporter final : public ImporterInterface
}

// Load data from the ROOT files
ImportData operator()();
ImportData operator()() final;

private:
// ROOT file
Expand Down
4 changes: 1 addition & 3 deletions src/celeritas/ext/detail/GeantBremsstrahlungProcess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ namespace detail
* Construct with model selection.
*/
GeantBremsstrahlungProcess::GeantBremsstrahlungProcess(ModelSelection selection)
: G4VEnergyLossProcess("eBrem")
, is_initialized_(false)
, model_selection_(selection)
: G4VEnergyLossProcess("eBrem"), model_selection_(selection)
{
CELER_VALIDATE(selection != ModelSelection::none,
<< "Cannot initialize GeantBremsstrahlungProcess with "
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/ext/detail/GeantBremsstrahlungProcess.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GeantBremsstrahlungProcess : public G4VEnergyLossProcess
void StreamProcessInfo(std::ostream& output) const override;

private:
bool is_initialized_;
bool is_initialized_{false};
ModelSelection model_selection_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/global/CoreState.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CoreState final : public CoreStateInterface
size_type num_track_slots);

// Default destructor
~CoreState();
~CoreState() final;

// Prevent move/copy
CELER_DELETE_COPY_MOVE(CoreState);
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/global/Stepper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Stepper final : public StepperInterface
explicit Stepper(Input input);

// Default destructor
~Stepper();
~Stepper() final;

// Warm up before stepping
void warm_up() final;
Expand Down
10 changes: 3 additions & 7 deletions src/celeritas/grid/GridIdFinder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@ GridIdFinder<K, V>::operator()(argument_type quant) const -> result_type
{
auto iter
= celeritas::lower_bound(grid_.begin(), grid_.end(), quant.value());
if (iter == grid_.end())
if (iter == grid_.end()
|| (iter == grid_.begin() && quant.value() != *iter))
{
// Higher than end point
return {};
}
else if (iter == grid_.begin() && quant.value() != *iter)
{
// Below first point
// Higher than end point or below first point
return {};
}
else if (iter + 1 == grid_.end() || quant.value() != *iter)
Expand Down
2 changes: 2 additions & 0 deletions src/celeritas/io/EventReader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class EventReader : public EventReaderInterface
//! Prevent copying and moving
CELER_DELETE_COPY_MOVE(EventReader);

~EventReader() override = default;

// Read a single event from the event record
result_type operator()() final;

Expand Down
2 changes: 2 additions & 0 deletions src/celeritas/io/EventWriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class EventWriter : public EventWriterInterface
//! Prevent copying and moving due to file ownership
CELER_DELETE_COPY_MOVE(EventWriter);

~EventWriter() override = default;

// Write all the primaries from a single event
void operator()(VecPrimary const& primaries) final;

Expand Down
1 change: 1 addition & 0 deletions src/celeritas/io/ImporterInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ImporterInterface
protected:
ImporterInterface() = default;
CELER_DEFAULT_COPY_MOVE(ImporterInterface);
~ImporterInterface() = default;
};

//---------------------------------------------------------------------------//
Expand Down
3 changes: 2 additions & 1 deletion src/celeritas/io/RootEventReader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class RootEventReader : public EventReaderInterface

//! Prevent copying and moving
CELER_DELETE_COPY_MOVE(RootEventReader);
~RootEventReader() override = default;

// Read a user-defined event from the ROOT file
result_type operator()(EventId event_id);
Expand Down Expand Up @@ -86,7 +87,7 @@ inline RootEventReader::RootEventReader(std::string const&, SPConstParticles)
CELER_DISCARD(num_events_);
CELER_DISCARD(entry_count_);
CELER_DISCARD(expected_event_id_);
CELER_DISCARD(event_to_entry_);
CELER_DISCARD(event_to_entry_); // NOLINT(bugprone-sizeof-container)
CELER_NOT_CONFIGURED("ROOT");
}

Expand Down
3 changes: 2 additions & 1 deletion src/celeritas/io/RootEventWriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class RootEventWriter : public EventWriterInterface

//! Prevent copying and moving
CELER_DELETE_COPY_MOVE(RootEventWriter);
~RootEventWriter() override = default;

// Export primaries to ROOT
void operator()(VecPrimary const& primaries);
void operator()(VecPrimary const& primaries) override;

private:
//// DATA ////
Expand Down
6 changes: 2 additions & 4 deletions src/celeritas/mat/ElementSelector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ElementSelector

private:
Span<MatElementComponent const> elements_;
real_type material_xs_;
real_type material_xs_{0};
real_type* elemental_xs_;
};

Expand All @@ -96,9 +96,7 @@ template<class MicroXsCalc>
CELER_FUNCTION ElementSelector::ElementSelector(MaterialView const& material,
MicroXsCalc&& calc_micro_xs,
SpanReal storage)
: elements_(material.elements())
, material_xs_(0)
, elemental_xs_(storage.data())
: elements_(material.elements()), elemental_xs_(storage.data())
{
CELER_EXPECT(!elements_.empty());
CELER_EXPECT(storage.size() >= material.num_elements());
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/optical/CoreState.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CoreStateInterface : public AuxStateInterface

public:
// Support polymorphic deletion
virtual ~CoreStateInterface();
~CoreStateInterface() override;

//! Thread/stream ID
virtual StreamId stream_id() const = 0;
Expand Down
Loading
Loading