Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/celeritas/ext/detail/AllElementReader.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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