Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-18 08:22:23

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/Detector/Blueprint.hpp"
0012 #include "Acts/Detector/detail/BlueprintDrawer.hpp"
0013 
0014 #include <fstream>
0015 
0016 namespace Acts::Experimental {
0017 class IInternalStructureBuilder {};
0018 }  // namespace Acts::Experimental
0019 
0020 using namespace Acts;
0021 
0022 namespace ActsTests {
0023 
0024 BOOST_AUTO_TEST_SUITE(DetectorSuite)
0025 
0026 BOOST_AUTO_TEST_CASE(BlueprintTest) {
0027   std::vector<double> bValues = {0., 10., 100.};
0028 
0029   // Create  root node
0030   std::vector<AxisDirection> binning = {AxisDirection::AxisR};
0031   auto root = std::make_unique<Experimental::Gen2Blueprint::Node>(
0032       "detector", Transform3::Identity(), VolumeBounds::eOther, bValues,
0033       binning);
0034   // Check the root node
0035   BOOST_CHECK(root->isRoot());
0036   BOOST_CHECK_EQUAL(root->parent, nullptr);
0037   BOOST_CHECK(root->children.empty());
0038   BOOST_CHECK_EQUAL(root->name, "detector");
0039 
0040   auto leaf0 = std::make_unique<Experimental::Gen2Blueprint::Node>(
0041       "volume_0", Transform3::Identity(), VolumeBounds::eOther, bValues);
0042   BOOST_CHECK(leaf0->isLeaf());
0043 
0044   auto branch = std::make_unique<Experimental::Gen2Blueprint::Node>(
0045       "container_0", Transform3::Identity(), VolumeBounds::eOther, bValues,
0046       binning);
0047 
0048   auto leaf1 = std::make_unique<Experimental::Gen2Blueprint::Node>(
0049       "volume_1", Transform3::Identity(), VolumeBounds::eOther, bValues);
0050 
0051   auto leaf2 = std::make_unique<Experimental::Gen2Blueprint::Node>(
0052       "volume_2", Transform3::Identity(), VolumeBounds::eOther, bValues,
0053       std::make_shared<Experimental::IInternalStructureBuilder>());
0054 
0055   // Keep around the pointers of the branch & leaves
0056   auto* leaf0Ptr = leaf0.get();
0057   auto* leaf1Ptr = leaf1.get();
0058   auto* leaf2Ptr = leaf2.get();
0059   auto* branchPtr = branch.get();
0060 
0061   branch->add(std::move(leaf1));
0062   branch->add(std::move(leaf2));
0063 
0064   // Branch has two children
0065   BOOST_CHECK_EQUAL(branch->children.size(), 2u);
0066 
0067   // Parent of the leaves is the branch
0068   BOOST_CHECK_EQUAL(leaf1Ptr->parent, branchPtr);
0069   BOOST_CHECK_EQUAL(leaf2Ptr->parent, branchPtr);
0070 
0071   root->add(std::move(branch));
0072 
0073   // Root stays root
0074   BOOST_CHECK(root->isRoot());
0075   // Parent of the branch is the root
0076   BOOST_CHECK_EQUAL(branchPtr->parent, root.get());
0077 
0078   root->add(std::move(leaf0));
0079 
0080   // Parent of the leaf is the root
0081   BOOST_CHECK_EQUAL(leaf0Ptr->parent, root.get());
0082 
0083   std::ofstream fs("blueprint.dot");
0084   Experimental::detail::BlueprintDrawer::dotStream(fs, *root);
0085   fs.close();
0086 }
0087 
0088 BOOST_AUTO_TEST_SUITE_END()
0089 
0090 }  // namespace ActsTests