Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 09:43:35

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file accel/LocalOpticalGenOffload.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <vector>
0010 
0011 #include "corecel/Types.hh"
0012 #include "celeritas/Types.hh"
0013 #include "celeritas/optical/gen/GeneratorData.hh"
0014 
0015 #include "LocalOffloadInterface.hh"
0016 
0017 class G4EventManager;
0018 
0019 namespace celeritas
0020 {
0021 namespace optical
0022 {
0023 class CoreStateBase;
0024 class GeneratorAction;
0025 class Transporter;
0026 }  // namespace optical
0027 
0028 struct SetupOptions;
0029 class SharedParams;
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Manage offloading of optical distribution data to Celeritas.
0034  */
0035 class LocalOpticalGenOffload final : public LocalOffloadInterface
0036 {
0037   public:
0038     //!@{
0039     //! \name Type aliases
0040     using DistributionData = optical::GeneratorDistributionData;
0041     //!@}
0042 
0043   public:
0044     // Construct in an invalid state
0045     LocalOpticalGenOffload() = default;
0046 
0047     // Construct with shared (across threads) params
0048     LocalOpticalGenOffload(SetupOptions const& options, SharedParams& params);
0049 
0050     //!@{
0051     //! \name LocalOffload interface
0052 
0053     // Initialize with options and shared data
0054     void Initialize(SetupOptions const&, SharedParams&) final;
0055 
0056     // Set the event ID and reseed the Celeritas RNG at the start of an event
0057     void InitializeEvent(int) final;
0058 
0059     // Transport all buffered tracks to completion
0060     void Flush() final;
0061 
0062     // Clear local data and return to an invalid state
0063     void Finalize() final;
0064 
0065     // Whether the class instance is initialized
0066     bool Initialized() const final { return static_cast<bool>(state_); }
0067 
0068     // Number of buffered tracks
0069     size_type GetBufferSize() const final { return num_photons_; }
0070 
0071     // Get accumulated action times
0072     MapStrDbl GetActionTime() const final;
0073     //!@}
0074 
0075     // Offload optical distribution data to Celeritas
0076     void Push(DistributionData const&);
0077 
0078     //! Whether the class instance is initialized
0079     explicit operator bool() const { return this->Initialized(); }
0080 
0081   private:
0082     // Transport pending optical tracks
0083     std::shared_ptr<optical::Transporter> transport_;
0084 
0085     // Action for generating optical photons from distribution data
0086     std::shared_ptr<optical::GeneratorAction const> generate_;
0087 
0088     // Thread-local state data
0089     std::shared_ptr<optical::CoreStateBase> state_;
0090 
0091     // Buffered distributions for offloading
0092     std::vector<DistributionData> buffer_;
0093 
0094     // Accumulated number of buffered photons
0095     size_type num_photons_{};
0096 
0097     // Number of photons to buffer before offloading
0098     size_type auto_flush_{};
0099 
0100     // Current event ID or manager for obtaining it
0101     UniqueEventId event_id_;
0102     G4EventManager* event_manager_{nullptr};
0103 };
0104 
0105 //---------------------------------------------------------------------------//
0106 }  // namespace celeritas