File indexing completed on 2025-01-30 09:15:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Json/GridJsonConverter.hpp"
0010
0011 #include "Acts/Plugins/Json/AlgebraJsonConverter.hpp"
0012 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0013 #include "Acts/Utilities/IAxis.hpp"
0014
0015 nlohmann::json Acts::AxisJsonConverter::toJson(const IAxis& ia) {
0016 nlohmann::json jAxis;
0017
0018 jAxis["boundary_type"] = ia.getBoundaryType();
0019
0020 if (ia.isEquidistant()) {
0021 jAxis["type"] = AxisType::Equidistant;
0022 jAxis["range"] = std::array<double, 2u>({ia.getMin(), ia.getMax()});
0023 jAxis["bins"] = ia.getNBins();
0024 } else {
0025 jAxis["type"] = AxisType::Variable;
0026 jAxis["boundaries"] = ia.getBinEdges();
0027 }
0028 return jAxis;
0029 }
0030
0031 nlohmann::json Acts::AxisJsonConverter::toJsonDetray(const IAxis& ia) {
0032 nlohmann::json jAxis;
0033 jAxis["bounds"] =
0034 ia.getBoundaryType() == Acts::AxisBoundaryType::Bound ? 1 : 2;
0035 jAxis["binning"] = ia.isEquidistant() ? 0 : 1;
0036 jAxis["bins"] = ia.getNBins();
0037 if (ia.isEquidistant()) {
0038 std::array<double, 2u> range = {ia.getBinEdges().front(),
0039 ia.getBinEdges().back()};
0040 jAxis["edges"] = range;
0041
0042 } else {
0043 jAxis["edges"] = ia.getBinEdges();
0044 }
0045 return jAxis;
0046 }
0047
0048 namespace {
0049
0050 template <typename Subspace>
0051 void encodeSubspace(
0052 nlohmann::json& jGlobalToGridLocal,
0053 const Acts::GridAccess::IGlobalToGridLocal& globalToGridLocal,
0054 const Subspace& ) {
0055 const Subspace* subspace = dynamic_cast<const Subspace*>(&globalToGridLocal);
0056 if (subspace != nullptr) {
0057 jGlobalToGridLocal["type"] = "subspace";
0058 jGlobalToGridLocal["accessors"] = subspace->axisDirs;
0059 }
0060 }
0061
0062 template <typename Subspace>
0063 void encodeTransformedSubspace(
0064 nlohmann::json& jGlobalToGridLocal,
0065 const Acts::GridAccess::IGlobalToGridLocal& globalToGridLocal,
0066 const Subspace& subscpace) {
0067 const Acts::GridAccess::Affine3Transformed<Subspace>* tsubspace =
0068 dynamic_cast<const Acts::GridAccess::Affine3Transformed<Subspace>*>(
0069 &globalToGridLocal);
0070 if (tsubspace != nullptr) {
0071 encodeSubspace(jGlobalToGridLocal, tsubspace->globalToGridLocal, subscpace);
0072 jGlobalToGridLocal["transform"] =
0073 Acts::Transform3JsonConverter::toJson(tsubspace->transform);
0074 }
0075 }
0076
0077 template <typename... Args>
0078 void encodeSubspaces(
0079 nlohmann::json& jGlobalToGridLocal,
0080 const Acts::GridAccess::IGlobalToGridLocal& globalToGridLocal,
0081 bool transformed, const std::tuple<Args...>& tAcessors) {
0082 if (transformed) {
0083 std::apply(
0084 [&](auto&&... vals) {
0085 (encodeTransformedSubspace(jGlobalToGridLocal, globalToGridLocal,
0086 vals),
0087 ...);
0088 },
0089 tAcessors);
0090 } else {
0091 std::apply(
0092 [&](auto&&... vals) {
0093 (encodeSubspace(jGlobalToGridLocal, globalToGridLocal, vals), ...);
0094 },
0095 tAcessors);
0096 }
0097 }
0098
0099 template <Acts::AxisDirection... Args>
0100 std::unique_ptr<const Acts::GridAccess::GlobalSubspace<Args...>> decodeSubspace(
0101 const nlohmann::json& ) {
0102 return std::make_unique<const Acts::GridAccess::GlobalSubspace<Args...>>();
0103 }
0104
0105 template <Acts::AxisDirection... Args>
0106 std::unique_ptr<const Acts::GridAccess::Affine3Transformed<
0107 Acts::GridAccess::GlobalSubspace<Args...>>>
0108 decodeTransformedSubspace(const nlohmann::json& jGlobalToGridLocal) {
0109 Acts::Transform3 transform = Acts::Transform3JsonConverter::fromJson(
0110 jGlobalToGridLocal.at("transform"));
0111 Acts::GridAccess::GlobalSubspace<Args...> globalSubspace;
0112 return std::make_unique<const Acts::GridAccess::Affine3Transformed<
0113 Acts::GridAccess::GlobalSubspace<Args...>>>(std::move(globalSubspace),
0114 transform);
0115 }
0116
0117 template <Acts::AxisDirection... Args>
0118 std::unique_ptr<const Acts::GridAccess::IGlobalToGridLocal>
0119 decodeGeneralSubspace(const nlohmann::json& jGlobalToGridLocal) {
0120 if (jGlobalToGridLocal.find("transform") != jGlobalToGridLocal.end()) {
0121 return decodeTransformedSubspace<Args...>(jGlobalToGridLocal);
0122 }
0123 return decodeSubspace<Args...>(jGlobalToGridLocal);
0124 }
0125
0126 template <typename Delegate, Acts::AxisDirection... Args>
0127 void decorateGlobalDelegate(Delegate& delegate,
0128 const nlohmann::json& jGlobalToGridLocal) {
0129
0130 if (delegate.connected()) {
0131 return;
0132 }
0133
0134
0135 bool hasTransform =
0136 jGlobalToGridLocal.find("transform") != jGlobalToGridLocal.end();
0137
0138
0139 std::vector<Acts::AxisDirection> accessors =
0140 jGlobalToGridLocal.at("accessors")
0141 .get<std::vector<Acts::AxisDirection>>();
0142
0143
0144 if constexpr (sizeof...(Args) == 1u) {
0145 if (std::get<0>(std::forward_as_tuple(Args...)) == accessors[0]) {
0146 if (hasTransform) {
0147 using TransformedSubspace = Acts::GridAccess::Affine3Transformed<
0148 Acts::GridAccess::GlobalSubspace<Args...>>;
0149 auto globalToGridLocal =
0150 decodeTransformedSubspace<Args...>(jGlobalToGridLocal);
0151 delegate.template connect<&TransformedSubspace::toGridLocal>(
0152 std::move(globalToGridLocal));
0153 } else {
0154 auto globalToGridLocal = decodeSubspace<Args...>(jGlobalToGridLocal);
0155 delegate.template connect<
0156 &Acts::GridAccess::GlobalSubspace<Args...>::toGridLocal>(
0157 std::move(globalToGridLocal));
0158 }
0159 }
0160 }
0161
0162
0163 if constexpr (sizeof...(Args) == 2u) {
0164 if (std::get<0>(std::forward_as_tuple(Args...)) == accessors[0] &&
0165 std::get<1>(std::forward_as_tuple(Args...)) == accessors[1]) {
0166 if (hasTransform) {
0167 using TransformedSubspace = Acts::GridAccess::Affine3Transformed<
0168 Acts::GridAccess::GlobalSubspace<Args...>>;
0169 auto globalToGridLocal =
0170 decodeTransformedSubspace<Args...>(jGlobalToGridLocal);
0171 delegate.template connect<&TransformedSubspace::toGridLocal>(
0172 std::move(globalToGridLocal));
0173 } else {
0174 auto globalToGridLocal = decodeSubspace<Args...>(jGlobalToGridLocal);
0175 delegate.template connect<
0176 &Acts::GridAccess::GlobalSubspace<Args...>::toGridLocal>(
0177 std::move(globalToGridLocal));
0178 }
0179 }
0180 }
0181 }
0182
0183 template <Acts::AxisDirection... Args>
0184 void decorateGlobal1DimDelegate(
0185 Acts::GridAccess::GlobalToGridLocal1DimDelegate& delegate,
0186 const nlohmann::json& jGlobalToGridLocal) {
0187 (((decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal1DimDelegate,
0188 Args>(delegate, jGlobalToGridLocal))),
0189 ...);
0190 }
0191
0192 }
0193
0194 nlohmann::json Acts::GridAccessJsonConverter::toJson(
0195 const GridAccess::IGlobalToGridLocal& globalToGridLocal) {
0196 nlohmann::json jGlobalToGridLocal;
0197
0198 std::array<bool, 2u> transformOptions = {false, true};
0199
0200
0201 const std::tuple<GridAccess::GlobalSubspace<AxisDirection::AxisX>,
0202 GridAccess::GlobalSubspace<AxisDirection::AxisY>,
0203 GridAccess::GlobalSubspace<AxisDirection::AxisZ>,
0204 GridAccess::GlobalSubspace<AxisDirection::AxisR>,
0205 GridAccess::GlobalSubspace<AxisDirection::AxisPhi>,
0206 GridAccess::GlobalSubspace<AxisDirection::AxisEta>>
0207 oneDimSubspaces = {};
0208
0209 for (bool transform : transformOptions) {
0210 encodeSubspaces(jGlobalToGridLocal, globalToGridLocal, transform,
0211 oneDimSubspaces);
0212 if (!jGlobalToGridLocal.empty()) {
0213 return jGlobalToGridLocal;
0214 }
0215 }
0216
0217
0218 const std::tuple<
0219 GridAccess::GlobalSubspace<AxisDirection::AxisX, AxisDirection::AxisY>,
0220 GridAccess::GlobalSubspace<AxisDirection::AxisY, AxisDirection::AxisX>,
0221 GridAccess::GlobalSubspace<AxisDirection::AxisX, AxisDirection::AxisZ>,
0222 GridAccess::GlobalSubspace<AxisDirection::AxisZ, AxisDirection::AxisX>,
0223 GridAccess::GlobalSubspace<AxisDirection::AxisY, AxisDirection::AxisZ>,
0224 GridAccess::GlobalSubspace<AxisDirection::AxisZ, AxisDirection::AxisY>,
0225 GridAccess::GlobalSubspace<AxisDirection::AxisR, AxisDirection::AxisPhi>,
0226 GridAccess::GlobalSubspace<AxisDirection::AxisPhi, AxisDirection::AxisR>,
0227 GridAccess::GlobalSubspace<AxisDirection::AxisZ, AxisDirection::AxisPhi>,
0228 GridAccess::GlobalSubspace<AxisDirection::AxisPhi, AxisDirection::AxisZ>>
0229 twoDimSubspaces = {};
0230
0231 for (bool transform : transformOptions) {
0232 encodeSubspaces(jGlobalToGridLocal, globalToGridLocal, transform,
0233 twoDimSubspaces);
0234 if (!jGlobalToGridLocal.empty()) {
0235 return jGlobalToGridLocal;
0236 }
0237 }
0238 return jGlobalToGridLocal;
0239 }
0240
0241 std::unique_ptr<const Acts::GridAccess::IGlobalToGridLocal>
0242 Acts::GridAccessJsonConverter::globalToGridLocalFromJson(
0243 const nlohmann::json& jGlobalToGridLocal) {
0244 std::unique_ptr<const Acts::GridAccess::IGlobalToGridLocal>
0245 globalToGridLocal = nullptr;
0246
0247 std::vector<AxisDirection> accessors =
0248 jGlobalToGridLocal.at("accessors").get<std::vector<AxisDirection>>();
0249
0250
0251 if (accessors.size() == 1u) {
0252 switch (accessors[0]) {
0253 case AxisDirection::AxisX:
0254 globalToGridLocal =
0255 decodeGeneralSubspace<AxisDirection::AxisX>(jGlobalToGridLocal);
0256 break;
0257 case AxisDirection::AxisY:
0258 globalToGridLocal =
0259 decodeGeneralSubspace<AxisDirection::AxisY>(jGlobalToGridLocal);
0260 break;
0261 case AxisDirection::AxisZ:
0262 globalToGridLocal =
0263 decodeGeneralSubspace<AxisDirection::AxisZ>(jGlobalToGridLocal);
0264 break;
0265 case AxisDirection::AxisR:
0266 globalToGridLocal =
0267 decodeGeneralSubspace<AxisDirection::AxisR>(jGlobalToGridLocal);
0268 break;
0269 case AxisDirection::AxisPhi:
0270 globalToGridLocal =
0271 decodeGeneralSubspace<AxisDirection::AxisPhi>(jGlobalToGridLocal);
0272 break;
0273 case AxisDirection::AxisEta:
0274 globalToGridLocal =
0275 decodeGeneralSubspace<AxisDirection::AxisEta>(jGlobalToGridLocal);
0276 break;
0277 default:
0278
0279 break;
0280 }
0281 }
0282
0283
0284 if (accessors.size() == 2u) {
0285 if (accessors == std::vector<AxisDirection>{AxisDirection::AxisX,
0286 AxisDirection::AxisY}) {
0287 globalToGridLocal =
0288 decodeGeneralSubspace<AxisDirection::AxisX, AxisDirection::AxisY>(
0289 jGlobalToGridLocal);
0290 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisY,
0291 AxisDirection::AxisX}) {
0292 globalToGridLocal =
0293 decodeGeneralSubspace<AxisDirection::AxisY, AxisDirection::AxisX>(
0294 jGlobalToGridLocal);
0295 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisX,
0296 AxisDirection::AxisZ}) {
0297 globalToGridLocal =
0298 decodeGeneralSubspace<AxisDirection::AxisX, AxisDirection::AxisZ>(
0299 jGlobalToGridLocal);
0300 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisZ,
0301 AxisDirection::AxisX}) {
0302 globalToGridLocal =
0303 decodeGeneralSubspace<AxisDirection::AxisZ, AxisDirection::AxisX>(
0304 jGlobalToGridLocal);
0305 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisY,
0306 AxisDirection::AxisZ}) {
0307 globalToGridLocal =
0308 decodeGeneralSubspace<AxisDirection::AxisY, AxisDirection::AxisZ>(
0309 jGlobalToGridLocal);
0310 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisZ,
0311 AxisDirection::AxisY}) {
0312 globalToGridLocal =
0313 decodeGeneralSubspace<AxisDirection::AxisZ, AxisDirection::AxisY>(
0314 jGlobalToGridLocal);
0315 } else if (accessors == std::vector<AxisDirection>{
0316 AxisDirection::AxisR, AxisDirection::AxisPhi}) {
0317 globalToGridLocal =
0318 decodeGeneralSubspace<AxisDirection::AxisR, AxisDirection::AxisPhi>(
0319 jGlobalToGridLocal);
0320 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisPhi,
0321 AxisDirection::AxisR}) {
0322 globalToGridLocal =
0323 decodeGeneralSubspace<AxisDirection::AxisPhi, AxisDirection::AxisR>(
0324 jGlobalToGridLocal);
0325 } else if (accessors == std::vector<AxisDirection>{
0326 AxisDirection::AxisZ, AxisDirection::AxisPhi}) {
0327 globalToGridLocal =
0328 decodeGeneralSubspace<AxisDirection::AxisZ, AxisDirection::AxisPhi>(
0329 jGlobalToGridLocal);
0330 } else if (accessors == std::vector<AxisDirection>{AxisDirection::AxisPhi,
0331 AxisDirection::AxisZ}) {
0332 globalToGridLocal =
0333 decodeGeneralSubspace<AxisDirection::AxisPhi, AxisDirection::AxisZ>(
0334 jGlobalToGridLocal);
0335 }
0336
0337 }
0338 return globalToGridLocal;
0339 }
0340
0341 Acts::GridAccess::GlobalToGridLocal1DimDelegate
0342 Acts::GridAccessJsonConverter::globalToGridLocal1DimDelegateFromJson(
0343 const nlohmann::json& jGlobalToGridLocal) {
0344
0345 if (jGlobalToGridLocal.at("accessors").size() != 1u) {
0346 throw std::invalid_argument(
0347 "GridAccessJsonConverter: json input does not describe 1D case.");
0348 }
0349
0350 Acts::GridAccess::GlobalToGridLocal1DimDelegate delegate;
0351 decorateGlobal1DimDelegate<AxisDirection::AxisX, AxisDirection::AxisY,
0352 AxisDirection::AxisZ, AxisDirection::AxisR,
0353 AxisDirection::AxisPhi, AxisDirection::AxisEta>(
0354 delegate, jGlobalToGridLocal);
0355 return delegate;
0356 }
0357
0358 Acts::GridAccess::GlobalToGridLocal2DimDelegate
0359 Acts::GridAccessJsonConverter::globalToGridLocal2DimDelegateFromJson(
0360 const nlohmann::json& jGlobalToGridLocal) {
0361
0362 if (jGlobalToGridLocal.at("accessors").size() != 2u) {
0363 throw std::invalid_argument(
0364 "GridAccessJsonConverter: json input does not describe 2D case.");
0365 }
0366
0367 Acts::GridAccess::GlobalToGridLocal2DimDelegate delegate;
0368
0369
0370 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0371 AxisDirection::AxisX, AxisDirection::AxisY>(
0372 delegate, jGlobalToGridLocal);
0373 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0374 AxisDirection::AxisY, AxisDirection::AxisX>(
0375 delegate, jGlobalToGridLocal);
0376 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0377 AxisDirection::AxisX, AxisDirection::AxisZ>(
0378 delegate, jGlobalToGridLocal);
0379 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0380 AxisDirection::AxisZ, AxisDirection::AxisX>(
0381 delegate, jGlobalToGridLocal);
0382 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0383 AxisDirection::AxisY, AxisDirection::AxisZ>(
0384 delegate, jGlobalToGridLocal);
0385 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0386 AxisDirection::AxisZ, AxisDirection::AxisY>(
0387 delegate, jGlobalToGridLocal);
0388 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0389 AxisDirection::AxisR, AxisDirection::AxisPhi>(
0390 delegate, jGlobalToGridLocal);
0391 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0392 AxisDirection::AxisPhi, AxisDirection::AxisR>(
0393 delegate, jGlobalToGridLocal);
0394 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0395 AxisDirection::AxisZ, AxisDirection::AxisPhi>(
0396 delegate, jGlobalToGridLocal);
0397 decorateGlobalDelegate<Acts::GridAccess::GlobalToGridLocal2DimDelegate,
0398 AxisDirection::AxisPhi, AxisDirection::AxisZ>(
0399 delegate, jGlobalToGridLocal);
0400 return delegate;
0401 }
0402
0403 nlohmann::json Acts::GridAccessJsonConverter::toJson(
0404 const GridAccess::IBoundToGridLocal& boundToGridLocal) {
0405 nlohmann::json jBoundToGridLocal;
0406
0407 auto localSubSpace0 =
0408 dynamic_cast<const GridAccess::LocalSubspace<0u>*>(&boundToGridLocal);
0409 if (localSubSpace0 != nullptr) {
0410 jBoundToGridLocal["type"] = "subspace";
0411 jBoundToGridLocal["accessors"] = localSubSpace0->accessors;
0412 }
0413
0414 auto localSubSpace1 =
0415 dynamic_cast<const GridAccess::LocalSubspace<1u>*>(&boundToGridLocal);
0416 if (localSubSpace1 != nullptr) {
0417 jBoundToGridLocal["type"] = "subspace";
0418 jBoundToGridLocal["accessors"] = localSubSpace1->accessors;
0419 }
0420
0421 auto localSubSpace01 =
0422 dynamic_cast<const GridAccess::LocalSubspace<0u, 1u>*>(&boundToGridLocal);
0423 if (localSubSpace01 != nullptr) {
0424 jBoundToGridLocal["type"] = "subspace";
0425 jBoundToGridLocal["accessors"] = localSubSpace01->accessors;
0426 }
0427
0428 auto localSubSpace10 =
0429 dynamic_cast<const GridAccess::LocalSubspace<1u, 0u>*>(&boundToGridLocal);
0430 if (localSubSpace10 != nullptr) {
0431 jBoundToGridLocal["type"] = "subspace";
0432 jBoundToGridLocal["accessors"] = localSubSpace10->accessors;
0433 }
0434
0435 auto boundCylinderToZPhi =
0436 dynamic_cast<const GridAccess::BoundCylinderToZPhi*>(&boundToGridLocal);
0437 if (boundCylinderToZPhi != nullptr) {
0438 jBoundToGridLocal["type"] = "cylinder_to_zphi";
0439 jBoundToGridLocal["radius"] = boundCylinderToZPhi->radius;
0440 jBoundToGridLocal["shift"] = boundCylinderToZPhi->shift;
0441 }
0442
0443 if (jBoundToGridLocal.empty()) {
0444 throw std::invalid_argument(
0445 "GridAccessJsonConverter: boundToGridLocal type not supported.");
0446 }
0447
0448 return jBoundToGridLocal;
0449 }
0450
0451 std::unique_ptr<Acts::GridAccess::IBoundToGridLocal>
0452 Acts::GridAccessJsonConverter::boundToGridLocalFromJson(
0453 const nlohmann::json& jBoundToGridLocal) {
0454 std::unique_ptr<Acts::GridAccess::IBoundToGridLocal> boundToGridLocal =
0455 nullptr;
0456 std::string type = jBoundToGridLocal.at("type").get<std::string>();
0457 if (type == "subspace") {
0458 std::vector<std::size_t> accessors =
0459 jBoundToGridLocal.at("accessors").get<std::vector<std::size_t>>();
0460 if (accessors.size() == 1 && accessors[0] == 0) {
0461 boundToGridLocal =
0462 std::make_unique<Acts::GridAccess::LocalSubspace<0u>>();
0463 } else if (accessors.size() == 1 && accessors[0] == 1) {
0464 boundToGridLocal =
0465 std::make_unique<Acts::GridAccess::LocalSubspace<1u>>();
0466 } else if (accessors.size() == 2 && accessors[0] == 0 &&
0467 accessors[1] == 1) {
0468 boundToGridLocal =
0469 std::make_unique<Acts::GridAccess::LocalSubspace<0u, 1u>>();
0470 } else if (accessors.size() == 2 && accessors[0] == 1 &&
0471 accessors[1] == 0) {
0472 boundToGridLocal =
0473 std::make_unique<Acts::GridAccess::LocalSubspace<1u, 0u>>();
0474 }
0475 } else if (type == "cylinder_to_zphi") {
0476 double radius = jBoundToGridLocal.at("radius").get<double>();
0477 double shift = jBoundToGridLocal.at("shift").get<double>();
0478 boundToGridLocal =
0479 std::make_unique<Acts::GridAccess::BoundCylinderToZPhi>(radius, shift);
0480 }
0481 return boundToGridLocal;
0482 }
0483
0484 Acts::GridAccess::BoundToGridLocal1DimDelegate
0485 Acts::GridAccessJsonConverter::boundToGridLocal1DimDelegateFromJson(
0486 const nlohmann::json& jBoundToGridLocal) {
0487 Acts::GridAccess::BoundToGridLocal1DimDelegate delegate;
0488
0489 std::string type = jBoundToGridLocal.at("type").get<std::string>();
0490 if (type == "subspace") {
0491 std::vector<std::size_t> accessors =
0492 jBoundToGridLocal.at("accessors").get<std::vector<std::size_t>>();
0493
0494 if (accessors.size() != 1u) {
0495 throw std::invalid_argument(
0496 "GridAccessJsonConverter: json input does not describe 1D case.");
0497 }
0498
0499 if (accessors[0] == 0) {
0500 auto boundToGridLocal =
0501 std::make_unique<const Acts::GridAccess::LocalSubspace<0u>>();
0502 delegate.connect<&Acts::GridAccess::LocalSubspace<0u>::toGridLocal>(
0503 std::move(boundToGridLocal));
0504 } else if (accessors[0] == 1) {
0505 auto boundToGridLocal =
0506 std::make_unique<const Acts::GridAccess::LocalSubspace<1u>>();
0507 delegate.connect<&Acts::GridAccess::LocalSubspace<1u>::toGridLocal>(
0508 std::move(boundToGridLocal));
0509 }
0510 }
0511 return delegate;
0512 }
0513
0514 Acts::GridAccess::BoundToGridLocal2DimDelegate
0515 Acts::GridAccessJsonConverter::boundToGridLocal2DimDelegateFromJson(
0516 const nlohmann::json& jBoundToGridLocal) {
0517 Acts::GridAccess::BoundToGridLocal2DimDelegate delegate;
0518
0519 std::string type = jBoundToGridLocal.at("type").get<std::string>();
0520 if (type == "subspace") {
0521 std::vector<std::size_t> accessors =
0522 jBoundToGridLocal.at("accessors").get<std::vector<std::size_t>>();
0523
0524
0525 if (accessors.size() != 2u) {
0526 throw std::invalid_argument(
0527 "GridAccessJsonConverter: json input does not describe 2D case.");
0528 }
0529 if (accessors[0] == 0u && accessors[1] == 1u) {
0530 auto boundToGridLocal =
0531 std::make_unique<const Acts::GridAccess::LocalSubspace<0u, 1u>>();
0532 delegate.connect<&Acts::GridAccess::LocalSubspace<0u, 1u>::toGridLocal>(
0533 std::move(boundToGridLocal));
0534 } else if (accessors[0] == 1u && accessors[1] == 0u) {
0535 auto boundToGridLocal =
0536 std::make_unique<const Acts::GridAccess::LocalSubspace<1u, 0u>>();
0537 delegate.connect<&Acts::GridAccess::LocalSubspace<1u, 0u>::toGridLocal>(
0538 std::move(boundToGridLocal));
0539 }
0540 } else if (type == "cylinder_to_zphi") {
0541 double radius = jBoundToGridLocal.at("radius").get<double>();
0542 double shift = jBoundToGridLocal.at("shift").get<double>();
0543 auto boundToGridLocal =
0544 std::make_unique<const Acts::GridAccess::BoundCylinderToZPhi>(radius,
0545 shift);
0546 delegate.connect<&Acts::GridAccess::BoundCylinderToZPhi::toGridLocal>(
0547 std::move(boundToGridLocal));
0548 }
0549
0550 return delegate;
0551 }