File indexing completed on 2025-08-05 08:10:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Json/ProtoDetectorJsonConverter.hpp"
0010
0011 #include "Acts/Detector/ProtoDetector.hpp"
0012 #include "Acts/Geometry/Extent.hpp"
0013 #include "Acts/Plugins/Json/ExtentJsonConverter.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/BinningData.hpp"
0016
0017 #include <optional>
0018 #include <string>
0019 #include <vector>
0020
0021 void Acts::to_json(nlohmann::json& j, const Acts::ProtoVolume& pv) {
0022 j["name"] = pv.name;
0023 j["extent"] = pv.extent;
0024
0025
0026
0027
0028
0029
0030 auto writeBinning = [&](nlohmann::json& root,
0031 const std::vector<BinningData>& binning,
0032 const std::string& key) -> void {
0033 nlohmann::json jbinning;
0034 for (const auto& bd : binning) {
0035 jbinning.push_back(bd);
0036 }
0037 root[key] = jbinning;
0038 };
0039
0040
0041 if (pv.internal.has_value()) {
0042 auto& its = pv.internal.value();
0043 nlohmann::json jinternal;
0044 if (its.layerType != Surface::SurfaceType::Other) {
0045 jinternal["layerType"] = static_cast<int>(its.layerType);
0046 }
0047 if (!its.surfaceBinning.empty()) {
0048 writeBinning(jinternal, its.surfaceBinning, "surfaceBinning");
0049 }
0050 j["internalStructure"] = jinternal;
0051 }
0052
0053
0054 if (pv.container.has_value()) {
0055 auto& cts = pv.container.value();
0056 nlohmann::json jcontainer;
0057 nlohmann::json jconstituents;
0058 for (const auto& pvc : cts.constituentVolumes) {
0059 jconstituents.push_back(pvc);
0060 }
0061 jcontainer["constituents"] = jconstituents;
0062 writeBinning(jcontainer, cts.constituentBinning, "constituentBinning");
0063 jcontainer["layerContainer"] = cts.layerContainer;
0064 j["containerStructure"] = jcontainer;
0065 }
0066 }
0067
0068 void Acts::from_json(const nlohmann::json& j, Acts::ProtoVolume& pv) {
0069 pv.name = j["name"];
0070 pv.extent = j["extent"];
0071
0072
0073
0074
0075
0076
0077 auto readBinning = [&](const nlohmann::json& root,
0078 std::vector<BinningData>& binning,
0079 const std::string& key) -> void {
0080
0081 if (root.find(key) == root.end() || root[key].is_null()) {
0082 return;
0083 }
0084
0085 for (const auto& jbinning : root[key]) {
0086 binning.push_back(jbinning);
0087 }
0088 };
0089
0090
0091 if (j.find("internalStructure") != j.end() &&
0092 !j["internalStructure"].is_null()) {
0093 auto& jinternal = j["internalStructure"];
0094 Surface::SurfaceType layerType =
0095 static_cast<Surface::SurfaceType>(jinternal["layerType"]);
0096 std::vector<BinningData> surfaceBinning;
0097 readBinning(jinternal, surfaceBinning, "surfaceBinning");
0098 pv.internal = ProtoVolume::InternalStructure{layerType, surfaceBinning};
0099 }
0100
0101
0102 if (j.find("containerStructure") != j.end() &&
0103 !j["containerStructure"].is_null()) {
0104 std::vector<ProtoVolume> constituentVolumes;
0105 auto& jcontainer = j["containerStructure"];
0106 for (const auto& jc : jcontainer["constituents"]) {
0107 constituentVolumes.push_back(jc);
0108 }
0109 std::vector<BinningData> constituentBinning;
0110 readBinning(jcontainer, constituentBinning, "constituentBinning");
0111 bool layerContainer = jcontainer["layerContainer"];
0112 pv.container = ProtoVolume::ContainerStructure{
0113 constituentVolumes, constituentBinning, layerContainer};
0114 }
0115 }
0116
0117 void Acts::to_json(nlohmann::json& j, const Acts::ProtoDetector& pd) {
0118 j["name"] = pd.name;
0119 j["world"] = pd.worldVolume;
0120 }
0121
0122 void Acts::from_json(const nlohmann::json& j, Acts::ProtoDetector& pd) {
0123 pd.name = j["name"];
0124 pd.worldVolume = j["world"];
0125 }