diff --git a/app/celer-g4/ActionInitialization.cc b/app/celer-g4/ActionInitialization.cc index 31b3f52761..76998c8bc0 100644 --- a/app/celer-g4/ActionInitialization.cc +++ b/app/celer-g4/ActionInitialization.cc @@ -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" @@ -36,14 +38,18 @@ ActionInitialization::ActionInitialization(SPParams params) // Create Geant4 diagnostics to be shared across worker threads diagnostics_ = std::make_shared(); - 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( + 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); @@ -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 generator_action; + if (hepmc_gen_) { - this->SetUserAction(new HepMC3PrimaryGeneratorAction(hepmc_gen)); + ExceptionConverter call_g4exception{"celer0007"}; + CELER_TRY_HANDLE( + generator_action + = std::make_unique(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( + 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(); diff --git a/app/celer-g4/ActionInitialization.hh b/app/celer-g4/ActionInitialization.hh index 4d83dcb4e8..b1b9facf0e 100644 --- a/app/celer-g4/ActionInitialization.hh +++ b/app/celer-g4/ActionInitialization.hh @@ -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. @@ -28,7 +29,6 @@ class ActionInitialization final : public G4VUserActionInitialization //!@{ //! \name Type aliases using SPParams = std::shared_ptr; - using SPDiagnostics = std::shared_ptr; //!@} public: @@ -41,7 +41,8 @@ class ActionInitialization final : public G4VUserActionInitialization private: SPParams params_; - SPDiagnostics diagnostics_; + std::shared_ptr diagnostics_; + std::shared_ptr hepmc_gen_; int num_events_{0}; mutable bool init_shared_{true}; }; diff --git a/app/celer-g4/GlobalSetup.cc b/app/celer-g4/GlobalSetup.cc index ceb65b87c7..07a4c583fd 100644 --- a/app/celer-g4/GlobalSetup.cc +++ b/app/celer-g4/GlobalSetup.cc @@ -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( - input_.event_file); - return static_cast(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; diff --git a/app/celer-g4/GlobalSetup.hh b/app/celer-g4/GlobalSetup.hh index 96c1e219f9..f556c670eb 100644 --- a/app/celer-g4/GlobalSetup.hh +++ b/app/celer-g4/GlobalSetup.hh @@ -23,7 +23,6 @@ class G4GenericMessenger; namespace celeritas { -class HepMC3PrimaryGenerator; namespace app { //---------------------------------------------------------------------------// @@ -32,12 +31,6 @@ namespace app */ class GlobalSetup { - public: - //!@{ - //! \name Type aliases - using SPPrimaryGenerator = std::shared_ptr; - //!@} - public: // Return non-owning pointer to a singleton static GlobalSetup* Instance(); @@ -98,9 +91,6 @@ 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(); @@ -108,7 +98,6 @@ class GlobalSetup // Data std::shared_ptr options_; - SPPrimaryGenerator hepmc_gen_; RunInput input_; Stopwatch get_setup_time_; bool root_sd_io_{false}; diff --git a/app/celer-g4/RunInput.hh b/app/celer-g4/RunInput.hh index 11189ff8cf..9a5f09a563 100644 --- a/app/celer-g4/RunInput.hh +++ b/app/celer-g4/RunInput.hh @@ -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}; diff --git a/app/celer-g4/celer-g4.cc b/app/celer-g4/celer-g4.cc index caca6d8252..656aada2aa 100644 --- a/app/celer-g4/celer-g4.cc +++ b/app/celer-g4/celer-g4.cc @@ -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" diff --git a/doc/introduction/usage/app.rst b/doc/introduction/usage/app.rst index 646096a14c..f451359f23 100644 --- a/doc/introduction/usage/app.rst +++ b/doc/introduction/usage/app.rst @@ -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/``