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/LocalOpticalTrackOffload.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Types.hh"
0010 #include "celeritas/Types.hh"
0011 #include "celeritas/optical/TrackInitializer.hh"
0012 #include "celeritas/optical/gen/DirectGeneratorAction.hh"
0013 
0014 #include "TrackOffloadInterface.hh"
0015 
0016 class G4EventManager;
0017 namespace celeritas
0018 {
0019 namespace optical
0020 {
0021 class CoreStateBase;
0022 class Transporter;
0023 }  // namespace optical
0024 
0025 struct SetupOptions;
0026 class SharedParams;
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Offload Geant4 optical photon tracks to Celeritas.
0031  */
0032 class LocalOpticalTrackOffload final : public TrackOffloadInterface
0033 {
0034   public:
0035     //!@{
0036     //! \name Type aliases
0037     using TrackData = optical::TrackInitializer;
0038     //!@}
0039 
0040   public:
0041     // Construct in an invalid state
0042     LocalOpticalTrackOffload() = default;
0043 
0044     // Construct with shared (across threads) params
0045     LocalOpticalTrackOffload(SetupOptions const& options, SharedParams& params);
0046 
0047     //!@{
0048     //! \name TrackOffloadInterface
0049 
0050     // Initialize with options and shared data
0051     void Initialize(SetupOptions const&, SharedParams&) final;
0052 
0053     // Set the event ID and reseed the Celeritas RNG at the start of an event
0054     void InitializeEvent(int) final;
0055 
0056     // Transport all buffered tracks to completion
0057     void Flush() final;
0058 
0059     // Clear local data and return to an invalid state
0060     void Finalize() final;
0061 
0062     // Whether the class instance is initialized
0063     bool Initialized() const final { return static_cast<bool>(transport_); }
0064 
0065     // Number of buffered tracks
0066     size_type GetBufferSize() const final { return buffer_.size(); }
0067 
0068     // Get accumulated action times
0069     MapStrDbl GetActionTime() const final;
0070     //!@}
0071 
0072     // Offload optical photon track to Celeritas
0073     void Push(G4Track&) final;
0074 
0075     // Number of optical tracks pushed to offload
0076     size_type num_pushed() const { return num_pushed_; }
0077 
0078   private:
0079     // Transport pending optical tracks
0080     std::shared_ptr<optical::Transporter> transport_;
0081 
0082     // Thread-local state data
0083     std::shared_ptr<optical::CoreStateBase> state_;
0084 
0085     // Generator action for injecting buffered tracks into optical state
0086     std::shared_ptr<optical::DirectGeneratorAction const> direct_gen_;
0087 
0088     // Buffered tracks for offloading
0089     std::vector<TrackData> buffer_;
0090 
0091     // Number of photons tracks to buffer before offloading
0092     size_type auto_flush_{};
0093 
0094     // Accumulated number of optical photon tracks
0095     size_type num_pushed_{};
0096 
0097     // Accumulated number of tracks pushed over flushes
0098     size_type num_flushed_{};
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