Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BlueprintTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BlueprintTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
12 
13 #include <fstream>
14 
15 namespace Acts {
16 namespace Experimental {
17 class IInternalStructureBuilder {};
18 } // namespace Experimental
19 } // namespace Acts
20 
21 BOOST_AUTO_TEST_SUITE(Experimental)
22 
23 BOOST_AUTO_TEST_CASE(BlueprintTest) {
24  std::vector<Acts::ActsScalar> bValues = {0., 10., 100.};
25 
26  // Create root node
27  std::vector<Acts::BinningValue> binning = {Acts::binR};
28  auto root = std::make_unique<Acts::Experimental::Blueprint::Node>(
29  "detector", Acts::Transform3::Identity(), Acts::VolumeBounds::eOther,
30  bValues, binning);
31  // Check the root node
32  BOOST_CHECK(root->isRoot());
33  BOOST_CHECK(root->parent == nullptr);
34  BOOST_CHECK(root->children.empty());
35  BOOST_CHECK(root->name == "detector");
36 
37  auto leaf0 = std::make_unique<Acts::Experimental::Blueprint::Node>(
38  "volume_0", Acts::Transform3::Identity(), Acts::VolumeBounds::eOther,
39  bValues);
40  BOOST_CHECK(leaf0->isLeaf());
41 
42  auto branch = std::make_unique<Acts::Experimental::Blueprint::Node>(
43  "container_0", Acts::Transform3::Identity(), Acts::VolumeBounds::eOther,
44  bValues, binning);
45 
46  auto leaf1 = std::make_unique<Acts::Experimental::Blueprint::Node>(
47  "volume_1", Acts::Transform3::Identity(), Acts::VolumeBounds::eOther,
48  bValues);
49 
50  auto leaf2 = std::make_unique<Acts::Experimental::Blueprint::Node>(
51  "volume_2", Acts::Transform3::Identity(), Acts::VolumeBounds::eOther,
52  bValues,
53  std::make_shared<Acts::Experimental::IInternalStructureBuilder>());
54 
55  // Keep around the pointers of the branch & leaves
56  auto* leaf0Ptr = leaf0.get();
57  auto* leaf1Ptr = leaf1.get();
58  auto* leaf2Ptr = leaf2.get();
59  auto* branchPtr = branch.get();
60 
61  branch->add(std::move(leaf1));
62  branch->add(std::move(leaf2));
63 
64  // Branch has two children
65  BOOST_CHECK(branch->children.size() == 2u);
66 
67  // Parent of the leaves is the branch
68  BOOST_CHECK(leaf1Ptr->parent == branchPtr);
69  BOOST_CHECK(leaf2Ptr->parent == branchPtr);
70 
71  root->add(std::move(branch));
72 
73  // Root stays root
74  BOOST_CHECK(root->isRoot());
75  // Parent of the branch is the root
76  BOOST_CHECK(branchPtr->parent == root.get());
77 
78  root->add(std::move(leaf0));
79 
80  // Parent of the leaf is the root
81  BOOST_CHECK(leaf0Ptr->parent == root.get());
82 
83  std::ofstream fs("blueprint.dot");
84  root->dotStream(fs);
85  fs.close();
86 }
87 
88 BOOST_AUTO_TEST_SUITE_END()