Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-14 08:01:42

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Material/ISurfaceMaterial.hpp"
0012 #include "Acts/Material/IVolumeMaterial.hpp"
0013 #include "Acts/Material/Material.hpp"
0014 #include "Acts/Material/MaterialSlab.hpp"
0015 #include "ActsPlugins/Json/ActsJson.hpp"
0016 
0017 #include <nlohmann/json.hpp>
0018 
0019 // Custom Json encoder/decoders. Naming is mandated by nlohmann::json and thus
0020 // can not match our naming guidelines.
0021 namespace Acts {
0022 
0023 class Surface;
0024 class ISurfaceMaterial;
0025 class IVolumeMaterial;
0026 class BinUtility;
0027 
0028 /// Pointer to a constant volume material object
0029 using volumeMaterialPointer = const Acts::IVolumeMaterial*;
0030 /// Pointer to a constant surface material object
0031 using surfaceMaterialPointer = const Acts::ISurfaceMaterial*;
0032 
0033 /// Convert Material to JSON
0034 /// @param j Destination JSON object
0035 /// @param t Source Material to convert
0036 void to_json(nlohmann::json& j, const Material& t);
0037 
0038 /// Convert JSON to Material
0039 /// @param j Source JSON object
0040 /// @param t Destination Material to populate
0041 void from_json(const nlohmann::json& j, Material& t);
0042 
0043 /// Convert MaterialSlab to JSON
0044 /// @param j Destination JSON object
0045 /// @param t Source MaterialSlab to convert
0046 void to_json(nlohmann::json& j, const MaterialSlab& t);
0047 
0048 /// Convert JSON to MaterialSlab
0049 /// @param j Source JSON object
0050 /// @param t Destination MaterialSlab to populate
0051 void from_json(const nlohmann::json& j, MaterialSlab& t);
0052 
0053 /// Convert JSON to MaterialSlabMatrix
0054 /// @param j Source JSON object
0055 /// @param t Destination MaterialSlabMatrix to populate
0056 void from_json(const nlohmann::json& j, MaterialSlabMatrix& t);
0057 
0058 /// Convert volumeMaterialPointer to JSON
0059 /// @param j Destination JSON object
0060 /// @param material Source volumeMaterialPointer to convert
0061 void to_json(nlohmann::json& j, const volumeMaterialPointer& material);
0062 
0063 /// Convert JSON to volumeMaterialPointer
0064 /// @param j Source JSON object
0065 /// @param material Destination volumeMaterialPointer to populate
0066 void from_json(const nlohmann::json& j, volumeMaterialPointer& material);
0067 
0068 /// Convert surfaceMaterialPointer to JSON
0069 /// @param j Destination JSON object
0070 /// @param material Source surfaceMaterialPointer to convert
0071 void to_json(nlohmann::json& j, const surfaceMaterialPointer& material);
0072 
0073 /// Convert JSON to surfaceMaterialPointer
0074 /// @param j Source JSON object
0075 /// @param material Destination surfaceMaterialPointer to populate
0076 void from_json(const nlohmann::json& j, surfaceMaterialPointer& material);
0077 
0078 /// JSON serialization mapping for MappingType enum
0079 // This macro create a conversion for the mapping type enum
0080 NLOHMANN_JSON_SERIALIZE_ENUM(Acts::MappingType,
0081                              {
0082                                  {Acts::MappingType::PreMapping, "PreMapping"},
0083                                  {Acts::MappingType::Default, "Default"},
0084                                  {Acts::MappingType::PostMapping,
0085                                   "PostMapping"},
0086                                  {Acts::MappingType::Sensor, "Sensor"},
0087                              })
0088 
0089 namespace MaterialJsonConverter {
0090 
0091 /// @brief Convert a surface material to json - detray format
0092 ///
0093 /// @param surfaceMaterial is the surface material to be converted
0094 /// @param surface is the surface the material is attached to
0095 /// @param surfaceIndex is the index of the surface
0096 /// @param gridLink [in, out] is the grid index in the volume
0097 ///
0098 /// @note the surface is needed to shift the z boundaries for concentric cylinders
0099 ///
0100 /// @return a json object representing the surface material in detray format
0101 nlohmann::json toJsonDetray(const ISurfaceMaterial& material,
0102                             const Acts::Surface& surface,
0103                             std::size_t surfaceIndex,
0104                             std::map<std::size_t, std::size_t>& gridLink);
0105 
0106 /// @brief Convert a bin utility to json - detray format
0107 ///
0108 /// @param binUtility is the bin utility to be converted
0109 /// @param surface is the surface the material is attached to
0110 ///
0111 /// @note the surface is needed to shift the z boundaries for concentric cylinders
0112 ///
0113 /// @return a json object representing the bin utility in detray format
0114 nlohmann::json toJsonDetray(const Acts::BinUtility& binUtility,
0115                             const Acts::Surface& surface);
0116 
0117 }  // namespace MaterialJsonConverter
0118 
0119 }  // namespace Acts