Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 07:36:09

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/Definitions/Units.hpp"
0012 #include "Acts/EventData/SourceLink.hpp"
0013 #include "Acts/EventData/detail/TestSourceLink.hpp"
0014 #include "Acts/Geometry/GeometryIdentifier.hpp"
0015 
0016 #include <any>
0017 #include <sstream>
0018 
0019 using namespace Acts;
0020 using namespace Acts::UnitLiterals;
0021 
0022 namespace ActsTests {
0023 
0024 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0025 
0026 BOOST_AUTO_TEST_CASE(TestSourceLinkCoverage) {
0027   using detail::Test::TestSourceLink;
0028 
0029   Vector2 stddev(0.01, 0.1);
0030   SquareMatrix2 cov = stddev.cwiseProduct(stddev).asDiagonal();
0031   TestSourceLink l1(eBoundLoc0, 0.1, cov(0, 0), GeometryIdentifier(0x999), 0);
0032   TestSourceLink l2(l1);
0033 
0034   BOOST_CHECK(l1 == l2);     // testing the ==
0035   BOOST_CHECK(!(l1 != l2));  // testing the !=
0036   std::ostringstream str;
0037   str << l1;
0038 }
0039 
0040 struct MySourceLink {
0041   GeometryIdentifier m_geometryId;
0042 
0043   GeometryIdentifier geometryId() const { return m_geometryId; }
0044 };
0045 
0046 BOOST_AUTO_TEST_CASE(Construct) {
0047   MySourceLink msl;
0048   msl.m_geometryId = GeometryIdentifier().withSensitive(42);
0049   {
0050     SourceLink sl{msl};
0051     BOOST_CHECK_EQUAL(sl.get<MySourceLink>().geometryId(), msl.geometryId());
0052     BOOST_CHECK_THROW(sl.get<int>(), std::bad_any_cast);
0053   }
0054 }
0055 
0056 BOOST_AUTO_TEST_CASE(GetPtr) {
0057   {
0058     // correct type returns non-null pointer
0059     MySourceLink msl;
0060     msl.m_geometryId = GeometryIdentifier().withSensitive(7);
0061     SourceLink sl{msl};
0062 
0063     auto* p = sl.getPtr<MySourceLink>();
0064     BOOST_REQUIRE_NE(p, static_cast<MySourceLink*>(nullptr));
0065     BOOST_CHECK_EQUAL(p->geometryId(), msl.geometryId());
0066 
0067     // wrong type returns nullptr
0068     BOOST_CHECK_EQUAL(sl.getPtr<int>(), static_cast<int*>(nullptr));
0069     BOOST_CHECK_EQUAL(sl.getPtr<double>(), static_cast<double*>(nullptr));
0070   }
0071 
0072   {
0073     // const overload
0074     int value = 42;
0075     const SourceLink sl{value};
0076 
0077     const int* p = sl.getPtr<int>();
0078     BOOST_REQUIRE_NE(p, static_cast<const int*>(nullptr));
0079     BOOST_CHECK_EQUAL(*p, 42);
0080 
0081     BOOST_CHECK_EQUAL(sl.getPtr<float>(), static_cast<const float*>(nullptr));
0082   }
0083 
0084   {
0085     // mutation through pointer
0086     int value = 10;
0087     SourceLink sl{value};
0088     int* p = sl.getPtr<int>();
0089     BOOST_REQUIRE_NE(p, static_cast<int*>(nullptr));
0090     *p = 99;
0091     BOOST_CHECK_EQUAL(sl.get<int>(), 99);
0092   }
0093 }
0094 
0095 BOOST_AUTO_TEST_CASE(Reassign) {
0096   int value = 5;
0097   SourceLink sl{value};
0098 
0099   BOOST_CHECK_EQUAL(sl.get<int>(), value);
0100   BOOST_CHECK_THROW(sl.get<double>(), std::bad_any_cast);
0101 
0102   double otherValue = 42.42;
0103 
0104   // this changes the stored type
0105   sl = SourceLink{otherValue};
0106   BOOST_CHECK_EQUAL(sl.get<double>(), otherValue);
0107   BOOST_CHECK_THROW(sl.get<int>(), std::bad_any_cast);
0108 }
0109 
0110 BOOST_AUTO_TEST_SUITE_END()
0111 
0112 }  // namespace ActsTests