Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-12 08:52:57

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