File indexing completed on 2025-12-11 09:40:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "ActsPlugins/Json/ActsJson.hpp"
0013
0014 #include <nlohmann/json.hpp>
0015
0016
0017
0018 namespace Acts {
0019
0020 namespace GeometryIdentifierJsonConverter {
0021
0022
0023
0024 inline nlohmann::json encodeIdentifier(const GeometryIdentifier& geoId,
0025 bool compact = false) {
0026 nlohmann::json encoded;
0027 if (compact) {
0028
0029 encoded = geoId.value();
0030 return encoded;
0031 }
0032
0033
0034 if (geoId.volume() != 0u) {
0035 encoded["volume"] = geoId.volume();
0036 }
0037 if (geoId.boundary() != 0u) {
0038 encoded["boundary"] = geoId.boundary();
0039 }
0040 if (geoId.layer() != 0u) {
0041 encoded["layer"] = geoId.layer();
0042 }
0043 if (geoId.approach() != 0u) {
0044 encoded["approach"] = geoId.approach();
0045 }
0046 if (geoId.sensitive() != 0u) {
0047 encoded["sensitive"] = geoId.sensitive();
0048 }
0049 if (geoId.extra() != 0u) {
0050 encoded["extra"] = geoId.extra();
0051 }
0052 return encoded;
0053 }
0054
0055
0056
0057
0058 inline GeometryIdentifier decodeIdentifier(const nlohmann::json& encoded) {
0059 return GeometryIdentifier()
0060 .withVolume(encoded.value("volume", GeometryIdentifier::Value{0u}))
0061 .withBoundary(encoded.value("boundary", GeometryIdentifier::Value{0u}))
0062 .withLayer(encoded.value("layer", GeometryIdentifier::Value{0u}))
0063 .withApproach(encoded.value("approach", GeometryIdentifier::Value{0u}))
0064 .withSensitive(encoded.value("sensitive", GeometryIdentifier::Value{0u}))
0065 .withExtra(encoded.value("extra", GeometryIdentifier::Value{0u}));
0066 }
0067
0068 }
0069
0070
0071
0072
0073 void to_json(nlohmann::json& j, const GeometryIdentifier& geoId);
0074
0075
0076
0077
0078 void from_json(const nlohmann::json& j, GeometryIdentifier& geoId);
0079
0080 }