Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:35

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "ActsPlugins/Json/GeometryIdentifierJsonConverter.hpp"
0012 
0013 #include <nlohmann/json.hpp>
0014 
0015 using namespace Acts;
0016 
0017 namespace ActsTests {
0018 
0019 BOOST_AUTO_TEST_SUITE(JsonSuite)
0020 
0021 BOOST_AUTO_TEST_CASE(ReadingWritingFull) {
0022   GeometryIdentifier geoId = GeometryIdentifier()
0023                                  .withVolume(1)
0024                                  .withBoundary(2)
0025                                  .withLayer(3)
0026                                  .withApproach(4)
0027                                  .withSensitive(5)
0028                                  .withExtra(6);
0029 
0030   nlohmann::json j = GeometryIdentifierJsonConverter::encodeIdentifier(geoId);
0031 
0032   BOOST_CHECK_EQUAL(j["volume"], 1);
0033   BOOST_CHECK_EQUAL(j["boundary"], 2);
0034   BOOST_CHECK_EQUAL(j["layer"], 3);
0035   BOOST_CHECK_EQUAL(j["approach"], 4);
0036   BOOST_CHECK_EQUAL(j["sensitive"], 5);
0037   BOOST_CHECK_EQUAL(j["extra"], 6);
0038 
0039   // or simply
0040   nlohmann::json j2 = nlohmann::json(geoId);
0041   BOOST_CHECK_EQUAL(j2["volume"], 1);
0042   BOOST_CHECK_EQUAL(j2["boundary"], 2);
0043   BOOST_CHECK_EQUAL(j2["layer"], 3);
0044   BOOST_CHECK_EQUAL(j2["approach"], 4);
0045   BOOST_CHECK_EQUAL(j2["sensitive"], 5);
0046   BOOST_CHECK_EQUAL(j2["extra"], 6);
0047 
0048   GeometryIdentifier geoId2 =
0049       GeometryIdentifierJsonConverter::decodeIdentifier(j);
0050   BOOST_CHECK_EQUAL(geoId2.volume(), 1);
0051   BOOST_CHECK_EQUAL(geoId2.boundary(), 2);
0052   BOOST_CHECK_EQUAL(geoId2.layer(), 3);
0053   BOOST_CHECK_EQUAL(geoId2.approach(), 4);
0054   BOOST_CHECK_EQUAL(geoId2.sensitive(), 5);
0055   BOOST_CHECK_EQUAL(geoId2.extra(), 6);
0056   // or simply
0057   GeometryIdentifier geoId3 = j2.get<GeometryIdentifier>();
0058   BOOST_CHECK_EQUAL(geoId3.volume(), 1);
0059   BOOST_CHECK_EQUAL(geoId3.boundary(), 2);
0060   BOOST_CHECK_EQUAL(geoId3.layer(), 3);
0061   BOOST_CHECK_EQUAL(geoId3.approach(), 4);
0062   BOOST_CHECK_EQUAL(geoId3.sensitive(), 5);
0063   BOOST_CHECK_EQUAL(geoId3.extra(), 6);
0064 }
0065 
0066 BOOST_AUTO_TEST_CASE(ReadingWritingCompact) {
0067   GeometryIdentifier geoId = GeometryIdentifier()
0068                                  .withVolume(1)
0069                                  .withBoundary(2)
0070                                  .withLayer(3)
0071                                  .withApproach(4)
0072                                  .withSensitive(5)
0073                                  .withExtra(6);
0074 
0075   nlohmann::json j =
0076       GeometryIdentifierJsonConverter::encodeIdentifier(geoId, true);
0077 
0078   auto value = j.get<GeometryIdentifier::Value>();
0079   BOOST_CHECK_EQUAL(value, geoId.value());
0080 
0081   // Rely on the auto-detection of the compact reading
0082   GeometryIdentifier geoIdCompact = j.get<GeometryIdentifier>();
0083   BOOST_CHECK_EQUAL(geoIdCompact.volume(), 1);
0084   BOOST_CHECK_EQUAL(geoIdCompact.boundary(), 2);
0085   BOOST_CHECK_EQUAL(geoIdCompact.layer(), 3);
0086   BOOST_CHECK_EQUAL(geoIdCompact.approach(), 4);
0087   BOOST_CHECK_EQUAL(geoIdCompact.sensitive(), 5);
0088   BOOST_CHECK_EQUAL(geoIdCompact.extra(), 6);
0089 }
0090 
0091 BOOST_AUTO_TEST_SUITE_END()
0092 
0093 }  // namespace ActsTests