Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:27:19

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/SimpleOffload.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 class G4Run;
0010 class G4Event;
0011 class G4Track;
0012 
0013 namespace celeritas
0014 {
0015 class SharedParams;
0016 struct SetupOptions;
0017 class LocalTransporter;
0018 
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Compressed interface for running Celeritas in a multithread Geant4 app.
0022  *
0023  * This class *must* be a thread-local instance with references to data that
0024  * exceed the lifetime of the class: e.g. SharedParams can be a global
0025  * variable, and LocalTransporter can be a global variable with \c thread_local
0026  * storage duration.
0027  *
0028  * The \c CELER_DISABLE environment variable, if set and non-empty, will
0029  * disable offloading so that Celeritas will not be built nor kill tracks.
0030  *
0031  * The method names correspond to methods in Geant4 User Actions and *must* be
0032  * called from all threads, both worker and master.
0033  *
0034  * \deprecated Use the \c UserActionIntegration class instead of this, or
0035  * manually interface with the \c SharedParams and \c LocalTransporter for
0036  * fine-grained control.
0037  *
0038  */
0039 class [[deprecated]] SimpleOffload  // REMOVE in 0.7
0040 {
0041   public:
0042     //! Construct with celeritas disabled
0043     SimpleOffload() = default;
0044 
0045     // Construct from a reference to shared params and local data
0046     SimpleOffload(SetupOptions const* setup,
0047                   SharedParams* params,
0048                   LocalTransporter* local);
0049 
0050     //! Lazy initialization of this class on a worker thread
0051     void Build(SetupOptions const* setup,
0052                SharedParams* params,
0053                LocalTransporter* local)
0054     {
0055         *this = {setup, params, local};
0056     }
0057 
0058     //! Lazy initialization of this class on the master thread
0059     void BuildForMaster(SetupOptions const* setup, SharedParams* params)
0060     {
0061         *this = {setup, params, nullptr};
0062     }
0063 
0064     // Initialize celeritas data from setup options
0065     void BeginOfRunAction(G4Run const* run);
0066 
0067     // Send Celeritas the event ID
0068     void BeginOfEventAction(G4Event const* event);
0069 
0070     // Send tracks to Celeritas if applicable and "StopAndKill" if so
0071     void PreUserTrackingAction(G4Track* track);
0072 
0073     // Flush offloaded tracks from Celeritas
0074     void EndOfEventAction(G4Event const* event);
0075 
0076     // Finalize
0077     void EndOfRunAction(G4Run const* run);
0078 
0079     // Whether offloading is enabled
0080     explicit operator bool() const;
0081 
0082   private:
0083     SetupOptions const* setup_{nullptr};
0084     SharedParams* params_{nullptr};
0085     LocalTransporter* local_{nullptr};
0086 };
0087 
0088 //---------------------------------------------------------------------------//
0089 }  // namespace celeritas