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/LocalOffloadInterface.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string>
0010 #include <unordered_map>
0011 
0012 #include "corecel/Types.hh"
0013 #include "celeritas/Types.hh"
0014 
0015 namespace celeritas
0016 {
0017 struct SetupOptions;
0018 class SharedParams;
0019 
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Abstract base class for offloading tracks to Celeritas.
0023  *
0024  * This class \em must be constructed locally on each worker
0025  * thread/task/stream,
0026  *
0027  * \warning Due to Geant4 thread-local allocators, this class \em must be
0028  * finalized or destroyed on the same CPU thread in which is created and used!
0029  */
0030 class LocalOffloadInterface
0031 {
0032   public:
0033     //!@{
0034     //! \name Type aliases
0035     using MapStrDbl = std::unordered_map<std::string, double>;
0036     //!@}
0037 
0038   public:
0039     virtual ~LocalOffloadInterface() = default;
0040 
0041     // Initialize with options and core shared data
0042     virtual void Initialize(SetupOptions const&, SharedParams&) = 0;
0043 
0044     // Set the event ID and reseed the Celeritas RNG at the start of an event
0045     virtual void InitializeEvent(int) = 0;
0046 
0047     // Transport all buffered tracks to completion
0048     virtual void Flush() = 0;
0049 
0050     // Clear local data and return to an invalid state
0051     virtual void Finalize() = 0;
0052 
0053     // Whether the class instance is initialized
0054     virtual bool Initialized() const = 0;
0055 
0056     // Get the number of buffered tracks
0057     virtual size_type GetBufferSize() const = 0;
0058 
0059     // Get accumulated action times
0060     virtual MapStrDbl GetActionTime() const = 0;
0061 
0062     //! Whether the class instance is initialized
0063     explicit operator bool() const { return this->Initialized(); }
0064 
0065   protected:
0066     //!@{
0067     //! Allow construction and assignment only through daughter classes
0068     LocalOffloadInterface() = default;
0069     CELER_DEFAULT_COPY_MOVE(LocalOffloadInterface);
0070     //!@}
0071 };
0072 
0073 //---------------------------------------------------------------------------//
0074 }  // namespace celeritas