Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:05

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 celeritas/global/KernelContextException.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string_view>
0010 
0011 #include "corecel/Assert.hh"
0012 #include "celeritas/Quantities.hh"
0013 #include "celeritas/Types.hh"
0014 
0015 #include "CoreTrackDataFwd.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 class CoreTrackView;
0021 struct JsonPimpl;
0022 
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Provide contextual information about failed errors on CPU.
0026  *
0027  * When a CPU track hits an exception, gather properties about the current
0028  * thread and failing track. These properties are accessible through this
0029  * exception class *or* they can be chained into the failing exception and
0030  * processed by \c ExceptionOutput as context for the failure.
0031  *
0032  * \code
0033     CELER_TRY_HANDLE_CONTEXT(
0034         step(ThreadId{i}),
0035         capture_exception,
0036         KernelContextException(data.params, data.states, ThreadId{i},
0037  this->label())
0038     );
0039  * \endcode
0040  */
0041 class KernelContextException : public RichContextException
0042 {
0043   public:
0044     //!@{
0045     //! \name Type aliases
0046     using Energy = units::MevEnergy;
0047     //!@}
0048 
0049   public:
0050     // Construct with track data and kernel label
0051     KernelContextException(HostCRef<CoreParamsData> const& params,
0052                            HostRef<CoreStateData> const& states,
0053                            ThreadId tid,
0054                            std::string_view label);
0055 
0056     // This class type
0057     char const* type() const final;
0058 
0059     // Save context to a JSON object
0060     void output(JsonPimpl* json) const final;
0061 
0062     //! Get an explanatory message
0063     char const* what() const noexcept final { return what_.c_str(); }
0064 
0065     //!@{
0066     //! \name Track accessors
0067 
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