Skip to content

Commit

Permalink
Use string view for interface labels and descriptions (celeritas-proj…
Browse files Browse the repository at this point in the history
…ect#1210)

* Use string_view instead of string for interface labels+descriptions

* Use string view in scoped profiling

* Preallocate stepping counters in transport loop

* Fix device build errors

* Incorporate review feedback
  • Loading branch information
sethrj committed Apr 30, 2024
1 parent 69cdb1a commit 2767efe
Show file tree
Hide file tree
Showing 91 changed files with 191 additions and 165 deletions.
2 changes: 1 addition & 1 deletion app/celer-g4/TimerOutput.hh
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
12 changes: 10 additions & 2 deletions app/celer-sim/Transporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ auto Transporter<M>::operator()(SpanConstPrimary primaries)
result.alive.push_back(track_counts.alive);
};

constexpr size_type min_alloc{65536};
result.initializers.reserve(std::min(min_alloc, max_steps_));
result.active.reserve(std::min(min_alloc, max_steps_));
result.alive.reserve(std::min(min_alloc, max_steps_));
if (store_step_times_)
{
result.step_times.reserve(std::min(min_alloc, max_steps_));
}

// Abort cleanly for interrupt and user-defined signals
#ifndef _WIN32
ScopedSignalHandler interrupted{SIGINT, SIGUSR2};
Expand Down Expand Up @@ -165,8 +174,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 2767efe

Please sign in to comment.