Skip to content

Commit

Permalink
Merge branch 'develop' into speedup-clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
esseivaju authored Dec 5, 2024
2 parents 170e2f1 + cbf14de commit dce7c2a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 41 deletions.
31 changes: 23 additions & 8 deletions app/celer-g4/ActionInitialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include "ActionInitialization.hh"

#include "corecel/io/Logger.hh"
#include "accel/ExceptionConverter.hh"
#include "accel/HepMC3PrimaryGenerator.hh"
#include "accel/LocalTransporter.hh"

#include "EventAction.hh"
#include "GeantDiagnostics.hh"
#include "GlobalSetup.hh"
#include "HepMC3PrimaryGeneratorAction.hh"
#include "PGPrimaryGeneratorAction.hh"
Expand All @@ -36,14 +38,18 @@ ActionInitialization::ActionInitialization(SPParams params)
// Create Geant4 diagnostics to be shared across worker threads
diagnostics_ = std::make_shared<GeantDiagnostics>();

if (auto const& hepmc_gen = GlobalSetup::Instance()->hepmc_gen())
auto const& input = GlobalSetup::Instance()->input();
if (!input.event_file.empty())
{
num_events_ = hepmc_gen->NumEvents();
ExceptionConverter call_g4exception{"celer0007"};
CELER_TRY_HANDLE(hepmc_gen_ = std::make_shared<HepMC3PrimaryGenerator>(
input.event_file),
call_g4exception);
num_events_ = hepmc_gen_->NumEvents();
}
else
{
num_events_
= GlobalSetup::Instance()->input().primary_options.num_events;
num_events_ = input.primary_options.num_events;
}

CELER_ENSURE(num_events_ > 0);
Expand Down Expand Up @@ -82,15 +88,24 @@ void ActionInitialization::Build() const
CELER_LOG_LOCAL(status) << "Constructing user action";

// Primary generator emits source particles
if (auto const& hepmc_gen = GlobalSetup::Instance()->hepmc_gen())
std::unique_ptr<G4VUserPrimaryGeneratorAction> generator_action;
if (hepmc_gen_)
{
this->SetUserAction(new HepMC3PrimaryGeneratorAction(hepmc_gen));
ExceptionConverter call_g4exception{"celer0007"};
CELER_TRY_HANDLE(
generator_action
= std::make_unique<HepMC3PrimaryGeneratorAction>(hepmc_gen_),
call_g4exception);
}
else
{
this->SetUserAction(new PGPrimaryGeneratorAction(
GlobalSetup::Instance()->input().primary_options));
ExceptionConverter call_g4exception{"celer0006"};
CELER_TRY_HANDLE(
generator_action = std::make_unique<PGPrimaryGeneratorAction>(
GlobalSetup::Instance()->input().primary_options),
call_g4exception);
}
this->SetUserAction(generator_action.release());

// Create thread-local transporter to share between actions
auto transport = std::make_shared<LocalTransporter>();
Expand Down
9 changes: 5 additions & 4 deletions app/celer-g4/ActionInitialization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

#include "accel/SharedParams.hh"

#include "GeantDiagnostics.hh"

namespace celeritas
{
class HepMC3PrimaryGenerator;

namespace app
{
class GeantDiagnostics;
//---------------------------------------------------------------------------//
/*!
* Set up demo-specific action initializations.
Expand All @@ -28,7 +29,6 @@ class ActionInitialization final : public G4VUserActionInitialization
//!@{
//! \name Type aliases
using SPParams = std::shared_ptr<SharedParams>;
using SPDiagnostics = std::shared_ptr<GeantDiagnostics>;
//!@}

public:
Expand All @@ -41,7 +41,8 @@ class ActionInitialization final : public G4VUserActionInitialization

private:
SPParams params_;
SPDiagnostics diagnostics_;
std::shared_ptr<GeantDiagnostics> diagnostics_;
std::shared_ptr<HepMC3PrimaryGenerator> hepmc_gen_;
int num_events_{0};
mutable bool init_shared_{true};
};
Expand Down
18 changes: 3 additions & 15 deletions app/celer-g4/GlobalSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,9 @@ void GlobalSetup::ReadInput(std::string const& filename)

// Apply Celeritas \c SetupOptions commands
options_->max_num_tracks = input_.num_track_slots;
options_->max_num_events = [this] {
CELER_VALIDATE(input_.primary_options || !input_.event_file.empty(),
<< "no event input file nor primary options were "
"specified");
if (!input_.event_file.empty())
{
hepmc_gen_ = std::make_shared<HepMC3PrimaryGenerator>(
input_.event_file);
return static_cast<size_type>(hepmc_gen_->NumEvents());
}
else
{
return input_.primary_options.num_events;
}
}();
CELER_VALIDATE(input_.primary_options || !input_.event_file.empty(),
<< "no event input file nor primary options were "
"specified");
options_->max_steps = input_.max_steps;
options_->initializer_capacity = input_.initializer_capacity;
options_->secondary_stack_factor = input_.secondary_stack_factor;
Expand Down
11 changes: 0 additions & 11 deletions app/celer-g4/GlobalSetup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class G4GenericMessenger;

namespace celeritas
{
class HepMC3PrimaryGenerator;
namespace app
{
//---------------------------------------------------------------------------//
Expand All @@ -32,12 +31,6 @@ namespace app
*/
class GlobalSetup
{
public:
//!@{
//! \name Type aliases
using SPPrimaryGenerator = std::shared_ptr<HepMC3PrimaryGenerator>;
//!@}

public:
// Return non-owning pointer to a singleton
static GlobalSetup* Instance();
Expand Down Expand Up @@ -98,17 +91,13 @@ class GlobalSetup
//! Whether ROOT I/O for SDs is enabled
bool root_sd_io() const { return root_sd_io_; }

//! Get HepMC3 primary generator
SPPrimaryGenerator const& hepmc_gen() const { return hepmc_gen_; }

private:
// Private constructor since we're a singleton
GlobalSetup();
~GlobalSetup();

// Data
std::shared_ptr<SetupOptions> options_;
SPPrimaryGenerator hepmc_gen_;
RunInput input_;
Stopwatch get_setup_time_;
bool root_sd_io_{false};
Expand Down
2 changes: 1 addition & 1 deletion app/celer-g4/RunInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct RunInput
size_type num_track_slots{};
size_type max_steps{unspecified};
size_type initializer_capacity{};
real_type secondary_stack_factor{};
real_type secondary_stack_factor{2};
size_type auto_flush{}; //!< Defaults to num_track_slots

bool action_times{false};
Expand Down
1 change: 1 addition & 0 deletions app/celer-g4/celer-g4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "corecel/Macros.hh"
#include "corecel/io/ExceptionOutput.hh"
#include "corecel/io/Logger.hh"
#include "corecel/io/OutputRegistry.hh"
#include "corecel/io/ScopedTimeAndRedirect.hh"
#include "corecel/io/ScopedTimeLog.hh"
#include "corecel/io/StringUtils.hh"
Expand Down
5 changes: 3 additions & 2 deletions doc/introduction/usage/app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ specified with a combination of the ``field_type``, ``field``, and
``field_file`` keys, and detailed field driver configuration options are set
with ``field_options`` corresponding to the ``FieldOptions`` class in :ref:`api_field_data`.

.. note:: The macro file usage is in the process of being replaced by JSON
input for improved automation.
.. deprecated:: The macro file usage is in the process of being replaced by JSON
input for improved automation. Until then, refer
to the source code at :file:`app/celer-g4/RunInput.hh` .

The input is a Geant4 macro file for executing the program. Celeritas defines
several macros in the ``/celer`` and (if CUDA is available) ``/celer/cuda/``
Expand Down

0 comments on commit dce7c2a

Please sign in to comment.