Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:54:09

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 corecel/sys/ActionGroups.t.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <algorithm>
0010 
0011 #include "corecel/cont/Range.hh"
0012 
0013 #include "ActionRegistry.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Construct from an action registry.
0020  */
0021 template<class P, template<MemSpace M> class S>
0022 ActionGroups<P, S>::ActionGroups(ActionRegistry const& reg)
0023 {
0024     // Loop over all action IDs
0025     for (auto aidx : range(reg.num_actions()))
0026     {
0027         // Get abstract action shared pointer to determine type
0028         auto const& base = reg.action(ActionId{aidx});
0029         if (auto step_act = std::dynamic_pointer_cast<StepActionT const>(base))
0030         {
0031             // Add stepping action to our array
0032             step_actions_.push_back(std::move(step_act));
0033         }
0034     }
0035 
0036     // Loop over all mutable actions
0037     for (auto const& base : reg.mutable_actions())
0038     {
0039         if (auto brun = std::dynamic_pointer_cast<BeginRunActionT>(base))
0040         {
0041             // Add beginning-of-run to the array
0042             begin_run_.emplace_back(std::move(brun));
0043         }
0044     }
0045 
0046     // Sort actions by increasing order (and secondarily, increasing IDs)
0047     std::sort(step_actions_.begin(),
0048               step_actions_.end(),
0049               [](SPConstStepAction const& a, SPConstStepAction const& b) {
0050                   return OrderedAction{a->order(), a->action_id()}
0051                          < OrderedAction{b->order(), b->action_id()};
0052               });
0053 }
0054 
0055 //---------------------------------------------------------------------------//
0056 }  // namespace celeritas