Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-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/StepInterface.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <map>
0011 
0012 #include "corecel/Types.hh"
0013 
0014 #include "StepData.hh"  // IWYU pragma: export
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 template<MemSpace M>
0020 struct StepState
0021 {
0022     //! Host pointer to externally owned step state data reference
0023     StepStateData<Ownership::reference, M> const& steps;
0024     //! Stream ID (local to each core state)
0025     StreamId stream_id;
0026 };
0027 
0028 //---------------------------------------------------------------------------//
0029 /*!
0030  * Callback class to gather and process data from many tracks at a single step.
0031  *
0032  * The filtering mechanism allows different step interfaces to gather data from
0033  * different detector volumes. Filtered step interfaces cannot be combined with
0034  * unfiltered in a single hit collector. (FIXME: maybe we need a slightly
0035  * different class hierarchy for the two cases?) If detectors are in use, and
0036  * all \c StepInterface instances in use by a \c StepCollector select the
0037  * "nonzero_energy_deposition" flag, then the \c StepStateData::detector entry
0038  * for a thread with no energy deposition will be cleared even if it is in a
0039  * sensitive detector. Otherwise entries with zero energy deposition will
0040  * remain.
0041  */
0042 class StepInterface
0043 {
0044   public:
0045     //@{
0046     //! \name Type aliases
0047     using HostStepState = StepState<MemSpace::host>;
0048     using DeviceStepState = StepState<MemSpace::device>;
0049     using MapVolumeDetector = std::map<VolumeId, DetectorId>;
0050     //@}
0051 
0052     //! Filtering to apply to the gathered data for this step.
0053     struct Filters
0054     {
0055         //! Only select data from these volume IDs and map to detectors
0056         MapVolumeDetector detectors;
0057         //! Only select data with nonzero energy deposition (if detectors)
0058         bool nonzero_energy_deposition{false};
0059     };
0060 
0061   public:
0062     //! Detector filtering required for this interface
0063     virtual Filters filters() const = 0;
0064 
0065     //! Selection of data required for this interface
0066     virtual StepSelection selection() const = 0;
0067 
0068     //! Process CPU-generated hit data
0069     virtual void process_steps(HostStepState) = 0;
0070 
0071     //! Process device-generated hit data
0072     virtual void process_steps(DeviceStepState) = 0;
0073 
0074     // TODO: hook for end-of-event and/or end-of-run
0075 
0076   protected:
0077     // Protected destructor prevents deletion of pointer-to-interface
0078     ~StepInterface() = default;
0079 };
0080 
0081 //---------------------------------------------------------------------------//
0082 }  // namespace celeritas