Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 07:49:54

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 "Acts/Plugins/Json/GeometryIdentifierJsonConverter.hpp"
0012 
0013 #include <nlohmann/json.hpp>
0014 
0015 using namespace Acts;
0016 
0017 BOOST_AUTO_TEST_SUITE(GeometryIdentifierJsonConverterTests)
0018 
0019 BOOST_AUTO_TEST_CASE(ReadingWritingFull) {
0020   GeometryIdentifier geoId = GeometryIdentifier()
0021                                  .withVolume(1)
0022                                  .withBoundary(2)
0023                                  .withLayer(3)
0024                                  .withApproach(4)
0025                                  .withSensitive(5)
0026                                  .withExtra(6);
0027 
0028   nlohmann::json j = GeometryIdentifierJsonConverter::encodeIdentifier(geoId);
0029 
0030   BOOST_CHECK_EQUAL(j["volume"], 1);
0031   BOOST_CHECK_EQUAL(j["boundary"], 2);
0032   BOOST_CHECK_EQUAL(j["layer"], 3);
0033   BOOST_CHECK_EQUAL(j["approach"], 4);
0034   BOOST_CHECK_EQUAL(j["sensitive"], 5);
0035   BOOST_CHECK_EQUAL(j["extra"], 6);
0036 
0037   // or simply
0038   nlohmann::json j2 = nlohmann::json(geoId);
0039   BOOST_CHECK_EQUAL(j2["volume"], 1);
0040   BOOST_CHECK_EQUAL(j2["boundary"], 2);
0041   BOOST_CHECK_EQUAL(j2["layer"], 3);
0042   BOOST_CHECK_EQUAL(j2["approach"], 4);
0043   BOOST_CHECK_EQUAL(j2["sensitive"], 5);
0044   BOOST_CHECK_EQUAL(j2["extra"], 6);
0045 
0046   GeometryIdentifier geoId2 =
0047       GeometryIdentifierJsonConverter::decodeIdentifier(j);
0048   BOOST_CHECK_EQUAL(geoId2.volume(), 1);
0049   BOOST_CHECK_EQUAL(geoId2.boundary(), 2);
0050   BOOST_CHECK_EQUAL(geoId2.layer(), 3);
0051   BOOST_CHECK_EQUAL(geoId2.approach(), 4);
0052   BOOST_CHECK_EQUAL(geoId2.sensitive(), 5);
0053   BOOST_CHECK_EQUAL(geoId2.extra(), 6);
0054   // or simply
0055   GeometryIdentifier geoId3 = j2.get<GeometryIdentifier>();
0056   BOOST_CHECK_EQUAL(geoId3.volume(), 1);
0057   BOOST_CHECK_EQUAL(geoId3.boundary(), 2);
0058   BOOST_CHECK_EQUAL(geoId3.layer(), 3);
0059   BOOST_CHECK_EQUAL(geoId3.approach(), 4);
0060   BOOST_CHECK_EQUAL(geoId3.sensitive(), 5);
0061   BOOST_CHECK_EQUAL(geoId3.extra(), 6);
0062 }
0063 
0064 BOOST_AUTO_TEST_CASE(ReadingWritingCompact) {
0065   GeometryIdentifier geoId = GeometryIdentifier()
0066                                  .withVolume(1)
0067                                  .withBoundary(2)
0068                                  .withLayer(3)
0069                                  .withApproach(4)
0070                                  .withSensitive(5)
0071                                  .withExtra(6);
0072 
0073   nlohmann::json j =
0074       GeometryIdentifierJsonConverter::encodeIdentifier(geoId, true);
0075 
0076   auto value = j.get<GeometryIdentifier::Value>();
0077   BOOST_CHECK_EQUAL(value, geoId.value());
0078 
0079   // Rely on the auto-detection of the compact reading
0080   GeometryIdentifier geoIdCompact = j.get<GeometryIdentifier>();
0081   BOOST_CHECK_EQUAL(geoIdCompact.volume(), 1);
0082   BOOST_CHECK_EQUAL(geoIdCompact.boundary(), 2);
0083   BOOST_CHECK_EQUAL(geoIdCompact.layer(), 3);
0084   BOOST_CHECK_EQUAL(geoIdCompact.approach(), 4);
0085   BOOST_CHECK_EQUAL(geoIdCompact.sensitive(), 5);
0086   BOOST_CHECK_EQUAL(geoIdCompact.extra(), 6);
0087 }
0088 
0089 BOOST_AUTO_TEST_SUITE_END()