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