Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:23

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/global/KernelContextException.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string_view>
0011 
0012 #include "corecel/Assert.hh"
0013 #include "celeritas/Quantities.hh"
0014 #include "celeritas/Types.hh"
0015 
0016 #include "CoreTrackDataFwd.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 class CoreTrackView;
0022 struct JsonPimpl;
0023 
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Provide contextual information about failed errors on CPU.
0027  *
0028  * When a CPU track hits an exception, gather properties about the current
0029  * thread and failing track. These properties are accessible through this
0030  * exception class *or* they can be chained into the failing exception and
0031  * processed by \c ExceptionOutput as context for the failure.
0032  *
0033  * \code
0034     CELER_TRY_HANDLE_CONTEXT(
0035         step(ThreadId{i}),
0036         capture_exception,
0037         KernelContextException(data.params, data.states, ThreadId{i},
0038  this->label())
0039     );
0040  * \endcode
0041  */
0042 class KernelContextException : public RichContextException
0043 {
0044   public:
0045     //!@{
0046     //! \name Type aliases
0047     using Energy = units::MevEnergy;
0048     //!@}
0049 
0050   public:
0051     // Construct with track data and kernel label
0052     KernelContextException(HostCRef<CoreParamsData> const& params,
0053                            HostRef<CoreStateData> const& states,
0054                            ThreadId tid,
0055                            std::string_view label);
0056 
0057     // This class type
0058     char const* type() const final;
0059 
0060     // Save context to a JSON object
0061     void output(JsonPimpl* json) const final;
0062 
0063     //! Get an explanatory message
0064     char const* what() const noexcept final { return what_.c_str(); }
0065 
0066     //!@{
0067     //! \name Track accessors
0068     //! Kernel thread ID
0069     ThreadId thread() const { return thread_; }
0070     //! Track slot ID
0071     TrackSlotId track_slot() const { return track_slot_; }
0072     //! Event ID
0073     EventId event() const { return event_; }
0074     //! Track ID
0075     TrackId track() const { return track_; }
0076     //! Parent track ID
0077     TrackId parent() const { return parent_; }
0078     //! Step counter
0079     size_type num_steps() const { return num_steps_; }
0080     //! Particle type
0081     ParticleId particle() const { return particle_; }
0082     //! Particle energy
0083     Energy energy() const { return energy_; }
0084     //! Position
0085     Real3 const& pos() const { return pos_; }
0086     //! Direction
0087     Real3 const& dir() const { return dir_; }
0088     //! Volume ID
0089     VolumeId volume() const { return volume_; }
0090     //! Surface
0091     SurfaceId surface() const { return surface_; }
0092     //!@}
0093 
0094     //! Label of the kernel that died
0095     std::string const& label() const { return label_; }
0096 
0097   private:
0098     ThreadId thread_;
0099     TrackSlotId track_slot_;
0100     EventId event_;
0101     TrackId track_;
0102     TrackId parent_;
0103     size_type num_steps_;
0104     ParticleId particle_;
0105     Energy energy_;
0106     Real3 pos_;
0107     Real3 dir_;
0108     VolumeId volume_;
0109     SurfaceId surface_;
0110 
0111     std::string label_;
0112     std::string what_;
0113 
0114     // Populate properties during construction
0115     void initialize(CoreTrackView const& core);
0116 };
0117 
0118 //---------------------------------------------------------------------------//
0119 }  // namespace celeritas