Skip to content

Commit

Permalink
Use string_view instead of string for interface labels+descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Apr 28, 2024
1 parent 772d57c commit 66e223f
Show file tree
Hide file tree
Showing 88 changed files with 170 additions and 157 deletions.
2 changes: 1 addition & 1 deletion app/celer-g4/TimerOutput.hh
Expand Up @@ -43,7 +43,7 @@ class TimerOutput final : public OutputInterface
//! Category of data to write
Category category() const final { return Category::result; }
//! Key for the entry inside the category.
std::string label() const final { return "time"; }
std::string_view label() const final { return "time"; }
// Write output to the given JSON object
void output(JsonPimpl*) const final;
//!@}
Expand Down
2 changes: 1 addition & 1 deletion app/celer-sim/RunnerOutput.hh
Expand Up @@ -49,7 +49,7 @@ class RunnerOutput final : public OutputInterface
Category category() const final { return Category::result; }

//! Name of the entry inside the category.
std::string label() const final { return "runner"; }
std::string_view label() const final { return "runner"; }

// Write output to the given JSON object
void output(JsonPimpl*) const final;
Expand Down
3 changes: 1 addition & 2 deletions app/celer-sim/Transporter.cc
Expand Up @@ -165,8 +165,7 @@ void Transporter<M>::accum_action_times(MapStrDouble* result) const
CELER_ASSERT(action_ptrs.size() == times.size());
for (auto i : range(action_ptrs.size()))
{
auto&& label = action_ptrs[i]->label();
(*result)[label] += times[i];
(*result)[std::string{action_ptrs[i]->label()}] += times[i];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/accel/GeantSimpleCalo.cc
Expand Up @@ -172,7 +172,7 @@ auto GeantSimpleCalo::CalcTotalEnergyDeposition() const -> VecReal
/*!
* Return the key in the JSON output.
*/
std::string GeantSimpleCalo::label() const
std::string_view GeantSimpleCalo::label() const
{
return storage_->name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/accel/GeantSimpleCalo.hh
Expand Up @@ -65,7 +65,7 @@ class GeantSimpleCalo final : public OutputInterface
//! Category of data to write
Category category() const final { return Category::result; }
// Key for the entry inside the category
std::string label() const final;
std::string_view label() const final;
// Write output to the given JSON object
void output(JsonPimpl*) const final;
//!@}
Expand Down
2 changes: 1 addition & 1 deletion src/accel/GeantStepDiagnostic.hh
Expand Up @@ -44,7 +44,7 @@ class GeantStepDiagnostic final : public OutputInterface
//! Category of data to write
Category category() const final { return Category::result; }
//! Key for the entry inside the category.
std::string label() const final { return "g4-step-diagnostic"; }
std::string_view label() const final { return "g4-step-diagnostic"; }
// Write output to the given JSON object
void output(JsonPimpl*) const final;
//!@}
Expand Down
3 changes: 1 addition & 2 deletions src/accel/LocalTransporter.cc
Expand Up @@ -262,8 +262,7 @@ auto LocalTransporter::GetActionTime() const -> MapStrReal
CELER_ASSERT(action_ptrs.size() == time.size());
for (auto i : range(action_ptrs.size()))
{
auto&& label = action_ptrs[i]->label();
result[label] = time[i];
result[std::string{action_ptrs[i]->label()}] = time[i];
}
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/BetheHeitlerModel.hh
Expand Up @@ -52,10 +52,10 @@ class BetheHeitlerModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "conv-bethe-heitler"; }
std::string_view label() const final { return "conv-bethe-heitler"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Bethe-Heitler gamma conversion";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/CombinedBremModel.hh
Expand Up @@ -67,10 +67,10 @@ class CombinedBremModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "brems-combined"; }
std::string_view label() const final { return "brems-combined"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by bremsstrahlung (combined SB/relativistic, e+/-)";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/CoulombScatteringModel.hh
Expand Up @@ -77,10 +77,10 @@ class CoulombScatteringModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "coulomb-wentzel"; }
std::string_view label() const final { return "coulomb-wentzel"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Coulomb scattering (Wentzel)";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/EPlusGGModel.hh
Expand Up @@ -41,10 +41,10 @@ class EPlusGGModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "annihil-2-gamma"; }
std::string_view label() const final { return "annihil-2-gamma"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by positron annihilation yielding two gammas";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/KleinNishinaModel.hh
Expand Up @@ -39,10 +39,10 @@ class KleinNishinaModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "scat-klein-nishina"; }
std::string_view label() const final { return "scat-klein-nishina"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Compton scattering (simple Klein-Nishina)";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/LivermorePEModel.hh
Expand Up @@ -57,10 +57,10 @@ class LivermorePEModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "photoel-livermore"; }
std::string_view label() const final { return "photoel-livermore"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Livermore photoelectric effect";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/MollerBhabhaModel.hh
Expand Up @@ -40,10 +40,10 @@ class MollerBhabhaModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "ioni-moller-bhabha"; }
std::string_view label() const final { return "ioni-moller-bhabha"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Moller+Bhabha ionization";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/MuBremsstrahlungModel.hh
Expand Up @@ -51,10 +51,10 @@ class MuBremsstrahlungModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "brems-muon"; }
std::string_view label() const final { return "brems-muon"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by bremsstrahlung (muon)";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/RayleighModel.hh
Expand Up @@ -58,10 +58,10 @@ class RayleighModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "scat-rayleigh"; }
std::string_view label() const final { return "scat-rayleigh"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Rayleigh scattering";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/RelativisticBremModel.hh
Expand Up @@ -61,10 +61,10 @@ class RelativisticBremModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "brems-rel"; }
std::string_view label() const final { return "brems-rel"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by relativistic bremsstrahlung";
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/SeltzerBergerModel.hh
Expand Up @@ -81,10 +81,10 @@ class SeltzerBergerModel final : public Model
ActionId action_id() const final;

//! Short name for the interaction kernel
std::string label() const final { return "brems-sb"; }
std::string_view label() const final { return "brems-sb"; }

//! Short description of the post-step action
std::string description() const final
std::string_view description() const final
{
return "interact by Seltzer-Berger bremsstrahlung";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/BremsstrahlungProcess.cc
Expand Up @@ -113,7 +113,7 @@ auto BremsstrahlungProcess::step_limits(Applicability applic) const
/*!
* Name of the process.
*/
std::string BremsstrahlungProcess::label() const
std::string_view BremsstrahlungProcess::label() const
{
return "Bremsstrahlung";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/BremsstrahlungProcess.hh
Expand Up @@ -69,7 +69,7 @@ class BremsstrahlungProcess : public Process
bool use_integral_xs() const final { return options_.use_integral_xs; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/ComptonProcess.cc
Expand Up @@ -53,7 +53,7 @@ auto ComptonProcess::step_limits(Applicability applic) const
/*!
* Name of the process.
*/
std::string ComptonProcess::label() const
std::string_view ComptonProcess::label() const
{
return "Compton scattering";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/ComptonProcess.hh
Expand Up @@ -43,7 +43,7 @@ class ComptonProcess : public Process
bool use_integral_xs() const final { return false; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/CoulombScatteringProcess.cc
Expand Up @@ -62,7 +62,7 @@ auto CoulombScatteringProcess::step_limits(Applicability applic) const
/*!
* Name of the process.
*/
std::string CoulombScatteringProcess::label() const
std::string_view CoulombScatteringProcess::label() const
{
return "Coulomb scattering";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/CoulombScatteringProcess.hh
Expand Up @@ -51,7 +51,7 @@ class CoulombScatteringProcess : public Process
bool use_integral_xs() const final;

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/EIonizationProcess.cc
Expand Up @@ -57,7 +57,7 @@ auto EIonizationProcess::step_limits(Applicability applicability) const
/*!
* Name of the process.
*/
std::string EIonizationProcess::label() const
std::string_view EIonizationProcess::label() const
{
return "Electron/positron ionization";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/EIonizationProcess.hh
Expand Up @@ -52,7 +52,7 @@ class EIonizationProcess : public Process
bool use_integral_xs() const final { return options_.use_integral_xs; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/EPlusAnnihilationProcess.cc
Expand Up @@ -63,7 +63,7 @@ auto EPlusAnnihilationProcess::step_limits(Applicability range) const
/*!
* Name of the process.
*/
std::string EPlusAnnihilationProcess::label() const
std::string_view EPlusAnnihilationProcess::label() const
{
return "Positron annihiliation";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/EPlusAnnihilationProcess.hh
Expand Up @@ -49,7 +49,7 @@ class EPlusAnnihilationProcess final : public Process
bool use_integral_xs() const final { return options_.use_integral_xs; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/GammaConversionProcess.cc
Expand Up @@ -59,7 +59,7 @@ auto GammaConversionProcess::step_limits(Applicability applic) const
/*!
* Name of the process.
*/
std::string GammaConversionProcess::label() const
std::string_view GammaConversionProcess::label() const
{
return "Photon annihiliation";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/GammaConversionProcess.hh
Expand Up @@ -51,7 +51,7 @@ class GammaConversionProcess : public Process
bool use_integral_xs() const final { return false; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/PhotoelectricProcess.cc
Expand Up @@ -62,7 +62,7 @@ auto PhotoelectricProcess::step_limits(Applicability applic) const
/*!
* Name of the process.
*/
std::string PhotoelectricProcess::label() const
std::string_view PhotoelectricProcess::label() const
{
return "Photoelectric effect";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/PhotoelectricProcess.hh
Expand Up @@ -53,7 +53,7 @@ class PhotoelectricProcess : public Process
bool use_integral_xs() const final { return false; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/RayleighProcess.cc
Expand Up @@ -57,7 +57,7 @@ auto RayleighProcess::step_limits(Applicability applic) const
/*!
* Name of the process.
*/
std::string RayleighProcess::label() const
std::string_view RayleighProcess::label() const
{
return "Rayleigh scattering";
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/process/RayleighProcess.hh
Expand Up @@ -47,7 +47,7 @@ class RayleighProcess : public Process
bool use_integral_xs() const final { return false; }

// Name of the process
std::string label() const final;
std::string_view label() const final;

private:
SPConstParticles particles_;
Expand Down
9 changes: 5 additions & 4 deletions src/celeritas/global/ActionInterface.hh
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <string>
#include <string_view>

#include "celeritas/Types.hh" // IWYU pragma: export

Expand Down Expand Up @@ -58,10 +59,10 @@ class ActionInterface
virtual ActionId action_id() const = 0;

//! Short unique label of the action
virtual std::string label() const = 0;
virtual std::string_view label() const = 0;

//! Description of the action
virtual std::string description() const = 0;
virtual std::string_view description() const = 0;

protected:
//!@{
Expand Down Expand Up @@ -194,10 +195,10 @@ class ConcreteAction : public virtual ActionInterface
ActionId action_id() const final { return id_; }

//! Short label
std::string label() const final { return label_; }
std::string_view label() const final { return label_; }

//! Descriptive label
std::string description() const final { return description_; }
std::string_view description() const final { return description_; }

private:
ActionId id_;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/global/ActionRegistry.cc
Expand Up @@ -49,7 +49,7 @@ void ActionRegistry::insert_const_impl(SPConstAction&& action)
*/
void ActionRegistry::insert_impl(SPConstAction&& action)
{
auto label = action->label();
auto label = std::string{action->label()};
CELER_VALIDATE(!label.empty(), << "action label is empty");

auto id = action->action_id();
Expand Down

0 comments on commit 66e223f

Please sign in to comment.