File indexing completed on 2025-07-15 08:12:49
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Json/JsonGeometryList.hpp"
0010
0011 #include <fstream>
0012 #include <initializer_list>
0013
0014 void ActsExamples::from_json(const nlohmann::json& data,
0015 Acts::GeometryIdentifier& geoId) {
0016 Acts::GeometryIdentifier::Value null(0u);
0017 geoId = geoId.withVolume(data.value("volume", null))
0018 .withBoundary(data.value("boundary", null))
0019 .withLayer(data.value("layer", null))
0020 .withApproach(data.value("approach", null))
0021 .withSensitive(data.value("sensitive", null))
0022 .withExtra(data.value("extra", null));
0023 }
0024
0025 void ActsExamples::to_json(nlohmann::json& data,
0026 const Acts::GeometryIdentifier& geoId) {
0027 if (geoId.volume() != 0u) {
0028 data["volume"] = geoId.volume();
0029 }
0030 if (geoId.boundary() != 0u) {
0031 data["boundary"] = geoId.boundary();
0032 }
0033 if (geoId.layer() != 0u) {
0034 data["layer"] = geoId.layer();
0035 }
0036 if (geoId.approach() != 0u) {
0037 data["approach"] = geoId.approach();
0038 }
0039 if (geoId.sensitive() != 0u) {
0040 data["sensitive"] = geoId.sensitive();
0041 }
0042 if (geoId.extra() != 0u) {
0043 data["extra"] = geoId.extra();
0044 }
0045 }
0046
0047 void ActsExamples::from_json(const nlohmann::json& data,
0048 std::vector<Acts::GeometryIdentifier>& geoIdList) {
0049 for (auto& entry : data) {
0050 Acts::GeometryIdentifier geoId;
0051 from_json(entry, geoId);
0052 geoIdList.push_back(geoId);
0053 }
0054 }
0055
0056 void ActsExamples::to_json(
0057 nlohmann::json& data,
0058 const std::vector<Acts::GeometryIdentifier>& geoIdList) {
0059 for (auto& geoId : geoIdList) {
0060 nlohmann::json entry;
0061 to_json(entry, geoId);
0062 data.push_back(entry);
0063 }
0064 }
0065
0066 std::vector<Acts::GeometryIdentifier> ActsExamples::readJsonGeometryList(
0067 const std::string& path) {
0068 nlohmann::json data;
0069 std::vector<Acts::GeometryIdentifier> geoIdList;
0070 std::ifstream infile(path, std::ifstream::in | std::ifstream::binary);
0071 infile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
0072 infile >> data;
0073 from_json(data, geoIdList);
0074 return geoIdList;
0075 }
0076
0077 void ActsExamples::writeJsonGeometryList(
0078 const std::vector<Acts::GeometryIdentifier>& geoIdList,
0079 const std::string& path) {
0080 nlohmann::json data;
0081 to_json(data, geoIdList);
0082 std::ofstream outfile(path, std::ofstream::out | std::ofstream::binary);
0083 outfile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
0084 outfile << data;
0085 }