Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:23

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 <algorithm>
0012 
0013 #include <pybind11/pybind11.h>
0014 
0015 namespace ActsPython {
0016 
0017 struct Context {
0018   std::unordered_map<std::string, pybind11::module_> modules;
0019 
0020   pybind11::module_& get(const std::string& name) { return modules.at(name); }
0021 
0022   template <typename... Args>
0023   auto get(Args&&... args)
0024     requires(sizeof...(Args) >= 2)
0025   {
0026     return std::make_tuple((modules.at(args))...);
0027   }
0028 };
0029 
0030 /// This method calls the acts adapter to patch the classes with a config object
0031 ///
0032 /// @param m the module to patch
0033 inline void patchClassesWithConfig(pybind11::module_& m) {
0034   pybind11::module::import("acts._adapter").attr("_patch_config")(m);
0035 }
0036 
0037 /// @brief This method patches a class with kwargs arguments
0038 /// @tparam T the config or class object type
0039 /// @param c the config or class object to patch
0040 template <typename T>
0041 void patchKwargsConstructor(T& c) {
0042   pybind11::module::import("acts._adapter").attr("_patchKwargsConstructor")(c);
0043 }
0044 
0045 /// @brief  This sets a range property on a class
0046 template <typename T, typename Ur, typename Ut>
0047 void pythonRangeProperty(T& obj, const std::string& name, Ur Ut::*begin,
0048                          Ur Ut::*end) {
0049   obj.def_property(
0050       name.c_str(), [=](Ut& self) { return std::pair{self.*begin, self.*end}; },
0051       [=](Ut& self, std::pair<Ur, Ur> p) {
0052         self.*begin = p.first;
0053         self.*end = p.second;
0054       });
0055 }
0056 
0057 }  // namespace ActsPython