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

refactor: explicit constructors (non-core) #3761

Merged
merged 15 commits into from
Oct 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct AlignmentFunctionImpl
: public ActsExamples::AlignmentAlgorithm::AlignmentFunction {
Alignment align;

AlignmentFunctionImpl(Alignment&& a) : align(std::move(a)) {}
explicit AlignmentFunctionImpl(Alignment&& a) : align(std::move(a)) {}

ActsExamples::AlignmentAlgorithm::AlignmentResult operator()(
const std::vector<std::vector<ActsExamples::IndexSourceLink>>&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DigitizationConfig {
bool doMerge, double mergeNsigma, bool mergeCommonCorner,
Acts::GeometryHierarchyMap<DigiComponentsConfig> &&digiCfgs);

DigitizationConfig(
explicit DigitizationConfig(
Acts::GeometryHierarchyMap<DigiComponentsConfig> &&digiCfgs);

/// Input collection of simulated hits.
Expand Down
3 changes: 2 additions & 1 deletion Examples/Algorithms/Digitization/src/MeasurementCreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ActsExamples::VariableBoundMeasurementProxy ActsExamples::createMeasurement(
return Acts::visit_measurement(
dParams.indices.size(), [&](auto dim) -> VariableBoundMeasurementProxy {
auto [indices, par, cov] = measurementConstituents<dim>(dParams);
return container.emplaceMeasurement<dim>(geometryId, indices, par, cov);
return VariableBoundMeasurementProxy{
container.emplaceMeasurement<dim>(geometryId, indices, par, cov)};
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class MaterialPhysicsList final : public G4VUserPhysicsList {
///
/// @param cfg the configuration struct for this Stepping action
/// @param logger is an Acts::Logger for unique logging
MaterialPhysicsList(std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("MaterialPhysicsList",
Acts::Logging::INFO));
explicit MaterialPhysicsList(std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("MaterialPhysicsList",
Acts::Logging::INFO));
~MaterialPhysicsList() override = default;

/// @brief Interface particle construction method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PhysicsListFactoryFunction final : public PhysicsListFactory {
public:
using Function = std::function<std::unique_ptr<G4VUserPhysicsList>()>;

PhysicsListFactoryFunction(Function function);
explicit PhysicsListFactoryFunction(Function function);

std::unique_ptr<G4VUserPhysicsList> factorize() const final;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SteppingActionList : public G4UserSteppingAction {
std::vector<std::shared_ptr<G4UserSteppingAction>> actions;
};

SteppingActionList(const Config &cfg) : m_cfg(cfg) {}
explicit SteppingActionList(const Config &cfg) : m_cfg(cfg) {}

void UserSteppingAction(const G4Step *step) override {
for (const auto &action : m_cfg.actions) {
Expand Down
2 changes: 1 addition & 1 deletion Examples/Algorithms/Geant4HepMC/src/EventAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EventAction final : public G4UserEventAction {
static EventAction* instance();

/// Construct the action and ensure singleton usage.
EventAction(std::vector<std::string> processFilter);
explicit EventAction(std::vector<std::string> processFilter);
~EventAction() override;

/// Interface method for begin of the event
Expand Down
2 changes: 1 addition & 1 deletion Examples/Algorithms/Geant4HepMC/src/SteppingAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ActsExamples::Geant4::HepMC3 {
/// Collects the particles history.
class SteppingAction : public G4UserSteppingAction {
public:
SteppingAction(std::vector<std::string> eventRejectionProcess);
explicit SteppingAction(std::vector<std::string> eventRejectionProcess);
~SteppingAction() override;

/// Static access method to the instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct FixedMultiplicityGenerator
: public EventGenerator::MultiplicityGenerator {
std::size_t n = 1;

FixedMultiplicityGenerator(std::size_t _n) : n{_n} {}
explicit FixedMultiplicityGenerator(std::size_t _n) : n{_n} {}
FixedMultiplicityGenerator() = default;

std::size_t operator()(RandomEngine& /*rng*/) const override { return n; }
Expand All @@ -28,7 +28,7 @@ struct FixedMultiplicityGenerator
struct PoissonMultiplicityGenerator
: public EventGenerator::MultiplicityGenerator {
double mean = 1;
PoissonMultiplicityGenerator(double _mean) : mean{_mean} {}
explicit PoissonMultiplicityGenerator(double _mean) : mean{_mean} {}
PoissonMultiplicityGenerator() = default;

std::size_t operator()(RandomEngine& rng) const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ ParametricParticleGenerator::operator()(RandomEngine& rng) {
SimParticleContainer::sequence_type particles;

// create the primary vertex
auto& primaryVertex =
vertices.emplace_back(0, SimVertex::Vector4(0., 0., 0., 0.));
auto& primaryVertex = vertices.emplace_back(
SimVertexBarcode{0}, SimVertex::Vector4(0., 0., 0., 0.));

// counter will be reused as barcode particle number which must be non-zero.
for (std::size_t ip = 1; ip <= m_cfg.numParticles; ++ip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ParametricParticleGenerator : public EventGenerator::ParticlesGenerator {
std::optional<double> mass;
};

ParametricParticleGenerator(const Config& cfg);
explicit ParametricParticleGenerator(const Config& cfg);

/// Generate a single primary vertex with the given number of particles.
std::pair<SimVertexContainer, SimParticleContainer> operator()(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ Pythia8Generator::operator()(RandomEngine& rng) {
}

// create the primary vertex
vertices.emplace_back(0, SimVertex::Vector4(0., 0., 0., 0.));
vertices.emplace_back(SimVertexBarcode{0},
SimVertex::Vector4(0., 0., 0., 0.));

// convert generated final state particles into internal format
for (int ip = 0; ip < m_pythia8->event.size(); ++ip) {
Expand Down Expand Up @@ -166,7 +167,8 @@ Pythia8Generator::operator()(RandomEngine& rng) {
} else {
// no matching secondary vertex exists -> create new one
particleId.setVertexSecondary(vertices.size());
auto& vertex = vertices.emplace_back(particleId.vertexId(), pos4);
auto& vertex = vertices.emplace_back(
static_cast<SimVertexBarcode>(particleId.vertexId()), pos4);
vertex.outgoing.insert(particleId);
ACTS_VERBOSE("created new secondary vertex " << pos4.transpose());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PropagatorInterface {
template <typename propagator_t>
class ConcretePropagator : public PropagatorInterface {
public:
ConcretePropagator(propagator_t propagator)
explicit ConcretePropagator(propagator_t propagator)
: m_propagator{std::move(propagator)} {}

Acts::Result<PropagationOutput> execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TrackFinderFunctionImpl
: public ActsExamples::TrackFindingAlgorithm::TrackFinderFunction {
CKF trackFinder;

TrackFinderFunctionImpl(CKF&& f) : trackFinder(std::move(f)) {}
explicit TrackFinderFunctionImpl(CKF&& f) : trackFinder(std::move(f)) {}

ActsExamples::TrackFindingAlgorithm::TrackFinderResult operator()(
const ActsExamples::TrackParameters& initialParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ ProcessCode AdaptiveMultiVertexFinderAlgorithm::execute(
// Count the number of particles associated with each vertex
std::size_t particleCount = 0;
for (const auto& particle : truthParticles) {
if (particle.particleId().vertexId() == truthVertex.vertexId()) {
if (static_cast<SimVertexBarcode>(particle.particleId().vertexId()) ==
truthVertex.vertexId()) {
++particleCount;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ struct DD4hepDetector {
DD4hepDetector() = default;
/// @brief Constructor from geometry service
/// @param _geometryService the geometry service
DD4hepDetector(std::shared_ptr<DD4hepGeometryService> _geometryService);
explicit DD4hepDetector(
std::shared_ptr<DD4hepGeometryService> _geometryService);
/// @brief Default destructor
~DD4hepDetector() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DD4hepGeometryService {
std::make_shared<const Acts::GeometryIdentifierHook>();
};

DD4hepGeometryService(const Config& cfg);
explicit DD4hepGeometryService(const Config& cfg);
DD4hepGeometryService(const DD4hepGeometryService&) = delete;
DD4hepGeometryService(DD4hepGeometryService&&) = delete;
~DD4hepGeometryService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ScalableBField final : public Acts::MagneticFieldProvider {
Acts::ActsScalar scalor = 1.;

/// @brief constructor with context
Cache(const Acts::MagneticFieldContext& mctx) {
explicit Cache(const Acts::MagneticFieldContext& mctx) {
scalor = mctx.get<const ScalableBFieldContext>().scalor;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MockupSectorBuilder {

/// Constructor
///@param config The configuration struct
MockupSectorBuilder(const Config& config);
explicit MockupSectorBuilder(const Config& config);

/// Destructor
~MockupSectorBuilder() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct TGeoDetector {
struct LayerTriplet {
LayerTriplet() = default;

LayerTriplet(T value)
explicit LayerTriplet(T value)
: negative{value}, central{value}, positive{value} {}

LayerTriplet(T _negative, T _central, T _positive)
Expand Down
3 changes: 2 additions & 1 deletion Examples/Framework/ML/src/NeuralCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ void ActsExamples::NeuralCalibrator::calibrate(
Acts::visit_measurement(measurement.size(), [&](auto N) -> void {
constexpr std::size_t kMeasurementSize = decltype(N)::value;
const ConstFixedBoundMeasurementProxy<kMeasurementSize> fixedMeasurement =
measurement;
static_cast<ConstFixedBoundMeasurementProxy<kMeasurementSize>>(
measurement);

Acts::ActsVector<kMeasurementSize> calibratedParameters =
fixedMeasurement.parameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class MeasurementProxyBase {
MeasurementProxyBase(Container& container_, Index index_)
: m_container(&container_), m_index(index_) {}
template <typename OtherDerived, bool OtherReadOnly>
MeasurementProxyBase(
explicit MeasurementProxyBase(
const MeasurementProxyBase<OtherDerived, FullSize, OtherReadOnly>& other)
requires(ReadOnly == OtherReadOnly || ReadOnly)
: m_container(&other.container()), m_index(other.index()) {}
Expand Down Expand Up @@ -358,7 +358,7 @@ class FixedMeasurementProxy
assert(container().m_entries.at(index()).size == Size && "Size mismatch");
}
template <typename OtherDerived, bool OtherReadOnly>
FixedMeasurementProxy(
explicit FixedMeasurementProxy(
const MeasurementProxyBase<OtherDerived, FullSize, OtherReadOnly>& other)
requires(ReadOnly == OtherReadOnly || ReadOnly)
: Base(other) {
Expand Down Expand Up @@ -450,7 +450,7 @@ class VariableMeasurementProxy
VariableMeasurementProxy(Container& container_, Index index_)
: Base(container_, index_) {}
template <typename OtherDerived, bool OtherReadOnly>
VariableMeasurementProxy(
explicit VariableMeasurementProxy(
const MeasurementProxyBase<OtherDerived, FullSize, OtherReadOnly>& other)
requires(ReadOnly == OtherReadOnly || ReadOnly)
: Base(other) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ScalingCalibrator : public MeasurementCalibrator {
}
};

ScalingCalibrator(const std::filesystem::path& path);
explicit ScalingCalibrator(const std::filesystem::path& path);

void calibrate(
const MeasurementContainer& measurements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class SimVertexBarcode {
using Value = SimBarcode::Value;

constexpr SimVertexBarcode() = default;
constexpr SimVertexBarcode(Value encoded) : m_id(SimBarcode(encoded)) {}
constexpr SimVertexBarcode(SimBarcode vertexId)
explicit constexpr SimVertexBarcode(Value encoded)
: m_id(SimBarcode(encoded)) {}
explicit constexpr SimVertexBarcode(SimBarcode vertexId)
: m_id(vertexId.setParticle(0).setSubParticle(0)) {
if (vertexId != vertexId.vertexId()) {
throw std::invalid_argument("SimVertexBarcode: invalid vertexId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class SpacePointContainer {
// the memory backend is independetly handled. This is only interfacing it to
// ACTS
SpacePointContainer(CollectionType&& container) = delete;
SpacePointContainer(CollectionType& container) : m_storage(container) {}
SpacePointContainer(CollectionType* container) : m_storage(container) {}
explicit SpacePointContainer(CollectionType& container)
: m_storage(container) {}
explicit SpacePointContainer(CollectionType* container)
: m_storage(container) {}

// No copy constructor or copy operation allowed
SpacePointContainer(const SpacePointContainer<collection_t>&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RandomNumbers {
std::uint64_t seed = 1234567890u; ///< random seed
};

RandomNumbers(const Config& cfg);
explicit RandomNumbers(const Config& cfg);

/// Spawn an algorithm-local random number generator. To avoid inefficiencies
/// and multiple uses of a given RNG seed, this should only be done once per
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Sequencer {
std::size_t fpeStackTraceLength = 8;
};

Sequencer(const Config &cfg);
explicit Sequencer(const Config &cfg);

/// Add a context decorator to the set of context decorators.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class WhiteBoard {
struct HolderT : public IHolder {
T value;

HolderT(T&& v) : value(std::move(v)) {}
explicit HolderT(T&& v) : value(std::move(v)) {}
const std::type_info& type() const override { return typeid(T); }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class queuing_mutex {
#endif
}

scoped_lock(queuing_mutex& ACTS_EXAMPLES_WITH_TBB(m)) {
explicit scoped_lock(queuing_mutex& ACTS_EXAMPLES_WITH_TBB(m)) {
#ifndef ACTS_EXAMPLES_NO_TBB
if (enableTBB()) {
tbb.emplace(*m.tbb);
Expand Down
3 changes: 2 additions & 1 deletion Examples/Framework/src/EventData/MeasurementCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void ActsExamples::PassThroughCalibrator::calibrate(
Acts::visit_measurement(measurement.size(), [&](auto N) -> void {
constexpr std::size_t kMeasurementSize = decltype(N)::value;
const ConstFixedBoundMeasurementProxy<kMeasurementSize> fixedMeasurement =
measurement;
static_cast<ConstFixedBoundMeasurementProxy<kMeasurementSize>>(
measurement);

trackState.allocateCalibrated(kMeasurementSize);
trackState.calibrated<kMeasurementSize>() = fixedMeasurement.parameters();
Expand Down
3 changes: 2 additions & 1 deletion Examples/Framework/src/EventData/ScalingCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ void ActsExamples::ScalingCalibrator::calibrate(
Acts::visit_measurement(measurement.size(), [&](auto N) -> void {
constexpr std::size_t kMeasurementSize = decltype(N)::value;
const ConstFixedBoundMeasurementProxy<kMeasurementSize> fixedMeasurement =
measurement;
static_cast<ConstFixedBoundMeasurementProxy<kMeasurementSize>>(
measurement);

Acts::ActsVector<kMeasurementSize> calibratedParameters =
fixedMeasurement.parameters();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Framework/src/Framework/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ struct StopWatch {
Timepoint start;
Duration& store;

StopWatch(Duration& s) : start(Clock::now()), store(s) {}
explicit StopWatch(Duration& s) : start(Clock::now()), store(s) {}
~StopWatch() { store += Clock::now() - start; }
};

Expand Down
2 changes: 1 addition & 1 deletion Examples/HelloWorld/HelloLoggerAlgorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ActsExamples {
/// A simple algorithm that just prints hello world.
class HelloLoggerAlgorithm : public ActsExamples::IAlgorithm {
public:
HelloLoggerAlgorithm(Acts::Logging::Level level);
explicit HelloLoggerAlgorithm(Acts::Logging::Level level);

// Log a few messages.
ActsExamples::ProcessCode execute(const AlgorithmContext& ctx) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class DsvReader {
/// Open a file at the given path.
///
/// \param path Path to the input file
DsvReader(const std::string& path);
explicit DsvReader(const std::string& path);

/// Read the next line from the file.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct EventFraction {
///
/// @param [in] event Tuple containing the initial particle, the particle
/// before the interaction and all final state particles after the interaction
EventFraction(const ActsExamples::ExtractedSimulationProcess& event)
explicit EventFraction(const ActsExamples::ExtractedSimulationProcess& event)
: initialParticle(event.initial),
interactingParticle(event.before),
finalParticles(event.after) {}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Io/Root/src/RootVertexReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ProcessCode RootVertexReader::read(const AlgorithmContext& context) {
for (unsigned int i = 0; i < nVertices; i++) {
SimVertex v;

v.id = (*m_vertexId)[i];
v.id = SimVertexBarcode{(*m_vertexId)[i]};
v.process = static_cast<ActsFatras::ProcessType>((*m_process)[i]);
v.position4 = Acts::Vector4((*m_vx)[i] * Acts::UnitConstants::mm,
(*m_vy)[i] * Acts::UnitConstants::mm,
Expand Down
5 changes: 3 additions & 2 deletions Examples/Io/Root/src/VertexNTupleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ ProcessCode VertexNTupleWriter::writeT(
fmap[vtxId].second += weight;
}
double truthMajorityVertexTrackWeights = 0;
SimVertexBarcode truthMajorityVertexId = 0;
SimVertexBarcode truthMajorityVertexId{0};
for (const auto& [vtxId, counter] : fmap) {
if (counter.second > truthMajorityVertexTrackWeights) {
truthMajorityVertexId = vtxId;
Expand Down Expand Up @@ -629,7 +629,8 @@ ProcessCode VertexNTupleWriter::writeT(
// Count number of reconstructible tracks on truth vertex
int nTracksOnTruthVertex = 0;
for (const auto& particle : selectedParticles) {
if (particle.particleId().vertexId() == truthVertex.vertexId()) {
if (static_cast<SimVertexBarcode>(particle.particleId().vertexId()) ==
truthVertex.vertexId()) {
++nTracksOnTruthVertex;
}
}
Expand Down
Loading
Loading