Back to home page

EIC code displayed by LXR

 
 

    


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

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/ext/detail/AllElementReader.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <map>
0011 #include <vector>
0012 
0013 #include "celeritas/io/ImportElement.hh"
0014 
0015 namespace celeritas
0016 {
0017 namespace detail
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Generate a map of read data for all loaded elements.
0022  *
0023  * This can be used to load EMLOW and other data into an ImportFile for
0024  * reproducibility. Note that the Celeritas interfaces uses the type-safe
0025  * \c AtomicNumber class but we store the atomic number as an int in
0026  * ImportFile.
0027  */
0028 class AllElementReader
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using VecElements = std::vector<ImportElement>;
0034     //!@}
0035 
0036   public:
0037     //! Construct from vector of imported elements
0038     explicit AllElementReader(VecElements const& els) : elements_(els)
0039     {
0040         CELER_EXPECT(!elements_.empty());
0041     }
0042 
0043     //! Load a map of data for all stored elements
0044     template<class ReadOneElement>
0045     auto operator()(ReadOneElement&& read_el) const -> decltype(auto)
0046     {
0047         using result_type = typename ReadOneElement::result_type;
0048 
0049         std::map<int, result_type> result_map;
0050 
0051         for (ImportElement const& element : elements_)
0052         {
0053             AtomicNumber z{element.atomic_number};
0054             CELER_ASSERT(z);
0055             result_map.insert({z.unchecked_get(), read_el(z)});
0056         }
0057         return result_map;
0058     }
0059 
0060   private:
0061     std::vector<ImportElement> const& elements_;
0062 };
0063 
0064 //---------------------------------------------------------------------------//
0065 }  // namespace detail
0066 }  // namespace celeritas