File indexing completed on 2025-01-31 09:17:02
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.setVolume(data.value("volume", null));
0018 geoId.setBoundary(data.value("boundary", null));
0019 geoId.setLayer(data.value("layer", null));
0020 geoId.setApproach(data.value("approach", null));
0021 geoId.setSensitive(data.value("sensitive", null));
0022 }
0023
0024 void ActsExamples::to_json(nlohmann::json& data,
0025 const Acts::GeometryIdentifier& geoId) {
0026 if (geoId.volume() != 0u) {
0027 data["volume"] = geoId.volume();
0028 }
0029 if (geoId.boundary() != 0u) {
0030 data["boundary"] = geoId.boundary();
0031 }
0032 if (geoId.layer() != 0u) {
0033 data["layer"] = geoId.layer();
0034 }
0035 if (geoId.approach() != 0u) {
0036 data["approach"] = geoId.approach();
0037 }
0038 if (geoId.sensitive() != 0u) {
0039 data["sensitive"] = geoId.sensitive();
0040 }
0041 }
0042
0043 void ActsExamples::from_json(const nlohmann::json& data,
0044 std::vector<Acts::GeometryIdentifier>& geoIdList) {
0045 for (auto& entry : data) {
0046 Acts::GeometryIdentifier geoId;
0047 from_json(entry, geoId);
0048 geoIdList.push_back(geoId);
0049 }
0050 }
0051
0052 void ActsExamples::to_json(
0053 nlohmann::json& data,
0054 const std::vector<Acts::GeometryIdentifier>& geoIdList) {
0055 for (auto& geoId : geoIdList) {
0056 nlohmann::json entry;
0057 to_json(entry, geoId);
0058 data.push_back(entry);
0059 }
0060 }
0061
0062 std::vector<Acts::GeometryIdentifier> ActsExamples::readJsonGeometryList(
0063 const std::string& path) {
0064 nlohmann::json data;
0065 std::vector<Acts::GeometryIdentifier> geoIdList;
0066 std::ifstream infile(path, std::ifstream::in | std::ifstream::binary);
0067 infile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
0068 infile >> data;
0069 from_json(data, geoIdList);
0070 return geoIdList;
0071 }
0072
0073 void ActsExamples::writeJsonGeometryList(
0074 const std::vector<Acts::GeometryIdentifier>& geoIdList,
0075 const std::string& path) {
0076 nlohmann::json data;
0077 to_json(data, geoIdList);
0078 std::ofstream outfile(path, std::ofstream::out | std::ofstream::binary);
0079 outfile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
0080 outfile << data;
0081 }