Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:47

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/track/StatusChecker.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string_view>
0010 
0011 #include "corecel/Types.hh"
0012 #include "corecel/data/AuxInterface.hh"
0013 #include "corecel/data/CollectionMirror.hh"
0014 #include "corecel/data/ParamsDataInterface.hh"
0015 #include "celeritas/Types.hh"
0016 #include "celeritas/global/ActionInterface.hh"
0017 
0018 #include "StatusCheckData.hh"
0019 
0020 namespace celeritas
0021 {
0022 //---------------------------------------------------------------------------//
0023 class ActionRegistry;
0024 class CoreParams;
0025 template<MemSpace>
0026 class CoreState;
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Verify a consistent simulation state after performing an action.
0031  *
0032  * This is used as a debug option in the step executor to check that actions
0033  * and simulation state are consistent.
0034  *
0035  * Since this is called manually by the stepper, multiple times per step, it is
0036  * \em not an "explicit" action. It's meant to be used inside the \c
0037  * ActionSequence itself, called after every action.
0038  */
0039 class StatusChecker final : public AuxParamsInterface,
0040                             public CoreBeginRunActionInterface,
0041                             public ParamsDataInterface<StatusCheckParamsData>
0042 {
0043   public:
0044     // Construct and add to core params
0045     static std::shared_ptr<StatusChecker>
0046     make_and_insert(CoreParams const& core);
0047 
0048     // Construct with IDs
0049     StatusChecker(ActionId action_id, AuxId aux_id);
0050 
0051     //!@{
0052     //! \name Aux/action metadata interface
0053 
0054     //! Label for the auxiliary data and action
0055     std::string_view label() const final { return "status-check"; }
0056     // Description of the action
0057     std::string_view description() const final;
0058     //!@}
0059 
0060     //!@{
0061     //! \name Aux params interface
0062 
0063     //! Index of this class instance in its registry
0064     AuxId aux_id() const final { return aux_id_; }
0065     // Build state data for a stream
0066     UPState create_state(MemSpace m, StreamId id, size_type size) const final;
0067     //!@}
0068 
0069     //!@{
0070     //! \name Begin run interface
0071 
0072     //! Index of this class instance in its registry
0073     ActionId action_id() const final { return action_id_; }
0074     // Set host data at the beginning of a run
0075     void begin_run(CoreParams const&, CoreStateHost&) final;
0076     // Set device data at the beginning of a run
0077     void begin_run(CoreParams const&, CoreStateDevice&) final;
0078     //!@}
0079 
0080     //!@{
0081     //! \name Data interface
0082 
0083     //! Access data on host
0084     HostRef const& host_ref() const final { return data_.host_ref(); }
0085     //! Access data on device
0086     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0087     //!@}
0088 
0089     // Execute *manually* with the last action's ID and the state
0090     template<MemSpace M>
0091     void
0092     step(ActionId prev_action, CoreParams const&, CoreState<M>& state) const;
0093 
0094   private:
0095     template<MemSpace M>
0096     using StatusStateRef = StatusCheckStateData<Ownership::reference, M>;
0097 
0098     //// DATA ////
0099 
0100     ActionId action_id_;
0101     AuxId aux_id_;
0102     CollectionMirror<StatusCheckParamsData> data_;
0103 
0104     //// HELPER FUNCTIONS ////
0105 
0106     void begin_run_impl(CoreParams const&);
0107 
0108     void launch_impl(CoreParams const&,
0109                      CoreState<MemSpace::host>&,
0110                      StatusStateRef<MemSpace::host> const&) const;
0111     void launch_impl(CoreParams const&,
0112                      CoreState<MemSpace::device>&,
0113                      StatusStateRef<MemSpace::device> const&) const;
0114 };
0115 
0116 //---------------------------------------------------------------------------//
0117 }  // namespace celeritas