Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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/user/detail/SlotDiagnosticExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/data/ObserverPtr.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/Atomics.hh"
0015 #include "celeritas/global/CoreTrackView.hh"
0016 
0017 #include "../ParticleTallyData.hh"
0018 
0019 namespace celeritas
0020 {
0021 namespace detail
0022 {
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Export the particle type.
0026  *
0027  * Later this class can be extended to write different properties per track,
0028  * e.g. action ID; or save into the "track" slot versus
0029  *
0030  * \note
0031  */
0032 struct SlotDiagnosticExecutor
0033 {
0034     inline CELER_FUNCTION void
0035     operator()(celeritas::CoreTrackView const& track);
0036 
0037     ObserverPtr<int> output;
0038 };
0039 
0040 //---------------------------------------------------------------------------//
0041 CELER_FUNCTION void
0042 SlotDiagnosticExecutor::operator()(CoreTrackView const& track)
0043 {
0044     int result = [&track] {
0045         auto sim = track.make_sim_view();
0046         if (sim.status() == TrackStatus::inactive)
0047         {
0048             return -1;
0049         }
0050         else if (sim.status() == TrackStatus::errored)
0051         {
0052             return -2;
0053         }
0054         // Save particle ID
0055         return static_cast<int>(track.make_particle_view().particle_id().get());
0056     }();
0057 
0058     size_type const index = track.track_slot_id().get();
0059     (&*output)[index] = result;
0060 }
0061 
0062 //---------------------------------------------------------------------------//
0063 }  // namespace detail
0064 }  // namespace celeritas