Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-26 09:25:00

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 #pragma once
0010 
0011 #include <type_traits>
0012 #include <utility>
0013 
0014 #include <pybind11/pybind11.h>
0015 
0016 /// Property-binding helpers shared by the track and track state proxy
0017 /// bindings (EventDataTracks.cpp, EventDataTrackStates.cpp).
0018 namespace ActsPython::EventDataHelpers {
0019 
0020 /// The plain Eigen type that `access(self)` evaluates to, e.g.
0021 /// `Eigen::Map<const Acts::BoundVector>::PlainObject` is `Acts::BoundVector`.
0022 template <typename Proxy, typename Access>
0023 using EigenValueT = typename std::decay_t<decltype(std::declval<Access>()(
0024     std::declval<const Proxy&>()))>::PlainObject;
0025 
0026 /// Bind a property whose accessor returns an Eigen::Map, always read-only
0027 /// (for accessors with no mutable overload, e.g. TrackStateProxy's "best
0028 /// available" parameters()/covariance()).
0029 template <typename Cls, typename Access>
0030 void bindEigenReadonly(Cls& cls, const char* name, Access access) {
0031   using Proxy = typename Cls::type;
0032   using Value = EigenValueT<Proxy, Access>;
0033   cls.def_property_readonly(
0034       name, [access](const Proxy& self) { return Value{access(self)}; });
0035 }
0036 
0037 /// Bind a property whose accessor returns an Eigen::Map, read-write when
0038 /// `!Proxy::ReadOnly`. `access` must be a generic lambda so the constness of
0039 /// `self` selects the const/mutable overload.
0040 template <typename Cls, typename Access>
0041 void bindEigen(Cls& cls, const char* name, Access access) {
0042   using Proxy = typename Cls::type;
0043   using Value = EigenValueT<Proxy, Access>;
0044   auto get = [access](const Proxy& self) { return Value{access(self)}; };
0045   if constexpr (Proxy::ReadOnly) {
0046     cls.def_property_readonly(name, get);
0047   } else {
0048     cls.def_property(
0049         name, get, [access](Proxy& self, const Value& v) { access(self) = v; });
0050   }
0051 }
0052 
0053 /// Bind a property for an accessor overloaded on const (by value) vs. mutable
0054 /// (by reference) with the same name, e.g. tipIndex, nMeasurements, chi2.
0055 /// Read-write when `!Proxy::ReadOnly`; see @ref bindEigen for `access`.
0056 template <typename Cls, typename Access>
0057 void bindScalar(Cls& cls, const char* name, Access access) {
0058   using Proxy = typename Cls::type;
0059   using T = std::decay_t<decltype(access(std::declval<const Proxy&>()))>;
0060   auto get = [access](const Proxy& self) -> T { return access(self); };
0061   if constexpr (Proxy::ReadOnly) {
0062     cls.def_property_readonly(name, get);
0063   } else {
0064     cls.def_property(name, get,
0065                      [access](Proxy& self, T v) { access(self) = v; });
0066   }
0067 }
0068 
0069 }  // namespace ActsPython::EventDataHelpers