diff --git a/Core/include/ACTS/Surfaces/DiamondBounds.hpp b/Core/include/ACTS/Surfaces/DiamondBounds.hpp index a6a5acd6fb287c9f87412a8744a8daa85a1c8ec0..b67b9f94d959b14b06afb35cc83421d601b2487f 100644 --- a/Core/include/ACTS/Surfaces/DiamondBounds.hpp +++ b/Core/include/ACTS/Surfaces/DiamondBounds.hpp @@ -19,6 +19,7 @@ #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" #include "ACTS/Utilities/ParameterDefinitions.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { @@ -118,6 +119,9 @@ public: /// This method returns the halflength in Y of trapezoid at positive Y double halflengthY2() const; + + variant_data + toVariantData() const override; private: double m_minHalfX, m_medHalfX, m_maxHalfX; diff --git a/Core/include/ACTS/Surfaces/EllipseBounds.hpp b/Core/include/ACTS/Surfaces/EllipseBounds.hpp index 33c985b6b686ad93d3ffd6f94c5be396ed7d3621..479fac5d396212667b515a15e583d3d4330abee4 100644 --- a/Core/include/ACTS/Surfaces/EllipseBounds.hpp +++ b/Core/include/ACTS/Surfaces/EllipseBounds.hpp @@ -19,6 +19,7 @@ #include "ACTS/Surfaces/PlanarBounds.hpp" #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { @@ -126,6 +127,9 @@ public: /// This method returns the halfPhiSector which is covered by the disc double halfPhiSector() const; + + variant_data + toVariantData() const override; private: double m_rMinX, m_rMinY, m_rMaxX, m_rMaxY, m_avgPhi, m_halfPhi; diff --git a/Core/include/ACTS/Surfaces/PlanarBounds.hpp b/Core/include/ACTS/Surfaces/PlanarBounds.hpp index 3db6616d4f171fc542a7f870b92976de6bc3acc6..9e61ccd83426fa1071bbfba288fef3004072fbde 100644 --- a/Core/include/ACTS/Surfaces/PlanarBounds.hpp +++ b/Core/include/ACTS/Surfaces/PlanarBounds.hpp @@ -16,6 +16,7 @@ #include <vector> #include "ACTS/Surfaces/SurfaceBounds.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { @@ -38,6 +39,10 @@ public: // Bounding box parameters virtual const RectangleBounds& boundingBox() const = 0; + + virtual + variant_data + toVariantData() const = 0; }; } // end of namespace diff --git a/Core/include/ACTS/Surfaces/PlaneSurface.hpp b/Core/include/ACTS/Surfaces/PlaneSurface.hpp index c45d2fe80d6b61f8f2c4c35f7ee8e1743c044a47..826fc951d65c3948e5e03f53a2e129fd81c14112 100644 --- a/Core/include/ACTS/Surfaces/PlaneSurface.hpp +++ b/Core/include/ACTS/Surfaces/PlaneSurface.hpp @@ -19,6 +19,7 @@ #include "ACTS/Surfaces/Surface.hpp" #include "ACTS/Utilities/Definitions.hpp" #include "ACTS/Utilities/Identifier.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { @@ -73,6 +74,8 @@ public: PlaneSurface(std::shared_ptr<const Transform3D> htrans, std::shared_ptr<const PlanarBounds> pbounds = nullptr); + PlaneSurface(const variant_data &data); + virtual ~PlaneSurface(); /// Assignment operator @@ -204,6 +207,9 @@ public: virtual std::string name() const override; + variant_data + toVariantData() const; + protected: /// the bounds of this surface std::shared_ptr<const PlanarBounds> m_bounds; diff --git a/Core/include/ACTS/Surfaces/RectangleBounds.hpp b/Core/include/ACTS/Surfaces/RectangleBounds.hpp index c6ef1fa91b32cd928ad95bc515f978fe64ada532..ddbb414705a677703becd989e3ea20be83c1cf02 100644 --- a/Core/include/ACTS/Surfaces/RectangleBounds.hpp +++ b/Core/include/ACTS/Surfaces/RectangleBounds.hpp @@ -15,9 +15,11 @@ #include "ACTS/Surfaces/PlanarBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { + /// @class RectangleBounds /// /// Bounds for a rectangular, planar surface. @@ -92,6 +94,9 @@ public: /// Return method for the half length in Y double halflengthY() const; + + variant_data + toVariantData() const override; private: double m_halfX, m_halfY; diff --git a/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp b/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp index 386d6973617628219159ff868d01d7c811270b7b..5afd0279792043867f6da673f85f73ec1d90818b 100644 --- a/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp +++ b/Core/include/ACTS/Surfaces/TrapezoidBounds.hpp @@ -19,6 +19,7 @@ #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" #include "ACTS/Utilities/ParameterDefinitions.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { @@ -145,6 +146,9 @@ public: /// (second coordinate of local surface frame) double halflengthY() const; + + variant_data + toVariantData() const override; private: double m_minHalfX; diff --git a/Core/include/ACTS/Surfaces/TriangleBounds.hpp b/Core/include/ACTS/Surfaces/TriangleBounds.hpp index 7f56eefd7352e0d98ed5778581bd7dc552d140ee..d86f299131686bbe4e0e4676220cb8cbee740ebf 100644 --- a/Core/include/ACTS/Surfaces/TriangleBounds.hpp +++ b/Core/include/ACTS/Surfaces/TriangleBounds.hpp @@ -14,11 +14,13 @@ #define ACTS_SURFACESTRIANGLEBOUNDS_H #include <utility> +#include <array> #include "ACTS/Surfaces/PlanarBounds.hpp" #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" #include "ACTS/Utilities/ParameterDefinitions.hpp" +#include "ACTS/Utilities/VariantDataFwd.hpp" namespace Acts { @@ -47,7 +49,7 @@ public: /// Constructor with coordinates of vertices /// /// @param vertices is the vector of vertices - TriangleBounds(const std::vector<Vector2D>& vertices); + TriangleBounds(const std::array<Vector2D, 3>& vertices); virtual ~TriangleBounds(); @@ -90,9 +92,12 @@ public: /// @param sl is the ostream to be dumped into virtual std::ostream& dump(std::ostream& sl) const final override; + + variant_data + toVariantData() const override; private: - Vector2D m_vertices[3]; + std::array<Vector2D, 3> m_vertices; RectangleBounds m_boundingBox; ///< internal bounding box cache }; diff --git a/Core/src/Surfaces/DiamondBounds.cpp b/Core/src/Surfaces/DiamondBounds.cpp index 51bf5206fedba2288497ec5dacd457915522c0af..9924c841ad3149bb6f542c8156a7fe5fd3467cfb 100644 --- a/Core/src/Surfaces/DiamondBounds.cpp +++ b/Core/src/Surfaces/DiamondBounds.cpp @@ -12,6 +12,7 @@ #include "ACTS/Surfaces/DiamondBounds.hpp" #include "ACTS/Utilities/ThrowAssert.hpp" +#include "ACTS/Utilities/VariantData.hpp" #include <cmath> #include <iomanip> @@ -107,3 +108,21 @@ Acts::DiamondBounds::dump(std::ostream& sl) const sl << std::setprecision(-1); return sl; } + +Acts::variant_data +Acts::DiamondBounds::toVariantData() const { + using namespace std::string_literals; + + variant_map payload; + payload["minHalfX"] = m_minHalfX; + payload["medHalfX"] = m_medHalfX; + payload["maxHalfX"] = m_maxHalfX; + payload["minY"] = m_minY; + payload["maxY"] = m_maxY; + + variant_map data; + data["type"] = "DiamondBounds"; + data["payload"] = payload; + + return data; +} diff --git a/Core/src/Surfaces/EllipseBounds.cpp b/Core/src/Surfaces/EllipseBounds.cpp index 0efee35fb43a73582615d0177c381d9ec274c197..ab8d7d9b3ad2375ea7ced9c24c52a62498b75938 100644 --- a/Core/src/Surfaces/EllipseBounds.cpp +++ b/Core/src/Surfaces/EllipseBounds.cpp @@ -17,6 +17,7 @@ #include <iostream> #include "ACTS/Utilities/detail/periodic.hpp" +#include "ACTS/Utilities/VariantData.hpp" Acts::EllipseBounds::EllipseBounds(double minRadius0, double minRadius1, @@ -180,3 +181,23 @@ Acts::EllipseBounds::dump(std::ostream& sl) const sl << std::setprecision(-1); return sl; } + +Acts::variant_data +Acts::EllipseBounds::toVariantData() const { + using namespace std::string_literals; + + variant_map payload; + payload["rMinX"] = m_rMinX; + payload["rMinY"] = m_rMinY; + payload["rMaxX"] = m_rMaxX; + payload["rMaxY"] = m_rMaxY; + payload["avgPhi"] = m_avgPhi; + payload["halfPhi"] = m_halfPhi; + + variant_map data; + data["type"] = "EllipseBounds"s; + data["payload"] = payload; + + return data; + +} diff --git a/Core/src/Surfaces/PlaneSurface.cpp b/Core/src/Surfaces/PlaneSurface.cpp index c0f398c11c0bb9deef19bbd43433b98cec113973..e0910140f1c003b1fc218a7c2e999138701c250a 100644 --- a/Core/src/Surfaces/PlaneSurface.cpp +++ b/Core/src/Surfaces/PlaneSurface.cpp @@ -19,6 +19,7 @@ #include "ACTS/Surfaces/InfiniteBounds.hpp" #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Identifier.hpp" +#include "ACTS/Utilities/VariantData.hpp" #include "ACTS/Utilities/ThrowAssert.hpp" Acts::PlaneSurface::PlaneSurface(const PlaneSurface& other) @@ -70,10 +71,19 @@ Acts::PlaneSurface::PlaneSurface(std::shared_ptr<const Transform3D> htrans, { } -Acts::PlaneSurface::~PlaneSurface() +Acts::PlaneSurface::PlaneSurface(const variant_data& data_) { + // we need to figure out which way the PS was constructed before + throw_assert(data_.which() == 5, "Variant data must be map"); + variant_map data = boost::get<variant_map>(data_); + throw_assert(data.count("type") && data["type"] == "PlaneSurface", + "Variant data must have type and type must be PlaneSurface"); + + std::cout << "go unpack" << std::endl; } +Acts::PlaneSurface::~PlaneSurface() {} + Acts::PlaneSurface& Acts::PlaneSurface::operator=(const PlaneSurface& other) { @@ -167,3 +177,19 @@ Acts::PlaneSurface::pathCorrection(const Acts::Vector3D&, /// we can ignore the global position here return 1. / std::abs(normal().dot(mom.unit())); } + +Acts::variant_data +Acts::PlaneSurface::toVariantData() const +{ + using namespace std::string_literals; + variant_map payload; + + variant_data bounds = m_bounds->toVariantData(); + payload["bounds"] = bounds; + + variant_map data; + data["type"] = "PlaneSurface"s; + data["payload"] = payload; + + return data; +} diff --git a/Core/src/Surfaces/RectangleBounds.cpp b/Core/src/Surfaces/RectangleBounds.cpp index cb0772ca923313d6650abfb20156c6b5a6c4a403..eb25fdd13921aab84812bfa8a67b22ccb852357b 100644 --- a/Core/src/Surfaces/RectangleBounds.cpp +++ b/Core/src/Surfaces/RectangleBounds.cpp @@ -11,6 +11,7 @@ /////////////////////////////////////////////////////////////////// #include "ACTS/Surfaces/RectangleBounds.hpp" +#include "ACTS/Utilities/VariantData.hpp" #include <cmath> #include <iomanip> @@ -71,6 +72,8 @@ Acts::RectangleBounds::boundingBox() const return (*this); } + + // ostream operator overload std::ostream& Acts::RectangleBounds::dump(std::ostream& sl) const @@ -82,3 +85,21 @@ Acts::RectangleBounds::dump(std::ostream& sl) const sl << std::setprecision(-1); return sl; } + +Acts::variant_data +Acts::RectangleBounds::toVariantData() const +{ + using namespace std::string_literals; + + variant_map payload; + payload["halflengthX"] = m_halfX; + payload["halflengthY"] = m_halfY; + + variant_map data({ + {"type", "RectangleBounds"s}, + {"payload", payload} + }); + + + return data; +} diff --git a/Core/src/Surfaces/TrapezoidBounds.cpp b/Core/src/Surfaces/TrapezoidBounds.cpp index df37e3a26a4801d79cfd3e827790d3c1b5e66523..29ee93c66ef65c0222c1595abf0b309fd2d98af6 100644 --- a/Core/src/Surfaces/TrapezoidBounds.cpp +++ b/Core/src/Surfaces/TrapezoidBounds.cpp @@ -15,6 +15,7 @@ #include <cmath> #include <iomanip> #include <iostream> +#include "ACTS/Utilities/VariantData.hpp" Acts::TrapezoidBounds::TrapezoidBounds(double minhalex, double maxhalex, @@ -92,3 +93,19 @@ Acts::TrapezoidBounds::dump(std::ostream& sl) const sl << std::setprecision(-1); return sl; } + +Acts::variant_data +Acts::TrapezoidBounds::toVariantData() const { + using namespace std::string_literals; + + variant_map payload; + payload["minHalfX"] = m_minHalfX; + payload["maxHalfX"] = m_maxHalfX; + payload["halfY"] = m_halfY; + + variant_map data; + data["type"] = "TrapezoidBounds"; + data["payload"] = payload; + + return data; +} diff --git a/Core/src/Surfaces/TriangleBounds.cpp b/Core/src/Surfaces/TriangleBounds.cpp index 1ca061c38a2997fca1abedb36c46e445ef1028c7..c705def380a3d495324d17caf3963ef4924cbcaf 100644 --- a/Core/src/Surfaces/TriangleBounds.cpp +++ b/Core/src/Surfaces/TriangleBounds.cpp @@ -11,12 +11,13 @@ /////////////////////////////////////////////////////////////////// #include "ACTS/Surfaces/TriangleBounds.hpp" +#include "ACTS/Utilities/VariantData.hpp" #include <iomanip> #include <iostream> -Acts::TriangleBounds::TriangleBounds(const std::vector<Vector2D>& vertices) - : m_vertices{vertices[0], vertices[1], vertices[2]}, m_boundingBox(0, 0) +Acts::TriangleBounds::TriangleBounds(const std::array<Vector2D, 3>& vertices) + : m_vertices(vertices), m_boundingBox(0, 0) { double mx = 0; double my = 0; @@ -94,3 +95,22 @@ Acts::TriangleBounds::dump(std::ostream& sl) const sl << std::setprecision(-1); return sl; } + +Acts::variant_data +Acts::TriangleBounds::toVariantData() const { + using namespace std::string_literals; + + variant_map payload; + + variant_vector vertices; + for(const auto &vtx : m_vertices) { + vertices.push_back(to_variant(vtx)); + } + + variant_map data; + data["type"] = "TriangleBounds"s; + data["payload"] = variant_map({{"vertices", vertices}}); + + return data; + +} diff --git a/Tests/Surfaces/PlaneSurfaceTests.cpp b/Tests/Surfaces/PlaneSurfaceTests.cpp index 1147fcff6d85d86cde8998eefb12d69600337d57..d1effa22e0da8819c3b9a2de322a25fdf0309e91 100644 --- a/Tests/Surfaces/PlaneSurfaceTests.cpp +++ b/Tests/Surfaces/PlaneSurfaceTests.cpp @@ -20,8 +20,10 @@ #include <limits> #include "ACTS/Surfaces/PlaneSurface.hpp" #include "ACTS/Surfaces/RectangleBounds.hpp" +#include "ACTS/Surfaces/TriangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" #include "DetectorElementStub.hpp" +#include "ACTS/Utilities/VariantData.hpp" namespace tt = boost::test_tools; using boost::test_tools::output_test_stream; @@ -193,6 +195,29 @@ namespace Test { /// Test equality of assigned to original BOOST_TEST(assignedPlaneSurface == PlaneSurfaceObject); } + + BOOST_AUTO_TEST_CASE(PlaneSurface_Serialization) + { + // build + auto rectBounds = std::make_shared<const RectangleBounds>(5, 10); + auto idTrf = std::make_shared<const Transform3D>(Transform3D::Identity()); + PlaneSurface rectSrf(idTrf, rectBounds); + variant_data rectVariant = rectSrf.toVariantData(); + std::cout << rectVariant << std::endl; + + // rebuild from variant + PlaneSurface rectSrfRec(rectVariant); + + + std::array<Vector2D, 3> vertices = {{Vector2D(1,1), Vector2D(1, -1), Vector2D(-1, 1)}}; + auto triangleBounds = std::make_shared<const TriangleBounds>(vertices); + PlaneSurface triangleSrf(idTrf, triangleBounds); + variant_data triangleVariant = triangleSrf.toVariantData(); + std::cout << triangleVariant << std::endl; + + } + + BOOST_AUTO_TEST_SUITE_END() } // end of namespace Test diff --git a/Tests/Surfaces/RectangleBoundsTests.cpp b/Tests/Surfaces/RectangleBoundsTests.cpp index 7e10ad49d465580ef5786968d4b68b353ca3023c..f805d3b4af090107a87e9acd095e89187264063d 100644 --- a/Tests/Surfaces/RectangleBoundsTests.cpp +++ b/Tests/Surfaces/RectangleBoundsTests.cpp @@ -21,6 +21,7 @@ #include <limits> #include "ACTS/Surfaces/RectangleBounds.hpp" #include "ACTS/Utilities/Definitions.hpp" +#include "ACTS/Utilities/VariantData.hpp" namespace utf = boost::unit_test; const double inf = std::numeric_limits<double>::infinity(); @@ -121,6 +122,14 @@ namespace Test { BOOST_TEST(originalVertices == clonedVertices); delete rectB; } + + BOOST_AUTO_TEST_CASE(RectangleBounds_toVariantData) { + RectangleBounds rect(10, 10); + variant_data var_rect = rect.toVariantData(); + + std::cout << var_rect << std::endl; + } + BOOST_AUTO_TEST_SUITE_END() } // end of namespace Test diff --git a/Tests/Surfaces/TriangleBoundsTests.cpp b/Tests/Surfaces/TriangleBoundsTests.cpp index dfe5bc338459823ddaedb4d376ddb5faa56ddd5f..7d39c492432e81a01fb3c2a0984e5c98ec5ce3c2 100644 --- a/Tests/Surfaces/TriangleBoundsTests.cpp +++ b/Tests/Surfaces/TriangleBoundsTests.cpp @@ -23,7 +23,7 @@ #include "ACTS/Utilities/Definitions.hpp" namespace utf = boost::unit_test; -const double NaN = std::numeric_limits<double>::quiet_NaN(); +//const double NaN = std::numeric_limits<double>::quiet_NaN(); namespace Acts { @@ -32,8 +32,7 @@ namespace Test { /// Unit test for creating compliant/non-compliant TriangleBounds object BOOST_AUTO_TEST_CASE(TriangleBoundsConstruction) { - std::vector<Vector2D> vertices{ - {1., 1.}, {4., 1.}, {4., 5.}}; // 3-4-5 triangle + std::array<Vector2D, 3> vertices({{Vector2D(1., 1.), Vector2D(4., 1.), Vector2D(4., 5.)}}); // 3-4-5 triangle // test default construction // TriangleBounds defaultConstructedTriangleBounds; //deleted // @@ -47,10 +46,10 @@ namespace Test { } /// Unit tests for TriangleBounds properties - BOOST_AUTO_TEST_CASE(TriangleBoundsProperties, *utf::expected_failures(2)) + BOOST_AUTO_TEST_CASE(TriangleBoundsProperties) { - std::vector<Vector2D> vertices{ - {1., 1.}, {4., 1.}, {4., 5.}}; // 3-4-5 triangle + std::array<Vector2D, 3> vertices({{ + Vector2D(1., 1.), Vector2D(4., 1.), Vector2D(4., 5.)}}); // 3-4-5 triangle /// Test clone TriangleBounds triangleBoundsObject(vertices); auto pClonedTriangleBounds = triangleBoundsObject.clone(); @@ -69,15 +68,16 @@ namespace Test { BOOST_TEST(triangleBoundsObject.distanceToBoundary(outside) == 26.); // ok // /// Test vertices : fail; there are in fact 6 vertices (10.03.2017) - std::vector<Vector2D> expectedVertices(vertices); + std::array<Vector2D, 3> expectedVertices = vertices; BOOST_TEST_MESSAGE( "Following two tests fail because the triangle has six vertices"); BOOST_TEST(triangleBoundsObject.vertices().size() == (size_t)3); - BOOST_TEST(triangleBoundsObject.vertices() == expectedVertices); - // for (auto i: triangleBoundsObject.vertices()){ - // std::cout<<i[0]<<", "<<i[1]<<std::endl; - //} - // + for(size_t i=0;i<3;i++) { + Vector2D act = triangleBoundsObject.vertices().at(i); + Vector2D exp = expectedVertices.at(i); + BOOST_CHECK_CLOSE(act[0], exp[0], 1e-6); + BOOST_CHECK_CLOSE(act[1], exp[1], 1e-6); + } /// Test boundingBox NOTE: Bounding box too big BOOST_TEST(triangleBoundsObject.boundingBox() == RectangleBounds(4., 5.)); // @@ -100,9 +100,9 @@ namespace Test { /// Unit test for testing TriangleBounds assignment BOOST_AUTO_TEST_CASE(TriangleBoundsAssignment) { - std::vector<Vector2D> vertices{ - {1., 1.}, {4., 1.}, {4., 5.}}; // 3-4-5 triangle - std::vector<Vector2D> invalid{{NaN, NaN}, {NaN, NaN}, {NaN, NaN}}; + std::array<Vector2D, 3> vertices({{ + Vector2D(1., 1.), Vector2D(4., 1.), Vector2D(4., 5)}}); // 3-4-5 triangle + std::array<Vector2D, 3> invalid({{Vector2D(-1, -1), Vector2D(-1, -1), Vector2D(-1, -1)}}); TriangleBounds triangleBoundsObject(vertices); // operator == not implemented in this class // @@ -110,7 +110,7 @@ namespace Test { TriangleBounds assignedTriangleBoundsObject( invalid); // invalid object, in some sense assignedTriangleBoundsObject = triangleBoundsObject; - BOOST_TEST(assignedTriangleBoundsObject == triangleBoundsObject); + BOOST_TEST(assignedTriangleBoundsObject.vertices() == triangleBoundsObject.vertices()); } BOOST_AUTO_TEST_SUITE_END()