Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more unit tests for Json writing #2693

2 changes: 1 addition & 1 deletion Core/include/Acts/Navigation/DetectorVolumeFinders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct IndexedDetectorVolumeExtractor {
///
/// @tparam grid_type is the grid type used for this
template <typename grid_type>
using IndexedDetectorVolumeImpl =
using IndexedDetectorVolumesImpl =
IndexedUpdatorImpl<grid_type, IndexedDetectorVolumeExtractor,
DetectorVolumeFiller>;

Expand Down
2 changes: 0 additions & 2 deletions Core/src/Detector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ target_sources(
GeometryIdGenerator.cpp
VolumeStructureBuilder.cpp
MultiWireStructureBuilder.cpp


)
7 changes: 4 additions & 3 deletions Core/src/Detector/IndexedRootVolumeFinderBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ Acts::Experimental::IndexedRootVolumeFinderBuilder::construct(
std::array<std::vector<ActsScalar>, 2u>{rzphis[1], rzphis[0]};
fillGridIndices2D(gctx, grid, rootVolumes, boundaries, casts);

using IndexedDetectorVolumeImpl =
using IndexedDetectorVolumesImpl =
IndexedUpdatorImpl<GridType, IndexedDetectorVolumeExtractor,
DetectorVolumeFiller>;

auto indexedDetectorVolumeImpl =
std::make_unique<const IndexedDetectorVolumeImpl>(std::move(grid), casts);
std::make_unique<const IndexedDetectorVolumesImpl>(std::move(grid),
casts);

// Return the root volume finder
DetectorVolumeUpdator rootVolumeFinder;
rootVolumeFinder.connect<&IndexedDetectorVolumeImpl::update>(
rootVolumeFinder.connect<&IndexedDetectorVolumesImpl::update>(
std::move(indexedDetectorVolumeImpl));
return rootVolumeFinder;
}
8 changes: 4 additions & 4 deletions Plugins/Json/src/DetectorVolumeFinderJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ struct IndexedVolumesGenerator {
grid_type&& grid,
const std::array<Acts::BinningValue, grid_type::DIM>& bv,
const Acts::Transform3& transform) {
using IndexedDetectorVolumeImpl = Acts::Experimental::IndexedUpdatorImpl<
using IndexedDetectorVolumesImpl = Acts::Experimental::IndexedUpdatorImpl<
grid_type, Acts::Experimental::IndexedDetectorVolumeExtractor,
Acts::Experimental::DetectorVolumeFiller>;

auto indexedDetectorVolumeImpl =
std::make_unique<const IndexedDetectorVolumeImpl>(std::move(grid), bv,
transform);
std::make_unique<const IndexedDetectorVolumesImpl>(std::move(grid), bv,
transform);

// Create the delegate and connect it
Acts::Experimental::DetectorVolumeUpdator vFinder;
vFinder.connect<&IndexedDetectorVolumeImpl::update>(
vFinder.connect<&IndexedDetectorVolumesImpl::update>(
std::move(indexedDetectorVolumeImpl));
return vFinder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ BOOST_AUTO_TEST_CASE(IndexedDetectorVolumeFinder) {
g.atPosition(std::array<Acts::ActsScalar, 1u>{50.}) = 1u;
g.atPosition(std::array<Acts::ActsScalar, 1u>{150.}) = 2u;

Acts::Experimental::IndexedDetectorVolumeImpl<decltype(g)> idv(std::move(g),
{Acts::binR});
Acts::Experimental::IndexedDetectorVolumesImpl<decltype(g)> idv(std::move(g),
{Acts::binR});

// Cylinder 0
nState.position = Acts::Vector3(5., 0., 0.);
Expand Down
2 changes: 2 additions & 0 deletions Tests/UnitTests/Plugins/Json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ set(unittest_extra_libraries ActsPluginJson)
add_unittest(AlgebraJsonConverter AlgebraJsonConverterTests.cpp)
add_unittest(DetectorJsonConverter DetectorJsonConverterTests.cpp)
add_unittest(DetectorVolumeJsonConverter DetectorVolumeJsonConverterTests.cpp)
add_unittest(DetectorVolumeFinderJsonConverter DetectorVolumeFinderJsonConverterTests.cpp)
add_unittest(ExtentJsonConverter ExtentJsonConverterTests.cpp)
add_unittest(GeometryHierarchyMapJsonConverter GeometryHierarchyMapJsonConverterTests.cpp)
add_unittest(GridJsonConverter GridJsonConverterTests.cpp)
add_unittest(MaterialMapJsonConverter MaterialMapJsonConverterTests.cpp)
add_unittest(PortalJsonConverter PortalJsonConverterTests.cpp)
add_unittest(ProtoDetectorJsonConverter ProtoDetectorJsonConverterTests.cpp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <boost/test/unit_test.hpp>

#include "Acts/Detector/detail/GridAxisGenerators.hpp"
#include "Acts/Navigation/DetectorVolumeFinders.hpp"
#include "Acts/Navigation/DetectorVolumeUpdators.hpp"
#include "Acts/Plugins/Json/DetectorVolumeFinderJsonConverter.hpp"

#include <fstream>
#include <memory>
#include <vector>

#include <nlohmann/json.hpp>

BOOST_AUTO_TEST_SUITE(DetectorVolumeFinderJsonConverter)

BOOST_AUTO_TEST_CASE(RzVolumes) {
std::vector<Acts::ActsScalar> zBoundaries = {-1000., -500, 150.};
std::vector<Acts::ActsScalar> rBoundaries = {0., 10., 30., 35.};

using AxesGeneratorType =
Acts::Experimental::detail::GridAxisGenerators::VarBoundVarBound;

AxesGeneratorType zrAxes{zBoundaries, rBoundaries};

// Create the grid with the provided axis generator
using GridType = typename AxesGeneratorType::template grid_type<std::size_t>;
GridType grid(zrAxes());

using PointType = typename GridType::point_t;

PointType p11 = {-800., 5.};
PointType p12 = {-800., 20.};
PointType p13 = {-800., 32.};

grid.atPosition(p11) = 11u;
grid.atPosition(p12) = 12u;
grid.atPosition(p13) = 13u;

PointType p21 = {0., 5.};
PointType p22 = {0., 20.};
PointType p23 = {0., 32.};

grid.atPosition(p21) = 21u;
grid.atPosition(p22) = 22u;
grid.atPosition(p23) = 23u;

auto casts = std::array<Acts::BinningValue, 2u>{Acts::binZ, Acts::binR};

using IndexedDetectorVolumesImpl = Acts::Experimental::IndexedUpdatorImpl<
GridType, Acts::Experimental::IndexedDetectorVolumeExtractor,
Acts::Experimental::DetectorVolumeFiller>;

auto indexedDetectorVolumesImpl =
std::make_unique<const IndexedDetectorVolumesImpl>(std::move(grid),
casts);

// Return the root volume finder
Acts::Experimental::DetectorVolumeUpdator rootVolumeFinder;
rootVolumeFinder.connect<&IndexedDetectorVolumesImpl::update>(
std::move(indexedDetectorVolumesImpl));

nlohmann::json rFinderJson =
Acts::DetectorVolumeFinderJsonConverter::toJson(rootVolumeFinder);

auto readInRootVolumeFinder =
Acts::DetectorVolumeFinderJsonConverter::fromJson(rFinderJson);

BOOST_REQUIRE(readInRootVolumeFinder.instance() != nullptr);

auto readInIndexedDetectorVolumesImpl =
dynamic_cast<const IndexedDetectorVolumesImpl*>(
readInRootVolumeFinder.instance());

BOOST_REQUIRE(readInIndexedDetectorVolumesImpl != nullptr);

const auto& gridRead = readInIndexedDetectorVolumesImpl->grid;

BOOST_CHECK_EQUAL(gridRead.atPosition(p11), 11u);
BOOST_CHECK_EQUAL(gridRead.atPosition(p12), 12u);
BOOST_CHECK_EQUAL(gridRead.atPosition(p13), 13u);
BOOST_CHECK_EQUAL(gridRead.atPosition(p21), 21u);
BOOST_CHECK_EQUAL(gridRead.atPosition(p22), 22u);
BOOST_CHECK_EQUAL(gridRead.atPosition(p23), 23u);
}

BOOST_AUTO_TEST_SUITE_END()
Loading
Loading