Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:11

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/Material/ISurfaceMaterial.hpp"
0012 #include "Acts/Plugins/Json/IVolumeMaterialJsonDecorator.hpp"
0013 #include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp"
0014 #include "Acts/Tests/CommonHelpers/DataDirectory.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 
0017 #include <fstream>
0018 #include <memory>
0019 
0020 #include <nlohmann/json.hpp>
0021 
0022 namespace Acts {
0023 class IVolumeMaterial;
0024 }  // namespace Acts
0025 
0026 class DummyDecorator : public Acts::IVolumeMaterialJsonDecorator {
0027  public:
0028   void decorate([[maybe_unused]] const Acts::ISurfaceMaterial &material,
0029                 [[maybe_unused]] nlohmann::json &json) const override {};
0030 
0031   void decorate([[maybe_unused]] const Acts::IVolumeMaterial &material,
0032                 [[maybe_unused]] nlohmann::json &json) const override {};
0033 };
0034 
0035 BOOST_AUTO_TEST_SUITE(MaterialMapJsonConverter)
0036 
0037 BOOST_AUTO_TEST_CASE(RoundtripFromFile) {
0038   // read reference map from file
0039   std::ifstream refFile(Acts::Test::getDataPath("material-map.json"));
0040   nlohmann::json refJson;
0041   refFile >> refJson;
0042 
0043   DummyDecorator decorator;
0044   // convert to the material map and back again
0045   Acts::MaterialMapJsonConverter::Config converterCfg;
0046   Acts::MaterialMapJsonConverter converter(converterCfg, Acts::Logging::INFO);
0047   auto materialMap = converter.jsonToMaterialMaps(refJson);
0048   nlohmann::json encodedJson =
0049       converter.materialMapsToJson(materialMap, &decorator);
0050 
0051   // verify identical encoded JSON values
0052   BOOST_CHECK_EQUAL(refJson, encodedJson);
0053 }
0054 
0055 BOOST_AUTO_TEST_SUITE_END()