|
| 1 | +// This file is part of the ACTS project. |
| 2 | +// |
| 3 | +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. |
| 8 | + |
| 9 | +#include "Acts/Geometry/GeometryModuleHelper.hpp" |
| 10 | + |
| 11 | +#include "Acts/Geometry/GeometryModule.h" |
| 12 | +#include "Acts/Geometry/TrackingGeometry.hpp" |
| 13 | +#include "Acts/Utilities/Logger.hpp" |
| 14 | + |
| 15 | +#include <exception> |
| 16 | +#include <memory> |
| 17 | + |
| 18 | +namespace Acts::detail { |
| 19 | + |
| 20 | +const ActsGeometryModuleV1* getGeometryModuleFromRaw( |
| 21 | + const char* module_abi_tag, const char* user_data_type, |
| 22 | + void* (*buildFunc)(const void*, const void*)) { |
| 23 | + static const ActsGeometryModuleV1 s_module = { |
| 24 | + .module_abi_tag = module_abi_tag, |
| 25 | + .user_data_type = user_data_type, |
| 26 | + .build = buildFunc, |
| 27 | + .destroy = |
| 28 | + [](void* handle) noexcept { |
| 29 | + if (handle == nullptr) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + delete static_cast<TrackingGeometry*>(handle); |
| 34 | + }, |
| 35 | + }; |
| 36 | + |
| 37 | + return &s_module; |
| 38 | +} |
| 39 | + |
| 40 | +const ActsGeometryModuleV1* getGeometryModule(const char* module_abi_tag, |
| 41 | + const char* user_data_type, |
| 42 | + BuildFunction buildFunc) { |
| 43 | + static BuildFunction s_buildFunc = buildFunc; |
| 44 | + |
| 45 | + return getGeometryModuleFromRaw( |
| 46 | + module_abi_tag, user_data_type, |
| 47 | + [](const void* /*userData*/, const void* loggerPtr) noexcept -> void* { |
| 48 | + if (loggerPtr == nullptr) { |
| 49 | + return nullptr; |
| 50 | + } |
| 51 | + const auto& logger = *static_cast<const Logger*>(loggerPtr); |
| 52 | + try { |
| 53 | + return s_buildFunc(logger).release(); |
| 54 | + } catch (const std::exception& e) { |
| 55 | + ACTS_ERROR("Failed to build geometry module: " << e.what()); |
| 56 | + return nullptr; |
| 57 | + } catch (...) { |
| 58 | + ACTS_ERROR("Failed to build geometry module"); |
| 59 | + return nullptr; |
| 60 | + } |
| 61 | + }); |
| 62 | +} |
| 63 | + |
| 64 | +} // namespace Acts::detail |
0 commit comments